Skip to content

Conversation

@ZuhairM7
Copy link

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

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

openshift-ci bot commented Nov 25, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ZuhairM7
Once this PR has been reviewed and has the lgtm label, please assign ashley-cui for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman build --secrets not storing secrets

4 participants