cli: add guest hook path option in the configuration file

Add support for specifying an optional drop-in path for guest OCI hooks.
This is the runtime side for leveraging the agent change introduced in
kata-containers/agent@980023ec62

Fixes: #720

Co-authored-by: Edward Guzman <eguzman@nvidia.com>
Co-authored-by: Felix Abecassis <fabecassis@nvidia.com>
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
This commit is contained in:
Felix Abecassis 2018-10-29 13:06:22 -07:00
parent 6d17e27de0
commit 33abb3ecf8
6 changed files with 54 additions and 4 deletions

View File

@ -328,6 +328,7 @@ const defaultDisableNestingChecks bool = $(DEFDISABLENESTINGCHECKS)
const defaultMsize9p uint32 = $(DEFMSIZE9P) const defaultMsize9p uint32 = $(DEFMSIZE9P)
const defaultHotplugVFIOOnRootBus bool = $(DEFHOTPLUGVFIOONROOTBUS) const defaultHotplugVFIOOnRootBus bool = $(DEFHOTPLUGVFIOONROOTBUS)
const defaultEntropySource = "$(DEFENTROPYSOURCE)" const defaultEntropySource = "$(DEFENTROPYSOURCE)"
const defaultGuestHookPath string = ""
// Default config file used by stateless systems. // Default config file used by stateless systems.
var defaultRuntimeConfiguration = "$(CONFIG_PATH)" var defaultRuntimeConfiguration = "$(CONFIG_PATH)"

View File

@ -98,6 +98,7 @@ type hypervisor struct {
UseVSock bool `toml:"use_vsock"` UseVSock bool `toml:"use_vsock"`
HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"` HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"`
DisableVhostNet bool `toml:"disable_vhost_net"` DisableVhostNet bool `toml:"disable_vhost_net"`
GuestHookPath string `toml:"guest_hook_path"`
} }
type proxy struct { type proxy struct {
@ -303,6 +304,13 @@ func (h hypervisor) useVSock() bool {
return h.UseVSock return h.UseVSock
} }
func (h hypervisor) guestHookPath() string {
if h.GuestHookPath == "" {
return defaultGuestHookPath
}
return h.GuestHookPath
}
func (p proxy) path() string { func (p proxy) path() string {
if p.Path == "" { if p.Path == "" {
return defaultProxyPath return defaultProxyPath
@ -427,6 +435,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
UseVSock: useVSock, UseVSock: useVSock,
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus, HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
DisableVhostNet: h.DisableVhostNet, DisableVhostNet: h.DisableVhostNet,
GuestHookPath: h.guestHookPath(),
}, nil }, nil
} }
@ -548,6 +557,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
EnableIOThreads: defaultEnableIOThreads, EnableIOThreads: defaultEnableIOThreads,
Msize9p: defaultMsize9p, Msize9p: defaultMsize9p,
HotplugVFIOOnRootBus: defaultHotplugVFIOOnRootBus, HotplugVFIOOnRootBus: defaultHotplugVFIOOnRootBus,
GuestHookPath: defaultGuestHookPath,
} }
err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel) err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)

View File

@ -167,6 +167,23 @@ enable_iothreads = @DEFENABLEIOTHREADS@
# all practical purposes. # all practical purposes.
#entropy_source= "@DEFENTROPYSOURCE@" #entropy_source= "@DEFENTROPYSOURCE@"
# Path to OCI hook binaries in the *guest rootfs*.
# This does not affect host-side hooks which must instead be added to
# the OCI spec passed to the runtime.
#
# You can create a rootfs with hooks by customizing the osbuilder scripts:
# https://github.com/kata-containers/osbuilder
#
# Hooks must be stored in a subdirectory of guest_hook_path according to their
# hook type, i.e. "guest_hook_path/{prestart,postart,poststop}".
# The agent will scan these directories for executable files and add them, in
# lexicographical order, to the lifecycle of the guest container.
# Hooks are executed in the runtime namespace of the guest. See the official documentation:
# https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks
# Warnings will be logged if any error is encountered will scanning for hooks,
# but it will not abort container execution.
#guest_hook_path = "/usr/share/oci/hooks"
[factory] [factory]
# VM templating support. Once enabled, new VMs are created from template # VM templating support. Once enabled, new VMs are created from template
# using vm cloning. They will share the same initial kernel, initramfs and # using vm cloning. They will share the same initial kernel, initramfs and

View File

@ -61,6 +61,7 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
hotplug_vfio_on_root_bus = ` + strconv.FormatBool(hotplugVFIOOnRootBus) + ` hotplug_vfio_on_root_bus = ` + strconv.FormatBool(hotplugVFIOOnRootBus) + `
msize_9p = ` + strconv.FormatUint(uint64(defaultMsize9p), 10) + ` msize_9p = ` + strconv.FormatUint(uint64(defaultMsize9p), 10) + `
enable_debug = ` + strconv.FormatBool(hypervisorDebug) + ` enable_debug = ` + strconv.FormatBool(hypervisorDebug) + `
guest_hook_path = "` + defaultGuestHookPath + `"
[proxy.kata] [proxy.kata]
enable_debug = ` + strconv.FormatBool(proxyDebug) + ` enable_debug = ` + strconv.FormatBool(proxyDebug) + `
@ -163,6 +164,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
Msize9p: defaultMsize9p, Msize9p: defaultMsize9p,
MemSlots: defaultMemSlots, MemSlots: defaultMemSlots,
EntropySource: defaultEntropySource, EntropySource: defaultEntropySource,
GuestHookPath: defaultGuestHookPath,
} }
agentConfig := vc.KataAgentConfig{} agentConfig := vc.KataAgentConfig{}
@ -599,6 +601,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
Mlock: !defaultEnableSwap, Mlock: !defaultEnableSwap,
BlockDeviceDriver: defaultBlockDeviceDriver, BlockDeviceDriver: defaultBlockDeviceDriver,
Msize9p: defaultMsize9p, Msize9p: defaultMsize9p,
GuestHookPath: defaultGuestHookPath,
} }
expectedAgentConfig := vc.KataAgentConfig{} expectedAgentConfig := vc.KataAgentConfig{}
@ -1081,6 +1084,21 @@ func TestHypervisorDefaultsImage(t *testing.T) {
assert.Equal(p, "") assert.Equal(p, "")
} }
func TestHypervisorDefaultsGuestHookPath(t *testing.T) {
assert := assert.New(t)
h := hypervisor{}
guestHookPath := h.guestHookPath()
assert.Equal(guestHookPath, defaultGuestHookPath, "default guest hook path wrong")
testGuestHookPath := "/test/guest/hook/path"
h = hypervisor{
GuestHookPath: testGuestHookPath,
}
guestHookPath = h.guestHookPath()
assert.Equal(guestHookPath, testGuestHookPath, "custom guest hook path wrong")
}
func TestProxyDefaults(t *testing.T) { func TestProxyDefaults(t *testing.T) {
p := proxy{} p := proxy{}

View File

@ -250,6 +250,9 @@ type HypervisorConfig struct {
// DisableVhostNet is used to indicate if host supports vhost_net // DisableVhostNet is used to indicate if host supports vhost_net
DisableVhostNet bool DisableVhostNet bool
// GuestHookPath is the path within the VM that will be used for 'drop-in' hooks
GuestHookPath string
} }
type threadIDs struct { type threadIDs struct {

View File

@ -636,6 +636,7 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
Storages: storages, Storages: storages,
SandboxPidns: sandbox.sharePidNs, SandboxPidns: sandbox.sharePidNs,
SandboxId: sandbox.id, SandboxId: sandbox.id,
GuestHookPath: sandbox.config.HypervisorConfig.GuestHookPath,
} }
_, err = k.sendReq(req) _, err = k.sendReq(req)