mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +00:00
virtcontainers: Conditionally pass seccomp profile
Pass Seccomp profile to the agent only if the configuration.toml allows it to be passed and the agent/image is seccomp capable. Fixes: #688 Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
This commit is contained in:
parent
8161b4c1c1
commit
c2c9c844e2
5
Makefile
5
Makefile
@ -147,6 +147,9 @@ DEFMEMSLOTS := 10
|
|||||||
DEFBRIDGES := 1
|
DEFBRIDGES := 1
|
||||||
#Default network model
|
#Default network model
|
||||||
DEFNETWORKMODEL := macvtap
|
DEFNETWORKMODEL := macvtap
|
||||||
|
|
||||||
|
DEFDISABLEGUESTSECCOMP := true
|
||||||
|
|
||||||
#Default entropy source
|
#Default entropy source
|
||||||
DEFENTROPYSOURCE := /dev/urandom
|
DEFENTROPYSOURCE := /dev/urandom
|
||||||
|
|
||||||
@ -229,6 +232,7 @@ USER_VARS += DEFMEMSZ
|
|||||||
USER_VARS += DEFMEMSLOTS
|
USER_VARS += DEFMEMSLOTS
|
||||||
USER_VARS += DEFBRIDGES
|
USER_VARS += DEFBRIDGES
|
||||||
USER_VARS += DEFNETWORKMODEL
|
USER_VARS += DEFNETWORKMODEL
|
||||||
|
USER_VARS += DEFDISABLEGUESTSECCOMP
|
||||||
USER_VARS += DEFDISABLEBLOCK
|
USER_VARS += DEFDISABLEBLOCK
|
||||||
USER_VARS += DEFBLOCKSTORAGEDRIVER
|
USER_VARS += DEFBLOCKSTORAGEDRIVER
|
||||||
USER_VARS += DEFENABLEIOTHREADS
|
USER_VARS += DEFENABLEIOTHREADS
|
||||||
@ -398,6 +402,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
|
|||||||
-e "s|@DEFMEMSLOTS@|$(DEFMEMSLOTS)|g" \
|
-e "s|@DEFMEMSLOTS@|$(DEFMEMSLOTS)|g" \
|
||||||
-e "s|@DEFBRIDGES@|$(DEFBRIDGES)|g" \
|
-e "s|@DEFBRIDGES@|$(DEFBRIDGES)|g" \
|
||||||
-e "s|@DEFNETWORKMODEL@|$(DEFNETWORKMODEL)|g" \
|
-e "s|@DEFNETWORKMODEL@|$(DEFNETWORKMODEL)|g" \
|
||||||
|
-e "s|@DEFDISABLEGUESTSECCOMP@|$(DEFDISABLEGUESTSECCOMP)|g" \
|
||||||
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
|
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
|
||||||
-e "s|@DEFBLOCKSTORAGEDRIVER@|$(DEFBLOCKSTORAGEDRIVER)|g" \
|
-e "s|@DEFBLOCKSTORAGEDRIVER@|$(DEFBLOCKSTORAGEDRIVER)|g" \
|
||||||
-e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \
|
-e "s|@DEFENABLEIOTHREADS@|$(DEFENABLEIOTHREADS)|g" \
|
||||||
|
@ -291,6 +291,13 @@ path = "@NETMONPATH@"
|
|||||||
#
|
#
|
||||||
internetworking_model="@DEFNETWORKMODEL@"
|
internetworking_model="@DEFNETWORKMODEL@"
|
||||||
|
|
||||||
|
# disable guest seccomp
|
||||||
|
# Determines whether container seccomp profiles are passed to the virtual
|
||||||
|
# machine and applied by the kata agent. If set to true, seccomp is not applied
|
||||||
|
# within the guest
|
||||||
|
# (default: true)
|
||||||
|
disable_guest_seccomp=@DEFDISABLEGUESTSECCOMP@
|
||||||
|
|
||||||
# If enabled, the runtime will create opentracing.io traces and spans.
|
# If enabled, the runtime will create opentracing.io traces and spans.
|
||||||
# (See https://www.jaegertracing.io/docs/getting-started).
|
# (See https://www.jaegertracing.io/docs/getting-started).
|
||||||
# (default: disabled)
|
# (default: disabled)
|
||||||
|
@ -63,12 +63,13 @@ type RuntimeConfigInfo struct {
|
|||||||
|
|
||||||
// RuntimeInfo stores runtime details.
|
// RuntimeInfo stores runtime details.
|
||||||
type RuntimeInfo struct {
|
type RuntimeInfo struct {
|
||||||
Version RuntimeVersionInfo
|
Version RuntimeVersionInfo
|
||||||
Config RuntimeConfigInfo
|
Config RuntimeConfigInfo
|
||||||
Debug bool
|
Debug bool
|
||||||
Trace bool
|
Trace bool
|
||||||
DisableNewNetNs bool
|
DisableGuestSeccomp bool
|
||||||
Path string
|
DisableNewNetNs bool
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// RuntimeVersionInfo stores details of the runtime version
|
// RuntimeVersionInfo stores details of the runtime version
|
||||||
@ -174,12 +175,13 @@ func getRuntimeInfo(configFile string, config oci.RuntimeConfig) RuntimeInfo {
|
|||||||
runtimePath, _ := os.Executable()
|
runtimePath, _ := os.Executable()
|
||||||
|
|
||||||
return RuntimeInfo{
|
return RuntimeInfo{
|
||||||
Debug: config.Debug,
|
Debug: config.Debug,
|
||||||
Trace: config.Trace,
|
Trace: config.Trace,
|
||||||
Version: runtimeVersion,
|
Version: runtimeVersion,
|
||||||
Config: runtimeConfig,
|
Config: runtimeConfig,
|
||||||
Path: runtimePath,
|
Path: runtimePath,
|
||||||
DisableNewNetNs: config.DisableNewNetNs,
|
DisableNewNetNs: config.DisableNewNetNs,
|
||||||
|
DisableGuestSeccomp: config.DisableGuestSeccomp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,10 +120,11 @@ type proxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type runtime struct {
|
type runtime struct {
|
||||||
Debug bool `toml:"enable_debug"`
|
Debug bool `toml:"enable_debug"`
|
||||||
Tracing bool `toml:"enable_tracing"`
|
Tracing bool `toml:"enable_tracing"`
|
||||||
DisableNewNetNs bool `toml:"disable_new_netns"`
|
DisableNewNetNs bool `toml:"disable_new_netns"`
|
||||||
InterNetworkModel string `toml:"internetworking_model"`
|
DisableGuestSeccomp bool `toml:"disable_guest_seccomp"`
|
||||||
|
InterNetworkModel string `toml:"internetworking_model"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type shim struct {
|
type shim struct {
|
||||||
@ -795,6 +796,8 @@ func LoadConfiguration(configPath string, ignoreLogging, builtIn bool) (resolved
|
|||||||
return "", config, err
|
return "", config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.DisableGuestSeccomp = tomlConf.Runtime.DisableGuestSeccomp
|
||||||
|
|
||||||
// use no proxy if HypervisorConfig.UseVSock is true
|
// use no proxy if HypervisorConfig.UseVSock is true
|
||||||
if config.HypervisorConfig.UseVSock {
|
if config.HypervisorConfig.UseVSock {
|
||||||
kataUtilsLogger.Info("VSOCK supported, configure to not use proxy")
|
kataUtilsLogger.Info("VSOCK supported, configure to not use proxy")
|
||||||
|
@ -773,16 +773,17 @@ func (k *kataAgent) replaceOCIMountsForStorages(spec *specs.Spec, volumeStorages
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func constraintGRPCSpec(grpcSpec *grpc.Spec, systemdCgroup bool) {
|
func constraintGRPCSpec(grpcSpec *grpc.Spec, systemdCgroup bool, passSeccomp bool) {
|
||||||
// Disable Hooks since they have been handled on the host and there is
|
// Disable Hooks since they have been handled on the host and there is
|
||||||
// no reason to send them to the agent. It would make no sense to try
|
// no reason to send them to the agent. It would make no sense to try
|
||||||
// to apply them on the guest.
|
// to apply them on the guest.
|
||||||
grpcSpec.Hooks = nil
|
grpcSpec.Hooks = nil
|
||||||
|
|
||||||
// Disable Seccomp since they cannot be handled properly by the agent
|
// Pass seccomp only if disable_guest_seccomp is set to false in
|
||||||
// until we provide a guest image with libseccomp support. More details
|
// configuration.toml and guest image is seccomp capable.
|
||||||
// here: https://github.com/kata-containers/agent/issues/104
|
if passSeccomp == false {
|
||||||
grpcSpec.Linux.Seccomp = nil
|
grpcSpec.Linux.Seccomp = nil
|
||||||
|
}
|
||||||
|
|
||||||
// By now only CPU constraints are supported
|
// By now only CPU constraints are supported
|
||||||
// Issue: https://github.com/kata-containers/runtime/issues/158
|
// Issue: https://github.com/kata-containers/runtime/issues/158
|
||||||
@ -1055,9 +1056,11 @@ func (k *kataAgent) createContainer(sandbox *Sandbox, c *Container) (p *Process,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passSeccomp := !sandbox.config.DisableGuestSeccomp && sandbox.seccompSupported
|
||||||
|
|
||||||
// We need to constraint the spec to make sure we're not passing
|
// We need to constraint the spec to make sure we're not passing
|
||||||
// irrelevant information to the agent.
|
// irrelevant information to the agent.
|
||||||
constraintGRPCSpec(grpcSpec, sandbox.config.SystemdCgroup)
|
constraintGRPCSpec(grpcSpec, sandbox.config.SystemdCgroup, passSeccomp)
|
||||||
|
|
||||||
k.handleShm(grpcSpec, sandbox)
|
k.handleShm(grpcSpec, sandbox)
|
||||||
|
|
||||||
|
@ -471,11 +471,11 @@ func TestConstraintGRPCSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
constraintGRPCSpec(g, true)
|
constraintGRPCSpec(g, true, true)
|
||||||
|
|
||||||
// check nil fields
|
// check nil fields
|
||||||
assert.Nil(g.Hooks)
|
assert.Nil(g.Hooks)
|
||||||
assert.Nil(g.Linux.Seccomp)
|
assert.NotNil(g.Linux.Seccomp)
|
||||||
assert.Nil(g.Linux.Resources.Devices)
|
assert.Nil(g.Linux.Resources.Devices)
|
||||||
assert.NotNil(g.Linux.Resources.Memory)
|
assert.NotNil(g.Linux.Resources.Memory)
|
||||||
assert.Nil(g.Linux.Resources.Pids)
|
assert.Nil(g.Linux.Resources.Pids)
|
||||||
|
@ -122,6 +122,9 @@ type RuntimeConfig struct {
|
|||||||
Debug bool
|
Debug bool
|
||||||
Trace bool
|
Trace bool
|
||||||
|
|
||||||
|
//Determines if seccomp should be applied inside guest
|
||||||
|
DisableGuestSeccomp bool
|
||||||
|
|
||||||
//Determines if create a netns for hypervisor process
|
//Determines if create a netns for hypervisor process
|
||||||
DisableNewNetNs bool
|
DisableNewNetNs bool
|
||||||
}
|
}
|
||||||
@ -489,6 +492,8 @@ func SandboxConfig(ocispec CompatOCISpec, runtime RuntimeConfig, bundlePath, cid
|
|||||||
ShmSize: shmSize,
|
ShmSize: shmSize,
|
||||||
|
|
||||||
SystemdCgroup: systemdCgroup,
|
SystemdCgroup: systemdCgroup,
|
||||||
|
|
||||||
|
DisableGuestSeccomp: runtime.DisableGuestSeccomp,
|
||||||
}
|
}
|
||||||
|
|
||||||
addAssetAnnotations(ocispec, &sandboxConfig)
|
addAssetAnnotations(ocispec, &sandboxConfig)
|
||||||
|
@ -361,6 +361,8 @@ type SandboxConfig struct {
|
|||||||
|
|
||||||
// SystemdCgroup enables systemd cgroup support
|
// SystemdCgroup enables systemd cgroup support
|
||||||
SystemdCgroup bool
|
SystemdCgroup bool
|
||||||
|
|
||||||
|
DisableGuestSeccomp bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sandbox) trace(name string) (opentracing.Span, context.Context) {
|
func (s *Sandbox) trace(name string) (opentracing.Span, context.Context) {
|
||||||
@ -490,9 +492,10 @@ type Sandbox struct {
|
|||||||
|
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
|
|
||||||
shmSize uint64
|
shmSize uint64
|
||||||
sharePidNs bool
|
sharePidNs bool
|
||||||
stateful bool
|
stateful bool
|
||||||
|
seccompSupported bool
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
|
||||||
@ -734,6 +737,10 @@ func (s *Sandbox) getAndStoreGuestDetails() error {
|
|||||||
|
|
||||||
if guestDetailRes != nil {
|
if guestDetailRes != nil {
|
||||||
s.state.GuestMemoryBlockSizeMB = uint32(guestDetailRes.MemBlockSizeBytes >> 20)
|
s.state.GuestMemoryBlockSizeMB = uint32(guestDetailRes.MemBlockSizeBytes >> 20)
|
||||||
|
if guestDetailRes.AgentDetails != nil {
|
||||||
|
s.seccompSupported = guestDetailRes.AgentDetails.SupportsSeccomp
|
||||||
|
}
|
||||||
|
|
||||||
if err = s.storage.storeSandboxResource(s.id, stateFileType, s.state); err != nil {
|
if err = s.storage.storeSandboxResource(s.id, stateFileType, s.state); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user