@@ -18,6 +18,18 @@ import (
18
18
19
19
var generateFlags = []cli.Flag {
20
20
cli.StringSliceFlag {Name : "args" , Usage : "command to run in the container" },
21
+ << << << < 9e0 e42dbf918070406a2a4a2e1476e7350ba9129
22
+ == == == =
23
+ cli.StringSliceFlag {Name : "bind" , Usage : "bind mount directories src:dest[:options...]" },
24
+ cli.StringSliceFlag {Name : "cap-add" , Usage : "add Linux capabilities" },
25
+ cli.StringSliceFlag {Name : "cap-drop" , Usage : "drop Linux capabilities" },
26
+ cli.StringFlag {Name : "cgroup" , Usage : "cgroup namespace" },
27
+ cli.StringFlag {Name : "cgroups-path" , Usage : "specify the path to the cgroups" },
28
+ cli.StringFlag {Name : "cwd" , Value : "/" , Usage : "current working directory for the process" },
29
+ cli.StringSliceFlag {Name : "device-access-add" , Usage : "add a device access rule" },
30
+ cli.StringSliceFlag {Name : "device-access-remove" , Usage : "remove a device access rule" },
31
+ cli.BoolFlag {Name : "disable-oom-kill" , Usage : "disable OOM Killer" },
32
+ >> >> >> > generate : add - - device - access - add and - - device - access - remove option
21
33
cli.StringSliceFlag {Name : "env" , Usage : "add environment variable e.g. key=value" },
22
34
cli.StringSliceFlag {Name : "env-file" , Usage : "read in a file of environment variables" },
23
35
cli.StringSliceFlag {Name : "hooks-poststart" , Usage : "set command to run in poststart hooks" },
@@ -234,8 +246,35 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
234
246
g .SetLinuxCgroupsPath (context .String ("linux-cgroups-path" ))
235
247
}
236
248
249
+ << << << < 9e0 e42dbf918070406a2a4a2e1476e7350ba9129
237
250
if context .IsSet ("linux-masked-paths" ) {
238
251
paths := context .StringSlice ("linux-masked-paths" )
252
+ == == == =
253
+ if context .IsSet ("device-access-add" ) {
254
+ devices := context .StringSlice ("device-access-add" )
255
+ for _ , device := range devices {
256
+ dev , err := parseLinuxResourcesDeviceAccess (device , g )
257
+ if err != nil {
258
+ return err
259
+ }
260
+ g .AddLinuxResourcesDevice (dev .Allow , dev .Type , dev .Major , dev .Minor , dev .Access )
261
+ }
262
+ }
263
+
264
+ if context .IsSet ("device-access-remove" ) {
265
+ devices := context .StringSlice ("device-access-remove" )
266
+ for _ , device := range devices {
267
+ dev , err := parseLinuxResourcesDeviceAccess (device , g )
268
+ if err != nil {
269
+ return err
270
+ }
271
+ g .RemoveLinuxResourcesDevice (dev .Allow , dev .Type , dev .Major , dev .Minor , dev .Access )
272
+ }
273
+ }
274
+
275
+ if context .IsSet ("masked-paths" ) {
276
+ paths := context .StringSlice ("masked-paths" )
277
+ >> >> >> > generate: add -- device - access - add and -- device - access - remove option
239
278
for _ , path := range paths {
240
279
g .AddLinuxMaskedPaths (path )
241
280
}
@@ -811,6 +850,7 @@ func parseRlimit(rlimit string) (string, uint64, uint64, error) {
811
850
return parts [0 ], uint64 (hard ), uint64 (soft ), nil
812
851
}
813
852
853
+ << << << < 9e0 e42dbf918070406a2a4a2e1476e7350ba9129
814
854
func parseNamespace (ns string ) (string , string , error ) {
815
855
parts := strings .SplitN (ns , ":" , 2 )
816
856
if len (parts ) == 0 || parts [0 ] == "" {
@@ -904,6 +944,82 @@ func parseDevice(device string, g *generate.Generator) (rspec.LinuxDevice, error
904
944
}
905
945
906
946
return dev , nil
947
+ == == == =
948
+ var cgroupDeviceType = map [string ]bool {
949
+ "a" : true , // all
950
+ "b" : true , // block device
951
+ "c" : true , // character device
952
+ }
953
+ var cgroupDeviceAccess = map [string ]bool {
954
+ "r" : true , //read
955
+ "w" : true , //write
956
+ "m" : true , //mknod
957
+ }
958
+
959
+ // parseLinuxResourcesDeviceAccess parses the raw string passed with the --device-access-add flag
960
+ func parseLinuxResourcesDeviceAccess (device string , g * generate.Generator ) (rspec.DeviceCgroup , error ) {
961
+ var allow bool
962
+ var devType , access * string
963
+ var major , minor * int64
964
+
965
+ argsParts := strings .Split (device , "," )
966
+
967
+ switch argsParts [0 ] {
968
+ case "allow" :
969
+ allow = true
970
+ case "deny" :
971
+ allow = false
972
+ default :
973
+ return rspec.DeviceCgroup {},
974
+ fmt .Errorf ("Only 'allow' and 'deny' are allowed in the first field of device-access-add: %s" , device )
975
+ }
976
+
977
+ for _ , s := range argsParts [1 :] {
978
+ s = strings .TrimSpace (s )
979
+ if s == "" {
980
+ continue
981
+ }
982
+ parts := strings .SplitN (s , "=" , 2 )
983
+ if len (parts ) != 2 {
984
+ return rspec.DeviceCgroup {}, fmt .Errorf ("Incomplete device-access-add arguments: %s" , s )
985
+ }
986
+ name , value := parts [0 ], parts [1 ]
987
+
988
+ switch name {
989
+ case "type" :
990
+ if ! cgroupDeviceType [value ] {
991
+ return rspec.DeviceCgroup {}, fmt .Errorf ("Invalid device type in device-access-add: %s" , value )
992
+ }
993
+ devType = & value
994
+ case "major" :
995
+ i , err := strconv .ParseInt (value , 10 , 64 )
996
+ if err != nil {
997
+ return rspec.DeviceCgroup {}, err
998
+ }
999
+ major = & i
1000
+ case "minor" :
1001
+ i , err := strconv .ParseInt (value , 10 , 64 )
1002
+ if err != nil {
1003
+ return rspec.DeviceCgroup {}, err
1004
+ }
1005
+ minor = & i
1006
+ case "access" :
1007
+ for _ , c := range strings .Split (value , "" ) {
1008
+ if ! cgroupDeviceAccess [c ] {
1009
+ return rspec.DeviceCgroup {}, fmt .Errorf ("Invalid device access in device-access-add: %s" , c )
1010
+ }
1011
+ }
1012
+ access = & value
1013
+ }
1014
+ }
1015
+ return rspec.DeviceCgroup {
1016
+ Allow : allow ,
1017
+ Type : devType ,
1018
+ Major : major ,
1019
+ Minor : minor ,
1020
+ Access : access ,
1021
+ }, nil
1022
+ >> >> >> > generate: add -- device - access - add and -- device - access - remove option
907
1023
}
908
1024
909
1025
func addSeccomp (context * cli.Context , g * generate.Generator ) error {
0 commit comments