Skip to content

Remote build: nTar secrets with relative paths and ignore bypass#28356

Merged
Luap99 merged 2 commits into
containers:mainfrom
Honny1:fix-remote-build
Apr 8, 2026
Merged

Remote build: nTar secrets with relative paths and ignore bypass#28356
Luap99 merged 2 commits into
containers:mainfrom
Honny1:fix-remote-build

Conversation

@Honny1
Copy link
Copy Markdown
Member

@Honny1 Honny1 commented Mar 24, 2026

When podman-remote tars the context, extra podman-build-secret* paths were either dropped by .dockerignore (#25314) or archived as absolute paths so COPY . . pulled host-shaped trees into the image (#28334).

Use relative names under the primary context for extra sources and do not apply .dockerignore to those forced entries.

Fixes: #25314
Fixes: #28334

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?

Remote build now correctly archives secret temp files, fixing `.dockerignore=*` secret failures and preventing `podman-build-secret*` host-path leaks in `COPY . .`.

@Honny1 Honny1 force-pushed the fix-remote-build branch from 5f6bd39 to c7b1275 Compare March 24, 2026 10:02
@packit-as-a-service
Copy link
Copy Markdown

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

Comment thread pkg/bindings/images/build.go Outdated
Comment on lines +1167 to +1173
fsSep := string(filepath.Separator)
if strings.HasPrefix(path, firstSourceAbs+fsSep) {
name = filepath.ToSlash(strings.TrimPrefix(path, firstSourceAbs+fsSep))
} else {
name = filepath.ToSlash(path)
}
skipExclude = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is really hard to reason about what this is doing and WHY it is needed, please add comments

also HasPrefix() followed by TrimPrefix() means you should be using CutPrefix() most likely

Comment thread test/e2e/build_test.go Outdated
Comment on lines +148 to +149
os.Setenv("MYSECRET", secret)
defer os.Unsetenv("MYSECRET")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this could use GinkgoT().Setenv() to safe the unset call

Comment thread test/e2e/build_test.go

session := podmanTest.PodmanExitCleanly("build", "-f", "build/remote-secret-copy/Dockerfile", "--secret", "id=mysecret,env=MYSECRET", "build/remote-secret-copy")
Expect(session.OutputToString()).To(ContainSubstring(secret))
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we just not extend the test case above "podman build with a secret from file and verify if secret file is not leaked into image"? or at the very least I assume these two test cases are a superset of the above one so then why do we still need that one?
putting the critical file existence check into the containerfile hides the important check IMO and it is harder to get that sh -c 'test -z "$(find / -name '\''podman-build-secret*'\'' 2>/dev/null | head -n1)"' is the important thing here, in general that comamnd seem over complicated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have consolidated tests of the build with secrets.

When `podman-remote` tars the context, extra `podman-build-secret*` paths were
either dropped by `.dockerignore` (containers#25314) or archived as absolute paths so
`COPY . .` pulled host-shaped trees into the image (containers#28334).

Use relative names under the primary context for extra sources and do not apply
`.dockerignore` to those forced entries.

Fixes: containers#25314
Fixes: containers#28334

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@Honny1 Honny1 force-pushed the fix-remote-build branch from c7b1275 to 7e29609 Compare March 25, 2026 14:12
@Honny1 Honny1 marked this pull request as ready for review March 25, 2026 14:14
@TomSweeneyRedHat
Copy link
Copy Markdown
Member

@Honny1 I think you may have some real errors here.

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Mar 25, 2026

Yes, it seems that local podman leaks secrets into the image. I will investigate that.

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@Honny1 Honny1 force-pushed the fix-remote-build branch from 7e29609 to 765ffb9 Compare March 25, 2026 18:02
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Mar 26, 2026

PTAL @containers/podman-maintainers

@Honny1 Honny1 requested a review from Luap99 March 30, 2026 09:26
@mheon
Copy link
Copy Markdown
Member

mheon commented Mar 31, 2026

LGTM

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 7, 2026

@containers/podman-maintainers PTAL

Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 8, 2026

@Luap99 Can you please do a final review and merge?

Copy link
Copy Markdown
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

@Luap99 Luap99 merged commit 3f28865 into containers:main Apr 8, 2026
85 checks passed
@Luap99
Copy link
Copy Markdown
Member

Luap99 commented Apr 8, 2026

/cherry-pick v5.8

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

Labels

None yet

Projects

None yet

5 participants