Move apparmor to top level pkg

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-04-13 23:33:25 +00:00
parent 811700f9f4
commit 613c48e3dd
4 changed files with 1 additions and 159 deletions

View File

@ -1,35 +0,0 @@
// +build apparmor,linux,amd64
package apparmor
// #cgo LDFLAGS: -lapparmor
// #include <sys/apparmor.h>
// #include <stdlib.h>
import "C"
import (
"io/ioutil"
"os"
"unsafe"
)
func IsEnabled() bool {
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
return err == nil && len(buf) > 1 && buf[0] == 'Y'
}
return false
}
func ApplyProfile(pid int, name string) error {
if name == "" {
return nil
}
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
if _, err := C.aa_change_onexec(cName); err != nil {
return err
}
return nil
}

View File

@ -1,13 +0,0 @@
// +build !apparmor !linux !amd64
package apparmor
import ()
func IsEnabled() bool {
return false
}
func ApplyProfile(pid int, name string) error {
return nil
}

View File

@ -1,110 +0,0 @@
package apparmor
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
)
const (
DefaultProfilePath = "/etc/apparmor.d/docker"
)
const DefaultProfile = `
#include <tunables/global>
profile docker-default flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/base>
network,
capability,
file,
umount,
mount fstype=tmpfs,
mount fstype=mqueue,
mount fstype=fuse.*,
mount fstype=binfmt_misc -> /proc/sys/fs/binfmt_misc/,
mount fstype=efivarfs -> /sys/firmware/efi/efivars/,
mount fstype=fusectl -> /sys/fs/fuse/connections/,
mount fstype=securityfs -> /sys/kernel/security/,
mount fstype=debugfs -> /sys/kernel/debug/,
mount fstype=proc -> /proc/,
mount fstype=sysfs -> /sys/,
deny @{PROC}/sys/fs/** wklx,
deny @{PROC}/sysrq-trigger rwklx,
deny @{PROC}/mem rwklx,
deny @{PROC}/kmem rwklx,
deny @{PROC}/sys/kernel/[^s][^h][^m]* wklx,
deny @{PROC}/sys/kernel/*/** wklx,
deny mount options=(ro, remount) -> /,
deny mount fstype=debugfs -> /var/lib/ureadahead/debugfs/,
deny mount fstype=devpts,
deny /sys/[^f]*/** wklx,
deny /sys/f[^s]*/** wklx,
deny /sys/fs/[^c]*/** wklx,
deny /sys/fs/c[^g]*/** wklx,
deny /sys/fs/cg[^r]*/** wklx,
deny /sys/firmware/efi/efivars/** rwklx,
deny /sys/kernel/security/** rwklx,
}
`
func InstallDefaultProfile(backupPath string) error {
if !IsEnabled() {
return nil
}
// 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(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
if err := os.MkdirAll(path.Dir(DefaultProfilePath), 0755); err != nil {
return err
}
if err := ioutil.WriteFile(DefaultProfilePath, []byte(DefaultProfile), 0644); err != nil {
return err
}
// the current functionality of the load script is the exit 0 if the parser does not exist.
// we think we should fail loudly if you have apparmor enabled but not the parser to load
// the profile for use.
output, err := exec.Command("/sbin/apparmor_parser", "-r", "-W", "docker").CombinedOutput()
if err != nil {
return fmt.Errorf("Error loading docker profile: %s (%s)", err, output)
}
return nil
}

View File

@ -8,9 +8,9 @@ import (
"runtime"
"syscall"
"github.com/dotcloud/docker/pkg/apparmor"
"github.com/dotcloud/docker/pkg/label"
"github.com/dotcloud/docker/pkg/libcontainer"
"github.com/dotcloud/docker/pkg/libcontainer/apparmor"
"github.com/dotcloud/docker/pkg/libcontainer/capabilities"
"github.com/dotcloud/docker/pkg/libcontainer/network"
"github.com/dotcloud/docker/pkg/libcontainer/utils"