mirror of
https://github.com/moby/moby.git
synced 2025-12-04 19:23:06 +03:00
Align default seccomp profile with selected capabilities
Currently the default seccomp profile is fixed. This changes it so that it varies depending on the Linux capabilities selected with the --cap-add and --cap-drop options. Without this, if a user adds privileges, eg to allow ptrace with --cap-add sys_ptrace then still cannot actually use ptrace as it is still blocked by seccomp, so they will probably disable seccomp or use --privileged. With this change the syscalls that are needed for the capability are also allowed by the seccomp profile based on the selected capabilities. While this patch makes it easier to do things with for example cap_sys_admin enabled, as it will now allow creating new namespaces and use of mount, it still allows less than --cap-add cap_sys_admin --security-opt seccomp:unconfined would have previously. It is not recommended that users run containers with cap_sys_admin as this does give full access to the host machine. It also cleans up some architecture specific system calls to be only selected when needed. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
@@ -948,10 +948,10 @@ func (s *DockerSuite) TestRunSeccompDefaultProfile(c *check.C) {
|
||||
testRequires(c, SameHostDaemon, seccompEnabled, NotUserNamespace)
|
||||
|
||||
var group sync.WaitGroup
|
||||
group.Add(4)
|
||||
group.Add(11)
|
||||
errChan := make(chan error, 4)
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "acct-test")
|
||||
out, _, err := dockerCmdWithError("run", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "Operation not permitted") {
|
||||
errChan <- fmt.Errorf("expected Operation not permitted, got: %s", out)
|
||||
}
|
||||
@@ -959,13 +959,69 @@ func (s *DockerSuite) TestRunSeccompDefaultProfile(c *check.C) {
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "ns-test", "echo", "hello")
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "sys_admin", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "Operation not permitted") {
|
||||
errChan <- fmt.Errorf("expected Operation not permitted, got: %s", out)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "sys_pacct", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
errChan <- fmt.Errorf("expected No such file or directory, got: %s", out)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
errChan <- fmt.Errorf("expected No such file or directory, got: %s", out)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-drop", "ALL", "--cap-add", "sys_pacct", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
errChan <- fmt.Errorf("expected No such file or directory, got: %s", out)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "syscall-test", "ns-test", "echo", "hello0")
|
||||
if err == nil || !strings.Contains(out, "Operation not permitted") {
|
||||
errChan <- fmt.Errorf("expected Operation not permitted, got: %s", out)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "sys_admin", "syscall-test", "ns-test", "echo", "hello1")
|
||||
if err != nil || !strings.Contains(out, "hello1") {
|
||||
errChan <- fmt.Errorf("expected hello1, got: %s, %v", out, err)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-drop", "all", "--cap-add", "sys_admin", "syscall-test", "ns-test", "echo", "hello2")
|
||||
if err != nil || !strings.Contains(out, "hello2") {
|
||||
errChan <- fmt.Errorf("expected hello2, got: %s, %v", out, err)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "ns-test", "echo", "hello3")
|
||||
if err != nil || !strings.Contains(out, "hello3") {
|
||||
errChan <- fmt.Errorf("expected hello3, got: %s, %v", out, err)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "--security-opt", "seccomp=unconfined", "syscall-test", "acct-test")
|
||||
if err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
@@ -975,9 +1031,9 @@ func (s *DockerSuite) TestRunSeccompDefaultProfile(c *check.C) {
|
||||
}()
|
||||
|
||||
go func() {
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "--security-opt", "seccomp=unconfined", "syscall-test", "ns-test", "echo", "hello")
|
||||
if err != nil || !strings.Contains(out, "hello") {
|
||||
errChan <- fmt.Errorf("expected hello, got: %s, %v", out, err)
|
||||
out, _, err := dockerCmdWithError("run", "--cap-add", "ALL", "--security-opt", "seccomp=unconfined", "syscall-test", "ns-test", "echo", "hello4")
|
||||
if err != nil || !strings.Contains(out, "hello4") {
|
||||
errChan <- fmt.Errorf("expected hello4, got: %s, %v", out, err)
|
||||
}
|
||||
group.Done()
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user