Verify existence of auth file if specified

Fixes: https://github.com/containers/podman/issues/9572

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2021-04-05 12:27:36 -04:00
parent 1c8d3d0f6f
commit 28251f41ff
2 changed files with 12 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
buildahDefine "github.com/containers/buildah/define" buildahDefine "github.com/containers/buildah/define"
buildahCLI "github.com/containers/buildah/pkg/cli" buildahCLI "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse" "github.com/containers/buildah/pkg/parse"
"github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
encconfig "github.com/containers/ocicrypt/config" encconfig "github.com/containers/ocicrypt/config"
@ -330,6 +331,12 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
pullPolicy = buildahDefine.PullNever pullPolicy = buildahDefine.PullNever
} }
if c.Flag("authfile").Changed {
if err := auth.CheckAuthFile(flags.Authfile); err != nil {
return nil, err
}
}
args := make(map[string]string) args := make(map[string]string)
if c.Flag("build-arg").Changed { if c.Flag("build-arg").Changed {
for _, arg := range flags.BuildArg { for _, arg := range flags.BuildArg {

View File

@ -752,6 +752,11 @@ EOF
run_podman rmi -f build_test run_podman rmi -f build_test
} }
@test "podman build --authfile bogus test" {
run_podman 125 build --authfile=/tmp/bogus - <<< "from scratch"
is "$output" ".*/tmp/bogus: no such file or directory"
}
function teardown() { function teardown() {
# A timeout or other error in 'build' can leave behind stale images # A timeout or other error in 'build' can leave behind stale images
# that podman can't even see and which will cascade into subsequent # that podman can't even see and which will cascade into subsequent