-
Notifications
You must be signed in to change notification settings - Fork 882
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
Replace abandoned dgrijalva/jwt-go with golang-jwt/jwt #2339
Changes from 2 commits
bd83c6e
80d6182
2815dbd
341cb36
5ec0126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import ( | |
"fmt" | ||
"strings" | ||
|
||
"github.com/dgrijalva/jwt-go/v4" | ||
"github.com/golang-jwt/jwt/v4" | ||
"go.temporal.io/api/serviceerror" | ||
|
||
"go.temporal.io/server/common/config" | ||
|
@@ -130,12 +130,7 @@ func parseJWT(tokenString string, keyProvider TokenKeyProvider) (jwt.MapClaims, | |
|
||
func parseJWTWithAudience(tokenString string, keyProvider TokenKeyProvider, audience string) (jwt.MapClaims, error) { | ||
|
||
var parser *jwt.Parser | ||
if strings.TrimSpace(audience) == "" { | ||
parser = jwt.NewParser(jwt.WithoutAudienceValidation()) | ||
} else { | ||
parser = jwt.NewParser(jwt.WithAudience(audience)) | ||
} | ||
parser := jwt.NewParser(jwt.WithValidMethods(keyProvider.SupportedMethods())) | ||
token, err := parser.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { | ||
|
||
kid, ok := token.Header["kid"].(string) | ||
|
@@ -159,11 +154,17 @@ func parseJWTWithAudience(tokenString string, keyProvider TokenKeyProvider, audi | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if claims, ok := token.Claims.(jwt.MapClaims); ok { | ||
return claims, nil | ||
claims, ok := token.Claims.(jwt.MapClaims) | ||
if !ok { | ||
return nil, serviceerror.NewPermissionDenied("invalid token with no claims", "") | ||
} | ||
if err := claims.Valid(); err != nil { | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this be caught and returned as a permission denied error elsewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, here. |
||
} | ||
if strings.TrimSpace(audience) != "" && !claims.VerifyAudience(audience, true) { | ||
return nil, serviceerror.NewPermissionDenied("audience mismatch", "") | ||
} | ||
return nil, serviceerror.NewPermissionDenied("invalid token with no claims", "") | ||
return claims, nil | ||
} | ||
|
||
func permissionToRole(permission string) Role { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ func (a *defaultTokenKeyProvider) Close() { | |
} | ||
|
||
func (a *defaultTokenKeyProvider) RsaKey(alg string, kid string) (*rsa.PublicKey, error) { | ||
if !strings.EqualFold(alg, "rs256") { | ||
if !strings.EqualFold(alg, "RS256") { | ||
return nil, fmt.Errorf("unexpected signing algorithm: %s", alg) | ||
} | ||
|
||
|
@@ -97,7 +97,7 @@ func (a *defaultTokenKeyProvider) RsaKey(alg string, kid string) (*rsa.PublicKey | |
} | ||
|
||
func (a *defaultTokenKeyProvider) EcdsaKey(alg string, kid string) (*ecdsa.PublicKey, error) { | ||
if !strings.EqualFold(alg, "es256") { | ||
if !strings.EqualFold(alg, "ES256") { | ||
return nil, fmt.Errorf("unexpected signing algorithm: %s", alg) | ||
} | ||
|
||
|
@@ -110,6 +110,10 @@ func (a *defaultTokenKeyProvider) EcdsaKey(alg string, kid string) (*ecdsa.Publi | |
return key, nil | ||
} | ||
|
||
func (a *defaultTokenKeyProvider) SupportedMethods() []string { | ||
return []string{"RS256", "ES256"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious is it necessary for this to be uppercase now? Also can we make these a const, it seems to be reused throughout this code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I replaced them with references to jwt.SigningMethod* now. |
||
} | ||
|
||
func (a *defaultTokenKeyProvider) timerCallback() { | ||
for { | ||
select { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this switch statement here for HmacKey redundant now that we are using the SupportedMethods feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't this it's redundant because we need to call
keyProvider.HmacKey()
in casekeyProvider
(configured as a separate plugin) supports HMAC. We just don't support it indefaultTokenKeyProvider
. They are indeed currently coupled here, but only for convenience.