Make sure users changes --authfile before checking

In certain cases REGISTRY_AUTH_FILE is set but the auth file
does not exists yet, do not throw error unless user specified
a file directly using --authfile.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2023-07-26 20:12:11 -04:00
parent cf1321f670
commit f540bbffa8
14 changed files with 61 additions and 28 deletions

View File

@ -68,8 +68,10 @@ func autoUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("`%s` takes no arguments", cmd.CommandPath()) return fmt.Errorf("`%s` takes no arguments", cmd.CommandPath())
} }
if err := auth.CheckAuthFile(autoUpdateOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(autoUpdateOptions.Authfile); err != nil {
return err
}
} }
if cmd.Flags().Changed("tls-verify") { if cmd.Flags().Changed("tls-verify") {
autoUpdateOptions.InsecureSkipTLSVerify = types.NewOptionalBool(!autoUpdateOptions.tlsVerify) autoUpdateOptions.InsecureSkipTLSVerify = types.NewOptionalBool(!autoUpdateOptions.tlsVerify)

View File

@ -156,8 +156,10 @@ func create(cmd *cobra.Command, args []string) error {
imageName = name imageName = name
} }
if err := auth.CheckAuthFile(cliVals.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(cliVals.Authfile); err != nil {
return err
}
} }
s := specgen.NewSpecGenerator(imageName, cliVals.RootFS) s := specgen.NewSpecGenerator(imageName, cliVals.RootFS)

View File

@ -115,8 +115,10 @@ func run(cmd *cobra.Command, args []string) error {
logrus.Warnf("The input device is not a TTY. The --tty and --interactive flags might not work properly") logrus.Warnf("The input device is not a TTY. The --tty and --interactive flags might not work properly")
} }
if err := auth.CheckAuthFile(cliVals.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(cliVals.Authfile); err != nil {
return err
}
} }
runOpts.CIDFile = cliVals.CIDFile runOpts.CIDFile = cliVals.CIDFile

View File

@ -90,8 +90,10 @@ func runlabel(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("tls-verify") { if cmd.Flags().Changed("tls-verify") {
runlabelOptions.SkipTLSVerify = types.NewOptionalBool(!runlabelOptions.TLSVerifyCLI) runlabelOptions.SkipTLSVerify = types.NewOptionalBool(!runlabelOptions.TLSVerifyCLI)
} }
if err := auth.CheckAuthFile(runlabelOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(runlabelOptions.Authfile); err != nil {
return err
}
} }
return registry.ContainerEngine().ContainerRunlabel(context.Background(), strings.TrimPrefix(args[0], "/"), args[1], args[2:], runlabelOptions.ContainerRunlabelOptions) return registry.ContainerEngine().ContainerRunlabel(context.Background(), strings.TrimPrefix(args[0], "/"), args[1], args[2:], runlabelOptions.ContainerRunlabelOptions)
} }

View File

@ -363,8 +363,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
} }
} }
if err := auth.CheckAuthFile(flags.Authfile); err != nil { if c.Flags().Changed("authfile") {
return nil, err if err := auth.CheckAuthFile(flags.Authfile); err != nil {
return nil, err
}
} }
commonOpts, err := parse.CommonBuildOptions(c) commonOpts, err := parse.CommonBuildOptions(c)

View File

@ -136,8 +136,10 @@ func imagePull(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("tls-verify") { if cmd.Flags().Changed("tls-verify") {
pullOptions.SkipTLSVerify = types.NewOptionalBool(!pullOptions.TLSVerifyCLI) pullOptions.SkipTLSVerify = types.NewOptionalBool(!pullOptions.TLSVerifyCLI)
} }
if err := auth.CheckAuthFile(pullOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(pullOptions.Authfile); err != nil {
return err
}
} }
platform, err := cmd.Flags().GetString("platform") platform, err := cmd.Flags().GetString("platform")
if err != nil { if err != nil {

View File

@ -173,8 +173,10 @@ func imagePush(cmd *cobra.Command, args []string) error {
pushOptions.SkipTLSVerify = types.NewOptionalBool(!pushOptions.TLSVerifyCLI) pushOptions.SkipTLSVerify = types.NewOptionalBool(!pushOptions.TLSVerifyCLI)
} }
if err := auth.CheckAuthFile(pushOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(pushOptions.Authfile); err != nil {
return err
}
} }
if pushOptions.CredentialsCLI != "" { if pushOptions.CredentialsCLI != "" {

View File

@ -138,8 +138,10 @@ func imageSearch(cmd *cobra.Command, args []string) error {
searchOptions.SkipTLSVerify = types.NewOptionalBool(!searchOptions.TLSVerifyCLI) searchOptions.SkipTLSVerify = types.NewOptionalBool(!searchOptions.TLSVerifyCLI)
} }
if err := auth.CheckAuthFile(searchOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(searchOptions.Authfile); err != nil {
return err
}
} }
if searchOptions.CredentialsCLI != "" { if searchOptions.CredentialsCLI != "" {

View File

@ -56,8 +56,10 @@ func init() {
} }
func sign(cmd *cobra.Command, args []string) error { func sign(cmd *cobra.Command, args []string) error {
if err := auth.CheckAuthFile(signOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(signOptions.Authfile); err != nil {
return err
}
} }
if signOptions.SignBy == "" { if signOptions.SignBy == "" {
return errors.New("no identity provided") return errors.New("no identity provided")

View File

@ -217,8 +217,10 @@ func play(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("build") { if cmd.Flags().Changed("build") {
playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI) playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI)
} }
if err := auth.CheckAuthFile(playOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(playOptions.Authfile); err != nil {
return err
}
} }
if playOptions.ContextDir != "" && playOptions.Build != types.OptionalBoolTrue { if playOptions.ContextDir != "" && playOptions.Build != types.OptionalBoolTrue {
return errors.New("--build must be specified when using --context-dir option") return errors.New("--build must be specified when using --context-dir option")

View File

@ -93,8 +93,10 @@ func init() {
} }
func add(cmd *cobra.Command, args []string) error { func add(cmd *cobra.Command, args []string) error {
if err := auth.CheckAuthFile(manifestAddOpts.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(manifestAddOpts.Authfile); err != nil {
return err
}
} }
if manifestAddOpts.CredentialsCLI != "" { if manifestAddOpts.CredentialsCLI != "" {

View File

@ -44,8 +44,10 @@ func init() {
} }
func inspect(cmd *cobra.Command, args []string) error { func inspect(cmd *cobra.Command, args []string) error {
if err := auth.CheckAuthFile(inspectOptions.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(inspectOptions.Authfile); err != nil {
return err
}
} }
if cmd.Flags().Changed("tls-verify") { if cmd.Flags().Changed("tls-verify") {
inspectOptions.SkipTLSVerify = types.NewOptionalBool(!tlsVerifyCLI) inspectOptions.SkipTLSVerify = types.NewOptionalBool(!tlsVerifyCLI)

View File

@ -114,8 +114,10 @@ func init() {
} }
func push(cmd *cobra.Command, args []string) error { func push(cmd *cobra.Command, args []string) error {
if err := auth.CheckAuthFile(manifestPushOpts.Authfile); err != nil { if cmd.Flags().Changed("authfile") {
return err if err := auth.CheckAuthFile(manifestPushOpts.Authfile); err != nil {
return err
}
} }
listImageSpec := args[0] listImageSpec := args[0]
destSpec := args[len(args)-1] destSpec := args[len(args)-1]

View File

@ -1163,10 +1163,11 @@ EOF
# #
# Table format is: # Table format is:
# podman command | arguments | '-' if it does not work with podman-remote # podman command | arguments | '-' if it does not work with podman-remote
echo "from $IMAGE" > $PODMAN_TMPDIR/Containerfile
tests=" tests="
auto-update | | - auto-update | | -
build | $PODMAN_TMPDIR | build | $PODMAN_TMPDIR |
container runlabel | $IMAGE argument | - container runlabel | run $IMAGE | -
create | $IMAGE argument | create | $IMAGE argument |
image sign | $IMAGE | - image sign | $IMAGE | -
kube play | argument | kube play | argument |
@ -1176,7 +1177,7 @@ manifest inspect | $IMAGE |
manifest push | $IMAGE argument | manifest push | $IMAGE argument |
pull | $IMAGE argument | pull | $IMAGE argument |
push | $IMAGE argument | push | $IMAGE argument |
run | $IMAGE argument | run | $IMAGE false |
search | $IMAGE | search | $IMAGE |
" "
@ -1197,6 +1198,12 @@ search | $IMAGE |
run_podman 125 $command --authfile=$bogus $args run_podman 125 $command --authfile=$bogus $args
assert "$output" = "Error: checking authfile: stat $bogus: no such file or directory" \ assert "$output" = "Error: checking authfile: stat $bogus: no such file or directory" \
"$command --authfile=nonexistent-path" "$command --authfile=nonexistent-path"
if [[ "$command" != "logout" ]]; then
REGISTRY_AUTH_FILE=$bogus run_podman ? $command $args
assert "$output" !~ "checking authfile" \
"$command REGISTRY_AUTH_FILE=nonexistent-path"
fi
done < <(parse_table "$tests") done < <(parse_table "$tests")
} }