Browse code

daemon: also ensureDefaultApparmorProfile in exec path

When 567ef8e7858c ("daemon: switch to 'ensure' workflow for AppArmor
profiles") was merged, it didn't correctly handle the exec path if
AppArmor profiles were deleted. Fix this by duplicating the
ensureDefaultApparmorProfile code in the exec code.

Fixes: 567ef8e7858c ("daemon: switch to 'ensure' workflow for AppArmor profiles")
Signed-off-by: Aleksa Sarai <asarai@suse.de>
(cherry picked from commit 790a81ea9acce318d0e037771c253951b874140b)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Aleksa Sarai authored on 2017/03/13 12:57:35
Showing 1 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"github.com/docker/docker/daemon/caps"
6 6
 	"github.com/docker/docker/daemon/exec"
7 7
 	"github.com/docker/docker/libcontainerd"
8
+	"github.com/opencontainers/runc/libcontainer/apparmor"
8 9
 	"github.com/opencontainers/runtime-spec/specs-go"
9 10
 )
10 11
 
... ...
@@ -23,5 +24,27 @@ func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainer
23 23
 	if ec.Privileged {
24 24
 		p.Capabilities = caps.GetAllCapabilities()
25 25
 	}
26
+	if apparmor.IsEnabled() {
27
+		var appArmorProfile string
28
+		if c.AppArmorProfile != "" {
29
+			appArmorProfile = c.AppArmorProfile
30
+		} else if c.HostConfig.Privileged {
31
+			appArmorProfile = "unconfined"
32
+		} else {
33
+			appArmorProfile = "docker-default"
34
+		}
35
+
36
+		if appArmorProfile == "docker-default" {
37
+			// Unattended upgrades and other fun services can unload AppArmor
38
+			// profiles inadvertently. Since we cannot store our profile in
39
+			// /etc/apparmor.d, nor can we practically add other ways of
40
+			// telling the system to keep our profile loaded, in order to make
41
+			// sure that we keep the default profile enabled we dynamically
42
+			// reload it if necessary.
43
+			if err := ensureDefaultAppArmorProfile(); err != nil {
44
+				return err
45
+			}
46
+		}
47
+	}
26 48
 	return nil
27 49
 }