From 917d5cff1cf57e2555426b6dd8bf59dc3b7f0901 Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Fri, 13 Oct 2023 11:22:45 +0800 Subject: [PATCH] cdh/kms/kbs: raise warning when failed to read file for offline-fs-kbc Before this commit, if the given offline-fs-kbc file is not abled to be read when offline-fs-kbc is initialized, an error will be raised. This will cause the whole CDH process to exit. In real scenarios, this would require a user to embed an empty aa-offline_fs_kbc-resources.json and aa-offline_fs_kbc-keys.json to the guest image, which is meaningless. This patch fixes this. Signed-off-by: Xynnn007 --- .../kms/src/plugins/kbs/offline_fs.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs b/confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs index 75f8944a0..378e6dbd7 100644 --- a/confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs +++ b/confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs @@ -50,9 +50,14 @@ impl OfflineFsKbc { } async fn init_with_file(&mut self, path: &str) -> Result<()> { - let file = fs::read(path).await.map_err(|e| { - Error::KbsClientError(format!("offline-fs-kbc: read {path} failed: {e}")) - })?; + let file = match fs::read(path).await { + Ok(f) => f, + Err(e) => { + warn!("Failed to read file {path} to init offline-fs-kbc: {e}"); + return Ok(()); + } + }; + let map: HashMap = serde_json::from_slice(&file).map_err(|e| { Error::KbsClientError(format!("offline-fs-kbc: illegal resource file {path}: {e}")) })?;