Skip to content

Commit 2e1657c

Browse files
committed
packages/kata-runtime: alow arbitrary CDI annotations
As discussed via Teams, there is no sense in checking CDI annotations if the agent doesn't care about them anyway. This allows arbitrary CDI annotations in the policy.
1 parent 9997d79 commit 2e1657c

5 files changed

+52
-251
lines changed

Diff for: packages/by-name/kata/kata-runtime/0018-agent-remove-CDI-support.patch

-239
This file was deleted.

Diff for: packages/by-name/kata/kata-runtime/0020-agent-clear-log-pipes-if-denied-by-policy.patch renamed to packages/by-name/kata/kata-runtime/0019-agent-clear-log-pipes-if-denied-by-policy.patch

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Fixes: #10680
2020
1 file changed, 15 insertions(+), 7 deletions(-)
2121

2222
diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs
23-
index fd824e9ec26728bf8088939aac7a1edb6d886aac..cb5dac7a4a941e11fb9a086ff01633672364902a 100644
23+
index 5f2a3eb955ea427478c842ba80ad2a17299b182f..06fbcca57e8f5d8e729a379809950ce4f87359e4 100644
2424
--- a/src/agent/src/rpc.rs
2525
+++ b/src/agent/src/rpc.rs
26-
@@ -638,11 +638,11 @@ impl AgentService {
26+
@@ -649,11 +649,11 @@ impl AgentService {
2727

2828
async fn do_read_stream(
2929
&self,
@@ -38,7 +38,7 @@ index fd824e9ec26728bf8088939aac7a1edb6d886aac..cb5dac7a4a941e11fb9a086ff0163367
3838

3939
let term_exit_notifier;
4040
let reader = {
41-
@@ -889,8 +889,12 @@ impl agent_ttrpc::AgentService for AgentService {
41+
@@ -900,8 +900,12 @@ impl agent_ttrpc::AgentService for AgentService {
4242
_ctx: &TtrpcContext,
4343
req: protocols::agent::ReadStreamRequest,
4444
) -> ttrpc::Result<ReadStreamResponse> {
@@ -53,7 +53,7 @@ index fd824e9ec26728bf8088939aac7a1edb6d886aac..cb5dac7a4a941e11fb9a086ff0163367
5353
}
5454

5555
async fn read_stderr(
56-
@@ -898,8 +902,12 @@ impl agent_ttrpc::AgentService for AgentService {
56+
@@ -909,8 +913,12 @@ impl agent_ttrpc::AgentService for AgentService {
5757
_ctx: &TtrpcContext,
5858
req: protocols::agent::ReadStreamRequest,
5959
) -> ttrpc::Result<ReadStreamResponse> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Moritz Sanft <[email protected]>
3+
Date: Fri, 7 Feb 2025 13:12:28 +0100
4+
Subject: [PATCH] runtime: remove CDI annotations
5+
6+
We want to remove CDI annotations before they get to the agent, as they should only influence VM creation. Passing them to the agent is likely to create problems in policy checking, as they are often dynamically injected.
7+
---
8+
src/runtime/virtcontainers/kata_agent.go | 12 ++++++++++++
9+
1 file changed, 12 insertions(+)
10+
11+
diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go
12+
index 9a794392b927fc8fa231a72ce35bc3fcb2773d85..8e6385e274b16f5ab5be0a90a2229b9cf9f1f83e 100644
13+
--- a/src/runtime/virtcontainers/kata_agent.go
14+
+++ b/src/runtime/virtcontainers/kata_agent.go
15+
@@ -14,6 +14,7 @@ import (
16+
"os"
17+
"path"
18+
"path/filepath"
19+
+ "regexp"
20+
"strconv"
21+
"strings"
22+
"sync"
23+
@@ -1080,6 +1081,17 @@ func (k *kataAgent) constrainGRPCSpec(grpcSpec *grpc.Spec, passSeccomp bool, dis
24+
grpcSpec.Linux.Devices = linuxDevices
25+
}
26+
27+
+ cdiRegexp, err := regexp.Compile(`^cdi\.k8s\.io\/.*$`)
28+
+ if err != nil {
29+
+ k.Logger().WithError(err).Error("compile CDI annotation regexp")
30+
+ }
31+
+
32+
+ for key := range grpcSpec.Annotations {
33+
+ if cdiRegexp.MatchString(key) {
34+
+ delete(grpcSpec.Annotations, key)
35+
+ }
36+
+ }
37+
+
38+
return nil
39+
}
40+

Diff for: packages/by-name/kata/kata-runtime/package.nix

+8-8
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,25 @@ buildGoModule rec {
114114
# Upstream issue: https://github.com/kata-containers/kata-containers/issues/10633
115115
./0017-genpolicy-support-guest-hooks.patch
116116

117-
# Revert CDI support in kata-agent, which breaks legacy mode GPU facilitation which
118-
# we currently use.
119-
# TODO(msanft): Get native CDI working, which will allow us to drop this patch / undo the revert.
120-
# See https://dev.azure.com/Edgeless/Edgeless/_workitems/edit/5061
121-
./0018-agent-remove-CDI-support.patch
122-
123117
# This adds support for annotations with dynamic keys *and* values to Genpolicy.
124118
# This is required for e.g. GPU containers, which get annotated by an in-cluster
125119
# component (i.e. after policy generation based on the Pod spec) with an annotation
126120
# like `cdi.k8s.io/vfioXY`, where `XY` corresponds to a dynamic ID.
127121
# Upstream issue: https://github.com/kata-containers/kata-containers/issues/10745
128-
./0019-genpolicy-support-dynamic-annotations.patch
122+
./0018-genpolicy-support-dynamic-annotations.patch
129123

130124
# This allows denying ReadStream requests without blocking the container on its
131125
# stdout/stderr, by redacting the streams instead of blocking them.
132126
# Upstream:
133127
# * https://github.com/kata-containers/kata-containers/issues/10680
134128
# * https://github.com/kata-containers/kata-containers/pull/10818
135-
./0020-agent-clear-log-pipes-if-denied-by-policy.patch
129+
./0019-agent-clear-log-pipes-if-denied-by-policy.patch
130+
131+
# This removes CDI annotations from the OCI spec before it is passed to the agent,
132+
# which helps with policy handling of the (oftentimes dynamic) CDI annotations.
133+
# TODO(msanft): Get native CDI working, which will allow us to drop this patch / undo the revert.
134+
# See https://dev.azure.com/Edgeless/Edgeless/_workitems/edit/5061
135+
./0020-runtime-remove-CDI-annotations.patch
136136
];
137137
};
138138

0 commit comments

Comments
 (0)