mirror of https://github.com/docker/docs.git
change default docker-engine profile to a template based on apparmor_parser version
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
This commit is contained in:
parent
bece5b82a8
commit
8cf89245f5
|
@ -0,0 +1,85 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type profileData struct {
|
||||||
|
MajorVersion int
|
||||||
|
MinorVersion int
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
log.Fatal("pass a filename to save the profile in.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse the arg
|
||||||
|
apparmorProfilePath := os.Args[1]
|
||||||
|
|
||||||
|
// get the apparmor_version version
|
||||||
|
cmd := exec.Command("/sbin/apparmor_parser", "--version")
|
||||||
|
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("getting apparmor_parser version failed: %s (%s)", err, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse the version from the output
|
||||||
|
// output is in the form of the following:
|
||||||
|
// AppArmor parser version 2.9.1
|
||||||
|
// Copyright (C) 1999-2008 Novell Inc.
|
||||||
|
// Copyright 2009-2012 Canonical Ltd.
|
||||||
|
lines := strings.SplitN(string(output), "\n", 2)
|
||||||
|
words := strings.Split(lines[0], " ")
|
||||||
|
version := words[len(words)-1]
|
||||||
|
// split by major minor version
|
||||||
|
v := strings.Split(version, ".")
|
||||||
|
if len(v) < 2 {
|
||||||
|
log.Fatalf("parsing major minor version failed for %q", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
majorVersion, err := strconv.Atoi(v[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
minorVersion, err := strconv.Atoi(v[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
data := profileData{
|
||||||
|
MajorVersion: majorVersion,
|
||||||
|
MinorVersion: minorVersion,
|
||||||
|
}
|
||||||
|
fmt.Printf("apparmor_parser is of version %+v\n", data)
|
||||||
|
|
||||||
|
// parse the template
|
||||||
|
compiled, err := template.New("apparmor_profile").Parse(dockerProfileTemplate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("parsing template failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure /etc/apparmor.d exists
|
||||||
|
if err := os.MkdirAll(path.Dir(apparmorProfilePath), 0755); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.OpenFile(apparmorProfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
if err := compiled.Execute(f, data); err != nil {
|
||||||
|
log.Fatalf("executing template failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("created apparmor profile for version %+v at %q\n", data, apparmorProfilePath)
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
@{DOCKER_GRAPH_PATH}=/var/lib/docker
|
package main
|
||||||
|
|
||||||
|
const dockerProfileTemplate = `@{DOCKER_GRAPH_PATH}=/var/lib/docker
|
||||||
|
|
||||||
profile /usr/bin/docker (attach_disconnected, complain) {
|
profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
# Prevent following links to these files during container setup.
|
# Prevent following links to these files during container setup.
|
||||||
|
@ -15,9 +17,11 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
|
|
||||||
umount,
|
umount,
|
||||||
pivot_root,
|
pivot_root,
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
signal (receive) peer=@{profile_name},
|
signal (receive) peer=@{profile_name},
|
||||||
signal (receive) peer=unconfined,
|
signal (receive) peer=unconfined,
|
||||||
signal (send),
|
signal (send),
|
||||||
|
{{end}}{{end}}
|
||||||
ipc rw,
|
ipc rw,
|
||||||
network,
|
network,
|
||||||
capability,
|
capability,
|
||||||
|
@ -34,10 +38,12 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
/etc/localtime r,
|
/etc/localtime r,
|
||||||
/etc/ld.so.cache r,
|
/etc/ld.so.cache r,
|
||||||
|
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
ptrace peer=@{profile_name},
|
ptrace peer=@{profile_name},
|
||||||
ptrace (read) peer=docker-default,
|
ptrace (read) peer=docker-default,
|
||||||
deny ptrace (trace) peer=docker-default,
|
deny ptrace (trace) peer=docker-default,
|
||||||
deny ptrace peer=/usr/bin/docker///bin/ps,
|
deny ptrace peer=/usr/bin/docker///bin/ps,
|
||||||
|
{{end}}{{end}}
|
||||||
|
|
||||||
/usr/lib/** rm,
|
/usr/lib/** rm,
|
||||||
/lib/** rm,
|
/lib/** rm,
|
||||||
|
@ -57,9 +63,11 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
/sbin/zfs rCx,
|
/sbin/zfs rCx,
|
||||||
/sbin/apparmor_parser rCx,
|
/sbin/apparmor_parser rCx,
|
||||||
|
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
# Transitions
|
# Transitions
|
||||||
change_profile -> docker-*,
|
change_profile -> docker-*,
|
||||||
change_profile -> unconfined,
|
change_profile -> unconfined,
|
||||||
|
{{end}}{{end}}
|
||||||
|
|
||||||
profile /bin/cat (complain) {
|
profile /bin/cat (complain) {
|
||||||
/etc/ld.so.cache r,
|
/etc/ld.so.cache r,
|
||||||
|
@ -81,8 +89,10 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
/dev/null rw,
|
/dev/null rw,
|
||||||
/bin/ps mr,
|
/bin/ps mr,
|
||||||
|
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
# We don't need ptrace so we'll deny and ignore the error.
|
# We don't need ptrace so we'll deny and ignore the error.
|
||||||
deny ptrace (read, trace),
|
deny ptrace (read, trace),
|
||||||
|
{{end}}{{end}}
|
||||||
|
|
||||||
# Quiet dac_override denials
|
# Quiet dac_override denials
|
||||||
deny capability dac_override,
|
deny capability dac_override,
|
||||||
|
@ -100,11 +110,15 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
/proc/tty/drivers r,
|
/proc/tty/drivers r,
|
||||||
}
|
}
|
||||||
profile /sbin/iptables (complain) {
|
profile /sbin/iptables (complain) {
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
signal (receive) peer=/usr/bin/docker,
|
signal (receive) peer=/usr/bin/docker,
|
||||||
|
{{end}}{{end}}
|
||||||
capability net_admin,
|
capability net_admin,
|
||||||
}
|
}
|
||||||
profile /sbin/auplink flags=(attach_disconnected, complain) {
|
profile /sbin/auplink flags=(attach_disconnected, complain) {
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
signal (receive) peer=/usr/bin/docker,
|
signal (receive) peer=/usr/bin/docker,
|
||||||
|
{{end}}{{end}}
|
||||||
capability sys_admin,
|
capability sys_admin,
|
||||||
capability dac_override,
|
capability dac_override,
|
||||||
|
|
||||||
|
@ -123,7 +137,9 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
/proc/[0-9]*/mounts rw,
|
/proc/[0-9]*/mounts rw,
|
||||||
}
|
}
|
||||||
profile /sbin/modprobe /bin/kmod (complain) {
|
profile /sbin/modprobe /bin/kmod (complain) {
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
signal (receive) peer=/usr/bin/docker,
|
signal (receive) peer=/usr/bin/docker,
|
||||||
|
{{end}}{{end}}
|
||||||
capability sys_module,
|
capability sys_module,
|
||||||
/etc/ld.so.cache r,
|
/etc/ld.so.cache r,
|
||||||
/lib/** rm,
|
/lib/** rm,
|
||||||
|
@ -137,7 +153,9 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
}
|
}
|
||||||
# xz works via pipes, so we do not need access to the filesystem.
|
# xz works via pipes, so we do not need access to the filesystem.
|
||||||
profile /usr/bin/xz (complain) {
|
profile /usr/bin/xz (complain) {
|
||||||
|
{{if ge .MajorVersion 2}}{{if ge .MinorVersion 9}}
|
||||||
signal (receive) peer=/usr/bin/docker,
|
signal (receive) peer=/usr/bin/docker,
|
||||||
|
{{end}}{{end}}
|
||||||
/etc/ld.so.cache r,
|
/etc/ld.so.cache r,
|
||||||
/lib/** rm,
|
/lib/** rm,
|
||||||
/usr/bin/xz rm,
|
/usr/bin/xz rm,
|
||||||
|
@ -238,4 +256,4 @@ profile /usr/bin/docker (attach_disconnected, complain) {
|
||||||
|
|
||||||
capability mac_admin,
|
capability mac_admin,
|
||||||
}
|
}
|
||||||
}
|
}`
|
Loading…
Reference in New Issue