Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[carry 1738] Clear hook environ variables on empty Env #4323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/integration/hooks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,42 @@ function teardown() {
[[ "$output" == *"error running $hook hook #1:"* ]]
done
}

@test "runc run [hook with env property]" {
update_config '.process.args = ["/bin/true"]'
update_config '.process.env = ["TEST_VAR=val"]'
# All hooks except Poststop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not test poststop?

for hook in prestart createRuntime createContainer startContainer poststart; do
echo "testing hook $hook"
# shellcheck disable=SC2016
update_config '.hooks = {
"'$hook'": [{
"path": "/bin/sh",
"args": ["/bin/sh", "-c", "[ \"$TEST_VAR\"==\"val\" ] && echo yes, we got val from the env TEST_VAR && exit 1 || exit 0"],
"env": ["TEST_VAR=val"]
}]
}'
TEST_VAR="val" runc run "test_hook-$hook"
[ "$status" -ne 0 ]
[[ "$output" == *"yes, we got val from the env TEST_VAR"* ]]
done
}
Comment on lines +46 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this test case checks that hooks.$name.env is set as expected ($TEST_VAR == "val", but the test code also sets the same TEST_ENV=val for

  1. process.env
  2. host env

It's not clear why 1 and 2 are needed, and why they use the same name and value.

To me, if you want to check that host env and/or process env is not leaking into hook's env, you should use different names, and check they are not present.

Or, just don't set either host or process env, and merely check that hook env is exactly the same as specified.


# https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks
@test "runc run [hook without env property should not inherit host env]" {
update_config '.process.args = ["/bin/true"]'
update_config '.process.env = ["TEST_VAR=val"]'
# All hooks except Poststop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not test poststop?

for hook in prestart createRuntime createContainer startContainer poststart; do
echo "testing hook $hook"
# shellcheck disable=SC2016
update_config '.hooks = {
"'$hook'": [{
"path": "/bin/sh",
"args": ["/bin/sh", "-c", "[[ \"$TEST_VAR\" == \"val\" ]] && echo \"$TEST_VAR\" && exit 1 || exit 0"]
}]
}'
TEST_VAR="val" runc run "test_hook-$hook"
[ "$status" -eq 0 ]
done
Comment on lines +66 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the previous @test, this one actually makes sense (but maybe add a comment that here we set TEST_VAR=val for runc run and for the process spec, and check that neither one leaks to hook's env.

}
Loading