Skip to content

Commit 84da157

Browse files
committed
convert to hostname if needed when trying to authenticate
Used for the push using Docker's cli. See https://github.com/docker/cli/blob/23446275646041f9b598d64c51be24d5d0e49376/cli/config/credentials/file_store.go#L32-L47 (current used revision) to have more information about this fix. By example if you are logged on multiple registries, you can have something like that in your `config.json`. { "auths": { "https://index.docker.io/v1/": {}, "quay.io": {}, } } This fix allows to handle auth configurations with and without `http[s]://` prefix. Signed-off-by: Yves Brissaud <yves.brissaud@docker.com>
1 parent 75ab1e3 commit 84da157

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

remotes/push.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"io"
99
"os"
1010

11+
"github.com/docker/cli/cli/config/credentials"
12+
1113
"github.com/docker/cnab-to-oci/internal"
1214

1315
"github.com/docker/cli/cli/config"
@@ -291,8 +293,16 @@ func resolveAuthConfig(index *registrytypes.IndexInfo) configtypes.AuthConfig {
291293
return configtypes.AuthConfig{}
292294
}
293295

296+
// See https://github.com/docker/cli/blob/23446275646041f9b598d64c51be24d5d0e49376/cli/config/credentials/file_store.go#L32-L47
297+
// We are looking for the hostname in the configuration, and if not we are trying with a pure hostname (so without
298+
// http/https).
294299
authConfig, ok := configs[hostName]
295300
if !ok {
301+
for reg, config := range configs {
302+
if hostName == credentials.ConvertToHostname(reg) {
303+
return config
304+
}
305+
}
296306
return configtypes.AuthConfig{}
297307
}
298308
return authConfig

0 commit comments

Comments
 (0)