-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
policy for seccomp-profile selection #4806
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ import ( | |
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// seccompAnnotationKey is the key of the image annotation embedding a seccomp | ||
// profile. | ||
const seccompAnnotationKey = "io.containers.seccomp.profile" | ||
|
||
func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod.Runtime) (*libpod.Container, *cc.CreateConfig, error) { | ||
var ( | ||
healthCheck *manifest.Schema2HealthConfig | ||
|
@@ -67,7 +71,7 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod. | |
} | ||
|
||
imageName := "" | ||
var data *inspect.ImageData = nil | ||
var imageData *inspect.ImageData = nil | ||
|
||
// Set the storage if there is no rootfs specified | ||
if rootfs == "" { | ||
|
@@ -99,17 +103,17 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod. | |
if err != nil { | ||
return nil, nil, err | ||
} | ||
data, err = newImage.Inspect(ctx) | ||
imageData, err = newImage.Inspect(ctx) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
if overrideOS == "" && data.Os != goruntime.GOOS { | ||
return nil, nil, errors.Errorf("incompatible image OS %q on %q host", data.Os, goruntime.GOOS) | ||
if overrideOS == "" && imageData.Os != goruntime.GOOS { | ||
return nil, nil, errors.Errorf("incompatible image OS %q on %q host", imageData.Os, goruntime.GOOS) | ||
} | ||
|
||
if overrideArch == "" && data.Architecture != goruntime.GOARCH { | ||
return nil, nil, errors.Errorf("incompatible image architecture %q on %q host", data.Architecture, goruntime.GOARCH) | ||
if overrideArch == "" && imageData.Architecture != goruntime.GOARCH { | ||
return nil, nil, errors.Errorf("incompatible image architecture %q on %q host", imageData.Architecture, goruntime.GOARCH) | ||
} | ||
|
||
names := newImage.Names() | ||
|
@@ -171,7 +175,7 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod. | |
} | ||
} | ||
|
||
createConfig, err := ParseCreateOpts(ctx, c, runtime, imageName, data) | ||
createConfig, err := ParseCreateOpts(ctx, c, runtime, imageName, imageData) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
@@ -711,6 +715,18 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod. | |
return nil, err | ||
} | ||
|
||
// SECCOMP | ||
if data != nil { | ||
if value, exists := data.Annotations[seccompAnnotationKey]; exists { | ||
secConfig.SeccompProfileFromImage = value | ||
} | ||
} | ||
if policy, err := cc.LookupSeccompPolicy(c.String("seccomp-policy")); err != nil { | ||
return nil, err | ||
} else { | ||
secConfig.SeccompPolicy = policy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where this is actually consumed - where are we trying to decode/use the image seccomp annotation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're doing that in |
||
} | ||
|
||
config := &cc.CreateConfig{ | ||
Annotations: annotations, | ||
BuiltinImgVolumes: ImageVolumes, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// +build !remoteclient | ||
|
||
package integration | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/containers/libpod/test/utils" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Podman run", func() { | ||
var ( | ||
tempdir string | ||
err error | ||
podmanTest *PodmanTestIntegration | ||
) | ||
|
||
BeforeEach(func() { | ||
tempdir, err = CreateTempDirInTempDir() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
podmanTest = PodmanTestCreate(tempdir) | ||
podmanTest.Setup() | ||
podmanTest.SeedImages() | ||
}) | ||
|
||
AfterEach(func() { | ||
podmanTest.Cleanup() | ||
f := CurrentGinkgoTestDescription() | ||
processTestResult(f) | ||
|
||
}) | ||
|
||
It("podman run --seccomp-policy default", func() { | ||
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "default", alpineSeccomp, "ls"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
}) | ||
|
||
It("podman run --seccomp-policy ''", func() { | ||
// Empty string is interpreted as "default". | ||
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "", alpineSeccomp, "ls"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session.ExitCode()).To(Equal(0)) | ||
}) | ||
|
||
It("podman run --seccomp-policy invalid", func() { | ||
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "invalid", alpineSeccomp, "ls"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session.ExitCode()).ToNot(Equal(0)) | ||
}) | ||
|
||
It("podman run --seccomp-policy image (block all syscalls)", func() { | ||
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "image", alpineSeccomp, "ls"}) | ||
session.WaitWithDefaultTimeout() | ||
// TODO: we're getting a "cannot start a container that has | ||
// stopped" error which seems surprising. Investigate | ||
// why that is so. | ||
Expect(session.ExitCode()).ToNot(Equal(0)) | ||
}) | ||
|
||
It("podman run --seccomp-policy image (bogus profile)", func() { | ||
session := podmanTest.Podman([]string{"run", "--seccomp-policy", "image", alpineBogusSeccomp, "ls"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session.ExitCode()).To(Equal(125)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is a
return
inside theif
clause, you could happy path this.