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

libpod: pass entire environment to conmon #20148

Merged
merged 1 commit into from
Sep 27, 2023

Conversation

vrothberg
Copy link
Member

Pass the entire environment to conmon instead of selectively enabling only specific variables. The main reasoning is to make sure that conmon and the podman-cleanup callback process operate in the exact same environment than the initial podman process. Some configuration files may be passed via environment variables. Podman not passing those down to conmon has led to subtle and hard to debug issues in the past, so passing all down will avoid such kinds of issues in the future.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added release-note-none do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 26, 2023
@vrothberg vrothberg marked this pull request as ready for review September 26, 2023 07:45
@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 26, 2023
Comment on lines 1316 to 1318
env = append(env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
env = append(env, fmt.Sprintf("_CONTAINERS_USERNS_CONFIGURED=%s", os.Getenv("_CONTAINERS_USERNS_CONFIGURED")))
env = append(env, fmt.Sprintf("_CONTAINERS_ROOTLESS_UID=%s", os.Getenv("_CONTAINERS_ROOTLESS_UID")))
home := homedir.Get()
if home != "" {
if home := homedir.Get(); home != "" {
env = append(env, fmt.Sprintf("HOME=%s", home))
Copy link
Member

Choose a reason for hiding this comment

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

libpod always sets XDG_RUNTIME_DIR so I don't think we need that at all and can leave the env just nil so that the golang API just passes down the env as is

@vrothberg vrothberg force-pushed the conmon-env branch 2 times, most recently from c02cd14 to c2934cc Compare September 26, 2023 11:40
@packit-as-a-service
Copy link

Cockpit tests failed for commit c02cd14eee9ab81672e967960eeacd3263fa3546. @martinpitt, @jelly, @mvollmer please check.

@packit-as-a-service
Copy link

Cockpit tests failed for commit c2934cc0373625304dbebb49e69aa6bbcaffe66d. @martinpitt, @jelly, @mvollmer please check.

@martinpitt
Copy link
Contributor

@vrothberg : That breakage of podman run -d --name test-sh-system --stop-timeout 0 quay.io/jitesoft/alpinesh, is that on your radar? (also seems to happen with busybox) Or do you need help with reproducing that regression? Thanks!

Comment on lines 1312 to 1317
if strings.HasPrefix(v, "NOTIFY_SOCKET=") {
// The NOTIFY_SOCKET cannot leak into the environment.
continue
Copy link
Member

Choose a reason for hiding this comment

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

  1. I think you can remove the startCommand() function workaround with this change

  2. Looking at the test failure I think we also need to unset XDG_RUNTIME_DIR when run as root, the problem is that when you login with ssh for example we also get XDG_RUNTIME_DIR=/run/user/0 as root so this makes crun store its files under a different location thus failing to find it.

@vrothberg
Copy link
Member Author

@vrothberg : That breakage of podman run -d --name test-sh-system --stop-timeout 0 quay.io/jitesoft/alpinesh, is that on your radar? (also seems to happen with busybox) Or do you need help with reproducing that regression? Thanks!

Thanks for checking, Martin! I will take a look

Pass the _entire_ environment to conmon instead of selectively enabling
only specific variables.  The main reasoning is to make sure that conmon
and the podman-cleanup callback process operate in the exact same
environment than the initial podman process.  Some configuration files
may be passed via environment variables.  Podman not passing those down
to conmon has led to subtle and hard to debug issues in the past, so
passing all down will avoid such kinds of issues in the future.

Signed-off-by: Valentin Rothberg <[email protected]>
@mheon
Copy link
Member

mheon commented Sep 26, 2023

Code changes LGTM

conmonEnv, err := r.configureConmonEnv()
if err != nil {
return 0, fmt.Errorf("configuring conmon env: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

LGTM. I've been trying my best to find a way to break this, like setting IFS or other nasties, and can't find any problems.

One suggestion for cleanup: if you scroll down a few lines, to 1200, cmd.Env = r.conmonEnv, that seems to be a NOP. r.conmonEnv is set above to .Engine.ConmonEnvVars, which in turn is defined in

podman/libpod/options.go

Lines 191 to 192 in 94f47d6

// WithConmonEnv specifies the environment variable list for the conmon process.
func WithConmonEnv(environment []string) RuntimeOption {
... which in turn does not seem to be invoked from anywhere. It dates back to the 2017 crio import, and I think that's all dead code. A future maintainer might appreciate not having to waste time chasing that wild goose.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch! Ough ... I really don't like how we threw containers.conf over the wall and years after still find (on a weekly basis) that many options are not tested at all :( Rushed things turn into ghosts 👻

Copy link
Member Author

Choose a reason for hiding this comment

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

@edsantiago, I made a note to fix this in another PR. I think it's time to sit down and check which containers.conf options/fields are actually used and then decide case-by-case what to do with them.

Copy link
Member Author

Choose a reason for hiding this comment

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

@baude something for 5.0.

@TomSweeneyRedHat
Copy link
Member

Changes LGTM
The rootles host boltdb test failed in a way that I've not seen before. I didn't restart.

@vrothberg
Copy link
Member Author

@Luap99 PTAL

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 35824b6 into containers:main Sep 27, 2023
97 checks passed
@vrothberg vrothberg deleted the conmon-env branch September 27, 2023 09:11
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Dec 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants