set default seccomp profile
Signed-off-by: Jessica Frazelle <acidburn@docker.com> Upstream-commit: 947293a28084cb5ee2e10e4d128c6e2b9d9da89d Component: engine
This commit is contained in:
@@ -2858,18 +2858,25 @@ func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
|
||||
testRequires(c, Apparmor, DaemonIsLinux, NotUserNamespace)
|
||||
|
||||
name := "acidburn"
|
||||
if out, _, err := dockerCmdWithError("run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount"); err == nil || !strings.Contains(out, "Permission denied") {
|
||||
out, _, err := dockerCmdWithError("run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount")
|
||||
if err == nil ||
|
||||
!(strings.Contains(strings.ToLower(out), "permission denied") ||
|
||||
strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
c.Fatalf("unshare with --mount-proc should have failed with permission denied, got: %s, %v", out, err)
|
||||
}
|
||||
|
||||
name = "cereal"
|
||||
if out, _, err := dockerCmdWithError("run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc"); err == nil || !strings.Contains(out, "Permission denied") {
|
||||
out, _, err = dockerCmdWithError("run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
|
||||
if err == nil ||
|
||||
!(strings.Contains(strings.ToLower(out), "permission denied") ||
|
||||
strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
c.Fatalf("unshare and mount of /proc should have failed with permission denied, got: %s, %v", out, err)
|
||||
}
|
||||
|
||||
/* Ensure still fails if running privileged with the default policy */
|
||||
name = "crashoverride"
|
||||
if out, _, err := dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor:docker-default", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc"); err == nil || !(strings.Contains(strings.ToLower(out), "permission denied") || strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
out, _, err = dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor:docker-default", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
|
||||
if err == nil || !(strings.Contains(strings.ToLower(out), "permission denied") || strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
c.Fatalf("privileged unshare with apparmor should have failed with permission denied, got: %s, %v", out, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,3 +548,39 @@ func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *check.C) {
|
||||
c.Fatalf("expected chmod with seccomp profile denied to fail, got %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunSeccompProfileDenyUserns checks that 'docker run jess/unshare unshare --map-root-user --user sh -c whoami' exits with operation not permitted.
|
||||
func (s *DockerSuite) TestRunSeccompProfileDenyUserns(c *check.C) {
|
||||
testRequires(c, SameHostDaemon, seccompEnabled)
|
||||
// from sched.h
|
||||
jsonData := fmt.Sprintf(`{
|
||||
"defaultAction": "SCMP_ACT_ALLOW",
|
||||
"syscalls": [
|
||||
{
|
||||
"name": "unshare",
|
||||
"action": "SCMP_ACT_ERRNO",
|
||||
"args": [
|
||||
{
|
||||
"index": 0,
|
||||
"value": %d,
|
||||
"op": "SCMP_CMP_EQ"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}`, uint64(0x10000000))
|
||||
tmpFile, err := ioutil.TempFile("", "profile.json")
|
||||
defer tmpFile.Close()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := tmpFile.Write([]byte(jsonData)); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp:"+tmpFile.Name(), "jess/unshare", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami")
|
||||
out, _, _ := runCommandWithOutput(runCmd)
|
||||
if !strings.Contains(out, "Operation not permitted") {
|
||||
c.Fatalf("expected unshare userns with seccomp profile denied to fail, got %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user