-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kata.genpolicy: fail when layer can't be processed
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
- Loading branch information
1 parent
99e7aeb
commit a62af98
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/by-name/kata/kata-runtime/0021-genpolicy-fail-when-layer-can-t-be-processed.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Paul Meyer <katexochen0@gmail.com> | ||
Date: Mon, 24 Feb 2025 09:27:40 +0100 | ||
Subject: [PATCH] genpolicy: fail when layer can't be processed | ||
|
||
Currently, if a layer can't be processed, we log this a warning and | ||
continue execution, finally exit with a zero exit code. This can lead | ||
to the generation of invalid policies. One reason a layer might not be | ||
processed is that the pull of that layer fails. | ||
|
||
We need all layers to be processed successfully to generate a valid | ||
policy, as otherwise we will miss the verity hash for that layer or | ||
we might miss the USER information from a passwd stored in that layer. | ||
This will cause our VM to not get through the agent's policy validation. | ||
|
||
Returning an error instead of printing a warning will cause genpolicy | ||
to fail in such cases. | ||
|
||
Signed-off-by: Paul Meyer <katexochen0@gmail.com> | ||
--- | ||
src/tools/genpolicy/src/registry.rs | 4 ++-- | ||
src/tools/genpolicy/src/registry_containerd.rs | 4 ++-- | ||
2 files changed, 4 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/src/tools/genpolicy/src/registry.rs b/src/tools/genpolicy/src/registry.rs | ||
index cc7f58dab031eff0cfa47ac35e9c6ac8c1e2e4de..e36350bb5982d6295253a2bd09e2a445ad9bd403 100644 | ||
--- a/src/tools/genpolicy/src/registry.rs | ||
+++ b/src/tools/genpolicy/src/registry.rs | ||
@@ -11,7 +11,7 @@ use crate::policy; | ||
use crate::utils::Config; | ||
use crate::verity; | ||
|
||
-use anyhow::{anyhow, Result}; | ||
+use anyhow::{anyhow, bail, Result}; | ||
use docker_credential::{CredentialRetrievalError, DockerCredential}; | ||
use fs2::FileExt; | ||
use log::{debug, info, warn, LevelFilter}; | ||
@@ -441,7 +441,7 @@ async fn get_verity_and_users( | ||
if let Some(path) = layers_cache_file_path.as_ref() { | ||
std::fs::remove_file(path)?; | ||
} | ||
- warn!("{error_message}"); | ||
+ bail!(error_message); | ||
} | ||
Ok((verity_hash, passwd)) | ||
} | ||
diff --git a/src/tools/genpolicy/src/registry_containerd.rs b/src/tools/genpolicy/src/registry_containerd.rs | ||
index 6541cfbda5379a4caea0361a5993db8f15adf6a2..b004065e7b6ffa523009910153569ddb52453d0a 100644 | ||
--- a/src/tools/genpolicy/src/registry_containerd.rs | ||
+++ b/src/tools/genpolicy/src/registry_containerd.rs | ||
@@ -10,7 +10,7 @@ use crate::registry::{ | ||
Container, DockerConfigLayer, ImageLayer, | ||
}; | ||
|
||
-use anyhow::{anyhow, Result}; | ||
+use anyhow::{anyhow, bail, Result}; | ||
use containerd_client::{services::v1::GetImageRequest, with_namespace}; | ||
use docker_credential::{CredentialRetrievalError, DockerCredential}; | ||
use k8s_cri::v1::{image_service_client::ImageServiceClient, AuthConfig}; | ||
@@ -354,7 +354,7 @@ async fn get_verity_and_users( | ||
if let Some(path) = layers_cache_file_path.as_ref() { | ||
std::fs::remove_file(path)?; | ||
} | ||
- warn!("{error_message}"); | ||
+ bail!(error_message); | ||
} | ||
Ok((verity_hash, passwd)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters