mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
a1150245cc
Movified from686be57d0a
, and re-ran gofmt again to address for files not present in 20.10 and vice-versa. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit686be57d0a
) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"testing"
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/container"
|
|
"github.com/docker/docker/daemon/exec"
|
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestExecSetPlatformOpt(t *testing.T) {
|
|
if !apparmor.IsEnabled() {
|
|
t.Skip("requires AppArmor to be enabled")
|
|
}
|
|
d := &Daemon{}
|
|
c := &container.Container{AppArmorProfile: "my-custom-profile"}
|
|
ec := &exec.Config{}
|
|
p := &specs.Process{}
|
|
|
|
err := d.execSetPlatformOpt(c, ec, p)
|
|
assert.NilError(t, err)
|
|
assert.Equal(t, "my-custom-profile", p.ApparmorProfile)
|
|
}
|
|
|
|
// TestExecSetPlatformOptPrivileged verifies that `docker exec --privileged`
|
|
// does not disable AppArmor profiles. Exec currently inherits the `Privileged`
|
|
// configuration of the container. See https://github.com/moby/moby/pull/31773#discussion_r105586900
|
|
//
|
|
// This behavior may change in future, but test for the behavior to prevent it
|
|
// from being changed accidentally.
|
|
func TestExecSetPlatformOptPrivileged(t *testing.T) {
|
|
if !apparmor.IsEnabled() {
|
|
t.Skip("requires AppArmor to be enabled")
|
|
}
|
|
d := &Daemon{}
|
|
c := &container.Container{AppArmorProfile: "my-custom-profile"}
|
|
ec := &exec.Config{Privileged: true}
|
|
p := &specs.Process{}
|
|
|
|
err := d.execSetPlatformOpt(c, ec, p)
|
|
assert.NilError(t, err)
|
|
assert.Equal(t, "my-custom-profile", p.ApparmorProfile)
|
|
|
|
c.HostConfig = &containertypes.HostConfig{Privileged: true}
|
|
err = d.execSetPlatformOpt(c, ec, p)
|
|
assert.NilError(t, err)
|
|
assert.Equal(t, unconfinedAppArmorProfile, p.ApparmorProfile)
|
|
}
|