From 89868cbbb623ec0cc6bdd2a12be409a2be225d53 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 21 Dec 2024 11:52:25 -0800 Subject: [PATCH] tests: add test to check StartContainer hook env This is to ensure that changes in Process.Env handling won't affect StartContainer hook. Reported-by: lfbzhm Signed-off-by: Kir Kolyshkin --- tests/integration/hooks.bats | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/integration/hooks.bats b/tests/integration/hooks.bats index 099337a2b2c..e9d62b0e6c5 100644 --- a/tests/integration/hooks.bats +++ b/tests/integration/hooks.bats @@ -42,3 +42,24 @@ function teardown() { [[ "$output" == *"error running $hook hook #1:"* ]] done } + +# While runtime-spec does not say what environment variables hooks should have, +# if not explicitly specified, historically the StartContainer hook inherited +# the process environment specified for init. +# +# Check this behavior is preserved. +@test "runc run [startContainer hook should inherit process environment]" { + cat >"rootfs/check-env.sh" <<-'EOF' + #!/bin/sh -ue + test $ONE = two + test $FOO = bar + echo $HOME # Test HOME is set w/o checking the value. + EOF + chmod +x "rootfs/check-env.sh" + + update_config ' .process.args = ["/bin/true"] + | .process.env = ["ONE=two", "FOO=bar"] + | .hooks |= {"startContainer": [{"path": "/check-env.sh"}]}' + runc run ct1 + [ "$status" -eq 0 ] +}