Skip to content

Commit

Permalink
Merge pull request #1427 from vrothberg/fix-podman-11636
Browse files Browse the repository at this point in the history
docker/config: handle credentials not found errors
  • Loading branch information
vrothberg committed Dec 7, 2021
2 parents 08ebaed + 08a4c70 commit 6f3c845
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/docker/config/config.go
Expand Up @@ -620,6 +620,10 @@ func getAuthFromCredHelper(credHelper, registry string) (types.DockerAuthConfig,
p := helperclient.NewShellProgramFunc(helperName)
creds, err := helperclient.Get(p, registry)
if err != nil {
if credentials.IsErrCredentialsNotFoundMessage(err.Error()) {
logrus.Debugf("Not logged in to %s with credential helper %s", registry, credHelper)
err = nil
}
return types.DockerAuthConfig{}, err
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/docker/config/config_test.go
Expand Up @@ -547,6 +547,14 @@ func TestGetAllCredentials(t *testing.T) {
SystemRegistriesConfDirPath: filepath.Join("testdata", "IdoNotExist"),
}

// Make sure that we can handle no-creds-found errors.
os.Setenv("DOCKER_CONFIG", filepath.Join(path, "testdata"))
authConfigs, err := GetAllCredentials(nil)
require.NoError(t, err)
require.Len(t, authConfigs, 1)
require.Equal(t, authConfigs["registry-no-creds.com"], types.DockerAuthConfig{})
os.Unsetenv("DOCKER_CONFIG")

for _, data := range [][]struct {
writeKey string
expectedKey string
Expand Down
5 changes: 5 additions & 0 deletions pkg/docker/config/testdata/config.json
@@ -0,0 +1,5 @@
{
"credHelpers" : {
"registry-no-creds.com" : "helper-registry"
}
}
Expand Up @@ -6,6 +6,7 @@ case "${1}" in
case "${REGISTRY}" in
("registry-a.com") echo "{\"ServerURL\":\"${REGISTRY}\",\"Username\":\"foo\",\"Secret\":\"bar\"}" ;;
("registry-b.com") echo "{\"ServerURL\":\"${REGISTRY}\",\"Username\":\"<token>\",\"Secret\":\"fizzbuzz\"}" ;;
("registry-no-creds.com") echo "credentials not found in native keychain" && exit 1 ;;
(*) echo "{}" ;;
esac
exit 0
Expand Down

0 comments on commit 6f3c845

Please sign in to comment.