Skip to content

Commit

Permalink
packages/kata-runtime: alow arbitrary CDI annotations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msanft committed Feb 7, 2025
1 parent f9f3ae0 commit 86b1a59
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <[email protected]>
Date: Fri, 7 Feb 2025 13:12:28 +0100
Subject: [PATCH] runtime: remove CDI annotations

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.
---
src/runtime/virtcontainers/kata_agent.go | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go
index 9a794392b927fc8fa231a72ce35bc3fcb2773d85..5e3548774154585251e192743b78363c53a00019 100644
--- a/src/runtime/virtcontainers/kata_agent.go
+++ b/src/runtime/virtcontainers/kata_agent.go
@@ -14,6 +14,7 @@ import (
"os"
"path"
"path/filepath"
+ "regexp"
"strconv"
"strings"
"sync"
@@ -1080,6 +1081,17 @@ func (k *kataAgent) constrainGRPCSpec(grpcSpec *grpc.Spec, passSeccomp bool, dis
grpcSpec.Linux.Devices = linuxDevices
}

+ cdiRegexp, err := regexp.Compile(`$cdi\.k8s\.io\/.*^`)
+ if err != nil {
+ k.Logger().WithError(err).Error("compile CDI annotation regexp")
+ }
+
+ for key := range grpcSpec.Annotations {
+ if cdiRegexp.MatchString(key) {
+ delete(grpcSpec.Annotations, key)
+ }
+ }
+
return nil
}

6 changes: 6 additions & 0 deletions packages/by-name/kata/kata-runtime/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ buildGoModule rec {
# * https://github.com/kata-containers/kata-containers/issues/10680
# * https://github.com/kata-containers/kata-containers/pull/10818
./0020-agent-clear-log-pipes-if-denied-by-policy.patch

# This removes CDI annotations from the OCI spec before it is passed to the agent,
# which helps with policy handling of the (oftentimes dynamic) CDI annotations.
# TODO(msanft): Get native CDI working, which will allow us to drop this patch / undo the revert.
# See https://dev.azure.com/Edgeless/Edgeless/_workitems/edit/5061
./0021-runtime-remove-CDI-annotations.patch
];
};

Expand Down

0 comments on commit 86b1a59

Please sign in to comment.