Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log all token verification failures #16625

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions util/oidc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ func (p *providerImpl) newGoOIDCProvider() (*gooidc.Provider, error) {
return prov, nil
}

type tokenVerificationError struct {
errorsByAudience map[string]error
}

func (t tokenVerificationError) Error() string {
var errorStrings []string
for aud, err := range t.errorsByAudience {
errorStrings = append(errorStrings, fmt.Sprintf("error for aud %q: %v", aud, err))
}
return fmt.Sprintf("token verification failed for all audiences: %s", strings.Join(errorStrings, ", "))
}

func (p *providerImpl) Verify(tokenString string, argoSettings *settings.ArgoCDSettings) (*gooidc.IDToken, error) {
// According to the JWT spec, the aud claim is optional. The spec also says (emphasis mine):
//
Expand Down Expand Up @@ -104,6 +116,7 @@ func (p *providerImpl) Verify(tokenString string, argoSettings *settings.ArgoCDS
if len(allowedAudiences) == 0 {
return nil, errors.New("token has an audience claim, but no allowed audiences are configured")
}
tokenVerificationErrors := make(map[string]error)
// Token must be verified for at least one allowed audience
for _, aud := range allowedAudiences {
idToken, err = p.verify(aud, tokenString, false)
Expand All @@ -117,6 +130,13 @@ func (p *providerImpl) Verify(tokenString string, argoSettings *settings.ArgoCDS
if err == nil {
break
}
// We store the error for each audience so that we can return a more detailed error message to the user.
// If this gets merged, we'll be able to detect failures unrelated to audiences and short-circuit this loop
// to avoid logging irrelevant warnings: https://github.com/coreos/go-oidc/pull/406
tokenVerificationErrors[aud] = err
}
if len(tokenVerificationErrors) > 0 {
err = tokenVerificationError{errorsByAudience: tokenVerificationErrors}
}
}

Expand Down
Loading