Browse code

apparmor: write & load the profile on every start

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/06/04 03:49:34
Showing 2 changed files
... ...
@@ -21,9 +21,8 @@ import (
21 21
 )
22 22
 
23 23
 const (
24
-	DriverName                = "native"
25
-	Version                   = "0.2"
26
-	BackupApparmorProfilePath = "apparmor/docker.back" // relative to docker root
24
+	DriverName = "native"
25
+	Version    = "0.2"
27 26
 )
28 27
 
29 28
 func init() {
... ...
@@ -72,7 +71,7 @@ func NewDriver(root, initPath string) (*driver, error) {
72 72
 	}
73 73
 
74 74
 	// native driver root is at docker_root/execdriver/native. Put apparmor at docker_root
75
-	if err := apparmor.InstallDefaultProfile(filepath.Join(root, "../..", BackupApparmorProfilePath)); err != nil {
75
+	if err := apparmor.InstallDefaultProfile(); err != nil {
76 76
 		return nil, err
77 77
 	}
78 78
 
... ...
@@ -2,7 +2,6 @@ package apparmor
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"io"
6 5
 	"os"
7 6
 	"os/exec"
8 7
 	"path"
... ...
@@ -12,42 +11,11 @@ const (
12 12
 	DefaultProfilePath = "/etc/apparmor.d/docker"
13 13
 )
14 14
 
15
-func InstallDefaultProfile(backupPath string) error {
15
+func InstallDefaultProfile() error {
16 16
 	if !IsEnabled() {
17 17
 		return nil
18 18
 	}
19 19
 
20
-	// If the profile already exists, check if we already have a backup
21
-	// if not, do the backup and override it. (docker 0.10 upgrade changed the apparmor profile)
22
-	// see gh#5049, apparmor blocks signals in ubuntu 14.04
23
-	if _, err := os.Stat(DefaultProfilePath); err == nil {
24
-		if _, err := os.Stat(backupPath); err == nil {
25
-			// If both the profile and the backup are present, do nothing
26
-			return nil
27
-		}
28
-		// Make sure the directory exists
29
-		if err := os.MkdirAll(path.Dir(backupPath), 0755); err != nil {
30
-			return err
31
-		}
32
-
33
-		// Create the backup file
34
-		f, err := os.Create(backupPath)
35
-		if err != nil {
36
-			return err
37
-		}
38
-		defer f.Close()
39
-
40
-		src, err := os.Open(DefaultProfilePath)
41
-		if err != nil {
42
-			return err
43
-		}
44
-		defer src.Close()
45
-
46
-		if _, err := io.Copy(f, src); err != nil {
47
-			return err
48
-		}
49
-	}
50
-
51 20
 	// Make sure /etc/apparmor.d exists
52 21
 	if err := os.MkdirAll(path.Dir(DefaultProfilePath), 0755); err != nil {
53 22
 		return err