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

cdh: support to encrypt block device #617

Merged
merged 3 commits into from
Jul 22, 2024

Conversation

ChengyuZhu6
Copy link
Member

Support to encrypt block device in cdh.

Fixed: #540 -- part II

Copy link
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

Nice PR! We could image that storage of CoCo could be handled in near future

confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
pub(crate) struct Rbd;

async fn random_encrypt_key() -> anyhow::Result<String> {
let storage_key_path = "/tmp/random_encrypt_rbd.key";
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 support multiple multiple encrypted rbd mounts? If so, do we need different keys?

confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
@zvonkok
Copy link
Member

zvonkok commented Jul 17, 2024

Can we make sure we have proper documentation about this feature? Issues, PRs and discussions are easily consumed by developers, end users need a concise way of consuming such cool features without digging through github.

@ChengyuZhu6
Copy link
Member Author

Can we make sure we have proper documentation about this feature? Issues, PRs and discussions are easily consumed by developers, end users need a concise way of consuming such cool features without digging through github.

Of course we should have a good document about it!

Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

Looks good. A few comments.

Might be nice to come up with some kind of test.

confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
confidential-data-hub/storage/src/volume_type/rbd/mod.rs Outdated Show resolved Hide resolved
Ok(base64::engine::general_purpose::STANDARD.encode(&buffer))
}

async fn get_plaintext_secret(secret: &str) -> anyhow::Result<String> {
Copy link
Member

Choose a reason for hiding this comment

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

I think I was expecting the encryption key to be a resource uri. Maybe having it be a sealed secret is better because that contains info about the KBS/HSM, integrity protection, etc., but so far we haven't used a sealed secret this way in any other parts of the CDH. Are we planning to adopt sealed secret format as a general wrapper around a resource uri?

cc: @Xynnn007

Copy link
Member

@Xynnn007 Xynnn007 Jul 18, 2024

Choose a reason for hiding this comment

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

I think they are for different scenarios. Given that we now support both KMS as a KBS backend (use KBS URI to index a key) and KMS as a CDH plugin (use Sealed Secret to index a key), we might need to support both. We can add a condition judgement here, if with kbs:// prefix, use

new_getter("kbs", ProviderSettings::default()).await?.get_secret(&secret, &Annotations::default())

if with sealed. prefix, use

secret::unseal_secret(secret.as_bytes()).await?

else, raise an error saying that illegal keyid format.

Thus we could support both inside CDH code. The consequence is both deploy model / solution could be used and the user does need to worry about underlying logic.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I think supporting both makes sense. Each scheme has some pros/cons. I wonder if we should do something similar for other features.

let rbd_parameter: RbdParameters = serde_json::from_str(&parameters)?;

if rbd_parameter.encrypt_type == RbdEncryptType::LUKS {
let storage_key_path = create_storage_key_file(&rbd_parameter).await?;
Copy link
Member

Choose a reason for hiding this comment

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

should we delete this file at some point?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be removed in the binary luks-encrypt-storage

@@ -61,6 +62,12 @@ impl Storage {
.await?;
Ok(self.mount_point.clone())
}
Volume::Rbd => {
Copy link
Member

Choose a reason for hiding this comment

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

Rbd = rados block device? I don't see anything in this PR that is specific to RBD. Maybe this should just be called Volume::Luks or Volume::Encrypted in case we support gocryptfs in the future.

It's also interesting to note that a number of storage implementations might share the same encryption scheme but have different ways to mount the volume. I wonder if at some point we should refactor the storage design to have two phases (setup device and decrypt volume) so that some of the code could be shared. In this case we aren't doing anything to setup the device so we can probably worry about it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I mean RBD = raw block device. To avoid any ambiguity, we may consider coming up with a better name.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add some document for this. I think the RBD plugin here would mean "given a raw block device, mount it to the target path and decrypt it with given/ephemeral key".

The initial code does not care about the device setup. This also raises some open question. If CDH cares about the setup of the device, how to ensure the availability? I am not sure how kata now handles volumes if volumes are broken during runtime. Maybe we can learn something from kata.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe spell it out as RawBlockDevice or just call it something else to avoid confusion.

Provisioning the device can involve operations by the kata agent (i.e. mounting something from the host) and/or operations by the CDH (i.e. pulling data from cloud storage). In the first case (this PR) I think we basically have to assume that the kata agent (or more generally the caller of the CDH) has set things up correctly.

When we start implementing more sophisticated storage backends maybe it will make sense to make things a little bit more modular.

@ChengyuZhu6 ChengyuZhu6 force-pushed the encrypt-device branch 17 times, most recently from a0b9eac to f35dc71 Compare July 18, 2024 04:41
@ChengyuZhu6 ChengyuZhu6 force-pushed the encrypt-device branch 6 times, most recently from 6978b62 to d25571a Compare July 18, 2024 06:13
Copy link
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

Nice, some nits.

@ChengyuZhu6 ChengyuZhu6 force-pushed the encrypt-device branch 3 times, most recently from f5eea20 to d96113f Compare July 19, 2024 05:40
@ChengyuZhu6 ChengyuZhu6 marked this pull request as ready for review July 19, 2024 05:40
@ChengyuZhu6 ChengyuZhu6 requested a review from sameo as a code owner July 19, 2024 05:40
Copy link
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

Nice. Only last questions

Comment on lines 78 to 81
A[Block Device] -- mount --> B[Block Device]
subgraph TEE Guest
B -- encrypt by cryptsetup --> C[LUKS Block Device]
C -- mount --> D[Target Path]
Copy link
Member

Choose a reason for hiding this comment

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

Could we mark which devices are encrypted, and which are plaintext?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


2. Install `luks-encrypt-storage`

Install [luks-encrypt-storage](../../storage/scripts/luks-encrypt-storage) into `/usr/local/bin`
Copy link
Member

Choose a reason for hiding this comment

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

As a separate service, CDH could require install extra things. I am thinking about whether we can integrate the installations of luks-encrypt-storage, cachefs and ossfs binaries/scripts in CDH's Makefile. In CCv0, we explicit install them in kata scripts. This would bring extra maintaining cost for kata. cc @fitzthum @fidencio

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that we can move the tasks of installing binaries or scripts to CDH, as they are only used in the CDH. CDH is responsible for installing them, and we can simplify the code in kata.

@ChengyuZhu6 ChengyuZhu6 force-pushed the encrypt-device branch 2 times, most recently from 7509271 to 7f9554d Compare July 19, 2024 07:00
Copy link
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM

I'm not sure exactly the best way to handle dependencies like the script. Maybe it would be ideal if we converted that to rust at some point. For now you can probably find some way to get it into the rootfs.

pub(crate) struct BlockDevice;

#[async_trait]
pub trait Encryptor {
Copy link
Member

Choose a reason for hiding this comment

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

should this be encryptor or decryptor?

Copy link
Member Author

Choose a reason for hiding this comment

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

For trusted storage, this should be encryptor. The guest will need to follow three steps: encrypt the block device from the host as a LUKS-encrypted block device, open the encrypted device with the key, and mount it. However, for secure storage, the guest will only need to perform the latter two steps. Overall, I think encryptor or decryptor are not suitable names for it. Therefore, I have renamed it to Interpreter.

@ChengyuZhu6
Copy link
Member Author

@zvonkok Does the documentation make sense to you? Is there anything else that needs to be added or clarified?

@ChengyuZhu6
Copy link
Member Author

I'm not sure exactly the best way to handle dependencies like the script. Maybe it would be ideal if we converted that to rust at some point. For now you can probably find some way to get it into the rootfs.

Sounds like a good idea for the future. I’ll keep that in mind and we can revisit it later.

@ChengyuZhu6 ChengyuZhu6 force-pushed the encrypt-device branch 2 times, most recently from 3b0a06f to 5178802 Compare July 20, 2024 09:16
ChengyuZhu6 added 3 commits July 20, 2024 17:34
Add secure mount interface for block device.

Fixed: confidential-containers#540 -- part II

Signed-off-by: ChengyuZhu6 <[email protected]>
Mount block device encrypted by LUKS.

Signed-off-by: ChengyuZhu6 <[email protected]>
add document for secure mount with block devices.

Signed-off-by: ChengyuZhu6 <[email protected]>
@Xynnn007 Xynnn007 merged commit a43a325 into confidential-containers:main Jul 22, 2024
5 checks passed
@ChengyuZhu6 ChengyuZhu6 deleted the encrypt-device branch July 22, 2024 01:11
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.

CDH | EncryptedDirectMount plugin for SecureMount
4 participants