Skip to content

Commit 3561269

Browse files
committed
Add flag to ctr for running with NoNewPrivileges: false
Add flag and With-helper to set NoNewPrivileges to false since it is on by default in the default UNIX spec for containerd, but off by default in Docker and CRI plugin use. This allows for easy testing with it off for comparison. Signed-off-by: Phil Estes <[email protected]>
1 parent 013c509 commit 3561269

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

cmd/ctr/commands/commands.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ var (
124124
Name: "gpus",
125125
Usage: "add gpus to the container",
126126
},
127+
cli.BoolFlag{
128+
Name: "allow-new-privs",
129+
Usage: "turn off OCI spec's NoNewPrivileges feature flag",
130+
},
127131
}
128132
)
129133

cmd/ctr/commands/run/run_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
113113
Path: parts[1],
114114
}))
115115
}
116+
if context.IsSet("allow-new-privs") {
117+
opts = append(opts, oci.WithNewPrivileges)
118+
}
116119
if context.IsSet("config") {
117120
var s specs.Spec
118121
if err := loadSpec(context.String("config"), &s); err != nil {

oci/spec_opts_unix.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ func WithNoNewPrivileges(_ context.Context, _ Client, _ *containers.Container, s
172172
return nil
173173
}
174174

175+
// WithNewPrivileges turns off the NoNewPrivileges feature flag in the spec
176+
func WithNewPrivileges(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
177+
setProcess(s)
178+
s.Process.NoNewPrivileges = false
179+
180+
return nil
181+
}
182+
175183
// WithHostHostsFile bind-mounts the host's /etc/hosts into the container as readonly
176184
func WithHostHostsFile(_ context.Context, _ Client, _ *containers.Container, s *specs.Spec) error {
177185
s.Mounts = append(s.Mounts, specs.Mount{

0 commit comments

Comments
 (0)