Skip to content

Commit a9c2bd6

Browse files
Merge pull request containerd#2668 from estesp/cherry-pick-no-new-privs-flag
[release/1.1] Backport: Add flag to ctr for running with NoNewPrivileges: false
2 parents 013c509 + 3561269 commit a9c2bd6

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

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)