Skip to content

Commit 9d54648

Browse files
committed
ctr: add AppArmor flags
e.g. ``` $ sudo ./bin/ctr run --apparmor-default-profile "cri-containerd.apparmor.d" docker.io/library/alpine:latest foo cat /proc/self/attr/current cri-containerd.apparmor.d (enforce) ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent 31a6d11 commit 9d54648

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

cmd/ctr/commands/commands.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ var (
159159
Name: "seccomp-profile",
160160
Usage: "file path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile",
161161
},
162+
cli.StringFlag{
163+
Name: "apparmor-default-profile",
164+
Usage: "enable AppArmor with the default profile with the specified name, e.g. \"cri-containerd.apparmor.d\"",
165+
},
166+
cli.StringFlag{
167+
Name: "apparmor-profile",
168+
Usage: "enable AppArmor with an existing custom profile",
169+
},
162170
}
163171
)
164172

cmd/ctr/commands/run/run_unix.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/containerd/containerd"
2929
"github.com/containerd/containerd/cmd/ctr/commands"
30+
"github.com/containerd/containerd/contrib/apparmor"
3031
"github.com/containerd/containerd/contrib/nvidia"
3132
"github.com/containerd/containerd/contrib/seccomp"
3233
"github.com/containerd/containerd/oci"
@@ -205,6 +206,17 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
205206
}
206207
}
207208

209+
if s := context.String("apparmor-default-profile"); len(s) > 0 {
210+
opts = append(opts, apparmor.WithDefaultProfile(s))
211+
}
212+
213+
if s := context.String("apparmor-profile"); len(s) > 0 {
214+
if len(context.String("apparmor-default-profile")) > 0 {
215+
return nil, fmt.Errorf("apparmor-profile conflicts with apparmor-default-profile")
216+
}
217+
opts = append(opts, apparmor.WithProfile(s))
218+
}
219+
208220
if cpus := context.Float64("cpus"); cpus > 0.0 {
209221
var (
210222
period = uint64(100000)

0 commit comments

Comments
 (0)