-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this test case checks that
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not test poststop?