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 16
16
17
17
set -eux -o pipefail
18
18
if [[ " $( 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
19
23
if [ -e /sys/kernel/security/apparmor/profiles ]; then
20
24
# Load the "nerdctl-default" profile for TestRunApparmor
21
25
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
19
19
root=" $( cd " $( dirname " ${BASH_SOURCE[0]:- $PWD } " ) " 2> /dev/null 1>&2 && pwd) "
20
20
readonly root
21
21
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
+
22
29
readonly timeout=" 60m"
23
30
readonly retries=" 2"
24
31
readonly needsudo=" ${WITH_SUDO:- } "
Original file line number Diff line number Diff line change @@ -25,10 +25,26 @@ import (
25
25
26
26
"github.com/moby/sys/userns"
27
27
28
- "github.com/containerd/containerd/v2/pkg/apparmor"
29
28
"github.com/containerd/log"
30
29
)
31
30
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
+
32
48
// CanLoadNewProfile returns whether the current process can load a new AppArmor profile.
33
49
//
34
50
// CanLoadNewProfile needs root.
@@ -37,7 +53,7 @@ import (
37
53
//
38
54
// Related: https://gitlab.com/apparmor/apparmor/-/blob/v3.0.3/libraries/libapparmor/src/kernel.c#L311
39
55
func CanLoadNewProfile () bool {
40
- return ! userns .RunningInUserNS () && os .Geteuid () == 0 && apparmor . HostSupports ()
56
+ return ! userns .RunningInUserNS () && os .Geteuid () == 0 && hostSupports ()
41
57
}
42
58
43
59
var (
You can’t perform that action at this time.
0 commit comments