Skip to content

Conversation

@ZuhairM7
Copy link
Contributor

@ZuhairM7 ZuhairM7 commented Nov 25, 2025

Previously, using --secret=id=foo,env=BAR in remote mode would fail because the client sent the env var name to the server, which tried to resolve it locally. This patch modifies the client to resolve the environment variable locally, write it to a temp file, and send it as a file-based secret.

This aligns Podman's remote behavior with Docker's behavior and ensures secrets are correctly passed to the build container.

Test to verify fix:
export MYSECRET='qwerty' podman build --secret=id=mysecret,env=MYSECRET -f - . <<EOF FROM alpine RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret EOF

Before (Remote Client): The secret is empty because the server cannot find MYSECRET in its environment.
STEP 1/2: FROM alpine STEP 2/2: RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret COMMIT --> 256d6061a45d

After (Remote Client): The client resolves MYSECRET to qwerty and sends it to the server.
STEP 1/2: FROM alpine STEP 2/2: RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret qwerty COMMIT --> d5c40b8863ce

Fixes #27494

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Fixed an issue where `podman build --secret ... env=VAR` failed in remote mode (e.g., macOS) by correctly resolving environment variables on the client side.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Nov 25, 2025
@packit-as-a-service
Copy link

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

Copy link
Member

@lsm5 lsm5 left a comment

Choose a reason for hiding this comment

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

@ZuhairM7 thanks for the PR.

For fixing the DCO job, you'll need to signoff on your commit.
Please also check out the Validate source code changes job failure. That needs to get fixed to get the other jobs moving.

Can you also add a test?

// read specified env into a tmp file
// move tmp file to tar and change secret source to relative tmp file
secretVal := os.Getenv(val)
tmpSecretFilePath, err := tempManager.CreateTempFileFromReader(contextDir, "podman-build-secret-*", strings.NewReader(secretVal))
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this could leak - a defer os.Remove(...) after the error check would fix that

Copy link
Member

Choose a reason for hiding this comment

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

Cleanup is handled by TempFileManager.

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Thanks, it looks good, except for the thing the others mentioned. I fixed the release notes in the PR description.

// read specified env into a tmp file
// move tmp file to tar and change secret source to relative tmp file
secretVal := os.Getenv(val)
tmpSecretFilePath, err := tempManager.CreateTempFileFromReader(contextDir, "podman-build-secret-*", strings.NewReader(secretVal))
Copy link
Member

Choose a reason for hiding this comment

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

Cleanup is handled by TempFileManager.

@openshift-ci openshift-ci bot added release-note and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Nov 26, 2025
Copy link
Collaborator

@ninja-quokka ninja-quokka left a comment

Choose a reason for hiding this comment

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

Thanks for your first patch!

It looks good to me and I would approve it once a test is added like @lsm5 mentioned, test/e2e/build_test.go looks like a good place to me.

This function could do with a refactor some time in the future.

@ZuhairM7 ZuhairM7 force-pushed the fix-remote-build-secrets branch 2 times, most recently from b90a1e5 to 7de97be Compare November 30, 2025 02:43
It("podman build with a secret from env", func() {
os.Setenv("MYSECRET", "somesecret")
defer os.Unsetenv("MYSECRET")
session := podmanTest.Podman([]string{"build", "-f", "build/Containerfile.with-secret", "-t", "secret-test", "--secret", "id=mysecret,env=MYSECRET", "build/"})
Copy link
Member

Choose a reason for hiding this comment

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

Use podmanTest.PodmanExitCleanly to simplify waiting and exit code verification.

Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(ContainSubstring("somesecret"))

session = podmanTest.Podman([]string{"rmi", "secret-test"})
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Previously, using --secret=id=foo,env=BAR in remote mode would fail because the client sent the env var name to the server, which tried to resolve it locally. This patch modifies the client to resolve the environment variable locally, write it to a temp file, and send it as a file-based secret.

Fixes containers#27494

Signed-off-by: ZuhairM7 <ZuhairM7>
Signed-off-by: ZuhairM7 <zuhairmerali@gmail.com>
@ZuhairM7 ZuhairM7 force-pushed the fix-remote-build-secrets branch from 7de97be to fdbb696 Compare December 2, 2025 22:21
Copy link
Collaborator

@ninja-quokka ninja-quokka left a comment

Choose a reason for hiding this comment

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

/lgtm


It("podman build with a secret from env", func() {
os.Setenv("MYSECRET", "somesecret")
defer os.Unsetenv("MYSECRET")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, we do unset some env vars on every test but not this one so it's good to unset it.

os.Unsetenv("CONTAINERS_CONF")
os.Unsetenv("CONTAINERS_CONF_OVERRIDE")
os.Unsetenv("PODMAN_CONNECTIONS_CONF")

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2025
@packit-as-a-service
Copy link

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

@ninja-quokka
Copy link
Collaborator

Hey @containers/podman-maintainers , could you please take a look at this one when you get a chance. Not sure about the failing testfarm test, looks unrelated to me.

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM. I reran the failed Packit tests.

Copy link
Member

@Honny1 Honny1 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
Copy link
Contributor

openshift-ci bot commented Dec 4, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Honny1, ninja-quokka, ZuhairM7

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 Dec 4, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 0bd2b4b into containers:main Dec 4, 2025
82 checks passed
@Fryguy
Copy link

Fryguy commented Dec 4, 2025

Does this fix #17382 ?

@Honny1
Copy link
Member

Honny1 commented Dec 4, 2025

I think so, I will check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman build --secrets not storing secrets

6 participants