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: add secure mount feature in cdh #345

Merged
merged 5 commits into from
Nov 21, 2023

Conversation

LindaYu17
Copy link
Contributor

No description provided.

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.

Thank you @LindaYu17 for the contribution! only some nits..

Comment on lines 1 to 21
{ "volume-type":"alibaba-cloud-oss",
"device":"/var/lib/kubelet/pods/xxxx-xxxx-xxxx-xxxx/volumes/kubernetes.io~csi/pv-oss-direct-assigned/mount",
"fstype":"oss",
"metadata":
{
"akId":"sealed.XXX",
"akSecret":"sealed.XXX",
"annotations":"",
"bucket":"oss",
"encrypted":"gocryptfs",
"encPasswd":"sealed.XXX",
"kmsKeyId":"",
"otherOpts":"-o max_stat_cache_size=0 -o allow_other",
"path":"/",
"readonly":"false",
"targetPath":"/var/lib/kubelet/pods/xxxx-xxxx-xxxx-xxxx/volumes/kubernetes.io~csi/pv-oss-direct-assigned/mount",
"url":"oss-cn-hangzhou.aliyuncs.com",
"volumeId":"pv-oss-direct-assigned"
},
"options":["-o","max_stat_cache_size=0","-o","allow_other"]
}
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 it is better to include this test json in the concrete implementation of fn secure_mount PR, or it would be confusing to other reviewers

@@ -18,10 +18,22 @@ message GetResourceResponse {
bytes Resource = 1;
}

message SecureMountRequest {
bytes mountInfo = 1;
Copy link
Member

Choose a reason for hiding this comment

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

so it is implied that the concrete mount type (s.t. driver type to be called) would be included inside the mountInfo? Thus do we have a common struct format of the parameter?

}

message SecureMountResponse {
bytes mountPath = 1;
Copy link
Member

Choose a reason for hiding this comment

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

only a little question: as path is a string, is it better to use a string rather than a bytes?

@@ -66,4 +66,8 @@ impl DataHub for Hub {
.map_err(|e| Error::GetResource(format!("get rersource failed: {e}")))?;
Ok(res)
}

async fn secure_mount(&self, mount_info: Vec<u8>) -> Result<Vec<u8>> {
todo!()
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to do this feature in multiple parts or should we wait for this to be implemented before merging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want to do this feature in multiple parts or should we wait for this to be implemented before merging?

the feature is still under development, and the patches will be submitted within this PR soon, so we can wait for them. Thank you @fitzthum

Copy link
Member

@fitzthum fitzthum Sep 13, 2023

Choose a reason for hiding this comment

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

You might want to make this PR into a draft for now btw

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the development is done now, and I will update based on the review comments.

@LindaYu17 LindaYu17 changed the title cdh/hub: add api for secure mount cdh: add secure mount feature in cdh Sep 15, 2023
@jepio
Copy link
Member

jepio commented Sep 15, 2023

Please don't add compiled binaries to the repository. If they are needed by this feature then you have to build them into the kata guest image in the kata-containers repo.

@fitzthum
Copy link
Member

Please don't add compiled binaries to the repository. If they are needed by this feature then you have to build them into the kata guest image in the kata-containers repo.

Also, depending on how large dependencies are (including for future storage options, we might need to think about whether we can really support a generic image.

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.

I know this isn't done yet, but I was looking through it and made a few comments.

.to_string();

match volumetype.as_str() {
"alibaba-cloud-oss" => {
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 have a feature to enable/disable particular storage vendors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

Copy link
Member

Choose a reason for hiding this comment

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

Can we just call ossfs and gocryptfs directly from Rust and get rid of this script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

need the oss account to do more test, and then I will update accordingly, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

call ossfs and gocryptfs from rust in latest commit, and the script is removed. Thanks

.arg("-o")
.arg(self.other_opts.clone())
.arg("-d")
.arg(source)
Copy link
Member

Choose a reason for hiding this comment

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

-d is the mountpoint according to the script. It's a bit confusing to me that it is set to the source here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mount.sh is removed.

@LindaYu17
Copy link
Contributor Author

Please don't add compiled binaries to the repository. If they are needed by this feature then you have to build them into the kata guest image in the kata-containers repo.

removed, thanks

Comment on lines 29 to 30
.ok_or(anyhow!("split by \"=\" failed"))
.map_err(|e| Error::SecureMountFailed(format!("split by \"=\" failed: {e}")))?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.ok_or(anyhow!("split by \"=\" failed"))
.map_err(|e| Error::SecureMountFailed(format!("split by \"=\" failed: {e}")))?;
.ok_or(Error::SecureMountFailed(format!("split by \"=\" failed)))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed ,thanks

Comment on lines 44 to 47
&_ => {
return Err(Error::SecureMountFailed(format!(
"illegal mount info with unsupported volumetype"
)))
Copy link
Member

Choose a reason for hiding this comment

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

We'd better mention what volume type is for better debugging

Suggested change
&_ => {
return Err(Error::SecureMountFailed(format!(
"illegal mount info with unsupported volumetype"
)))
other => {
return Err(Error::SecureMountFailed(format!(
"illegal mount info with unsupported volumetype: {other}"
)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

let res = storage
.mount()
.await
.map_err(|e| Error::SecureMount(format!("mount failed: {e}")))?;
Copy link
Member

Choose a reason for hiding this comment

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

duplicated error information

Suggested change
.map_err(|e| Error::SecureMount(format!("mount failed: {e}")))?;
.map_err(|e| Error::SecureMount(e.to_string())))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

confidential-data-hub/hub/src/api.rs Show resolved Hide resolved
#[derive(Error, Debug)]
pub enum Error {
#[error("secure mount failed: {0}")]
SecureMountFailed(String),
Copy link
Member

Choose a reason for hiding this comment

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

Nice to see that thiserror crate is used!

I suggest that we have some more fine grained error types. In fact SecureMountFailed applies all the errors returned from the crate.

The storage is somehow similiar with kms. I divided the errors by the plugin type here https://github.com/confidential-containers/guest-components/blob/main/confidential-data-hub/kms/src/error.rs and I know that is not perfect. Please think about this and refer to this in your preferred way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do some changes

.await;
}
other => {
println!("skip mount info with unsupported volumetype: {other}");
Copy link
Member

Choose a reason for hiding this comment

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

shall we use log here instead of println!? s.t. log::info! or log::debug!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

Copy link
Member

@bpradipt bpradipt left a comment

Choose a reason for hiding this comment

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

@LindaYu17 is there any description of the feature where I can read about the scope of secure mount, limitations etc. ?

@LindaYu17
Copy link
Contributor Author

@LindaYu17 is there any description of the feature where I can read about the scope of secure mount, limitations etc. ?
thank you @bpradipt for the review. I add some docs here, hope it will be helpful
8875291

Signed-off-by: Linda Yu <linda.yu@intel.com>
Signed-off-by: Linda Yu <linda.yu@intel.com>
@Xynnn007
Copy link
Member

LGTM

@Xynnn007
Copy link
Member

@fitzthum @jepio @bpradipt Can this pr be merged now?

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.

I think this is almost ready. I just added a few small comments.

impl Storage {
pub async fn mount(&self) -> Result<String> {
for driver_option in &self.driver_options {
let (volumetype, metadata) =
Copy link
Member

Choose a reason for hiding this comment

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

nit: volumetype -> volume_type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks.

}

message SecureMountResponse {
string mountPath = 1;
Copy link
Member

Choose a reason for hiding this comment

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

nit: mountPath -> mount_path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

confidential-data-hub/hub/protos/api.proto Show resolved Hide resolved
const OSSFS_PASSWD_FILE: &str = "/tmp/ossfs_passwd";
const GOCRYPTFS_PASSWD_FILE: &str = "/tmp/gocryptfs_passwd";
const OSSFS_BIN: &str = "/usr/local/bin/ossfs";
const GOCRYPTFS_BIN: &str = "/usr/local/bin/gocryptfs";
Copy link
Member

Choose a reason for hiding this comment

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

I assume there will be changes in Kata to install these in the rootfs? Are we going to add them to every rootfs or just certain runtime classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add the tools to rootfs image like this:
kata-containers/kata-containers@066e042

Ok(res)
}

async fn get_plain(secret: &str) -> 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.

Can this function name be a little more descriptive, like get_plaintext_secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks.

Signed-off-by: Linda Yu <linda.yu@intel.com>
Signed-off-by: Linda Yu <linda.yu@intel.com>
Signed-off-by: Linda Yu <linda.yu@intel.com>
@bpradipt
Copy link
Member

@fitzthum @jepio @bpradipt Can this pr be merged now?

@Xynnn007 @LindaYu17 I don't have the expertise to review this code. Although I wanted to have a document describing the details which @LindaYu17 kindly added. So I'm good with it. Thanks.

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. Thanks @LindaYu17

I think the test failure can be fixed by a rebase.

Copy link
Member

@arronwy arronwy left a comment

Choose a reason for hiding this comment

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

Thanks @LindaYu17 LGTM!

@arronwy arronwy merged commit 119feca into confidential-containers:main Nov 21, 2023
4 of 5 checks passed
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.

6 participants