Skip to content

Commit

Permalink
Verify authfile exists if user specifies it
Browse files Browse the repository at this point in the history
Fixes: containers#18938

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Jul 24, 2023
1 parent 3e6b99b commit ddfbcec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/podman/containers/create.go
Expand Up @@ -154,6 +154,13 @@ func create(cmd *cobra.Command, args []string) error {
}
imageName = name
}

if cliVals.Authfile != "" {
if _, err := os.Stat(cliVals.Authfile); err != nil {
return err
}
}

s := specgen.NewSpecGenerator(imageName, cliVals.RootFS)
if err := specgenutil.FillOutSpecGen(s, &cliVals, args); err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions test/system/030-run.bats
Expand Up @@ -1158,4 +1158,15 @@ EOF
run_podman rm -f -t0 $ctr
}

@test "podman run --authfile=/tmp/bogus " {
run_podman 125 run --authfile=/tmp/bogus $IMAGE false
is "$output" "Error: stat /tmp/bogus: no such file or directory" "should faile with not such file"

run_podman 125 create --authfile=/tmp/bogus $IMAGE false
is "$output" "Error: stat /tmp/bogus: no such file or directory" "should faile with not such file"

run_podman 125 pull --authfile=/tmp/bogus $IMAGE
is "$output" "Error: stat /tmp/bogus: no such file or directory" "should faile with not such file"
}

# vim: filetype=sh
9 changes: 9 additions & 0 deletions test/system/700-play.bats
Expand Up @@ -724,3 +724,12 @@ spec:

run_podman kube down $pod_file
}

@test "podman kube with --authfile=/tmp/bogus" {
TESTDIR=$PODMAN_TMPDIR/testdir
mkdir -p $TESTDIR
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml

run_podman 125 kube play --authfile=/tmp/bogus - < $PODMAN_TMPDIR/test.yaml
is "$output" "Error: stat /tmp/bogus: no such file or directory" "should faile with not such file"
}

0 comments on commit ddfbcec

Please sign in to comment.