Skip to content

Commit 96aff63

Browse files
committed
Revert "cdh: move kms crate to cdh module"
We use the KMS crate outside of the guest-components. Specifically, we use some of this functionality in Trustee as part of resource backends that use KMSes. We could potentially adjust Trustee to import the CDH and use the KMSes from there, but Trustee doesn't need anything else from the CDH. It probably does make sense to have the KMS logic in its own crate, hence revert the change that brough it into the CDH. This reverts commit 3ab8129. Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
1 parent 18cce30 commit 96aff63

File tree

51 files changed

+183
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+183
-136
lines changed

.github/workflows/cdh_basic.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ jobs:
7373
7474
- name: Run cargo test
7575
run: |
76-
sudo -E PATH=$PATH -s cargo test --features kbs,aliyun,sev,bin -p confidential-data-hub
76+
sudo -E PATH=$PATH -s cargo test --features kbs,aliyun,sev,bin -p kms -p confidential-data-hub
7777
7878
- name: Run cargo fmt check
7979
run: |
80-
sudo -E PATH=$PATH -s cargo fmt -p confidential-data-hub -- --check
80+
sudo -E PATH=$PATH -s cargo fmt -p kms -p confidential-data-hub -- --check
8181
8282
- name: Run rust lint check
8383
run: |
8484
# We are getting error in generated code due to derive_partial_eq_without_eq check, so ignore it for now
85-
sudo -E PATH=$PATH -s cargo clippy -p confidential-data-hub -- -D warnings -A clippy::derive-partial-eq-without-eq
85+
sudo -E PATH=$PATH -s cargo clippy -p kms -p confidential-data-hub -- -D warnings -A clippy::derive-partial-eq-without-eq

Cargo.lock

Lines changed: 46 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"attestation-agent/deps/sev",
1212
"attestation-agent/coco_keyprovider",
1313
"confidential-data-hub/hub",
14+
"confidential-data-hub/kms",
1415
"image-rs",
1516
"ocicrypt-rs",
1617
]

confidential-data-hub/docs/kms-providers/alibaba.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ Else if `client_type` is set to 'sts_token', provider_settings shall be as follo
5656
### Credential files
5757

5858
To connect to a KMS instance with `client_type` set to 'client_key', a client key is needed. A client key is actually
59-
[an json with encrypted inside](../../hub/src/kms/plugins/aliyun/client/client_key_client/example_credential/clientKey_KAAP.f4c8____.json)
59+
[an json with encrypted inside](../../kms/src/plugins/aliyun/client/client_key_client/example_credential/clientKey_KAAP.f4c8____.json)
6060
private key. The name of the client key is always derived from the client key id. Suppose the
6161
client key ID is `xxx`, then the client key file has name `clientKey_xxx.json`. The key to encrypt
62-
the private key is derived from a password that is also saved in [a file](../../hub/src/kms/plugins/aliyun/client/client_key_client/example_credential/password_KAAP.f4c8____.json).
62+
the private key is derived from a password that is also saved in [a file](../../kms/src/plugins/aliyun/client/client_key_client/example_credential/password_KAAP.f4c8____.json).
6363
Suppose the client key ID is `xxx`, then the password file has name `password_xxx.json`.
64-
Besides, [a cert of the KMS server](../../hub/src/kms/plugins/aliyun/client/client_key_client/example_credential/PrivateKmsCA_kst-shh64702cf2jvc_____.pem)
64+
Besides, [a cert of the KMS server](../../kms/src/plugins/aliyun/client/client_key_client/example_credential/PrivateKmsCA_kst-shh64702cf2jvc_____.pem)
6565
is also needed. Suppose the kms instance id is `xxx`, then the cert of the KMS server has name `PrivateKmsCA_xxx.pem`.
6666

6767
For more details please see the [developer document for aliyun](https://www.alibabacloud.com/help/en/key-management-service/latest/api-overview).
6868

69-
To connect to a KMS instance with `client_type` set to 'ecs_ram_role', a [ecsRamRole.json](../../hub/src/kms/plugins/aliyun/client/ecs_ram_role_client/example_credential/ecsRamRole.json) file is needed.
69+
To connect to a KMS instance with `client_type` set to 'ecs_ram_role', a [ecsRamRole.json](../../kms/src/plugins/aliyun/client/ecs_ram_role_client/example_credential/ecsRamRole.json) file is needed.
7070
In the json file, `ecs_ram_role_name` and `region_id` is set in order to get access to Dedicated KMS.
7171
Among them,`ecs_ram_role_name` refer to RAM role for ECS instances in a VPC network, where CDH runs. Can be set on Aliyun Console.
7272
And `region_id` refers to region id of Dedicated KMS, to which more details can be refered [here](https://www.alibabacloud.com/help/en/kms/product-overview/supported-regions).

confidential-data-hub/docs/kms-providers/ehsm-kms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The `annotations` should be set empty.
2828
### Credential files
2929

3030
To connect to a KMS instance, a credential file is needed. A credential file is actually
31-
[an json file with app_id and api_key](../../hub/src/kms/plugins/ehsm/example_credential/credential.4eb1____.json).
31+
[an json file with app_id and api_key](../../kms/src/plugins/ehsm/example_credential/credential.4eb1____.json).
3232
The name of the credential file is always derived from the app id. Suppose the
3333
App ID is `xxx`, then the credential file has name `credential.xxx.json`.
3434

confidential-data-hub/hub/Cargo.toml

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,22 @@ required-features = ["cli"]
3535
[dependencies]
3636
anyhow = { workspace = true, optional = true }
3737
async-trait.workspace = true
38-
attestation-agent = { path = "../../attestation-agent/attestation-agent", default-features = false }
38+
attestation-agent = { path = "../../attestation-agent/attestation-agent", default-features = false, optional = true }
3939
base64.workspace = true
40-
bincode = { workspace = true, optional = true }
4140
cfg-if.workspace = true
42-
chrono = { workspace = true, optional = true }
43-
clap = { workspace = true, features = ["derive"], optional = true }
44-
config.workspace = true
45-
const_format.workspace = true
41+
clap = { workspace = true, features = [ "derive" ], optional = true }
42+
config = { workspace = true, optional = true }
4643
crypto.path = "../../attestation-agent/deps/crypto"
47-
ehsm_client = { git = "https://github.com/intel/ehsm", rev = "3454cac66b968a593c3edc43410c0b52416bbd3e", optional = true }
4844
env_logger = { workspace = true, optional = true }
49-
hex = { workspace = true, optional = true }
50-
image-rs = { path = "../../image-rs", default-features = false, features = [
51-
"kata-cc-rustls-tls",
52-
] }
53-
kbs_protocol = { path = "../../attestation-agent/kbs_protocol", default-features = false, features = [
54-
"passport",
55-
"aa_ttrpc",
56-
"openssl",
57-
], optional = true }
45+
image-rs = { path = "../../image-rs", default-features = false, features = ["kata-cc-rustls-tls"] }
46+
kms = { path = "../kms", default-features = false }
5847
log.workspace = true
59-
p12 = { version = "0.6.3", optional = true }
6048
prost = { workspace = true, optional = true }
6149
protobuf = { workspace = true, optional = true }
6250
rand.workspace = true
63-
reqwest = { workspace = true, optional = true }
6451
resource_uri.path = "../../attestation-agent/deps/resource_uri"
65-
ring = "0.17"
6652
serde = { workspace = true, optional = true }
6753
serde_json.workspace = true
68-
sev = { path = "../../attestation-agent/deps/sev", optional = true }
69-
sha2 = { workspace = true, optional = true }
7054
strum = { workspace = true, features = ["derive"] }
7155
tempfile = { workspace = true, optional = true }
7256
thiserror.workspace = true
@@ -78,17 +62,13 @@ tokio = { workspace = true, features = [
7862
"rt-multi-thread",
7963
"sync",
8064
] }
81-
toml.workspace = true
8265
tonic = { workspace = true, optional = true }
8366
ttrpc = { workspace = true, features = ["async"], optional = true }
84-
url = { workspace = true, optional = true }
85-
uuid = { workspace = true, features = ["serde", "v4"], optional = true }
86-
yasna = { version = "0.5.2", optional = true }
8767
zeroize.workspace = true
8868

8969
[build-dependencies]
9070
anyhow.workspace = true
91-
tonic-build.workspace = true
71+
tonic-build = { workspace = true, optional = true }
9272
ttrpc-codegen = { workspace = true, optional = true }
9373

9474
[dev-dependencies]
@@ -104,34 +84,21 @@ tokio = { workspace = true, features = ["rt", "macros"] }
10484
default = ["aliyun", "kbs", "bin", "ttrpc", "grpc", "cli"]
10585

10686
# support aliyun stacks (KMS, ..)
107-
aliyun = [
108-
"anyhow",
109-
"chrono",
110-
"hex",
111-
"p12",
112-
"prost",
113-
"reqwest/rustls-tls",
114-
"sha2",
115-
"serde",
116-
"tempfile",
117-
"tonic",
118-
"url",
119-
"yasna",
120-
]
87+
aliyun = ["tempfile"]
12188

12289
# support coco-KBS to provide confidential resources
123-
kbs = ["kbs_protocol"]
90+
kbs = ["kms/kbs"]
12491

12592
# support sev to provide confidential resources
126-
sev = ["bincode", "dep:sev", "prost", "tonic", "uuid"]
93+
sev = ["kms/sev"]
12794

12895
# support eHSM stacks (KMS, ...)
129-
ehsm = ["ehsm_client"]
96+
ehsm = []
13097

13198
# Binary RPC type
132-
bin = ["anyhow", "clap", "env_logger", "serde"]
99+
bin = [ "anyhow", "attestation-agent", "clap", "config", "env_logger", "serde" ]
133100
ttrpc = ["dep:ttrpc", "protobuf", "ttrpc-codegen", "tokio/signal"]
134-
grpc = ["prost", "tonic", "tokio/signal"]
101+
grpc = ["prost", "tonic", "tonic-build", "tokio/signal"]
135102

136103
# for secret_cli
137104
cli = ["clap/derive", "tokio/rt-multi-thread", "tokio/sync", "tokio/macros"]

confidential-data-hub/hub/build.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44
//
55

66
fn main() {
7-
#[cfg(feature = "aliyun")]
8-
tonic_build::compile_protos(
9-
"./src/kms/plugins/aliyun/client/client_key_client/protobuf/dkms_api.proto",
10-
)
11-
.expect("Generate aliyun protocol code failed.");
12-
13-
#[cfg(feature = "sev")]
14-
tonic_build::configure()
15-
.build_server(true)
16-
.out_dir("./src/kms/plugins/kbs/sev")
17-
.compile_protos(
18-
&["./src/kms/plugins/kbs/sev/protos/getsecret.proto"],
19-
&["./src/kms/plugins/kbs/sev/protos"],
20-
)
21-
.expect("Generate sev protocol code failed.");
22-
237
#[cfg(feature = "grpc")]
248
{
259
tonic_build::configure()

confidential-data-hub/hub/src/auth/kbs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
99
use std::path::PathBuf;
1010

11+
use kms::{plugins::kbs::KbcClient, Annotations, Getter};
1112
use log::debug;
1213
use tokio::fs;
1314

14-
use crate::kms::{plugins::kbs::KbcClient, Annotations, Getter};
1515
use crate::{hub::Hub, Error, Result};
1616

1717
/// This directory is used to store all the kbs resources get by CDH's init

confidential-data-hub/hub/src/bin/secret_cli.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ use std::{env, path::Path};
77

88
use base64::{engine::general_purpose::STANDARD, Engine};
99
use clap::{command, Args, Parser, Subcommand};
10-
#[cfg(feature = "aliyun")]
11-
use confidential_data_hub::kms::plugins::aliyun::AliyunKmsClient;
12-
#[cfg(feature = "ehsm")]
13-
use confidential_data_hub::kms::plugins::ehsm::EhsmKmsClient;
14-
use confidential_data_hub::kms::{Encrypter, ProviderSettings};
1510
use confidential_data_hub::secret::{
1611
layout::{envelope::EnvelopeSecret, vault::VaultSecret},
1712
Secret, SecretContent, VERSION,
1813
};
19-
2014
use crypto::WrapType;
15+
#[cfg(feature = "aliyun")]
16+
use kms::plugins::aliyun::AliyunKmsClient;
17+
#[cfg(feature = "ehsm")]
18+
use kms::plugins::ehsm::EhsmKmsClient;
19+
use kms::{Encrypter, ProviderSettings};
2120
use rand::Rng;
2221
#[cfg(feature = "ehsm")]
2322
use serde_json::Value;

confidential-data-hub/hub/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use crate::{image, kms, secret, storage};
6+
use crate::{image, secret, storage};
77
use thiserror::Error;
88

99
pub type Result<T> = std::result::Result<T, Error>;

0 commit comments

Comments
 (0)