@@ -29,6 +29,8 @@ import (
29
29
"path"
30
30
"strings"
31
31
"text/template"
32
+
33
+ "github.com/containerd/log"
32
34
)
33
35
34
36
// NOTE: This code is copied from <github.com/docker/docker/profiles/apparmor>.
@@ -57,6 +59,10 @@ profile {{.Name}} flags=(attach_disconnected,mediate_deleted) {
57
59
signal (receive) peer={{.DaemonProfile}},
58
60
# Container processes may send signals amongst themselves.
59
61
signal (send,receive) peer={{.Name}},
62
+ {{if .RootlessKit}}
63
+ # https://github.com/containerd/nerdctl/issues/2730
64
+ signal (receive) peer={{.RootlessKit}},
65
+ {{end}}
60
66
61
67
deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir)
62
68
# deny write to files not in /proc/<number>/** or /proc/sys/**
@@ -90,6 +96,7 @@ type data struct {
90
96
Imports []string
91
97
InnerImports []string
92
98
DaemonProfile string
99
+ RootlessKit string
93
100
}
94
101
95
102
func cleanProfileName (profile string ) string {
@@ -125,6 +132,16 @@ func loadData(name string) (*data, error) {
125
132
}
126
133
p .DaemonProfile = cleanProfileName (string (currentProfile ))
127
134
135
+ // If we were running in Rootless mode, we could read `/proc/$(cat ${ROOTLESSKIT_STATE_DIR}/child_pid)/exe`,
136
+ // but `nerdctl apparmor load` has to be executed as the root.
137
+ // So, do not check ${ROOTLESSKIT_STATE_DIR} (nor EUID) here.
138
+ p .RootlessKit , err = exec .LookPath ("rootlesskit" )
139
+ if err != nil {
140
+ log .L .WithError (err ).Debug ("apparmor: failed to determine the RootlessKit binary path" )
141
+ p .RootlessKit = ""
142
+ }
143
+ log .L .Debugf ("apparmor: RootlessKit=%q" , p .RootlessKit )
144
+
128
145
return & p , nil
129
146
}
130
147
0 commit comments