Skip to content

Commit

Permalink
chroot: don't use the generate default seccomp filter for unit tests
Browse files Browse the repository at this point in the history
When we link our test helper statically using the external linker, the
hardwired default seccomp filter we get from the runtime-tools generator
triggers a hang in it at startup.

Rather than switch to the internal linker, which seems to work around
this, start using the same seccomp filter for unit tests that we
actually use in real life, leaving analysis of which difference between
the two is responsible for it for another day.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind authored and cevich committed Nov 5, 2021
1 parent 7017fc8 commit 4583c71
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chroot/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func testMinimal(t *testing.T, modify func(g *generate.Generator, rootDir, bundl
if err != nil {
t.Fatalf("generate.New(%q): %v", "linux", err)
}
if err = setupSeccomp(g.Config, ""); err != nil {
t.Fatalf("setupSeccomp(%q): %v", "", err)
}

tempDir, err := ioutil.TempDir("", "chroot-test")
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions chroot/seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
package chroot

import (
"io/ioutil"

"github.com/containers/common/pkg/seccomp"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
libseccomp "github.com/seccomp/libseccomp-golang"
Expand Down Expand Up @@ -171,3 +174,27 @@ func setSeccomp(spec *specs.Spec) error {
}
return nil
}

func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
switch seccompProfilePath {
case "unconfined":
spec.Linux.Seccomp = nil
case "":
seccompConfig, err := seccomp.GetDefaultProfile(spec)
if err != nil {
return errors.Wrapf(err, "loading default seccomp profile failed")
}
spec.Linux.Seccomp = seccompConfig
default:
seccompProfile, err := ioutil.ReadFile(seccompProfilePath)
if err != nil {
return errors.Wrapf(err, "opening seccomp profile (%s) failed", seccompProfilePath)
}
seccompConfig, err := seccomp.LoadProfile(string(seccompProfile), spec)
if err != nil {
return errors.Wrapf(err, "loading seccomp profile (%s) failed", seccompProfilePath)
}
spec.Linux.Seccomp = seccompConfig
}
return nil
}
8 changes: 8 additions & 0 deletions chroot/seccomp_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ func setSeccomp(spec *specs.Spec) error {
}
return nil
}

func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
if spec.Linux != nil {
// runtime-tools may have supplied us with a default filter
spec.Linux.Seccomp = nil
}
return nil
}

0 comments on commit 4583c71

Please sign in to comment.