Skip to content

Commit 5f74840

Browse files
Merge pull request #4709 from AkihiroSuda/ctr-apparmor
ctr: add AppArmor flags
2 parents 677aaad + 9d54648 commit 5f74840

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
@@ -163,6 +163,14 @@ var (
163163
Name: "seccomp-profile",
164164
Usage: "file path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile",
165165
},
166+
cli.StringFlag{
167+
Name: "apparmor-default-profile",
168+
Usage: "enable AppArmor with the default profile with the specified name, e.g. \"cri-containerd.apparmor.d\"",
169+
},
170+
cli.StringFlag{
171+
Name: "apparmor-profile",
172+
Usage: "enable AppArmor with an existing custom profile",
173+
},
166174
}
167175
)
168176

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"
@@ -206,6 +207,17 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
206207
}
207208
}
208209

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

0 commit comments

Comments
 (0)