mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-22 18:51:34 +02:00
Add guide when signing key is not found (#2942)
Some users face issues with their IdP due to signing key not being refreshed With this change we advise users to configure key refresh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * removing leftover --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
c6641be94b
commit
8efad1d170
@ -77,6 +77,8 @@ type JWTValidator struct {
|
|||||||
options Options
|
options Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyNotFound = errors.New("unable to find appropriate key")
|
||||||
|
|
||||||
// NewJWTValidator constructor
|
// NewJWTValidator constructor
|
||||||
func NewJWTValidator(ctx context.Context, issuer string, audienceList []string, keysLocation string, idpSignkeyRefreshEnabled bool) (*JWTValidator, error) {
|
func NewJWTValidator(ctx context.Context, issuer string, audienceList []string, keysLocation string, idpSignkeyRefreshEnabled bool) (*JWTValidator, error) {
|
||||||
keys, err := getPemKeys(ctx, keysLocation)
|
keys, err := getPemKeys(ctx, keysLocation)
|
||||||
@ -124,12 +126,18 @@ func NewJWTValidator(ctx context.Context, issuer string, audienceList []string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
publicKey, err := getPublicKey(ctx, token, keys)
|
publicKey, err := getPublicKey(ctx, token, keys)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.WithContext(ctx).Errorf("getPublicKey error: %s", err)
|
return publicKey, nil
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return publicKey, nil
|
msg := fmt.Sprintf("getPublicKey error: %s", err)
|
||||||
|
if errors.Is(err, keyNotFound) && !idpSignkeyRefreshEnabled {
|
||||||
|
msg = fmt.Sprintf("getPublicKey error: %s. You can enable key refresh by setting HttpServerConfig.IdpSignKeyRefreshEnabled to true in your management.json file and restart the service", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithContext(ctx).Error(msg)
|
||||||
|
|
||||||
|
return nil, err
|
||||||
},
|
},
|
||||||
EnableAuthOnOptions: false,
|
EnableAuthOnOptions: false,
|
||||||
}
|
}
|
||||||
@ -229,7 +237,7 @@ func getPublicKey(ctx context.Context, token *jwt.Token, jwks *Jwks) (interface{
|
|||||||
log.WithContext(ctx).Debugf("Key Type: %s not yet supported, please raise ticket!", jwks.Keys[k].Kty)
|
log.WithContext(ctx).Debugf("Key Type: %s not yet supported, please raise ticket!", jwks.Keys[k].Kty)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("unable to find appropriate key")
|
return nil, keyNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPublicKeyFromECDSA(jwk JSONWebKey) (publicKey *ecdsa.PublicKey, err error) {
|
func getPublicKeyFromECDSA(jwk JSONWebKey) (publicKey *ecdsa.PublicKey, err error) {
|
||||||
@ -310,4 +318,3 @@ func getMaxAgeFromCacheHeader(ctx context.Context, cacheControl string) int {
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user