Skip to content

Commit

Permalink
Allow plain annotation seccomp-profile.kubernetes.cri-o.io for images
Browse files Browse the repository at this point in the history
We now additionally allow the plain
`seccomp-profile.kubernetes.cri-o.io` annotation for container images,
to not require users to suffix the annotation using `/POD` or a
container name.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Feb 20, 2024
1 parent 87ff09f commit 6bd4f68
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions contrib/test/ci/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 159,7 @@ kata_skip_pod_tests:
kata_skip_seccomp_oci_artifacts_tests:
- 'test "seccomp OCI artifact with pod annotation"'
- 'test "seccomp OCI artifact with container annotation"'
- 'test "seccomp OCI artifact with image annotation without suffix"'
- 'test "seccomp OCI artifact with image annotation for pod"'
- 'test "seccomp OCI artifact with image annotation for container"'
- 'test "seccomp OCI artifact with image annotation and profile set to unconfined"'
Expand Down
2 changes: 2 additions & 0 deletions docs/crio.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 359,8 @@ The "crio.runtime.runtimes" table defines a list of OCI compatible runtimes. Th
- a specific container by using: "seccomp-profile.kubernetes.cri-o.io/<CONTAINER_NAME>"
- a whole pod by using: "seccomp-profile.kubernetes.cri-o.io/POD"
Note that the annotation works on containers as well as on images.
For images, the plain annotation `seccomp-profile.kubernetes.cri-o.io`
can be used without the required `/POD` suffix or a container name.

**platform_runtime_paths**={}
A mapping of platforms to the corresponding runtime executable paths for the runtime handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 49,9 @@ func (s *SeccompOCIArtifact) TryPull(
} else if val, ok := podAnnotations[SeccompProfilePodAnnotation]; ok {
log.Infof(ctx, "Found pod specific seccomp profile annotation: %s=%s", annotations.SeccompProfileAnnotation, val)
profileRef = val
} else if val, ok := imageAnnotations[annotations.SeccompProfileAnnotation]; ok {
log.Infof(ctx, "Found image specific seccomp profile annotation: %s=%s", annotations.SeccompProfileAnnotation, val)
profileRef = val
} else if val, ok := imageAnnotations[containerKey]; ok {
log.Infof(ctx, "Found image specific seccomp profile annotation for container %s: %s=%s", containerName, annotations.SeccompProfileAnnotation, val)
profileRef = val
Expand Down
2 changes: 2 additions & 0 deletions pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 77,8 @@ const (
// - a specific container by using: `seccomp-profile.kubernetes.cri-o.io/<CONTAINER_NAME>`
// - a whole pod by using: `seccomp-profile.kubernetes.cri-o.io/POD`
// Note that the annotation works on containers as well as on images.
// For images, the plain annotation `seccomp-profile.kubernetes.cri-o.io`
// can be used without the required `/POD` suffix or a container name.
SeccompProfileAnnotation = "seccomp-profile.kubernetes.cri-o.io"
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 210,8 @@ type RuntimeHandler struct {
// - a specific container by using: `seccomp-profile.kubernetes.cri-o.io/<CONTAINER_NAME>`
// - a whole pod by using: `seccomp-profile.kubernetes.cri-o.io/POD`
// Note that the annotation works on containers as well as on images.
// For images, the plain annotation `seccomp-profile.kubernetes.cri-o.io`
// can be used without the required `/POD` suffix or a container name.
AllowedAnnotations []string `toml:"allowed_annotations,omitempty"`

// DisallowedAnnotations is the slice of experimental annotations that are not allowed for this handler.
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 1269,8 @@ const templateStringCrioRuntimeRuntimesRuntimeHandler = `# The "crio.runtime.run
# - a specific container by using: "seccomp-profile.kubernetes.cri-o.io/<CONTAINER_NAME>"
# - a whole pod by using: "seccomp-profile.kubernetes.cri-o.io/POD"
# Note that the annotation works on containers as well as on images.
# For images, the plain annotation "seccomp-profile.kubernetes.cri-o.io"
# can be used without the required "/POD" suffix or a container name.
# - monitor_path (optional, string): The path of the monitor binary. Replaces
# deprecated option "conmon".
# - monitor_cgroup (optional, string): The cgroup the container monitor process will be put in.
Expand Down
18 changes: 18 additions & 0 deletions test/seccomp_oci_artifacts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,7 @@ function teardown() {
cleanup_test
}

ARTIFACT_IMAGE_WITH_ANNOTATION=quay.io/crio/nginx-seccomp:generic
ARTIFACT_IMAGE_WITH_POD_ANNOTATION=quay.io/crio/nginx-seccomp:pod
ARTIFACT_IMAGE_WITH_CONTAINER_ANNOTATION=quay.io/crio/nginx-seccomp:container
ARTIFACT_IMAGE=quay.io/crio/seccomp:v1
Expand All @@ -24,6 25,23 @@ ANNOTATION=seccomp-profile.kubernetes.cri-o.io
POD_ANNOTATION=seccomp-profile.kubernetes.cri-o.io/POD
TEST_SYSCALL=OCI_ARTIFACT_TEST

@test "seccomp OCI artifact with image annotation without suffix" {
# Run with enabled feature set
create_runtime_with_allowed_annotation seccomp $ANNOTATION
start_crio

jq '.image.image = "'$ARTIFACT_IMAGE_WITH_ANNOTATION'"' \
"$TESTDATA/container_config.json" > "$TESTDIR/container.json"

crictl pull $ARTIFACT_IMAGE_WITH_ANNOTATION
CTR=$(crictl run "$TESTDIR/container.json" "$TESTDATA/sandbox_config.json")

# Assert
grep -q "Found image specific seccomp profile annotation: $ANNOTATION=$ARTIFACT_IMAGE" "$CRIO_LOG"
grep -q "Retrieved OCI artifact seccomp profile" "$CRIO_LOG"
crictl inspect "$CTR" | jq -e .info.runtimeSpec.linux.seccomp | grep -q $TEST_SYSCALL
}

@test "seccomp OCI artifact with image annotation for pod" {
# Run with enabled feature set
create_runtime_with_allowed_annotation seccomp $ANNOTATION
Expand Down

0 comments on commit 6bd4f68

Please sign in to comment.