Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use a LUKS keys vault #65

Merged
merged 8 commits into from
Nov 13, 2019

Conversation

ghost
Copy link

@ghost ghost commented Nov 7, 2019

For customers that have LUKS encrypted devices, we need a way to pass the LUKS keys to virt-v2v. This PR implements it by allowing a luks_keys_vault key in the JSON input. Currently, the implementation is really basic and only accept a clear JSON file as vault. The expected JSON file structure is:

{
    "my_vm": [
        {
            "device": "/dev/sda1",
            "key": "0123456789abcdef"
        },
        {
            "device": "/dev/sda2",
            "key": "fedcba9876543210"
        }
    ]
}

With this format, we can have many virtual machines declared into a single file.
To reduce coupling with ManageIQ, there's a default path for the vault file, so that it only has to exist to be leveraged by virt-v2v-wrapper. In the future, ManageIQ may generate the vault file(s) and override that default value.

@ghost ghost requested a review from nyoxi November 7, 2019 11:54
@ovirt-infra
Copy link

Hello contributor, thanks for submitting a PR for this project!

I am the bot who triggers "standard-CI" builds for this project.
As a security measure, I will not run automated tests on PRs that are not from white-listed contributors.

In order to allow automated tests to run, please ask one of the project maintainers to review the code and then do one of the following:

  1. Type ci test please on this PR to trigger automated tests for it.
  2. Type ci add to whitelist on this PR to trigger automated tests for it and also add you to the contributor white-list so that your future PRs will be tested automatically. ( keep in mind this list might be overwritten if the job XML is refreshed, for permanent whitelisting, please follow Added support for network mappings #3 option )
  3. If you are planning to contribute to more than one project, maybe it's better to ask them to add you to the project organization, so you'll be able to run tests for all the organization's projects.

'device': '/dev/sda2',
'filename': '/tmp/luks/sda2',
}
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new dictionary with the LUKS specific lines. I.e. copy VDDK_RHV and extend it with the above lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it still be the case, now that I moved it to wrapper/tests/test_v2v_args.py ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pick this commit 745fe83. It will fix the tests.

wrapper/hosts.py Outdated
v2v_args.extend([
'--key',
'%s:file:%s' % (luks_key['device'], luks_key['filename'])
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should go to prepare_command() in virt_v2v_wrapper.py instead of into every host class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -62,6 +73,8 @@ def test_vddk_basic(self):
'-io', 'vddk-libdir=/opt/vmware-vix-disklib-distrib',
'-io', 'vddk-thumbprint=01:23:45:67:89:AB:CD:EA:DB:EE:F0:12:34:56:78:9A:BC:DE:F0:12', # NOQA E501
'--password-file', '/vmware/password',
'--key', '/dev/sda1:file:/tmp/luks/sda1',
'--key', '/dev/sda2:file:/tmp/luks/sda2',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create new test function for the LUKS related changes instead of reusing test_vddk_basic()

@@ -487,6 +487,21 @@ def main():
host.get_uid(),
host.get_gid())

if 'luks_keys_vault' not in data:
data['luks_keys_vault'] = '/tmp/v2v_luks_keys_vault.json'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a default? If yes, it may be worth using some other directory then /tmp, e.g. /etc or user's home directory. What do you think? Also what do you think about adding a check and refusing to load file that is readable/writable by someone else than owner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. Changed to use user's home directory and added checks on permissions.

@ghost
Copy link
Author

ghost commented Nov 8, 2019

@nyoxi the tests fail, but I don't know what's causing the errors. Could you look at it, please ?

@@ -748,7 +748,6 @@ def prepare_command(self, data, v2v_args, v2v_env, v2v_caps):
v2v_args.extend(['-oo', 'rhv-verifypeer=%s' %
('false' if data['insecure_connection'] else
'true')])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some leftover here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand. this line is already deleted.

'device': '/dev/sda2',
'filename': '/tmp/luks/sda2',
}
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pick this commit 745fe83. It will fix the tests.

if file_stat.st_uid != host.get_uid():
hard_error('LUKS keys vault does\'nt belong to'
'user running virt-v2v-wrapper')
if not bool(file_stat.st_mode & stat.S_IRWXO):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is ugly. I would prefer if file_stat.st_mode & stat.S_IRWXO > 0:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'user running virt-v2v-wrapper')
if not bool(file_stat.st_mode & stat.S_IRWXO):
hard_error('LUKS keys vault is accessible to others')
if not bool(file_stat.st_mode & stat.S_IRWXG):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nyoxi
Copy link
Member

nyoxi commented Nov 13, 2019

CI failure is unrelated

@nyoxi
Copy link
Member

nyoxi commented Nov 13, 2019

ci test please

@nyoxi nyoxi merged commit 86ba00e into oVirt:master Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants