From fce83dc560b84f90768f8067843fe2853bd0e550 Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Thu, 17 Aug 2023 13:26:26 +0800 Subject: [PATCH] cdh/hub: delete logic of resource provider 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 --- confidential-data-hub/hub/src/hub.rs | 42 +++------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/confidential-data-hub/hub/src/hub.rs b/confidential-data-hub/hub/src/hub.rs index a49ceab95..61ad8c0e2 100644 --- a/confidential-data-hub/hub/src/hub.rs +++ b/confidential-data-hub/hub/src/hub.rs @@ -7,44 +7,18 @@ use async_trait::async_trait; use base64::{engine::general_purpose::STANDARD, Engine}; use kms::{Annotations, ProviderSettings}; use secret::secret::Secret; -use tokio::fs; use crate::{DataHub, Error, Result}; -pub struct Hub { - /// the get resource provider type. Semantically same as kbc. - get_resource_provider: String, -} +pub struct Hub {} impl Hub { pub async fn new() -> Result { - let get_resource_provider = Self::get_resource_provider().await?; - let mut hub = Self { - get_resource_provider, - }; + let mut hub = Self {}; hub.init().await?; Ok(hub) } - - async fn get_resource_provider() -> Result { - let cmdline = fs::read_to_string("/proc/cmdline") - .await - .map_err(|e| Error::InitializationFailed(format!("read kernel cmdline failed: {e}")))?; - let resource_provider = cmdline - .split_ascii_whitespace() - .find(|para| para.starts_with("agent.aa_kbc_params=")) - .ok_or(Error::InitializationFailed( - "no `agent.aa_kbc_params` provided in kernel commandline!".into(), - ))? - .split("::") - .next() - .ok_or(Error::InitializationFailed( - "illegal input `agent.aa_kbc_params` format".into(), - ))? - .to_string(); - Ok(resource_provider) - } } #[async_trait] @@ -81,21 +55,13 @@ impl DataHub for Hub { async fn get_resource(&self, uri: String) -> Result> { // 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()) .await .map_err(|e| Error::GetResource(format!("create kbs client failed: {e}")))?; - let annotations = match &self.get_resource_provider[..] { - "online_sev_kbc" | "sev" => { - serde_json::from_str::(r#"{"secret_type":"resource"}"#) - .expect("deserialize sev hardcode failed") - } - _ => Annotations::default(), - }; - // to get resource using a get_resource_provider client we do not need the Annotations. let res = client - .get_secret(&uri, &annotations) + .get_secret(&uri, &Annotations::default()) .await .map_err(|e| Error::GetResource(format!("get rersource failed: {e}")))?; Ok(res)