Skip to content

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

Merged
merged 2 commits into from
Apr 7, 2025

Conversation

rata
Copy link
Member

@rata rata commented Apr 1, 2025

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.

@rata rata added the backport/1.3-todo A PR in main branch which needs to be backported to release-1.3 label Apr 1, 2025
@rata rata requested review from kolyshkin and Copilot April 1, 2025 15:43
Copy link

@Copilot Copilot AI left a 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

@rata rata force-pushed the env-var-fixes branch 5 times, most recently from 73e1250 to d0c89e4 Compare April 1, 2025 16:15
@rata rata requested a review from lifubang April 1, 2025 16:18
@rata rata added this to the 1.3.0-rc.2 milestone Apr 1, 2025
Copy link
Contributor

@kolyshkin kolyshkin left a 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.

@rata
Copy link
Member Author

rata commented Apr 2, 2025

@kolyshkin I thought about adding tests there. The unit tests are nice, but in a big refactor they might not exist anymore. In fact, prepareEnv() didn't exist before the last refactor, it might not exist after the next one.

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)

@rata rata force-pushed the env-var-fixes branch 3 times, most recently from 21c8d53 to e705f65 Compare April 2, 2025 13:00
@rata rata marked this pull request as ready for review April 2, 2025 13:02
@rata rata requested a review from kolyshkin April 2, 2025 13:02
@rata
Copy link
Member Author

rata commented Apr 2, 2025

This indeed fixes docker CI and it's ready for review now :)

@kolyshkin
Copy link
Contributor

@kolyshkin I thought about adding tests there. The unit tests are nice, but in a big refactor they might not exist anymore. In fact, prepareEnv() didn't exist before the last refactor, it might not exist after the next one.

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.

@rata rata requested a review from kolyshkin April 3, 2025 10:58
@rata
Copy link
Member Author

rata commented Apr 3, 2025

@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.

@rata rata force-pushed the env-var-fixes branch 4 times, most recently from 95d9f3c to ba1d2eb Compare April 3, 2025 14:59
Copy link
Contributor

@kolyshkin kolyshkin left a 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!

Copy link
Contributor

@kolyshkin kolyshkin left a 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>
@rata
Copy link
Member Author

rata commented Apr 4, 2025

@kolyshkin thanks, fixed!

@kolyshkin
Copy link
Contributor

Still LGTM, thanks!

@rata
Copy link
Member Author

rata commented Apr 7, 2025

@AkihiroSuda @lifubang PTAL

@AkihiroSuda AkihiroSuda merged commit a996fe8 into opencontainers:main Apr 7, 2025
34 checks passed
@rata rata removed this from the 1.3.0-rc.2 milestone Apr 7, 2025
AkihiroSuda added a commit that referenced this pull request Apr 7, 2025
[1.3]  Override HOME if its set to the empty string #4704
@rata rata deleted the env-var-fixes branch April 8, 2025 15:25
@kolyshkin
Copy link
Contributor

1.3 backport done (included into 1.3.0-rc.2): #4711

Fixing the labels accordingly.

@kolyshkin kolyshkin added backport/1.3-done A PR in main branch which has been backported to release-1.3 and removed backport/1.3-todo A PR in main branch which needs to be backported to release-1.3 labels Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.3-done A PR in main branch which has been backported to release-1.3 kind/bug regression
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants