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

Allow podman to run in an environment with keys containing spaces #15434

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Aug 23, 2022

Signed-off-by: Daniel J Walsh [email protected]

Fixes: #15251

Does this PR introduce a user-facing change?

Podman will work on systemd where environment variable keys contain spaces.

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note labels Aug 23, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

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-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 23, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Aug 23, 2022

@edsantiago I don't know how we can easily test this. Could I use python to test? Or do you have a better idea?

$ python -c 'import os; os.environ["this is a test"]="foo"; os.execl("/bin/podman", "podman", "run", "alpine", "echo", "hi")'
Error: error parsing host environment variables: name "this is a test" has white spaces, poorly formatted name
$ python -c 'import os; os.environ["this is a test"]="foo"; os.execl("./bin/podman", "podman", "run", "alpine", "echo", "hi")'
hi

@rhatdan rhatdan requested a review from baude August 23, 2022 14:58
@edsantiago
Copy link
Member

What's wrong with bin/podman run -e 'foo bar=baz' --rm $IMAGE env ?

@@ -140,7 +140,7 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
// First transform the os env into a map. We need it for the labels later in
// any case.
osEnv, err := envLib.ParseSlice(os.Environ())
osEnv, err := envLib.ParseSliceIgnoreErrors(os.Environ(), []error{envLib.ErrWhiteSpace})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this doing the parseEnv on os.Environ() at all?

os.Environ() is pretty much by definition correct:

  • So we shouldn’t trim any whitespace (from neither names nor values) like parseEnv does
  • So I don’t see why we should treat trailing * specially.

Is there some later consumer that imposes such restrictions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok just translating from a slice of strings to a map[string]string.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ACK, that looks reasonable.

(I didn’t read all of the code and other users of pkg/env.)

@rhatdan rhatdan changed the title [WIP] Allow podman to run in an environment with keys containing spaces Allow podman to run in an environment with keys containing spaces Aug 23, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 23, 2022
@@ -58,6 +58,13 @@ var _ = Describe("Podman run", func() {
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring("/bin"))

// Verify environ keys with spaces do not blow up podman command
os.Setenv("FOO BAR", "BAZ")
session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "true"})
Copy link
Member

Choose a reason for hiding this comment

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

Why not go for a full-on all-the-way test?

    ...{"run", "--rm", "-e", "FOO BAR", ALPINE, "printenv", "FOO BAR"})
   ...output-should-equal("BAZ")

(for extra credit, s/BAZ/BAZ OOKA or something with spaces/)

Copy link
Member Author

Choose a reason for hiding this comment

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

I could do that but that would be a separate test. What I was looking at was a failure to run if any environment variable contained a space, even if the variable was not being passed to the container.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also did not see an easy way to do this in a system test.

env "foo bar"="foo baz" run_podman ...

Blew up.

Copy link
Member

Choose a reason for hiding this comment

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

Would using --env-host work?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see a sane way to test this in system tests either. Bash won't allow it. It would be possible to build a test binary that uses prctl() to inject FOO BAR into the parent process's environ, but let's just not go there.

@edsantiago
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 24, 2022
@openshift-merge-robot openshift-merge-robot merged commit 361eb42 into containers:main Aug 24, 2022
@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 Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Windows] White spaces in environment variables' names prevent containers from starting
5 participants