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

Support LUKS keys for cold migrations from vSphere #676

Merged
merged 7 commits into from
Jun 9, 2024

Conversation

liranr23
Copy link
Member

@liranr23 liranr23 commented Dec 7, 2023

Add LUKS key to the vm
This patch adds the LUKS keys to the VM specs using a secret ref. It
expected to have list of strings. Each value will use the all selector
option based on virt-v2v docs
(https://www.libguestfs.org/virt-v2v.1.html).

The secret should be provided in the destination namespace, the key
should be luks and the values should be the arguments provided to
virt-v2v, such as:

passphrase1
passphrase2
...

Fixes #567

@liranr23 liranr23 force-pushed the luks branch 3 times, most recently from 2b6d825 to a6ef6ee Compare December 10, 2023 09:06
@ahadas
Copy link
Member

ahadas commented Dec 10, 2023

The secret should be provided in the destination namespace, the key should be luks and the values should be the arguments provided to virt-v2v, such as:

UUID:key:passphrase
UUID:clevis
DEVICE_NAME:key:passphrase

I see that it's already in progress, doesn't it make more sense to wait for it?

Copy link
Member

@ahadas ahadas left a comment

Choose a reason for hiding this comment

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

nice, looks good overall

virt-v2v/cold/entrypoint Outdated Show resolved Hide resolved
if [ -d "/etc/luks" ]; then
IFS=$'\n'
for line in $(cat /etc/luks/luks); do
args+=(--key "$line")
Copy link
Member

@ahadas ahadas Dec 10, 2023

Choose a reason for hiding this comment

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

as I commented at the top-level, I think we can wait to get the all option because otherwise, users would have to specify the name or the UIID of the device that may be different for different VMs in the plan (we can find the device UID probably, not sure about OVAs though, but as the all option is just around the corner...)

Copy link
Member

@ahadas ahadas Jan 3, 2024

Choose a reason for hiding this comment

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

since a selector of all devices will probably not be available for forklift 2.6, we decided not to wait for it
but I talked with @dankenigsberg, and he raised a vaild point that users that provide such input may expect us to support key per-devices also when that selector would be available.
@liranr23 can we save the user from specifying the device IDs, as we're supposed to have them in the inventory, and ask only for the encryption keys from users?

pkg/apis/forklift/v1beta1/plan.go Outdated Show resolved Hide resolved
@ahadas
Copy link
Member

ahadas commented Dec 10, 2023

The secret should be provided in the destination namespace, the key should be luks and the values should be the arguments provided to virt-v2v, such as:

UUID:key:passphrase
UUID:clevis
DEVICE_NAME:key:passphrase

I see that it's already in progress, doesn't it make more sense to wait for it?

BTW, need to check if the support for LUKS exists in el8 but if we rely on the all option then we anyway need to limit this to the flows we use virt-v2v on el9 (hopefully, all cold migration flows in 2.6)

@liranr23
Copy link
Member Author

The secret should be provided in the destination namespace, the key should be luks and the values should be the arguments provided to virt-v2v, such as:

UUID:key:passphrase
UUID:clevis
DEVICE_NAME:key:passphrase

I see that it's already in progress, doesn't it make more sense to wait for it?

yeah we can.
in this PR we give the chance for the user to choose (from all options).
there is a clear performance benefit if the user specify the device. i thought it might be better to give him the option. once we consume the change of virt-v2v, he can set all:key:passphrase. currently, i am not sure if we will have fallback to clevis, that means, we can either "force" it on the virt-v2v command and the user won't need to specify it at all or, adding all:clevis as well.
Bottom line, it's "all options[and possible better performance]" versus easy usage of the user (specifying list of keys and that's all).

@liranr23
Copy link
Member Author

liranr23 commented Dec 10, 2023

BTW, need to check if the support for LUKS exists in el8 but if we rely on the all option then we anyway need to limit this to the flows we use virt-v2v on el9 (hopefully, all cold migration flows in 2.6)

it's not as written in the 3rd commit

@ahadas
Copy link
Member

ahadas commented Dec 10, 2023

The secret should be provided in the destination namespace, the key should be luks and the values should be the arguments provided to virt-v2v, such as:

UUID:key:passphrase
UUID:clevis
DEVICE_NAME:key:passphrase

I see that it's already in progress, doesn't it make more sense to wait for it?

yeah we can. in this PR we give the chance for the user to choose (from all options). there is a clear performance benefit if the user specify the device. i thought it might be better to give him the option. once we consume the change of virt-v2v, he can set all:key:passphrase. currently, i am not sure if we will have fallback to clevis, that means, we can either "force" it on the virt-v2v command and the user won't need to specify it at all or, adding all:clevis as well. Bottom line, it's "all options[and possible better performance]" versus easy usage of the user (specifying list of keys and that's all).

if we like to consider the option of specifying devices, we need to see how to make it practical, especially in scale - specifying UUIDs/names is problematic, users would rather need to select disk(s) and a practical way...

@ahadas
Copy link
Member

ahadas commented Dec 10, 2023

BTW, need to check if the support for LUKS exists in el8 but if we rely on the all option then we anyway need to limit this to the flows we use virt-v2v on el9 (hopefully, all cold migration flows in 2.6)

it's not as written in the 3rd commit

ok, so need to add it to the plan admitter

@liranr23
Copy link
Member Author

liranr23 commented Dec 10, 2023

The secret should be provided in the destination namespace, the key should be luks and the values should be the arguments provided to virt-v2v, such as:

UUID:key:passphrase
UUID:clevis
DEVICE_NAME:key:passphrase

I see that it's already in progress, doesn't it make more sense to wait for it?

yeah we can. in this PR we give the chance for the user to choose (from all options). there is a clear performance benefit if the user specify the device. i thought it might be better to give him the option. once we consume the change of virt-v2v, he can set all:key:passphrase. currently, i am not sure if we will have fallback to clevis, that means, we can either "force" it on the virt-v2v command and the user won't need to specify it at all or, adding all:clevis as well. Bottom line, it's "all options[and possible better performance]" versus easy usage of the user (specifying list of keys and that's all).

if we like to consider the option of specifying devices, we need to see how to make it practical, especially in scale - specifying UUIDs/names is problematic, users would rather need to select disk(s) and a practical way...

OK, so we can wait for virt-v2v and change the commits + in the virt-v2v to handle it by adding all:key: prefix. Then the user will just provide keys in the secret.
We can also add --key all:clevis to support it as a fallback (in case virt-v2v won't do it).
This should be the simplest way to a user.

Copy link

sonarcloud bot commented Dec 10, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
7.1% 7.1% Duplication

@ahadas
Copy link
Member

ahadas commented Dec 24, 2023

the --key all:<selector> for LUKS was added in virt-v2v-2.3.7-1.el9 which is not yet available on centos9-stream

pkg/apis/forklift/v1beta1/plan.go Outdated Show resolved Hide resolved
pkg/controller/plan/kubevirt.go Outdated Show resolved Hide resolved
if [ -d "/etc/luks" ]; then
IFS=$'\n'
for line in $(cat /etc/luks/luks); do
args+=(--key "$line")
Copy link
Member

@ahadas ahadas Jan 3, 2024

Choose a reason for hiding this comment

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

since a selector of all devices will probably not be available for forklift 2.6, we decided not to wait for it
but I talked with @dankenigsberg, and he raised a vaild point that users that provide such input may expect us to support key per-devices also when that selector would be available.
@liranr23 can we save the user from specifying the device IDs, as we're supposed to have them in the inventory, and ask only for the encryption keys from users?

@ahadas ahadas changed the title Support LUKS keys when cold migrating from vsphere Support LUKS keys for cold migrations from vSphere Feb 15, 2024
@ahadas ahadas added this to the 2.6.1 milestone Apr 9, 2024
@ahadas ahadas removed this from the 2.6.1 milestone May 1, 2024
@liranr23 liranr23 force-pushed the luks branch 2 times, most recently from 8c3b642 to 1274d6e Compare May 23, 2024 12:29
Copy link
Member

@ahadas ahadas left a comment

Choose a reason for hiding this comment

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

to summarize an offline discussion about this - it would be better to switch back to passing the keys with a volume and ask virt-v2v to get it from the file, so that the keys won't be included in logs that are gathered from the cluster

@liranr23 liranr23 force-pushed the luks branch 2 times, most recently from e649f52 to 6afd76a Compare May 29, 2024 09:17
virt-v2v/cold/entrypoint.go Outdated Show resolved Hide resolved
virt-v2v/cold/entrypoint.go Outdated Show resolved Hide resolved
virt-v2v/cold/entrypoint.go Outdated Show resolved Hide resolved
virt-v2v/cold/entrypoint.go Outdated Show resolved Hide resolved
pkg/controller/plan/kubevirt.go Outdated Show resolved Hide resolved
pkg/controller/plan/kubevirt.go Outdated Show resolved Hide resolved
virt-v2v/cold/entrypoint.go Outdated Show resolved Hide resolved
Copy link
Member

@ahadas ahadas left a comment

Choose a reason for hiding this comment

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

I've made some cleanup, besides the comment inside it looks good

pkg/controller/plan/kubevirt.go Outdated Show resolved Hide resolved
liranr23 and others added 7 commits June 9, 2024 16:03
This patch adds the LUKS keys to the VM specs using a secret ref. It
expected to have list of strings. Each value will use the `all` selector
option based on virt-v2v docs
(https://www.libguestfs.org/virt-v2v.1.html).

The secret should be provided in the destination namespace, the key
should be `luks` and the values should be the arguments provided to
virt-v2v, such as:

```
passphrase1
passphrase2
...
```

Signed-off-by: Liran Rotenberg <[email protected]>
This patch will set the expected LUKS secret to virt-v2v pod as a volume
mounted to the virt-v2v container. This will later allow us to read the
secret and provide the arguments to the migration.

Signed-off-by: Liran Rotenberg <[email protected]>
This patch will read the given LUKS key provided to the container and
add them as arguments to the virt-v2v command. Since virt-v2v supports
this feature only since 2.2, it applies only for cold migrations.
It uses the `all` selector to each passphrase.

Signed-off-by: Liran Rotenberg <[email protected]>
When importing from vSphere or OVA and using EL8 virt-v2v (warm
migration), LUKS encryption is not supported.
In case the plan is set with LUKS secret, fail to validate such plan.

Signed-off-by: Liran Rotenberg <[email protected]>
Instead of the plan keep being running and the conversion pod try to
init, we can query and check the secret existence for LUKS keys before.
In the case it's doesn't exist, fail the migration properly. If it does
exist, post it on the target namespace for the conversion pod.

Signed-off-by: Liran Rotenberg <[email protected]>
Signed-off-by: Arik Hadas <[email protected]>
Signed-off-by: Arik Hadas <[email protected]>
Copy link

sonarcloud bot commented Jun 9, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
7.2% Duplication on New Code

See analysis details on SonarCloud

@ahadas ahadas merged commit 4b425e4 into kubev2v:main Jun 9, 2024
12 of 13 checks passed
@ahadas ahadas added this to the 2.6.3 milestone Jun 9, 2024
@liranr23 liranr23 deleted the luks branch June 9, 2024 13:26
@ahadas ahadas removed this from the 2.6.3 milestone Jun 9, 2024
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.

Migrate VMs with LUKS-encrypted disks from vSphere
3 participants