spiegel_podman/test/e2e/run_seccomp_test.go
Kir Kolyshkin 99136fbc4c test/e2e: fix 'block all syscalls' seccomp for runc
Error messages between runc and crun are not synchronized, and
in some case exit codes can be different, too.

Commit dd1bcabae9 ("CI: use local registry, part 2 of 3: fix tests")
removed the special case handling for runc from the
"podman run --seccomp-policy image (block all syscalls)"
test case, and so it fails, for example, like this:

	  Error: failed to connect to container's attach socket: /tmp/podman-e2e-2877753109/subtest-1698249469/p/root/overlay-containers/62585e98da7dc3fdb32d3b6de0980c762a8a6cde008ed35c68727fb97f5369c7/userdata/attach: no such file or directory
	  [FAILED] Command exited with status 127 (expected 126)

or this:

	  time="2025-08-29T17:16:52-07:00" level=error msg="cannot start a container that has stopped"
	  Error: `/usr/bin/runc start 63ce789f7037d9545cde832d29343704cab842e7288046407d0efa347d5ecb77` failed: exit status 1
	  [FAILED] Command exited 126 as expected, but did not emit 'OCI runtime error: runc: read from the init process'

(depending on runc version, phase of the moon etc.)

We can not reasonably expect a specific error message and exit code in
such an unusual scenario, but let's try.

With this commit, the above test passes successfully on my machine.

Tested with:

	make localintegration FOCUS="block all syscalls" OCI_RUNTIME=/usr/local/bin/runc
	make remoteintegration FOCUS="block all syscalls" OCI_RUNTIME=/usr/local/bin/runc

While at it, simplify the error message check for crun (we don't have to
check for the entire message, [the same] substring is fine for both
local and remote cases).

Fixes: dd1bcabae9 ("CI: use local registry, part 2 of 3: fix tests")
Reported-by: Yiqiao Pu <ypu@redhat.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-02-06 15:36:47 -05:00

83 lines
3.2 KiB
Go

//go:build linux || freebsd
package integration
import (
"path"
. "github.com/containers/podman/v5/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// Create an image with the given seccomp label
func makeLabeledImage(seccompLabel string) string {
ctrName := "temp-working-container"
imgName := "workingimage"
session := podmanTest.Podman([]string{"run", "--name", ctrName, CITEST_IMAGE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitCleanly())
session = podmanTest.Podman([]string{"commit", "-q", "--change", "LABEL io.containers.seccomp.profile=" + seccompLabel, ctrName, imgName})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitCleanly())
return imgName
}
var _ = Describe("Podman run", func() {
It("podman run --seccomp-policy default", func() {
session := podmanTest.Podman([]string{"run", "-q", "--seccomp-policy", "default", CITEST_IMAGE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
})
It("podman run --seccomp-policy ''", func() {
// Empty string is interpreted as "default".
session := podmanTest.Podman([]string{"run", "-q", "--seccomp-policy", "", CITEST_IMAGE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
})
It("podman run --seccomp-policy invalid", func() {
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "invalid", CITEST_IMAGE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError(125, `invalid seccomp policy "invalid": valid policies are ["default" "image"]`))
})
It("podman run --seccomp-policy image (block all syscalls)", func() {
// This image has seccomp profiles that blocks all syscalls.
// The intention behind blocking all syscalls is to prevent
// regressions in the future. The required syscalls can vary
// depending on which runtime we're using.
img := makeLabeledImage(`'{"defaultAction":"SCMP_ACT_ERRNO"}'`)
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "image", img, "ls"})
session.WaitWithDefaultTimeout()
switch path.Base(podmanTest.OCIRuntime) {
case "crun":
// "crun create" fails with "read from the init process" error.
Expect(session).To(ExitWithError(126, "read from the init process"))
case "runc":
// "runc create" succeeds, then...
Expect(session).To(Or(
// either "runc start" fails with "cannot start a container that has stopped",
ExitWithError(126, "cannot start a container that has stopped"),
// or podman itself fails with "failed to connect to container's attach socket".
ExitWithError(127, "failed to connect to container's attach socket"),
))
default:
Expect(session.ExitCode()).To(BeNumerically(">", 0), "Exit status using generic runtime")
}
})
It("podman run --seccomp-policy image (bogus profile)", func() {
// This image has a bogus/invalid seccomp profile which should
// yield a json error when being read.
img := makeLabeledImage(`'BOGUS - this should yield an error'`)
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "image", img, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, "loading seccomp profile failed: decoding seccomp profile failed: invalid character 'B' looking for beginning of value"))
})
})