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

Confidential DataHub Part 4: CDH binary & Attestation API for AA #322

Merged
merged 16 commits into from
Aug 23, 2023

Conversation

Xynnn007
Copy link
Member

@Xynnn007 Xynnn007 commented Aug 14, 2023

This PR is the last PR in v0.8.0 cycle for CDH & sealed secret. This PR

  • Added CDH binary
  • Added auth module for CDH binary. The auth module is to prepare necessary resources or environments for CDH
  • Added GetToken/GetEvidence API for AA
  • Hided the "kbc" abstraction and move it to a KMS plugin in CDH

This PR only added new features to current AA. It didn't delete any existed code.

Some TODOs after v0.8.0:

  • Attestation-Agent's code should be refactored to delete useless module and tidy the code structure. Only leave codes about get_token and get_evidence
  • Impl image decryption logic in CDH

cc @arronwy @LindaYu17 @Lu-Biao

see #296

KBCs are now impled as KMS drivers, also known as
`get_resource_provider` in CDH. To follow the forward compatibility,
`sev` is the same as previous `online_sev_kbc` and `kbs` is the same as
previous `cc_kbc`.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
@Xynnn007 Xynnn007 marked this pull request as draft August 15, 2023 06:48
@Xynnn007 Xynnn007 force-pushed the feat-cdh-binary branch 2 times, most recently from 5c5ac9e to 51de772 Compare August 15, 2023 09:33
@Xynnn007 Xynnn007 marked this pull request as ready for review August 16, 2023 01:45
@Xynnn007 Xynnn007 changed the title Confidential DataHub Part 4: CDH binary & GetToken API for AA Confidential DataHub Part 4: CDH binary & Attestation API for AA Aug 16, 2023
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.

Nice. Some comments.

| sev | For SEV based on efi secret pre-attestation |

Note: `offline-fs` is built-in, we do not need to manually enable. If no `RESOURCE_PROVIDER`
is given, all features will be enabled.
Copy link
Member

Choose a reason for hiding this comment

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

Are we deprecating the sample option?

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'm not sure whether we are still using sample in current CoCo (except enclave-cc). As all the tests can be covered by offline-fs-kbc, sample seem somehow useless. If it is still used I can add that.


package api;

message UnSealSecretInput {
Copy link
Member

Choose a reason for hiding this comment

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

nit: UnSeal -> Unseal

Copy link
Member Author

@Xynnn007 Xynnn007 Aug 20, 2023

Choose a reason for hiding this comment

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

Nice catch, we should sync with https://github.com/kata-containers/kata-containers/pull/7545/files#diff-e0bf528729d06d2a2c080a9689807bc7b8795745c6edb1a6803dbe67b3be2bddR5. Let me fix this here.

@Lu-Biao could you help to update the PR of yours ?

confidential-data-hub/hub/src/auth/kbs.rs Outdated Show resolved Hide resolved
//!
//! for example
//! ```
//! cdh.kbs_resources=kbs:///default/key/1::/run/temp1,kbs:///default/key/2::/run/temp2
Copy link
Member

Choose a reason for hiding this comment

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

I am skeptical of this format and of reading this config from the kernel command line.

Copy link
Member Author

Choose a reason for hiding this comment

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

To specify the resources (like credential for KMS) are needed. This is only a workaround up to now as we do not have a generic mechanism to inject these data. See kata-containers/kata-containers#7669 (comment) and maybe we can improve this in future

Copy link
Member

@fitzthum fitzthum Aug 21, 2023

Choose a reason for hiding this comment

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

Hmmm. I am not sure about the future proposal or the workaround tbh.Are you sure that this config actually needs to be measured? I will comment on the issue as well.

Also, it seems a bit odd to store all this on the FS. What is the advantage of this over holding credentials in the memory of the CDH process?

I guess one key question is who actually sets up all these configs? Does the user have to do that? Will the shim do it? I had pictured that a user who wrapped a key with the Aliyun KMS, the data in the wrapped secret would be enough to complete the entire process. I guess this allows us to decouple the credentials for that KBS from the information about the secret itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm. I am not sure about the future proposal or the workaround tbh.Are you sure that this config actually needs to be measured? I will comment on the issue as well.

Yes I think so. When the pod's attestation report can pass KBS's RCAR handshake, which resource will be fetched should be known and ensured to avoid abuse, or unexpected overwriting. The config specifies the resource names.

Also, it seems a bit odd to store all this on the FS. What is the advantage of this over holding credentials in the memory of the CDH process?

The FS is still inside the guest's encrypted memory as it is in /run so it can not be seen by the host. If we put them in the ram FS, the high-level code of hub do not need to care about how to organize the credential files and cosume them, it just get_resource and put to where it should be. All later work can be done by KMS plugin code.

I guess one key question is who actually sets up all these configs? Does the user have to do that? Will the shim do it? I had pictured that a user who wrapped a key with the Aliyun KMS, the data in the wrapped secret would be enough to complete the entire process. I guess this allows us to decouple the credentials for that KBS from the information about the secret itself?

The user should do that. Currently an user of aliyun kms does not have an open api to receive all the KMS requests. Instead we have different KMS "instances" like different servers which need different credential to connect to. So the information inside the sealed secret must include the kms instance id and the credential id. (kms instance and credential are not one-to-one)

So the whole story will be: an user makes a sealed secret with aliyun kms, then store the credential into kbs and set the launch parameter of cdh to get the credential from KBS. When launching cdh, it will gets enough credential from the kbs and put them into encrypted guest memory. When unsealling secret, it detects which credential will be used and get from the encrypted guest memory.

The workaround give a straightforward way. We can talk about the init data injection mechanism for kata/coco. If we have that, a more easy way for the user to specify the configs via k8s annotations can be done.

Moreover, for diffferent CSP, the steps can be automatic via outer web page or user interface.

Copy link
Member

Choose a reason for hiding this comment

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

Hm well I guess what we're getting into here are integration questions.

My main concern is that we're making things too complicated for the end user. It's true that the CSP could setup some of this stuff automatically, but keep in mind that today people can use CoCo simply by adding a runtime class to their yaml file. I'm a bit worried that the new features we're adding will be too hard to consume.

With the workaround the issues are mainly that the kernel params are not very robust. This will make validating the launch measurement much more difficult. For the short term, I guess that could be okay.

Anyway, we can probably go ahead here, but I think there are some unanswered integration questions still.

confidential-data-hub/hub/src/auth/sev_es.rs Outdated Show resolved Hide resolved
input: UnSealSecretInput,
) -> ::ttrpc::Result<UnSealSecretOutput> {
debug!("get new UnsealSecret request");
let reader = HUB.read().await;
Copy link
Member

Choose a reason for hiding this comment

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

I would just call this hub.

btw does this mean that the hub methods can't modify the state of the hub?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. UnsealSecret function does not change any state of the hub. It only

  1. read KMS credential and create a client
  2. use the kms plugin to unseal the secret

No modifications would be applied to local fs or the status of hub.

confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs Outdated Show resolved Hide resolved
confidential-data-hub/kms/src/plugins/mod.rs Outdated Show resolved Hide resolved
@@ -93,19 +55,13 @@ impl DataHub for Hub {

async fn get_resource(&self, uri: String) -> Result<Vec<u8>> {
// to initialize a get_resource_provider client we do not need the ProviderSettings.
let mut client = kms::new_getter(&self.get_resource_provider, ProviderSettings::default())
let mut client = kms::new_getter("kbs", ProviderSettings::default())
Copy link
Member

Choose a reason for hiding this comment

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

Any sev option here?

Also, why create a new getter for each request? That means that you have to use the fake client. Instead could we just create the getter once at the beginning?

Copy link
Member Author

Choose a reason for hiding this comment

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

the concrete kbc under kbs plugin is determined by aa_kbc_params. So we do not need to care if it uses online-sev-kbc of cc-kbc.

Also, why create a new getter for each request? That means that you have to use the fake client. Instead could we just create the getter once at the beginning?

Your idea is ok, too. But we will store an extra fake client object in CDH, while the fake client only provides the function pointer to the real client. Also, when an unseal secret request with kbs provider comes, it will still create a fake client. The consumption of creation a fake client is very low (check the lock), thus I think the way makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, the first part is a bit confusing because in the past the KbcClient was just for the KBS protocol, but here it can do both that and the SEV protocol. I guess that is ok tho.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
The kbs auth plugin helps to get the resouces that CDH will needs during
the runtime. Such as the credential files that KMS plugin need, etc.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
@Xynnn007 Xynnn007 force-pushed the feat-cdh-binary branch 2 times, most recently from 7601425 to 5dafdd2 Compare August 20, 2023 10:18
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 @Xynnn007 LGTM! verified with api-server-rest

attestation-agent/app/src/grpc.rs Outdated Show resolved Hide resolved
attestation-agent/lib/src/token.rs Show resolved Hide resolved
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
As everytime the guest launches, only one KBC will be specified by
aa_kbc_params in kernel commandline. Thus the KMS plugin only needs to
expose one API to hide the underlying kbc type.

Also, this commit adds offline-fs-kbc as the by default supported one.
If kernel does not specify  the offline-fs-kbc, no files will be read,
so we do not need to worry about the guest image.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
when aliyun feature is not enabled, the lint error will be raised.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Ttrpc api receives Arc<Box<A>> as a parameter to init the server, while
Arc<Box<A+B>> cannot downcast to Arc<Box<A>>. So a static variable is
used to be the actual server object.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Because we combine cc-kbc/offline-fs-kbc/online-sev-kbc into one KMS
plugin named kbs. Thus the high level caller hub does not need to care
about the concrete kbc type underneath.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
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. One or two things I might still tweak, but fine to get the code in.

@arronwy arronwy merged commit 3d8192f into confidential-containers:main Aug 23, 2023
9 checks passed
@Xynnn007 Xynnn007 deleted the feat-cdh-binary branch August 24, 2023 01:51
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.

4 participants