Skip to content

Commit c9f1f6e

Browse files
committed
kata.genpolicy: fail when layer can't be processed
Signed-off-by: Paul Meyer <[email protected]>
1 parent a41d2ec commit c9f1f6e

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Paul Meyer <[email protected]>
3+
Date: Mon, 24 Feb 2025 09:27:40 +0100
4+
Subject: [PATCH] genpolicy: fail when layer can't be processed
5+
6+
Currently, if a layer can't be processed, we log this a warning and
7+
continue execution, finally exit with a zero exit code. This can lead
8+
to the generation of invalid policies. One reason a layer might not be
9+
processed is that the pull of that layer fails.
10+
11+
We need all layers to be processed successfully to generate a valid
12+
policy, as otherwise we will miss the verity hash for that layer or
13+
we might miss the USER information from a passwd stored in that layer.
14+
This will cause our VM to not get through the agent's policy validation.
15+
16+
Returning an error instead of printing a warning will cause genpolicy
17+
to fail in such cases.
18+
19+
Signed-off-by: Paul Meyer <[email protected]>
20+
---
21+
src/tools/genpolicy/src/registry.rs | 4 ++--
22+
src/tools/genpolicy/src/registry_containerd.rs | 4 ++--
23+
2 files changed, 4 insertions(+), 4 deletions(-)
24+
25+
diff --git a/src/tools/genpolicy/src/registry.rs b/src/tools/genpolicy/src/registry.rs
26+
index cc7f58dab031eff0cfa47ac35e9c6ac8c1e2e4de..e36350bb5982d6295253a2bd09e2a445ad9bd403 100644
27+
--- a/src/tools/genpolicy/src/registry.rs
28+
+++ b/src/tools/genpolicy/src/registry.rs
29+
@@ -11,7 +11,7 @@ use crate::policy;
30+
use crate::utils::Config;
31+
use crate::verity;
32+
33+
-use anyhow::{anyhow, Result};
34+
+use anyhow::{anyhow, bail, Result};
35+
use docker_credential::{CredentialRetrievalError, DockerCredential};
36+
use fs2::FileExt;
37+
use log::{debug, info, warn, LevelFilter};
38+
@@ -441,7 +441,7 @@ async fn get_verity_and_users(
39+
if let Some(path) = layers_cache_file_path.as_ref() {
40+
std::fs::remove_file(path)?;
41+
}
42+
- warn!("{error_message}");
43+
+ bail!(error_message);
44+
}
45+
Ok((verity_hash, passwd))
46+
}
47+
diff --git a/src/tools/genpolicy/src/registry_containerd.rs b/src/tools/genpolicy/src/registry_containerd.rs
48+
index 6541cfbda5379a4caea0361a5993db8f15adf6a2..b004065e7b6ffa523009910153569ddb52453d0a 100644
49+
--- a/src/tools/genpolicy/src/registry_containerd.rs
50+
+++ b/src/tools/genpolicy/src/registry_containerd.rs
51+
@@ -10,7 +10,7 @@ use crate::registry::{
52+
Container, DockerConfigLayer, ImageLayer,
53+
};
54+
55+
-use anyhow::{anyhow, Result};
56+
+use anyhow::{anyhow, bail, Result};
57+
use containerd_client::{services::v1::GetImageRequest, with_namespace};
58+
use docker_credential::{CredentialRetrievalError, DockerCredential};
59+
use k8s_cri::v1::{image_service_client::ImageServiceClient, AuthConfig};
60+
@@ -354,7 +354,7 @@ async fn get_verity_and_users(
61+
if let Some(path) = layers_cache_file_path.as_ref() {
62+
std::fs::remove_file(path)?;
63+
}
64+
- warn!("{error_message}");
65+
+ bail!(error_message);
66+
}
67+
Ok((verity_hash, passwd))
68+
}

packages/by-name/kata/kata-runtime/package.nix

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ buildGoModule rec {
132132
# TODO(msanft): Get native CDI working, which will allow us to drop this patch / undo the revert.
133133
# See https://dev.azure.com/Edgeless/Edgeless/_workitems/edit/5061
134134
./0019-runtime-remove-CDI-annotations.patch
135+
136+
# This patch makes genpolicy fail when a layer can't be processed, preventing
137+
# creation of invlid/incomplete policies.
138+
# Upstream PR: https://github.com/kata-containers/kata-containers/pull/10925
139+
./0020-genpolicy-fail-when-layer-can-t-be-processed.patch
135140
];
136141
};
137142

0 commit comments

Comments
 (0)