Skip to content

Commit 2dd6fa3

Browse files
authored
Merge pull request containerd#10111 from AkihiroSuda/nerdctl-issue-2730
apparmor: add `signal (receive) peer=/usr/local/bin/rootlesskit,`
2 parents 444679c + eb5a0c0 commit 2dd6fa3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contrib/apparmor/template.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"path"
3030
"strings"
3131
"text/template"
32+
33+
"github.com/containerd/log"
3234
)
3335

3436
// NOTE: This code is copied from <github.com/docker/docker/profiles/apparmor>.
@@ -57,6 +59,10 @@ profile {{.Name}} flags=(attach_disconnected,mediate_deleted) {
5759
signal (receive) peer={{.DaemonProfile}},
5860
# Container processes may send signals amongst themselves.
5961
signal (send,receive) peer={{.Name}},
62+
{{if .RootlessKit}}
63+
# https://github.com/containerd/nerdctl/issues/2730
64+
signal (receive) peer={{.RootlessKit}},
65+
{{end}}
6066
6167
deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir)
6268
# deny write to files not in /proc/<number>/** or /proc/sys/**
@@ -90,6 +96,7 @@ type data struct {
9096
Imports []string
9197
InnerImports []string
9298
DaemonProfile string
99+
RootlessKit string
93100
}
94101

95102
func cleanProfileName(profile string) string {
@@ -125,6 +132,16 @@ func loadData(name string) (*data, error) {
125132
}
126133
p.DaemonProfile = cleanProfileName(string(currentProfile))
127134

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+
128145
return &p, nil
129146
}
130147

0 commit comments

Comments
 (0)