Skip to content

Commit e1b412d

Browse files
fvoznikashentubot
authored andcommitted
Error if container requires AppArmor, SELinux or seccomp
Closes google#35 PiperOrigin-RevId: 195840128 Change-Id: I31c1ad9b51ec53abb6f0b485d35622d4e9764b29
1 parent fea624b commit e1b412d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

runsc/sandbox/sandbox.go

+19
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ func validateID(id string) error {
5353
return nil
5454
}
5555

56+
func validateSpec(spec *specs.Spec) error {
57+
if spec.Process.SelinuxLabel != "" {
58+
return fmt.Errorf("SELinux is not supported: %s", spec.Process.SelinuxLabel)
59+
}
60+
61+
// Docker uses AppArmor by default, so just log that it's being ignored.
62+
if spec.Process.ApparmorProfile != "" {
63+
log.Warningf("AppArmor profile %q is being ignored", spec.Process.ApparmorProfile)
64+
}
65+
// TODO: Apply seccomp to application inside sandbox.
66+
if spec.Linux != nil && spec.Linux.Seccomp != nil {
67+
log.Warningf("Seccomp spec is being ignored")
68+
}
69+
return nil
70+
}
71+
5672
// Sandbox wraps a child sandbox process, and is responsible for saving and
5773
// loading sandbox metadata to disk.
5874
//
@@ -110,6 +126,9 @@ func Create(id string, spec *specs.Spec, conf *boot.Config, bundleDir, consoleSo
110126
if err := validateID(id); err != nil {
111127
return nil, err
112128
}
129+
if err := validateSpec(spec); err != nil {
130+
return nil, err
131+
}
113132

114133
sandboxRoot := filepath.Join(conf.RootDir, id)
115134
if exists(sandboxRoot) {

runsc/sandbox/sandbox_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,28 @@ func TestConsoleSocket(t *testing.T) {
567567
}
568568
}
569569

570+
func TestSpecUnsupported(t *testing.T) {
571+
spec := newSpecWithArgs("/bin/true")
572+
spec.Process.SelinuxLabel = "somelabel"
573+
574+
// These are normally set by docker and will just cause warnings to be logged.
575+
spec.Process.ApparmorProfile = "someprofile"
576+
spec.Linux = &specs.Linux{Seccomp: &specs.LinuxSeccomp{}}
577+
578+
rootDir, bundleDir, conf, err := setupSandbox(spec)
579+
if err != nil {
580+
t.Fatalf("error setting up sandbox: %v", err)
581+
}
582+
defer os.RemoveAll(rootDir)
583+
defer os.RemoveAll(bundleDir)
584+
585+
id := uniqueSandboxID()
586+
_, err = sandbox.Create(id, spec, conf, bundleDir, "", "", nil)
587+
if err == nil || !strings.Contains(err.Error(), "is not supported") {
588+
t.Errorf("sandbox.Create() wrong error, got: %v, want: *is not supported, spec.Process: %+v", err, spec.Process)
589+
}
590+
}
591+
570592
// procListsEqual is used to check whether 2 Process lists are equal for all
571593
// implemented fields.
572594
func procListsEqual(got, want []*control.Process) bool {

0 commit comments

Comments
 (0)