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

Replace abandoned dgrijalva/jwt-go with golang-jwt/jwt #2339

Merged
merged 5 commits into from
Jan 5, 2022

Conversation

sergeybykov
Copy link
Member

What changed?
Replaced abandoned dependency dgrijalva/jwt-go with golang-jwt/jwt.
Adjusted the code to address the differences in API.
Added SupportedMethods method to TokenKeyProvider. This is a small breaking change that can be avoided by introducing a separate interface, but I don't think that would be better.

Why?
Fixes #2313
Abandoned dependencies are a concern.

How did you test it?
Unit tests

Potential risks
This is a different implementation of the JWT library, which could in theory break something.
I could have made a mistake in adjusting the code.

Is hotfix candidate?
No

@sergeybykov sergeybykov requested review from mattkim, yiminc and a team January 4, 2022 02:12
return nil, serviceerror.NewPermissionDenied("invalid token with no claims", "")
}
if err := claims.Valid(); err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be caught and returned as a permission denied error elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here.

} 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)
Copy link
Member

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?

Copy link
Member Author

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 case keyProvider (configured as a separate plugin) supports HMAC. We just don't support it in defaultTokenKeyProvider. They are indeed currently coupled here, but only for convenience.

@@ -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"}
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I replaced them with references to jwt.SigningMethod* now.

Copy link
Member

@mattkim mattkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with some small comments

@sergeybykov sergeybykov merged commit 7a695e5 into temporalio:master Jan 5, 2022
@sergeybykov sergeybykov deleted the pr/golang-jwt branch January 5, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace abandoned github.com/dgrijalva/jwt-go with github.com/golang-jwt/jwt
3 participants