diff --git a/hack/dind b/hack/dind index 991282e1c2..456ba861a6 100755 --- a/hack/dind +++ b/hack/dind @@ -11,8 +11,39 @@ set -e # Usage: dind CMD [ARG...] # apparmor sucks and Docker needs to know that it's in a container (c) @tianon +# +# Set the container env-var, so that AppArmor is enabled in the daemon and +# containerd when running docker-in-docker. +# +# see: https://github.com/containerd/containerd/blob/787943dc1027a67f3b52631e084db0d4a6be2ccc/pkg/apparmor/apparmor_linux.go#L29-L45 +# see: https://github.com/moby/moby/commit/de191e86321f7d3136ff42ff75826b8107399497 export container=docker +# Allow AppArmor to work inside the container; +# +# aa-status +# apparmor filesystem is not mounted. +# apparmor module is loaded. +# +# mount -t securityfs none /sys/kernel/security +# +# aa-status +# apparmor module is loaded. +# 30 profiles are loaded. +# 30 profiles are in enforce mode. +# /snap/snapd/18357/usr/lib/snapd/snap-confine +# ... +# +# Note: https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts#sys-kernel-security +# +# ## /sys/kernel/security +# +# In /sys/kernel/security mounted the securityfs interface, which allows +# configuration of Linux Security Modules. This allows configuration of +# AppArmor policies, and so access to this may allow a container to disable +# its MAC system. +# +# Given that we're running privileged already, this should not be an issue. if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then mount -t securityfs none /sys/kernel/security || { echo >&2 'Could not mount /sys/kernel/security.'