@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "io/fs"
6
7
"os"
7
8
"path/filepath"
8
9
"runtime"
@@ -421,6 +422,21 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
421
422
422
423
func configHook () {
423
424
if dockerConfig != "" {
425
+ // NOTE: we dont allow pointing --config to a regular file. Code assumed config is a directory
426
+ // We do allow though pointing at a nonexistent path. Some downstream code will create the folder
427
+ // at runtime if it does not yet exist.
428
+ statInfo , err := os .Stat (dockerConfig )
429
+ if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
430
+ // Cases where the folder does not exist are allowed, BUT cases where some other Stat() error
431
+ // is returned should fail
432
+ fmt .Fprintf (os .Stderr , "Supplied --config folder (%s) exists but is not accessible: %s" , dockerConfig , err .Error ())
433
+ os .Exit (1 )
434
+ }
435
+ if err == nil && ! statInfo .IsDir () {
436
+ // Cases where it does exist but is a file should fail
437
+ fmt .Fprintf (os .Stderr , "Supplied --config file (%s) is not a directory" , dockerConfig )
438
+ os .Exit (1 )
439
+ }
424
440
if err := os .Setenv ("DOCKER_CONFIG" , dockerConfig ); err != nil {
425
441
fmt .Fprintf (os .Stderr , "cannot set DOCKER_CONFIG=%s: %s" , dockerConfig , err .Error ())
426
442
os .Exit (1 )
@@ -500,7 +516,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
500
516
_ = lFlags .MarkHidden ("host" )
501
517
502
518
configFlagName := "config"
503
- lFlags .StringVar (& dockerConfig , "config" , "" , "Location of authentication config file" )
519
+ lFlags .StringVar (& dockerConfig , "config" , "" , "Path to directory containing authentication config file" )
504
520
_ = cmd .RegisterFlagCompletionFunc (configFlagName , completion .AutocompleteDefault )
505
521
506
522
// Context option added just for compatibility with DockerCLI.
0 commit comments