mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Backup current docker apparmor profile and replace it with the new one
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
This commit is contained in:
parent
1bcb9ce69e
commit
4f828d67f0
2 changed files with 37 additions and 7 deletions
|
@ -2,13 +2,17 @@ package apparmor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultProfilePath = "/etc/apparmor.d/docker"
|
const (
|
||||||
|
DefaultProfilePath = "/etc/apparmor.d/docker"
|
||||||
|
)
|
||||||
|
|
||||||
const DefaultProfile = `
|
const DefaultProfile = `
|
||||||
# AppArmor profile from lxc for containers.
|
# AppArmor profile from lxc for containers.
|
||||||
|
|
||||||
|
@ -73,14 +77,38 @@ profile docker-default flags=(attach_disconnected,mediate_deleted) {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
func InstallDefaultProfile() error {
|
func InstallDefaultProfile(backupPath string) error {
|
||||||
if !IsEnabled() {
|
if !IsEnabled() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the profile already exists, let it be.
|
// If the profile already exists, check if we already have a backup
|
||||||
|
// if not, do the backup and override it. (docker 0.10 upgrade changed the apparmor profile)
|
||||||
|
// see gh#5049, apparmor blocks signals in ubuntu 14.04
|
||||||
if _, err := os.Stat(DefaultProfilePath); err == nil {
|
if _, err := os.Stat(DefaultProfilePath); err == nil {
|
||||||
return nil
|
if _, err := os.Stat(backupPath); err == nil {
|
||||||
|
// If both the profile and the backup are present, do nothing
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Make sure the directory exists
|
||||||
|
if err := os.MkdirAll(path.Dir(backupPath), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the backup file
|
||||||
|
f, err := os.Create(backupPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
src, err := os.Open(DefaultProfilePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
if _, err := io.Copy(f, src); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure /etc/apparmor.d exists
|
// Make sure /etc/apparmor.d exists
|
||||||
|
|
|
@ -21,8 +21,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DriverName = "native"
|
DriverName = "native"
|
||||||
Version = "0.1"
|
Version = "0.1"
|
||||||
|
BackupApparmorProfilePath = "apparmor/docker.back" // relative to docker root
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -66,7 +67,8 @@ func NewDriver(root, initPath string) (*driver, error) {
|
||||||
if err := os.MkdirAll(root, 0700); err != nil {
|
if err := os.MkdirAll(root, 0700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := apparmor.InstallDefaultProfile(); err != nil {
|
// native driver root is at docker_root/execdriver/native. Put apparmor at docker_root
|
||||||
|
if err := apparmor.InstallDefaultProfile(filepath.Join(root, "../..", BackupApparmorProfilePath)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &driver{
|
return &driver{
|
||||||
|
|
Loading…
Add table
Reference in a new issue