ctr: Add Linux Capabilities control flags
This allows Linux Capabilities to be modified via `ctr`. e.g. ``` $ sudo ./bin/ctr run --cap-add "CAP_SYS_ADMIN" --cap-drop "CAP_NET_RAW" \ --rm docker.io/library/busybox:latest foo cat /proc/self/status | grep Cap CapInh: 00000000a82405fb CapPrm: 00000000a82405fb CapEff: 00000000a82405fb CapBnd: 00000000a82405fb CapAmb: 0000000000000000 ``` Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
This commit is contained in:
@@ -218,6 +218,24 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
)
|
||||
}
|
||||
|
||||
if caps := context.StringSlice("cap-add"); len(caps) > 0 {
|
||||
for _, cap := range caps {
|
||||
if !strings.HasPrefix(cap, "CAP_") {
|
||||
return nil, fmt.Errorf("capabilities must be specified with 'CAP_' prefix")
|
||||
}
|
||||
}
|
||||
opts = append(opts, oci.WithAddedCapabilities(caps))
|
||||
}
|
||||
|
||||
if caps := context.StringSlice("cap-drop"); len(caps) > 0 {
|
||||
for _, cap := range caps {
|
||||
if !strings.HasPrefix(cap, "CAP_") {
|
||||
return nil, fmt.Errorf("capabilities must be specified with 'CAP_' prefix")
|
||||
}
|
||||
}
|
||||
opts = append(opts, oci.WithDroppedCapabilities(caps))
|
||||
}
|
||||
|
||||
seccompProfile := context.String("seccomp-profile")
|
||||
|
||||
if !context.Bool("seccomp") && seccompProfile != "" {
|
||||
|
Reference in New Issue
Block a user