-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathtemplate.go
More file actions
72 lines (63 loc) · 2.69 KB
/
template.go
File metadata and controls
72 lines (63 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright The Moby Authors.
// SPDX-License-Identifier: Apache-2.0
//go:build linux
package apparmor
// NOTE: This profile is replicated in containerd and libpod. If you make a
// change to this profile, please make follow-up PRs to those projects so
// that these rules can be synchronised (because any issue with this
// profile will likely affect libpod and containerd).
// baseTemplate defines the default apparmor profile for containers.
//
// It explicitly sets the AppArmor ABI to 3.0. In AppArmor ABI higher than 4.0,
// "network" no longer includes "network unix", resulting in access to unix sockets
// being denied. We use ABI 3.0 to account for some LTS distros that do not
// yet support ABI 4.0.
//
// See https://gitlab.com/apparmor/apparmor/-/issues/561
// And https://github.com/containerd/containerd/issues/12726
const baseTemplate = `# profile generated by github.com/moby/profiles/apparmor.
{{if .Abi}}abi <{{.Abi}}>,
{{- end}}
{{range $value := .Imports}}
{{$value}}
{{- end}}
profile "{{.Name}}" flags=(attach_disconnected,mediate_deleted) {
{{- range $value := .InnerImports}}
{{$value}}
{{- end}}{{if .InnerImports}}
{{end}}
network,
capability,
file,
umount,
# Host (privileged) processes may send signals to container processes.
signal (receive) peer=unconfined,
# runc may send signals to container processes (for "docker stop").
signal (receive) peer=runc,
# crun may send signals to container processes (for "docker stop" when used with crun OCI runtime).
signal (receive) peer=crun,
# dockerd may send signals to container processes (for "docker kill").
signal (receive) peer="{{.DaemonProfile}}",
# Container processes may send signals amongst themselves.
signal (send,receive) peer="{{.Name}}",
deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir)
# deny write to files not in /proc/<number>/** or /proc/sys/**
deny @{PROC}/{[^1-9/],[^1-9/][^0-9/],[^1-9s/][^0-9y/][^0-9s/],[^1-9/][^0-9/][^0-9/][^0-9/]*}/** w,
deny @{PROC}/sys/[^k]** w, # deny /proc/sys except /proc/sys/k* (effectively /proc/sys/kernel)
deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w, # deny everything except shm* in /proc/sys/kernel/
deny @{PROC}/sysrq-trigger rwklx,
deny @{PROC}/kcore rwklx,
deny mount,
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/** rwklx,
deny /sys/devices/virtual/powercap/** rwklx,
deny /sys/kernel/security/** rwklx,
# allow processes within the container to trace each other,
# provided all other LSM and yama setting allow it.
ptrace (trace,tracedby,read,readby) peer="{{.Name}}",
}
`