diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index 22182e81bc..b63270fba7 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -233,6 +233,7 @@ type agent struct { Debug bool `toml:"enable_debug"` Tracing bool `toml:"enable_tracing"` DebugConsoleEnabled bool `toml:"debug_console_enabled"` + DebugConsoleShell string `toml:"debug_console_shell"` DialTimeout uint32 `toml:"dial_timeout"` CdhApiTimeout uint32 `toml:"cdh_api_timeout"` LaunchProcessTimeout uint32 `toml:"launch_process_timeout"` @@ -797,6 +798,10 @@ func (a agent) debugConsoleEnabled() bool { return a.DebugConsoleEnabled } +func (a agent) debugConsoleShell() string { + return a.DebugConsoleShell +} + func (a agent) dialTimout() uint32 { return a.DialTimeout } @@ -1534,6 +1539,7 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc Trace: agent.trace(), KernelModules: agent.kernelModules(), EnableDebugConsole: agent.debugConsoleEnabled(), + DebugConsoleShell: agent.debugConsoleShell(), DialTimeout: agent.dialTimout(), CdhApiTimeout: agent.cdhApiTimout(), LaunchProcessTimeout: agent.launchProcessTimeout(), diff --git a/src/runtime/pkg/katautils/config_test.go b/src/runtime/pkg/katautils/config_test.go index e15ff00e13..d4a68e56d2 100644 --- a/src/runtime/pkg/katautils/config_test.go +++ b/src/runtime/pkg/katautils/config_test.go @@ -1841,6 +1841,36 @@ vfio_mode="vfio" assert.Equal(t, config.Runtime.VfioMode, "vfio") } +func TestLoadDropInAgentDebugConsoleShell(t *testing.T) { + tmpdir := t.TempDir() + + configPath := path.Join(tmpdir, "runtime.toml") + err := createConfig(configPath, ` +[hypervisor.qemu] +path = "/usr/bin/qemu-kvm" +[runtime] +hypervisor_name = "qemu" +agent_name = "kata" +`) + assert.NoError(t, err) + + dropInDir := path.Join(tmpdir, "config.d") + err = os.Mkdir(dropInDir, os.FileMode(0777)) + assert.NoError(t, err) + + err = createConfig(path.Join(dropInDir, "20-debug.toml"), ` +[agent.kata] +debug_console_enabled = true +debug_console_shell = "/run/kata-extensions/devkit/bin/sh" +`) + assert.NoError(t, err) + + _, runtimeConfig, err := LoadConfiguration(configPath, true) + assert.NoError(t, err) + assert.True(t, runtimeConfig.AgentConfig.EnableDebugConsole) + assert.Equal(t, "/run/kata-extensions/devkit/bin/sh", runtimeConfig.AgentConfig.DebugConsoleShell) +} + func TestUpdateRuntimeConfigHypervisor(t *testing.T) { assert := assert.New(t) diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index cc47c2f40d..dc0099d3f4 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -95,6 +95,7 @@ const ( kernelParamDebugConsole = "agent.debug_console" kernelParamDebugConsoleVPort = "agent.debug_console_vport" kernelParamDebugConsoleVPortValue = "1026" + kernelParamDebugConsoleShell = "agent.debug_console_shell" // Default SELinux type applied to the container process inside guest defaultSeLinuxContainerType = "container_t" @@ -309,6 +310,7 @@ type KataAgentConfig struct { Debug bool Trace bool EnableDebugConsole bool + DebugConsoleShell string VisibleCdiDevices bool Policy string } @@ -371,6 +373,10 @@ func KataAgentKernelParams(config KataAgentConfig) []Param { params = append(params, Param{Key: kernelParamDebugConsoleVPort, Value: kernelParamDebugConsoleVPortValue}) } + if config.DebugConsoleShell != "" { + params = append(params, Param{Key: kernelParamDebugConsoleShell, Value: config.DebugConsoleShell}) + } + if config.CdhApiTimeout > 0 { cdhApiTimeout := strconv.FormatUint(uint64(config.CdhApiTimeout), 10) params = append(params, Param{Key: vcAnnotations.CdhApiTimeoutKernelParam, Value: cdhApiTimeout}) diff --git a/src/runtime/virtcontainers/kata_agent_test.go b/src/runtime/virtcontainers/kata_agent_test.go index b38ec0683a..6e190c3ed0 100644 --- a/src/runtime/virtcontainers/kata_agent_test.go +++ b/src/runtime/virtcontainers/kata_agent_test.go @@ -1131,6 +1131,7 @@ func TestKataAgentKernelParams(t *testing.T) { containerPipeSize uint32 launchProcessTimeout uint32 visibleCdiDevices bool + debugConsoleShell string expectedParams []Param } @@ -1140,6 +1141,7 @@ func TestKataAgentKernelParams(t *testing.T) { containerPipeSizeParam := Param{Key: vcAnnotations.ContainerPipeSizeKernelParam, Value: "2097152"} launchProcessTimeoutParam := Param{Key: vcAnnotations.LaunchProcessTimeoutKernelParam, Value: "60"} visibleCdiDevicesParam := Param{Key: "agent.visible_cdi_devices", Value: "true"} + debugConsoleShellParam := Param{Key: "agent.debug_console_shell", Value: "/run/kata-extensions/devkit/bin/sh"} data := []testData{ {name: "no options", expectedParams: []Param{}}, @@ -1163,6 +1165,8 @@ func TestKataAgentKernelParams(t *testing.T) { {name: "debug and launch process timeout", debug: true, launchProcessTimeout: 60, expectedParams: []Param{debugParam, launchProcessTimeoutParam}}, {name: "visible cdi devices", visibleCdiDevices: true, expectedParams: []Param{visibleCdiDevicesParam}}, + + {name: "debug console shell", debugConsoleShell: "/run/kata-extensions/devkit/bin/sh", expectedParams: []Param{debugConsoleShellParam}}, } for _, d := range data { @@ -1175,6 +1179,7 @@ func TestKataAgentKernelParams(t *testing.T) { ContainerPipeSize: d.containerPipeSize, LaunchProcessTimeout: d.launchProcessTimeout, VisibleCdiDevices: d.visibleCdiDevices, + DebugConsoleShell: d.debugConsoleShell, } params := KataAgentKernelParams(config)