Skip to content

Commit

Permalink
cdh: move image crate into hub/image module
Browse files Browse the repository at this point in the history
the image crate is used exclusively by cdh, so we don't need to maintain
it as individual crate, helping with naming conflicts and reducing build
complexity.

Signed-off-by: Magnus Kulke <[email protected]>
  • Loading branch information
mkulke committed Nov 20, 2024
1 parent ed4356d commit 5420dd2
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cdh_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ jobs:

- name: Run cargo test
run: |
sudo -E PATH=$PATH -s cargo test --features kbs,aliyun,sev,bin -p kms -p confidential-data-hub -p secret -p image
sudo -E PATH=$PATH -s cargo test --features kbs,aliyun,sev,bin -p kms -p confidential-data-hub -p secret
- name: Run cargo fmt check
run: |
sudo -E PATH=$PATH -s cargo fmt -p kms -p confidential-data-hub -p secret -p image -- --check
sudo -E PATH=$PATH -s cargo fmt -p kms -p confidential-data-hub -p secret -- --check
- name: Run rust lint check
run: |
# We are getting error in generated code due to derive_partial_eq_without_eq check, so ignore it for now
sudo -E PATH=$PATH -s cargo clippy -p kms -p confidential-data-hub -p secret -p image -- -D warnings -A clippy::derive-partial-eq-without-eq
sudo -E PATH=$PATH -s cargo clippy -p kms -p confidential-data-hub -p secret -- -D warnings -A clippy::derive-partial-eq-without-eq
21 changes: 4 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ members = [
"attestation-agent/coco_keyprovider",
"confidential-data-hub/hub",
"confidential-data-hub/kms",
"confidential-data-hub/image",
"confidential-data-hub/secret",
"confidential-data-hub/storage",
"image-rs",
Expand Down
11 changes: 6 additions & 5 deletions confidential-data-hub/hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ base64.workspace = true
cfg-if = { workspace = true, optional = true }
clap = { workspace = true, features = [ "derive" ], optional = true }
config = { workspace = true, optional = true }
crypto.path = "../../attestation-agent/deps/crypto"
env_logger = { workspace = true, optional = true }
image = { path = "../image", default-features = false }
image-rs = { path = "../../image-rs", default-features = false, features = ["kata-cc-rustls-tls"] }
kms = { path = "../kms", default-features = false }
lazy_static.workspace = true
log.workspace = true
prost = { workspace = true, optional = true }
protobuf = { workspace = true, optional = true }
resource_uri.path = "../../attestation-agent/deps/resource_uri"
secret.path = "../secret"
storage.path = "../storage"
serde = { workspace = true, optional = true }
Expand All @@ -66,16 +67,16 @@ tempfile.workspace = true
default = ["kbs", "bin", "ttrpc", "grpc"]

# support aliyun stacks (KMS, ..)
aliyun = ["image/aliyun", "secret/aliyun"]
aliyun = ["secret/aliyun"]

# support coco-KBS to provide confidential resources
kbs = ["image/kbs", "kms/kbs", "secret/kbs"]
kbs = ["kms/kbs", "secret/kbs"]

# support sev to provide confidential resources
sev = ["image/sev", "kms/sev", "secret/sev"]
sev = ["kms/sev", "secret/sev"]

# support eHSM stacks (KMS, ...)
ehsm = ["image/ehsm", "secret/ehsm"]
ehsm = ["secret/ehsm"]

# Binary RPC type
bin = [ "anyhow", "attestation-agent", "cfg-if", "clap", "config", "env_logger", "serde" ]
Expand Down
1 change: 1 addition & 0 deletions confidential-data-hub/hub/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//

use crate::image;
use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;
Expand Down
2 changes: 1 addition & 1 deletion confidential-data-hub/hub/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use log::{debug, info};
use storage::volume_type::Storage;
use tokio::sync::{Mutex, OnceCell};

use crate::{CdhConfig, DataHub, Error, Result};
use crate::{image, CdhConfig, DataHub, Error, Result};

pub struct Hub {
pub(crate) credentials: HashMap<String, String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests {

#[test]
fn compatiblity_with_old_packets() {
let v1_raw = include_str!("../../test/v1.json");
let v1_raw = include_str!("../test/v1.json");
let _: AnnotationPacket = serde_json::from_str(v1_raw).expect("unable to parse V1 with V2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use resource_uri::ResourceUri;
use serde::{Deserialize, Serialize};

use crate::image::{Error, Result};

/// `AnnotationPacket` is what a encrypted image layer's
/// `org.opencontainers.image.enc.keys.provider.attestation-agent`
/// annotation should contain when it is encrypted by CoCo's
Expand All @@ -24,13 +26,11 @@ pub struct AnnotationPacket {
}

impl AnnotationPacket {
pub(crate) async fn unwrap_key(&self) -> crate::Result<Vec<u8>> {
pub(crate) async fn unwrap_key(&self) -> Result<Vec<u8>> {
use base64::{engine::general_purpose::STANDARD, Engine};
use crypto::WrapType;
use kms::{plugins::VaultProvider, Annotations, ProviderSettings};

use crate::Error;

let wrap_type = WrapType::try_from(&self.wrap_type[..])
.map_err(|_| Error::UnknownWrapType(self.wrap_type.to_string()))?;
let kbs_client = kms::new_getter(VaultProvider::Kbs.as_ref(), ProviderSettings::default())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kms::{plugins::VaultProvider, Annotations, ProviderSettings};
use serde::{Deserialize, Serialize};
use serde_json::Map;

use crate::{Error, Result};
use crate::image::{Error, Result};

pub const DEFAULT_VERSION: &str = "0.1.0";

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod error;

pub use annotation_packet::AnnotationPacket;
use anyhow::anyhow;
pub use error::*;
pub use error::{Error, Result};

pub async fn unwrap_key(annotation_packet: &[u8]) -> Result<Vec<u8>> {
let annotation_packet: AnnotationPacket =
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions confidential-data-hub/hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ pub mod auth;

pub mod config;
pub use config::*;

pub mod image;
30 changes: 0 additions & 30 deletions confidential-data-hub/image/Cargo.toml

This file was deleted.

0 comments on commit 5420dd2

Please sign in to comment.