@@ -24,7 +24,6 @@ var generateFlags = []cli.Flag{
2424 cli.StringSliceFlag {Name : "bind" , Usage : "bind mount directories src:dest[:options...]" },
2525 cli.StringSliceFlag {Name : "cap-add" , Usage : "add Linux capabilities" },
2626 cli.StringSliceFlag {Name : "cap-drop" , Usage : "drop Linux capabilities" },
27- cli.StringFlag {Name : "cgroup" , Usage : "cgroup namespace" },
2827 cli.StringFlag {Name : "cgroups-path" , Usage : "specify the path to the cgroups" },
2928 cli.StringFlag {Name : "cwd" , Value : "/" , Usage : "current working directory for the process" },
3029 cli.BoolFlag {Name : "disable-oom-kill" , Usage : "disable OOM Killer" },
@@ -34,7 +33,6 @@ var generateFlags = []cli.Flag{
3433 cli.StringSliceFlag {Name : "gidmappings" , Usage : "add GIDMappings e.g HostID:ContainerID:Size" },
3534 cli.StringSliceFlag {Name : "groups" , Usage : "supplementary groups for the process" },
3635 cli.StringFlag {Name : "hostname" , Usage : "hostname value for the container" },
37- cli.StringFlag {Name : "ipc" , Usage : "ipc namespace" },
3836 cli.StringSliceFlag {Name : "label" , Usage : "add annotations to the configuration e.g. key=value" },
3937 cli.Uint64Flag {Name : "linux-cpu-shares" , Usage : "the relative share of CPU time available to the tasks in a cgroup" },
4038 cli.Uint64Flag {Name : "linux-cpu-period" , Usage : "the CPU period to be used for hardcapping (in usecs)" },
@@ -47,21 +45,21 @@ var generateFlags = []cli.Flag{
4745 cli.Uint64Flag {Name : "linux-mem-swap" , Usage : "total memory limit (memory + swap) (in bytes)" },
4846 cli.Uint64Flag {Name : "linux-mem-swappiness" , Usage : "how aggressive the kernel will swap memory pages (Range from 0 to 100)" },
4947 cli.StringFlag {Name : "linux-mems" , Usage : "list of memory nodes in the cpuset (default is to use any available memory node)" },
48+ cli.StringSliceFlag {Name : "linux-namespace-add" , Usage : "adds a namespace to the set of namespaces to create or join of the form 'ns[:path]'" },
49+ cli.StringSliceFlag {Name : "linux-namespace-remove" , Usage : "removes a namespace from the set of namespaces to create or join of the form 'ns'" },
50+ cli.BoolFlag {Name : "linux-namespace-remove-all" , Usage : "removes all namespaces from the set of namespaces created or joined" },
5051 cli.IntFlag {Name : "linux-network-classid" , Usage : "specifies class identifier tagged by container's network packets" },
5152 cli.StringSliceFlag {Name : "linux-network-priorities" , Usage : "specifies priorities of network traffic" },
5253 cli.Int64Flag {Name : "linux-pids-limit" , Usage : "maximum number of PIDs" },
5354 cli.Uint64Flag {Name : "linux-realtime-period" , Usage : "CPU period to be used for realtime scheduling (in usecs)" },
5455 cli.Uint64Flag {Name : "linux-realtime-runtime" , Usage : "the time realtime scheduling may use (in usecs)" },
5556 cli.StringSliceFlag {Name : "masked-paths" , Usage : "specifies paths can not be read inside container" },
56- cli.StringFlag {Name : "mount" , Usage : "mount namespace" },
5757 cli.StringFlag {Name : "mount-cgroups" , Value : "no" , Usage : "mount cgroups (rw,ro,no)" },
5858 cli.StringFlag {Name : "mount-label" , Usage : "selinux mount context label" },
59- cli.StringFlag {Name : "network" , Usage : "network namespace" },
6059 cli.BoolFlag {Name : "no-new-privileges" , Usage : "set no new privileges bit for the container process" },
6160 cli.IntFlag {Name : "oom-score-adj" , Usage : "oom_score_adj for the container" },
6261 cli.StringFlag {Name : "os" , Value : runtime .GOOS , Usage : "operating system the container is created for" },
6362 cli.StringFlag {Name : "output" , Usage : "output file (defaults to stdout)" },
64- cli.StringFlag {Name : "pid" , Usage : "pid namespace" },
6563 cli.StringSliceFlag {Name : "poststart" , Usage : "set command to run in poststart hooks" },
6664 cli.StringSliceFlag {Name : "poststop" , Usage : "set command to run in poststop hooks" },
6765 cli.StringSliceFlag {Name : "prestart" , Usage : "set command to run in prestart hooks" },
@@ -91,8 +89,6 @@ var generateFlags = []cli.Flag{
9189 cli.BoolFlag {Name : "tty" , Usage : "allocate a new tty for the container process" },
9290 cli.IntFlag {Name : "uid" , Usage : "uid for the process" },
9391 cli.StringSliceFlag {Name : "uidmappings" , Usage : "add UIDMappings e.g HostID:ContainerID:Size" },
94- cli.StringFlag {Name : "user" , Usage : "user namespace" },
95- cli.StringFlag {Name : "uts" , Usage : "uts namespace" },
9692}
9793
9894var generateCommand = cli.Command {
@@ -280,8 +276,6 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
280276 }
281277 }
282278
283- needsNewUser := false
284-
285279 var uidMaps , gidMaps []string
286280
287281 if context .IsSet ("uidmappings" ) {
@@ -292,12 +286,11 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
292286 gidMaps = context .StringSlice ("gidmappings" )
293287 }
294288
289+ // Add default user namespace.
295290 if len (uidMaps ) > 0 || len (gidMaps ) > 0 {
296- needsNewUser = true
291+ g . AddOrReplaceLinuxNamespace ( "user" , "" )
297292 }
298293
299- setupLinuxNamespaces (context , g , needsNewUser )
300-
301294 if context .IsSet ("tmpfs" ) {
302295 tmpfsSlice := context .StringSlice ("tmpfs" )
303296 for _ , s := range tmpfsSlice {
@@ -457,6 +450,32 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
457450 }
458451 }
459452
453+ if context .IsSet ("linux-namespace-add" ) {
454+ namespaces := context .StringSlice ("linux-namespace-add" )
455+ for _ , ns := range namespaces {
456+ name , path , err := parseNamespace (ns )
457+ if err != nil {
458+ return err
459+ }
460+ if err := g .AddOrReplaceLinuxNamespace (name , path ); err != nil {
461+ return err
462+ }
463+ }
464+ }
465+
466+ if context .IsSet ("linux-namespace-remove" ) {
467+ namespaces := context .StringSlice ("linux-namespace-remove" )
468+ for _ , name := range namespaces {
469+ if err := g .RemoveLinuxNamespace (name ); err != nil {
470+ return err
471+ }
472+ }
473+ }
474+
475+ if context .Bool ("linux-namespace-remove-all" ) {
476+ g .ClearLinuxNamespaces ()
477+ }
478+
460479 if context .IsSet ("rlimits-add" ) {
461480 rlimits := context .StringSlice ("rlimits-add" )
462481 for _ , rlimit := range rlimits {
@@ -486,20 +505,6 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
486505 return err
487506}
488507
489- func setupLinuxNamespaces (context * cli.Context , g * generate.Generator , needsNewUser bool ) {
490- for _ , nsName := range generate .Namespaces {
491- if ! context .IsSet (nsName ) && ! (needsNewUser && nsName == "user" ) {
492- continue
493- }
494- nsPath := context .String (nsName )
495- if nsPath == "host" {
496- g .RemoveLinuxNamespace (nsName )
497- continue
498- }
499- g .AddOrReplaceLinuxNamespace (nsName , nsPath )
500- }
501- }
502-
503508func parseIDMapping (idms string ) (uint32 , uint32 , uint32 , error ) {
504509 idm := strings .Split (idms , ":" )
505510 if len (idm ) != 3 {
@@ -604,6 +609,22 @@ func parseRlimit(rlimit string) (string, uint64, uint64, error) {
604609 return parts [0 ], uint64 (hard ), uint64 (soft ), nil
605610}
606611
612+ func parseNamespace (ns string ) (string , string , error ) {
613+ parts := strings .SplitN (ns , ":" , 2 )
614+ if len (parts ) == 0 || parts [0 ] == "" {
615+ return "" , "" , fmt .Errorf ("invalid namespace value: %s" , ns )
616+ }
617+
618+ nsType := parts [0 ]
619+ nsPath := ""
620+
621+ if len (parts ) == 2 {
622+ nsPath = parts [1 ]
623+ }
624+
625+ return nsType , nsPath , nil
626+ }
627+
607628func addSeccomp (context * cli.Context , g * generate.Generator ) error {
608629
609630 // Set the DefaultAction of seccomp
0 commit comments