Skip to content

Commit c28ce39

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 05984a9 commit c28ce39

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
@@ -136,6 +136,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
136136
if context.IsSet("gpus") {
137137
opts = append(opts, nvidia.WithGPUs(nvidia.WithDevices(context.Int("gpus")), nvidia.WithAllCapabilities))
138138
}
139+
if context.IsSet("allow-new-privs") {
140+
opts = append(opts, oci.WithNewPrivileges)
141+
}
139142
}
140143

141144
cOpts = append(cOpts, containerd.WithContainerLabels(commands.LabelArgs(context.StringSlice("label"))))

oci/spec_opts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts {
268268
}
269269
}
270270

271+
// WithNewPrivileges turns off the NoNewPrivileges feature flag in the spec
272+
func WithNewPrivileges(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
273+
setProcess(s)
274+
s.Process.NoNewPrivileges = false
275+
276+
return nil
277+
}
278+
271279
// WithImageConfig configures the spec to from the configuration of an Image
272280
func WithImageConfig(image Image) SpecOpts {
273281
return WithImageConfigArgs(image, nil)

0 commit comments

Comments
 (0)