add unshare apparmor profile test
| ... | ... |
@@ -163,7 +163,8 @@ RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker |
| 163 | 163 |
COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/ |
| 164 | 164 |
RUN ./contrib/download-frozen-image.sh /docker-frozen-images \ |
| 165 | 165 |
busybox:latest@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125 \ |
| 166 |
- hello-world:frozen@e45a5af57b00862e5ef5782a9925979a02ba2b12dff832fd0991335f4a11e5c5 |
|
| 166 |
+ hello-world:frozen@e45a5af57b00862e5ef5782a9925979a02ba2b12dff832fd0991335f4a11e5c5 \ |
|
| 167 |
+ jess/unshare@5c9f6ea50341a2a8eb6677527f2bdedbf331ae894a41714fda770fb130f3314d |
|
| 167 | 168 |
# see also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) |
| 168 | 169 |
|
| 169 | 170 |
# Download man page generator |
| ... | ... |
@@ -27,6 +27,17 @@ if [ -n "$DOCKER_STORAGE_OPTS" ]; then |
| 27 | 27 |
fi |
| 28 | 28 |
|
| 29 | 29 |
if [ -z "$DOCKER_TEST_HOST" ]; then |
| 30 |
+ # Start apparmor if it is enabled |
|
| 31 |
+ if [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then |
|
| 32 |
+ # reset container variable so apparmor profile is applied to process |
|
| 33 |
+ # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16 |
|
| 34 |
+ export container="" |
|
| 35 |
+ ( |
|
| 36 |
+ set -x |
|
| 37 |
+ /etc/init.d/apparmor start |
|
| 38 |
+ ) |
|
| 39 |
+ fi |
|
| 40 |
+ |
|
| 30 | 41 |
export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one |
| 31 | 42 |
( set -x; exec \ |
| 32 | 43 |
docker --daemon --debug \ |
| ... | ... |
@@ -9,3 +9,13 @@ for pidFile in $(find "$DEST" -name docker.pid); do |
| 9 | 9 |
echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code" |
| 10 | 10 |
fi |
| 11 | 11 |
done |
| 12 |
+ |
|
| 13 |
+if [ -z "$DOCKER_TEST_HOST" ]; then |
|
| 14 |
+ # Stop apparmor if it is enabled |
|
| 15 |
+ if [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then |
|
| 16 |
+ ( |
|
| 17 |
+ set -x |
|
| 18 |
+ /etc/init.d/apparmor stop |
|
| 19 |
+ ) |
|
| 20 |
+ fi |
|
| 21 |
+fi |
| ... | ... |
@@ -3170,3 +3170,19 @@ func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
|
| 3170 | 3170 |
dockerCmd(c, "stop", "first") |
| 3171 | 3171 |
dockerCmd(c, "stop", "second") |
| 3172 | 3172 |
} |
| 3173 |
+ |
|
| 3174 |
+func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
|
|
| 3175 |
+ testRequires(c, Apparmor) |
|
| 3176 |
+ |
|
| 3177 |
+ name := "acidburn" |
|
| 3178 |
+ runCmd := exec.Command(dockerBinary, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount") |
|
| 3179 |
+ if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Permission denied") {
|
|
| 3180 |
+ c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
|
|
| 3181 |
+ } |
|
| 3182 |
+ |
|
| 3183 |
+ name = "cereal" |
|
| 3184 |
+ runCmd = exec.Command(dockerBinary, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc") |
|
| 3185 |
+ if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Permission denied") {
|
|
| 3186 |
+ c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
|
|
| 3187 |
+ } |
|
| 3188 |
+} |
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 | 5 |
"fmt" |
| 6 |
+ "io/ioutil" |
|
| 6 | 7 |
"log" |
| 7 | 8 |
"net/http" |
| 8 | 9 |
"os/exec" |
| ... | ... |
@@ -44,6 +45,13 @@ var ( |
| 44 | 44 |
}, |
| 45 | 45 |
"Test requires network availability, environment variable set to none to run in a non-network enabled mode.", |
| 46 | 46 |
} |
| 47 |
+ Apparmor = TestRequirement{
|
|
| 48 |
+ func() bool {
|
|
| 49 |
+ buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
|
| 50 |
+ return err == nil && len(buf) > 1 && buf[0] == 'Y' |
|
| 51 |
+ }, |
|
| 52 |
+ "Test requires apparmor is enabled.", |
|
| 53 |
+ } |
|
| 47 | 54 |
RegistryHosting = TestRequirement{
|
| 48 | 55 |
func() bool {
|
| 49 | 56 |
// for now registry binary is built only if we're running inside |
| ... | ... |
@@ -78,7 +86,6 @@ var ( |
| 78 | 78 |
}, |
| 79 | 79 |
"Test requires the native (libcontainer) exec driver.", |
| 80 | 80 |
} |
| 81 |
- |
|
| 82 | 81 |
NotOverlay = TestRequirement{
|
| 83 | 82 |
func() bool {
|
| 84 | 83 |
cmd := exec.Command("grep", "^overlay / overlay", "/proc/mounts")
|