Skip to content

Commit

Permalink
Add a warning if --authfile points to .docker/config.json
Browse files Browse the repository at this point in the history
Note that the warning can't be disabled.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Nov 7, 2023
1 parent 6cd4a0f commit 77dd5ce
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/containers/image/v5/pkg/docker/config"
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/types"
"github.com/containers/storage/pkg/homedir"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -86,10 +87,14 @@ func systemContextWithOptions(sys *types.SystemContext, authFile, dockerCompatAu
sys = &types.SystemContext{}
}

defaultDockerConfigPath := filepath.Join(homedir.Get(), ".docker", "config.json")
switch {
case authFile != "" && dockerCompatAuthFile != "":
return nil, errors.New("--authfile and --compat-auth-file can not be set simultaneously")
case authFile != "":
if authFile == defaultDockerConfigPath {
logrus.Warn("--authfile points to ~/.docker/config.json, but the file format is not fully compatible; use --compat-auth-file instead")
}
sys.AuthFilePath = authFile
case dockerCompatAuthFile != "":
sys.DockerCompatAuthFilePath = dockerCompatAuthFile
Expand All @@ -99,6 +104,9 @@ func systemContextWithOptions(sys *types.SystemContext, authFile, dockerCompatAu
// Note that c/image does not natively implement the REGISTRY_AUTH_FILE
// variable, so not all callers look for credentials in this location.
if authFileVar := os.Getenv("REGISTRY_AUTH_FILE"); authFileVar != "" {
if authFileVar == defaultDockerConfigPath {
logrus.Warn("$REGISTRY_AUTH_FILE points to ~/.docker/config.json, but the file format is not fully compatible; use --compat-auth-file instead")
}
sys.AuthFilePath = authFileVar
}
// This preserves pre-existing _inconsistent_ behavior:
Expand Down

0 comments on commit 77dd5ce

Please sign in to comment.