Skip to content

Commit

Permalink
tests: add test to check StartContainer hook env
Browse files Browse the repository at this point in the history
This is to ensure that changes in Process.Env handling won't affect
StartContainer hook.

Reported-by: lfbzhm <lifubang@acmcoder.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 2, 2025
1 parent f66670d commit b125583
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/integration/hooks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}

0 comments on commit b125583

Please # to comment.