Skip to content

Commit efaa669

Browse files
authored
Merge pull request #441 from Mashimiao/conflicting-options
generate: solve conflicting options problem
2 parents 8447bdd + 721fbce commit efaa669

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
302302

303303
g.SetupPrivileged(context.Bool("privileged"))
304304

305+
if context.Bool("process-cap-drop-all") {
306+
g.ClearProcessCapabilities()
307+
}
308+
305309
if context.IsSet("process-cap-add-ambient") {
306310
addCaps := context.StringSlice("process-cap-add-ambient")
307311
for _, cap := range addCaps {
@@ -347,10 +351,6 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
347351
}
348352
}
349353

350-
if context.Bool("process-cap-drop-all") {
351-
g.ClearProcessCapabilities()
352-
}
353-
354354
if context.IsSet("process-cap-drop-ambient") {
355355
dropCaps := context.StringSlice("process-cap-drop-ambient")
356356
for _, cap := range dropCaps {
@@ -704,6 +704,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
704704
}
705705
}
706706

707+
if context.Bool("linux-namespace-remove-all") {
708+
g.ClearLinuxNamespaces()
709+
}
710+
707711
if context.IsSet("linux-namespace-add") {
708712
namespaces := context.StringSlice("linux-namespace-add")
709713
for _, ns := range namespaces {
@@ -726,8 +730,8 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
726730
}
727731
}
728732

729-
if context.Bool("linux-namespace-remove-all") {
730-
g.ClearLinuxNamespaces()
733+
if context.Bool("process-rlimits-remove-all") {
734+
g.ClearProcessRlimits()
731735
}
732736

733737
if context.IsSet("process-rlimits-add") {
@@ -751,8 +755,8 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
751755
}
752756
}
753757

754-
if context.Bool("process-rlimits-remove-all") {
755-
g.ClearProcessRlimits()
758+
if context.Bool("linux-device-remove-all") {
759+
g.ClearLinuxDevices()
756760
}
757761

758762
if context.IsSet("linux-device-add") {
@@ -776,10 +780,6 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
776780
}
777781
}
778782

779-
if context.Bool("linux-device-remove-all") {
780-
g.ClearLinuxDevices()
781-
}
782-
783783
err := addSeccomp(context, g)
784784
return err
785785
}
@@ -1047,6 +1047,12 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
10471047
}
10481048

10491049
func addSeccomp(context *cli.Context, g *generate.Generator) error {
1050+
if context.Bool("linux-seccomp-remove-all") {
1051+
err := g.RemoveAllSeccompRules()
1052+
if err != nil {
1053+
return err
1054+
}
1055+
}
10501056

10511057
// Set the DefaultAction of seccomp
10521058
if context.IsSet("linux-seccomp-default") {
@@ -1118,12 +1124,6 @@ func addSeccomp(context *cli.Context, g *generate.Generator) error {
11181124
}
11191125
}
11201126

1121-
if context.Bool("linux-seccomp-remove-all") {
1122-
err := g.RemoveAllSeccompRules()
1123-
if err != nil {
1124-
return err
1125-
}
1126-
}
11271127
return nil
11281128
}
11291129

man/oci-runtime-tool-generate.1.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ read the configuration from `config.json`.
165165

166166
**--linux-device-remove-all**=true|false
167167
Remove all devices for linux inside the container. The default is *false*.
168+
This option conflicts with --linux-device-add and --linux-device-remove.
169+
When combined with them, no matter what the options' order is, parse this option first.
168170

169171
**--linux-device-cgroup-add**=allow|deny[,type=TYPE][,major=MAJOR][,minor=MINOR][,access=ACCESS]
170172
Add a device control rule.
@@ -244,6 +246,8 @@ read the configuration from `config.json`.
244246
**--linux-namespace-remove-all**=true|false
245247
Removes all namespaces from the set of namespaces configured for a container,
246248
such that the container will effectively run on the host.
249+
This option conflicts with --linux-namespace-add and --linux-namespace-remove.
250+
When combined with them, no matter what the options' order is, parse this option first.
247251

248252
**--linux-network-classid**=CLASSID
249253
Specifies network class identifier which will be tagged by container's network packets.
@@ -296,14 +300,16 @@ read the configuration from `config.json`.
296300
**--linux-seccomp-kill**=SYSCALL
297301
Specifies syscalls to create seccomp rule to respond with KILL.
298302

299-
**--linux-seccomp-only**==true|false
303+
**--linux-seccomp-only**=true|false
300304
Option to only export the seccomp section of output
301305

302306
**--linux-seccomp-remove**=[]
303307
Specifies syscall restrictions to remove from the configuration.
304308

305-
**--linux-seccomp-remove-all**==true|false
309+
**--linux-seccomp-remove-all**=true|false
306310
Option to remove all syscall restrictions.
311+
This option conflicts with other --linux-seccomp-xxx options.
312+
When combined with them, no matter what the options' order is, parse this option first.
307313

308314
**--linux-seccomp-trace**=SYSCALL
309315
Specifies syscalls to create seccomp rule to respond with TRACE.
@@ -374,8 +380,10 @@ read the configuration from `config.json`.
374380
**--process-cap-add-permitted**=[]
375381
Add Linux permitted capabilities
376382

377-
**--process-cap-drop-all**true|false
383+
**--process-cap-drop-all**=true|false
378384
Drop all Linux capabilities
385+
This option conflicts with other cap options, as --process-cap-*.
386+
When combined with them, no matter what the options' order is, parse this option first.
379387

380388
**--process-cap-drop-ambient**=[]
381389
Drop Linux ambient capabilities
@@ -420,6 +428,8 @@ read the configuration from `config.json`.
420428

421429
**--process-rlimits-remove-all**=true|false
422430
Remove all resource limits for process inside the container. The default is *false*.
431+
This option conflicts with --linux-rlimits-add and --linux-rlimits-remove.
432+
When combined with them, no matter what the options' order is, parse this option first.
423433

424434
**--process-terminal**=true|false
425435
Specifies whether a terminal is attached to the process. The default is *false*.

0 commit comments

Comments
 (0)