Skip to content

Commit 4339431

Browse files
authored
Merge pull request #4525 from shishir-a412ed/seccomp
ctr: CLI Flag (seccomp-profile) for setting custom seccomp profile.
2 parents cbb4e43 + 1eae524 commit 4339431

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

cmd/ctr/commands/commands.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ var (
155155
Name: "seccomp",
156156
Usage: "enable the default seccomp profile",
157157
},
158+
cli.StringFlag{
159+
Name: "seccomp-profile",
160+
Usage: "file path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile",
161+
},
158162
}
159163
)
160164

cmd/ctr/commands/run/run_unix.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package run
2020

2121
import (
2222
gocontext "context"
23+
"fmt"
2324
"path/filepath"
2425
"strconv"
2526
"strings"
@@ -185,9 +186,21 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
185186
if context.Bool("net-host") {
186187
opts = append(opts, oci.WithHostNamespace(specs.NetworkNamespace), oci.WithHostHostsFile, oci.WithHostResolvconf)
187188
}
189+
190+
seccompProfile := context.String("seccomp-profile")
191+
192+
if !context.Bool("seccomp") && seccompProfile != "" {
193+
return nil, fmt.Errorf("seccomp must be set to true, if using a custom seccomp-profile")
194+
}
195+
188196
if context.Bool("seccomp") {
189-
opts = append(opts, seccomp.WithDefaultProfile())
197+
if seccompProfile != "" {
198+
opts = append(opts, seccomp.WithProfile(seccompProfile))
199+
} else {
200+
opts = append(opts, seccomp.WithDefaultProfile())
201+
}
190202
}
203+
191204
if cpus := context.Float64("cpus"); cpus > 0.0 {
192205
var (
193206
period = uint64(100000)

0 commit comments

Comments
 (0)