Skip to content

Fix --from with absolute paths to local image transports - #6975

Open
Honny1 wants to merge 1 commit into
podman-container-tools:mainfrom
Honny1:fix-from-path
Open

Fix --from with absolute paths to local image transports#6975
Honny1 wants to merge 1 commit into
podman-container-tools:mainfrom
Honny1:fix-from-path

Conversation

@Honny1

@Honny1 Honny1 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes: #6932

What type of PR is this?

/kind api-change
/kind bug
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed `buildah build --from` with absolute paths to oci-archive, docker-archive, oci, and dir transports.

@Honny1
Honny1 marked this pull request as ready for review July 20, 2026 18:36

@nalind nalind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be much more careful about attempting to read data from the filesystem that isn't somewhere within the context directory.

Comment thread tests/bud.bats
Comment thread tests/bud.bats
Comment thread internal/sanitize/sanitize.go Outdated
imageArchive, err = chrootarchive.Tar(filepath.Join(contextDir, archiveSource), tarOptions, contextDir)
if filepath.IsAbs(archiveSource) {
if _, statErr := os.Stat(archiveSource); statErr == nil {
imageArchive, err = chrootarchive.Tar(archiveSource, tarOptions, filepath.Dir(archiveSource))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This bypasses the attempt to ensure that we're only reading content from the context directory for all cases, not only those where "--from" was used to provide the value that we're processing.

Comment thread internal/sanitize/sanitize.go Outdated
imageArchive, err = newSingleItemArchive(contextDir, archiveSource)
if filepath.IsAbs(archiveSource) {
if _, statErr := os.Stat(archiveSource); statErr == nil {
imageArchive, err = newSingleItemArchive(filepath.Dir(archiveSource), filepath.Base(archiveSource))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This bypasses the attempt to ensure that we're only reading content from the context directory for all cases, not only those where "--from" was used to provide the value that we're processing.

Comment thread internal/sanitize/sanitize.go Outdated
imageArchive, err = chrootarchive.Tar(filepath.Join(contextDir, archiveSource), tarOptions, contextDir)
if filepath.IsAbs(archiveSource) {
if _, statErr := os.Stat(archiveSource); statErr == nil {
imageArchive, err = chrootarchive.Tar(archiveSource, tarOptions, filepath.Dir(archiveSource))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This bypasses the attempt to ensure that we're only reading content from the context directory for all cases, not only those where "--from" was used to provide the value that we're processing.

@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

Fixes: podman-container-tools#6932

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@Honny1
Honny1 requested a review from nalind July 22, 2026 11:47

// Decide before source policy may rewrite from: absolute paths are only
// allowed for the value supplied via --from, not Containerfile FROM lines.
allowAbsolutePaths := s.executor.originalFromOverride != "" && from == s.executor.originalFromOverride

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This evaluates as true for every stage of a multi-stage build that uses the same base as the first stage. It isn't clear from the commit log if that's intentional.

// archive only the archive file for copying to the new archive file
imageArchive, err = newSingleItemArchive(contextDir, archiveSource)
if allowAbsolutePaths && filepath.IsAbs(archiveSource) {
imageArchive, err = newSingleItemArchive(filepath.Dir(archiveSource), filepath.Base(archiveSource))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Writing out a new copy seems unnecessary. Passing back a reader for the original file and setting isEmbeddedArchive false for this case would provide the same data.

tarOptions := &archive.TarOptions{}
imageArchive, err = chrootarchive.Tar(filepath.Join(contextDir, archiveSource), tarOptions, contextDir)
if allowAbsolutePaths && filepath.IsAbs(archiveSource) {
imageArchive, err = chrootarchive.Tar(archiveSource, tarOptions, filepath.Dir(archiveSource))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the intent here to disrupt links to items outside of the context directory when absolute paths are being allowed? If it is not, then we don't need to be calling this function.

imageArchive, err = chrootarchive.Tar(archiveSource, tarOptions, filepath.Dir(archiveSource))
} else {
// Leading "/" is context-absolute, not a host path; avoid filepath.Join
// dropping contextDir when archiveSource is absolute.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that filepath.Join() does that?

case directoryTransport.Transport.Name(): // this is also a directory tree
// this takes the form of just a path
transportRef := restOfImageName
archiveSource = transportRef

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moved for stylistic reasons?

if allowAbsolutePaths && filepath.IsAbs(archiveSource) {
archiveRoot = filepath.Dir(archiveSource)
}
return "", fmt.Errorf("error archiving source at %q under %q", archiveSource, archiveRoot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this error message wrap err?

Comment thread tests/bud.bats
cat > "${contextdir}"/Containerfile << 'EOF'
FROM overridden
RUN touch /absolute-path-test
EOF

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We expect --from to only replace the value referenced in the first FROM instruction, but this doesn't check that for the types of values that we're going to start handling specially here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buildah bud --from with absolute path to oci-archive fails

2 participants