Skip to content

Commit 7706154

Browse files
authored
Add missing permission needed to scan sysctl_net_core_bpf_jit_harden (#958)
Added CAP_SYS_ADMIN capability alongside CAP_SYS_CHROOT in the security context of the compliance scan pod.
1 parent cf41b00 commit 7706154

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pkg/controller/compliancescan/scan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ func newScanPodForNode(scanInstance *compv1alpha1.ComplianceScan, node *corev1.N
207207
Command: []string{OpenScapScriptPath},
208208
SecurityContext: &corev1.SecurityContext{
209209
Privileged: &falseP,
210-
AllowPrivilegeEscalation: &falseP,
210+
AllowPrivilegeEscalation: &trueP,
211211
ReadOnlyRootFilesystem: &trueP,
212212
Capabilities: &corev1.Capabilities{
213213
Drop: []corev1.Capability{"ALL"},
214-
Add: []corev1.Capability{"CAP_SYS_CHROOT"},
214+
Add: []corev1.Capability{"CAP_SYS_CHROOT", "CAP_SYS_ADMIN"},
215215
},
216216
// TODO(jaosorior): Figure out if the default
217217
// seccomp profile is sufficient here.

tests/e2e/parallel/main_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,23 @@ func TestSingleScanSucceeds(t *testing.T) {
614614
t.Fatalf("Expected scanner container to drop ALL capabilities, got: %v", droppedCaps)
615615
}
616616

617-
// Verify only CAP_SYS_CHROOT is added
617+
// Verify CAP_SYS_CHROOT and CAP_SYS_ADMIN are added
618618
addedCaps := container.SecurityContext.Capabilities.Add
619-
if len(addedCaps) != 1 || string(addedCaps[0]) != "CAP_SYS_CHROOT" {
620-
t.Fatalf("Expected scanner container to only have CAP_SYS_CHROOT capability, got: %v", addedCaps)
619+
if len(addedCaps) != 2 {
620+
t.Fatalf("Expected scanner container to have CAP_SYS_CHROOT and CAP_SYS_ADMIN capabilities, got: %v", addedCaps)
621+
}
622+
hasChroot := false
623+
hasSysAdmin := false
624+
for _, cap := range addedCaps {
625+
if string(cap) == "CAP_SYS_CHROOT" {
626+
hasChroot = true
627+
}
628+
if string(cap) == "CAP_SYS_ADMIN" {
629+
hasSysAdmin = true
630+
}
631+
}
632+
if !hasChroot || !hasSysAdmin {
633+
t.Fatalf("Expected scanner container to have both CAP_SYS_CHROOT and CAP_SYS_ADMIN capabilities, got: %v", addedCaps)
621634
}
622635
break
623636
}

0 commit comments

Comments
 (0)