Skip to content

Commit f8348f6

Browse files
committed
tests: integration: add runc-dmz smoke tests
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 6be763e commit f8348f6

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

libcontainer/container_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ func (c *Container) newParentProcess(p *Process) (parentProcess, error) {
524524
// runc-dmz.
525525
exePath = "/proc/self/exe"
526526
p.clonedExes = append(p.clonedExes, dmzExe)
527+
logrus.Debug("runc-dmz: using runc-dmz") // used for tests
527528
} else if errors.Is(err, dmz.ErrNoDmzBinary) {
528529
logrus.Debug("runc-dmz binary not embedded in runc binary, falling back to /proc/self/exe clone")
529530
} else if err != nil {
@@ -542,6 +543,7 @@ func (c *Container) newParentProcess(p *Process) (parentProcess, error) {
542543
}
543544
exePath = "/proc/self/fd/" + strconv.Itoa(int(safeExe.Fd()))
544545
p.clonedExes = append(p.clonedExes, safeExe)
546+
logrus.Debug("runc-dmz: using /proc/self/exe clone") // used for tests
545547
}
546548
// Just to make sure we don't run without protection.
547549
if dmzExe == nil && safeExe == nil {

tests/integration/helpers.bash

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,16 @@ function teardown_bundle() {
646646
remove_parent
647647
}
648648

649-
function requires_kernel() {
649+
function is_kernel_gte() {
650650
local major_required minor_required
651651
major_required=$(echo "$1" | cut -d. -f1)
652652
minor_required=$(echo "$1" | cut -d. -f2)
653-
if [[ "$KERNEL_MAJOR" -lt $major_required || ("$KERNEL_MAJOR" -eq $major_required && "$KERNEL_MINOR" -lt $minor_required) ]]; then
654-
skip "requires kernel $1"
653+
[[ "$KERNEL_MAJOR" -gt $major_required || ("$KERNEL_MAJOR" -eq $major_required && "$KERNEL_MINOR" -ge $minor_required) ]]
654+
}
655+
656+
function requires_kernel() {
657+
if ! is_kernel_gte "$@"; then
658+
skip "requires kernel >= $1"
655659
fi
656660
}
657661

tests/integration/run.bats

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,37 @@ function teardown() {
126126
[ "$status" -eq 0 ]
127127
[ "$output" = "410" ]
128128
}
129+
130+
@test "runc run [runc-dmz]" {
131+
runc --debug run test_hello
132+
[ "$status" -eq 0 ]
133+
[[ "$output" = *"Hello World"* ]]
134+
# We use runc-dmz if we can.
135+
[[ "$output" = *"runc-dmz: using runc-dmz"* ]]
136+
}
137+
138+
@test "runc run [cap_sys_ptrace -> /proc/self/exe clone]" {
139+
# Add CAP_SYS_PTRACE to the bounding set, the minimum needed to indicate a
140+
# container process _could_ get CAP_SYS_PTRACE.
141+
update_config '.process.capabilities.bounding += ["CAP_SYS_PTRACE"]'
142+
143+
runc --debug run test_hello
144+
[ "$status" -eq 0 ]
145+
[[ "$output" = *"Hello World"* ]]
146+
if [ "$EUID" -ne 0 ] && is_kernel_gte 4.10; then
147+
# For Linux 4.10 and later, rootless containers will use runc-dmz
148+
# because they are running in a user namespace. See isDmzBinarySafe().
149+
[[ "$output" = *"runc-dmz: using runc-dmz"* ]]
150+
else
151+
# If the container has CAP_SYS_PTRACE and is not rootless, we use
152+
# /proc/self/exe cloning.
153+
[[ "$output" = *"runc-dmz: using /proc/self/exe clone"* ]]
154+
fi
155+
}
156+
157+
@test "RUNC_DMZ=legacy runc run [/proc/self/exe clone]" {
158+
RUNC_DMZ=legacy runc --debug run test_hello
159+
[ "$status" -eq 0 ]
160+
[[ "$output" = *"Hello World"* ]]
161+
[[ "$output" = *"runc-dmz: using /proc/self/exe clone"* ]]
162+
}

tests/integration/seccomp-notify-compat.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
load helpers
44

55
function setup() {
6-
if [[ "$KERNEL_MAJOR" -gt 5 || ("$KERNEL_MAJOR" -eq 5 && "$KERNEL_MINOR" -ge 6) ]]; then
7-
skip "requires kernel less than 5.6"
6+
if is_kernel_gte 5.6; then
7+
skip "requires kernel < 5.6"
88
fi
99

1010
requires arch_x86_64

0 commit comments

Comments
 (0)