File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 1616
1717set -eux -o pipefail
1818if [[ " $( id -u) " = " 0" ]]; then
19+ # Ensure securityfs is mounted for apparmor to work
20+ if ! mountpoint -q /sys/kernel/security; then
21+ mount -tsecurityfs securityfs /sys/kernel/security
22+ fi
1923 if [ -e /sys/kernel/security/apparmor/profiles ]; then
2024 # Load the "nerdctl-default" profile for TestRunApparmor
2125 nerdctl apparmor load
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ set -o errexit -o errtrace -o functrace -o nounset -o pipefail
1919root=" $( cd " $( dirname " ${BASH_SOURCE[0]:- $PWD } " ) " 2> /dev/null 1>&2 && pwd) "
2020readonly root
2121
22+ if [[ " $( id -u) " = " 0" ]]; then
23+ # Ensure securityfs is mounted for apparmor to work
24+ if ! mountpoint -q /sys/kernel/security; then
25+ mount -tsecurityfs securityfs /sys/kernel/security
26+ fi
27+ fi
28+
2229readonly timeout=" 60m"
2330readonly retries=" 2"
2431readonly needsudo=" ${WITH_SUDO:- } "
Original file line number Diff line number Diff line change @@ -25,10 +25,26 @@ import (
2525
2626 "github.com/moby/sys/userns"
2727
28- "github.com/containerd/containerd/v2/pkg/apparmor"
2928 "github.com/containerd/log"
3029)
3130
31+ var (
32+ appArmorSupported bool
33+ checkAppArmor sync.Once
34+ )
35+
36+ // hostSupports returns true if apparmor is enabled for the host
37+ func hostSupports () bool {
38+ checkAppArmor .Do (func () {
39+ // see https://github.com/opencontainers/runc/blob/0d49470392206f40eaab3b2190a57fe7bb3df458/libcontainer/apparmor/apparmor_linux.go
40+ if _ , err := os .Stat ("/sys/kernel/security/apparmor" ); err == nil {
41+ buf , err := os .ReadFile ("/sys/module/apparmor/parameters/enabled" )
42+ appArmorSupported = err == nil && len (buf ) > 1 && buf [0 ] == 'Y'
43+ }
44+ })
45+ return appArmorSupported
46+ }
47+
3248// CanLoadNewProfile returns whether the current process can load a new AppArmor profile.
3349//
3450// CanLoadNewProfile needs root.
@@ -37,7 +53,7 @@ import (
3753//
3854// Related: https://gitlab.com/apparmor/apparmor/-/blob/v3.0.3/libraries/libapparmor/src/kernel.c#L311
3955func CanLoadNewProfile () bool {
40- return ! userns .RunningInUserNS () && os .Geteuid () == 0 && apparmor . HostSupports ()
56+ return ! userns .RunningInUserNS () && os .Geteuid () == 0 && hostSupports ()
4157}
4258
4359var (
You can’t perform that action at this time.
0 commit comments