github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/moby/profiles/apparmor/template.go (about)

     1  // +build linux
     2  
     3  package apparmor // import "github.com/docker/docker/profiles/apparmor"
     4  
     5  // NOTE: This profile is replicated in containerd and libpod. If you make a
     6  //       change to this profile, please make follow-up PRs to those projects so
     7  //       that these rules can be synchronised (because any issue with this
     8  //       profile will likely affect libpod and containerd).
     9  // TODO: Move this to a common project so we can maintain it in one spot.
    10  
    11  // baseTemplate defines the default apparmor profile for containers.
    12  const baseTemplate = `
    13  {{range $value := .Imports}}
    14  {{$value}}
    15  {{end}}
    16  
    17  profile {{.Name}} flags=(attach_disconnected,mediate_deleted) {
    18  {{range $value := .InnerImports}}
    19    {{$value}}
    20  {{end}}
    21  
    22    network,
    23    capability,
    24    file,
    25    umount,
    26  {{if ge .Version 208096}}
    27    # Host (privileged) processes may send signals to container processes.
    28    signal (receive) peer=unconfined,
    29    # dockerd may send signals to container processes (for "docker kill").
    30    signal (receive) peer={{.DaemonProfile}},
    31    # Container processes may send signals amongst themselves.
    32    signal (send,receive) peer={{.Name}},
    33  {{end}}
    34  
    35    deny @{PROC}/* w,   # deny write for all files directly in /proc (not in a subdir)
    36    # deny write to files not in /proc/<number>/** or /proc/sys/**
    37    deny @{PROC}/{[^1-9],[^1-9][^0-9],[^1-9s][^0-9y][^0-9s],[^1-9][^0-9][^0-9][^0-9]*}/** w,
    38    deny @{PROC}/sys/[^k]** w,  # deny /proc/sys except /proc/sys/k* (effectively /proc/sys/kernel)
    39    deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w,  # deny everything except shm* in /proc/sys/kernel/
    40    deny @{PROC}/sysrq-trigger rwklx,
    41    deny @{PROC}/kcore rwklx,
    42  
    43    deny mount,
    44  
    45    deny /sys/[^f]*/** wklx,
    46    deny /sys/f[^s]*/** wklx,
    47    deny /sys/fs/[^c]*/** wklx,
    48    deny /sys/fs/c[^g]*/** wklx,
    49    deny /sys/fs/cg[^r]*/** wklx,
    50    deny /sys/firmware/** rwklx,
    51    deny /sys/kernel/security/** rwklx,
    52  
    53  {{if ge .Version 208095}}
    54    # suppress ptrace denials when using 'docker ps' or using 'ps' inside a container
    55    ptrace (trace,read,tracedby,readby) peer={{.Name}},
    56  {{end}}
    57  }
    58  `