88 "encoding/json"
99 "errors"
1010 "fmt"
11- "io"
1211 "net/url"
1312 "os"
1413 "sync"
@@ -137,26 +136,14 @@ func (c *credentialsCache) Get(hostname, configKey string) (string, string, erro
137136 return user , password , nil
138137}
139138
140- // configFileKey returns a key to use for caching credentials based on
139+ // configKey returns a key to use for caching credentials based on
141140// the contents of the currently active config.
142- func configFileKey () (string , error ) {
143- configPath , err := dockercfg .ConfigPath ()
141+ func configKey (cfg dockercfg.Config ) (string , error ) {
142+ h := md5 .New ()
143+ err := json .NewEncoder (h ).Encode (cfg )
144144 if err != nil {
145145 return "" , err
146146 }
147-
148- f , err := os .Open (configPath )
149- if err != nil {
150- return "" , fmt .Errorf ("open config file: %w" , err )
151- }
152-
153- defer f .Close ()
154-
155- h := md5 .New ()
156- if _ , err := io .Copy (h , f ); err != nil {
157- return "" , fmt .Errorf ("copying config file: %w" , err )
158- }
159-
160147 return hex .EncodeToString (h .Sum (nil )), nil
161148}
162149
@@ -165,10 +152,11 @@ func configFileKey() (string, error) {
165152func getDockerAuthConfigs () (map [string ]registry.AuthConfig , error ) {
166153 cfg , err := getDockerConfig ()
167154 if err != nil {
168- return nil , err
155+ // accept no configured registries since all might be accessible anonymously
156+ return map [string ]registry.AuthConfig {}, nil
169157 }
170158
171- configKey , err := configFileKey ( )
159+ key , err := configKey ( cfg )
172160 if err != nil {
173161 return nil , err
174162 }
@@ -195,7 +183,7 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
195183 switch {
196184 case ac .Username == "" && ac .Password == "" :
197185 // Look up credentials from the credential store.
198- u , p , err := creds .Get (k , configKey )
186+ u , p , err := creds .Get (k , key )
199187 if err != nil {
200188 results <- authConfigResult {err : err }
201189 return
@@ -218,12 +206,11 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
218206 go func (k string ) {
219207 defer wg .Done ()
220208
221- u , p , err := creds .Get (k , configKey )
209+ u , p , err := creds .Get (k , key )
222210 if err != nil {
223211 results <- authConfigResult {err : err }
224212 return
225213 }
226-
227214 results <- authConfigResult {
228215 key : k ,
229216 cfg : registry.AuthConfig {
0 commit comments