@@ -362,7 +362,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
362
362
return nil , nil , nil , err
363
363
}
364
364
365
- securityOpts , err := parseSecurityOpts (p , service .SecurityOpt )
365
+ securityOpts , unconfined , err := parseSecurityOpts (p , service .SecurityOpt )
366
366
if err != nil {
367
367
return nil , nil , nil , err
368
368
}
@@ -401,35 +401,50 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
401
401
OomScoreAdj : int (service .OomScoreAdj ),
402
402
}
403
403
404
+ if unconfined {
405
+ hostConfig .MaskedPaths = []string {}
406
+ hostConfig .ReadonlyPaths = []string {}
407
+ }
408
+
404
409
return & containerConfig , & hostConfig , networkConfig , nil
405
410
}
406
411
407
412
// copy/pasted from https://github.com/docker/cli/blob/9de1b162f/cli/command/container/opts.go#L673-L697 + RelativePath
408
413
// TODO find so way to share this code with docker/cli
409
- func parseSecurityOpts (p * types.Project , securityOpts []string ) ([]string , error ) {
410
- for key , opt := range securityOpts {
414
+ func parseSecurityOpts (p * types.Project , securityOpts []string ) ([]string , bool , error ) {
415
+ var (
416
+ unconfined bool
417
+ parsed []string
418
+ )
419
+ for _ , opt := range securityOpts {
420
+ if opt == "systempaths=unconfined" {
421
+ unconfined = true
422
+ continue
423
+ }
411
424
con := strings .SplitN (opt , "=" , 2 )
412
425
if len (con ) == 1 && con [0 ] != "no-new-privileges" {
413
426
if strings .Contains (opt , ":" ) {
414
427
con = strings .SplitN (opt , ":" , 2 )
415
428
} else {
416
- return securityOpts , errors .Errorf ("Invalid security-opt: %q" , opt )
429
+ return securityOpts , false , errors .Errorf ("Invalid security-opt: %q" , opt )
417
430
}
418
431
}
419
432
if con [0 ] == "seccomp" && con [1 ] != "unconfined" {
420
433
f , err := os .ReadFile (p .RelativePath (con [1 ]))
421
434
if err != nil {
422
- return securityOpts , errors .Errorf ("opening seccomp profile (%s) failed: %v" , con [1 ], err )
435
+ return securityOpts , false , errors .Errorf ("opening seccomp profile (%s) failed: %v" , con [1 ], err )
423
436
}
424
437
b := bytes .NewBuffer (nil )
425
438
if err := json .Compact (b , f ); err != nil {
426
- return securityOpts , errors .Errorf ("compacting json for seccomp profile (%s) failed: %v" , con [1 ], err )
439
+ return securityOpts , false , errors .Errorf ("compacting json for seccomp profile (%s) failed: %v" , con [1 ], err )
427
440
}
428
- securityOpts [key ] = fmt .Sprintf ("seccomp=%s" , b .Bytes ())
441
+ parsed = append (parsed , fmt .Sprintf ("seccomp=%s" , b .Bytes ()))
442
+ } else {
443
+ parsed = append (parsed , opt )
429
444
}
430
445
}
431
446
432
- return securityOpts , nil
447
+ return parsed , unconfined , nil
433
448
}
434
449
435
450
func (s * composeService ) prepareLabels (service types.ServiceConfig , number int ) (map [string ]string , error ) {
0 commit comments