github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/profiles/apparmor/template.go (about)

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