manifest push: push error discarded when `--digestfile` is used, exits 0
Issue Description
buildah manifest push --digestfile writes an empty digest file and exits 0 when the push fails.
Two separate problems in manifestPush() in cmd/buildah/manifest.go combine to produce this:
_, digest, err := list.Push(getContext(), dest, options)
if err == nil && opts.rm {
_, err = store.DeleteImage(manifestList.ID(), true)
}
if opts.digestfile != "" {
if err = os.WriteFile(opts.digestfile, []byte(digest.String()), 0o644); err != nil {
return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", opts.digestfile, err))
}
}
return errThe
opts.digestfileblock is not guarded byerr == nil, so it runs even whenlist.Pushfailed. On the failure pathdigestis the zero value, and sincedigest.Digestis astringtype whoseString()is a plain cast,digest.String()returns""an empty file is written.if err = os.WriteFile(...)assigns to the existingerrrather than declaring a new one. WhenWriteFilesucceeds it overwrites the push error withnil, so the closingreturn errreturnsniland the command exits successfully.
The second point is the more serious one: the push error is swallowed entirely, so the failure is invisible to any caller checking the exit code.
Note that buildah push does not have this bug. In cmd/buildah/push.go the error path returns early, so the digestfile is only written after a successful push. Only manifest push is affected.
Steps to reproduce the issue
- Create a manifest list with at least one image:
$ buildah manifest create example
$ buildah build --manifest example --platform linux/amd64 -t example .- Push it to a destination that will fail, e.g. a registry you are not authenticated against, or one that does not exist:
$ buildah manifest push --all --digestfile /tmp/digest example docker://registry.invalid/nonexistent/repo
$ echo "exit status: $?"
$ ls -l /tmp/digest
$ wc -c /tmp/digestDescribe the results you received
The push fails, but the exit status is 0 and /tmp/digest exists with a size of 0 bytes. No error is reported from the push itself.
exit status: 0
-rw-r--r--. 1 user user 0 ... /tmp/digest
0 /tmp/digestDescribe the results you expected
A non-zero exit status and the push error propagated to the caller. The digest file should not be created or written at all when the push fails, a caller should never observe an empty digest file.
buildah version output
(verified by code inspection against tag v1.45.1 and main at 596ece93bbb07d15c53c5b044a08326c4a72acce; the affected code is identical in both)buildah info output
I'm running this from a CI pipeline, that only outputs buildah version
Version: 1.43.1
Go Version: go1.26.1-X:nodwarf5
Image Spec: 1.1.1
Runtime Spec: 1.2.1
CNI Spec: 1.1.0
libcni Version:
image Version: 5.39.2
Git Commit:
Built: Wed Apr 8 19:37:51 2026
OS/Arch: linux/arm64
BuildPlatform: linux/arm64/v8Provide your storage.conf
[storage]
driver = "vfs"
graphRoot = "${CI_PROJECT_DIR}/.buildah-storage"
runRoot = "/tmp/buildah-run"Upstream Latest Release
Yes
Additional environment details
Encountered in CI (GitLab CI) using the quay.io/buildah/stable image. The practical impact is that a pipeline step doing buildah manifest push --digestfile ... succeeds despite pushing nothing, and a later step that reads the digest file gets an empty value. In our case the next step signs the pushed image with cosign, so a failed push silently turned into a green pipeline with an unsigned (and nonexistent) image. We now have to defensively check that the digest file is both present and non-empty.
Additional information
A minimal fix is to guard the write and avoid clobbering err:
_, digest, err := list.Push(getContext(), dest, options)
if err != nil {
return err
}
if opts.rm {
if _, err := store.DeleteImage(manifestList.ID(), true); err != nil {
return err
}
}
if opts.digestfile != "" {
if err := os.WriteFile(opts.digestfile, []byte(digest.String()), 0o644); err != nil {
return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", opts.digestfile, err))
}
}
return nilSource: podman-container-tools/buildah