Skip to content

Commit

Permalink
GH-989: Handle osxkeychain rejecting the login request spuriously
Browse files Browse the repository at this point in the history
  • Loading branch information
ascopes committed Nov 15, 2024
1 parent 1156a26 commit f91526a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions helm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"net/url"
"os"
"reflect"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -508,10 +509,22 @@ func OCIRegistryPerformLogin(registryClient *registry.Client, ociURL string, use
debug("[INFO] Already logged into OCI registry %q", u.Host)
return nil
}
err = registryClient.Login(u.Host,
registry.LoginOptBasicAuth(username, password))

loginOpts := registry.LoginOptBasicAuth(username, password)
err = registryClient.Login(u.Host, loginOpts)

// Workaround for OSX Keychain rejecting the login request, which can cause
// spurious builds on MacOS. See GH-989.
if err != nil && strings.Contains(err.Error(), "`The specified item already exists in the keychain.`") {
debug("[WARN] Received error %v: %v when logging into registry %v, will try logging out and in again",
reflect.TypeOf(err), err, u.Host)
err = registryClient.Logout(u.Host)
debug("[INFO] Logout operation returned: %v, attempting to log in again", err)
err = registryClient.Login(u.Host, loginOpts)
}

if err != nil {
return fmt.Errorf("could not login to OCI registry %q: %v", u.Host, err)
return fmt.Errorf("could not login to OCI registry %q: %v %v", u.Host, reflect.TypeOf(err), err)
}
loggedInOCIRegistries[u.Host] = ""
debug("[INFO] Logged into OCI registry")
Expand Down

0 comments on commit f91526a

Please sign in to comment.