-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Override HOME if its set to the empty string #4704
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
Conversation
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.
Pull Request Overview
This PR restores the previous behavior of overriding the HOME environment variable when it’s set to an empty string, ensuring compatibility with longstanding expectations from Docker and earlier runc versions.
- Introduces a flag to determine whether HOME should be overridden.
- Adds conditional checks to preserve non-empty HOME values.
- Updates e2e tests to verify consistency with runc 1.2 behavior.
Files not reviewed (1)
- tests/integration/env.bats: Language not supported
Comments suppressed due to low confidence (1)
libcontainer/env.go:27
- [nitpick] Consider renaming 'overrideHome' to 'shouldOverrideHome' to better indicate that it's a flag controlling whether HOME should be overridden.
overrideHome := true
73e1250
to
d0c89e4
Compare
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.
WRT tests that you add -- maybe it's easier to write those in Go and add to libcontainer/env_test.go
, so all tests are in one place.
@kolyshkin I thought about adding tests there. The unit tests are nice, but in a big refactor they might not exist anymore. In fact, I really think we need e2e tests for this. I want us to be able to refactor and change heavily the way we set env vars, and have tests that catch any buggy behavior. These tests are testing runc behaves in the right way, no matter how it is implemented (that is why e2e tests instead of unit tests) |
21c8d53
to
e705f65
Compare
This indeed fixes docker CI and it's ready for review now :) |
In that case, the tests should migrate to a different place. But if you modify a function which already have a unit test, it's best to amend the unit test as well. Feel free to add bats tests, too; I understand their benefit. Just don't abandon the unit test. |
@kolyshkin Fixed all the comments and added unit tests. PTAL. I left unresolved the only comment that I think the discussion is interesting and you might want to see in more detail. |
95d9f3c
to
ba1d2eb
Compare
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.
LGTM except for a few nits (feel free to ignore). Thanks for testing runc 1.2, too, this is important.
It would be nice to add failed Docker tests links (those from this PR description) to the second commit message and/or to bats file comment.
Thanks!
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.
Almost forgot: please fix prepareEnv
docstring accordingly, i.e. something like:
-// - adds HOME to returned environment, if not found in the list.
+// - adds HOME to returned environment, if not found in the list,
+// or the value is empty.
Before commit 06f1e07 ("libct: speedup process.Env handling") we were overriding HOME if it was set to "" too[1]. But now we only override it if it wasn't set at all. This patch restores the old behavior of overriding it if it was set to an empty value. Docker relies on this behaviour since ages[2]. [1]: https://github.com/opencontainers/runc/blob/1c508045727231e7342e258ab30add1478c1f981/libcontainer/init_linux.go#L544-L549 [2]: https://github.com/moby/moby/blob/843e51459f14ebc964d349eba1013dc8a3e9d52e/integration-cli/docker_cli_run_test.go#L822-L843 Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This adds some e2e tests for environment variables set in the config.json. These were based on tests that failed on docker CI[1][2] after the refactor on 06f1e07 ("libct: speedup process.Env handling") and some bugs that I had along the way trying to fix it. These tests pass with runc 1.2 too. [1]: https://github.com/moby/moby/blob/843e51459f14ebc964d349eba1013dc8a3e9d52e/integration-cli/docker_cli_run_test.go#L822-L843 [2]: https://github.com/moby/moby/blob/843e51459f14ebc964d349eba1013dc8a3e9d52e/integration-cli/docker_cli_links_test.go#L197-L204 Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
@kolyshkin thanks, fixed! |
Still LGTM, thanks! |
@AkihiroSuda @lifubang PTAL |
[1.3] Override HOME if its set to the empty string #4704
1.3 backport done (included into 1.3.0-rc.2): #4711 Fixing the labels accordingly. |
I'm testing runc 1.3 in docker CI and I found these issues.
I've also added some e2e tests and verified that runc 1.2 behaves the same way.
Below the commit msg of the fix, but see each commit msg for more details
Before commit 06f1e07 ("libct: speedup process.Env handling") we were
overriding HOME if it was set to "" too1. But now we only override it
if it wasn't set at all.
This patch restores the old behavior of overriding it if it was set to
an empty value.
Docker relies on this behaviour since ages2.