Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (c *container) SpecAddAnnotations(ctx context.Context, sb *sandbox.Sandbox,
// The sandbox annotations are already filtered for the allowed
// annotations, there is no need to check it additionally here.
for k, v := range sb.Annotations() {
if strings.HasPrefix(k, crioann.OCISeccompBPFHookAnnotation) {
if k == crioann.OCISeccompBPFHookAnnotation+"/"+c.config.Metadata.Name {
// The OCI seccomp BPF hook
// (https://github.com/containers/oci-seccomp-bpf-hook)
// uses the annotation io.containers.trace-syscall as indicator
Expand All @@ -171,17 +171,14 @@ func (c *container) SpecAddAnnotations(ctx context.Context, sb *sandbox.Sandbox,
// 'io.containers.trace-syscall' if the metadata name is equal
// to 'container'. This allows us to trace containers into
// distinguishable files.
if strings.TrimPrefix(k, crioann.OCISeccompBPFHookAnnotation+"/") == c.config.Metadata.Name {
log.Debugf(ctx,
"Annotation key for container %q rewritten to %q (value is: %q)",
c.config.Metadata.Name, crioann.OCISeccompBPFHookAnnotation, v,
)
c.config.Annotations[crioann.OCISeccompBPFHookAnnotation] = v
c.spec.AddAnnotation(crioann.OCISeccompBPFHookAnnotation, v)
} else {
// Annotation not suffixed with the container name
c.spec.AddAnnotation(k, v)
}
log.Debugf(ctx,
"Annotation key for container %q rewritten to %q (value is: %q)",
c.config.Metadata.Name, crioann.OCISeccompBPFHookAnnotation, v,
)
c.config.Annotations[crioann.OCISeccompBPFHookAnnotation] = v
c.spec.AddAnnotation(crioann.OCISeccompBPFHookAnnotation, v)
} else {
c.spec.AddAnnotation(k, v)
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/ctr.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ function wait_until_exit() {
return 1
}

function check_oci_annotation() {
# check for OCI annotation in container's config.json
local ctr_id="$1"
local key="$2"
local value="$3"

config=$(runtime state "$ctr_id" | jq -r .bundle)/config.json

[ "$(jq -r .annotations.\""$key"\" < "$config")" = "$value" ]
}

@test "ctr not found correct error message" {
start_crio
! crictl inspect "container_not_exist"
Expand Down Expand Up @@ -886,6 +897,10 @@ function wait_until_exit() {
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)
crictl inspectp "$pod_id" | grep '"owner": "hmeng"'
crictl inspectp "$pod_id" | grep '"security.alpha.kubernetes.io/seccomp/pod": "unconfined"'

# sandbox annotations passed through to container OCI config
ctr_id=$(crictl create "$pod_id" "$TESTDATA"/container_config.json "$TESTDATA"/sandbox_config.json)
check_oci_annotation "$ctr_id" "com.example.test" "sandbox annotation"
}

@test "ctr with default_env set in configuration" {
Expand Down
3 changes: 2 additions & 1 deletion test/testdata/sandbox_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"annotations": {
"owner": "hmeng",
"security.alpha.kubernetes.io/seccomp/pod": "unconfined"
"security.alpha.kubernetes.io/seccomp/pod": "unconfined",
"com.example.test": "sandbox annotation"
},
"linux": {
"cgroup_parent": "pod_123-456.slice",
Expand Down