-
Notifications
You must be signed in to change notification settings - Fork 89
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
Allow for RS256 Token Signing #33
base: master
Are you sure you want to change the base?
Conversation
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.
Thank you for submitting this PR and being patient with our response.
I added some remarks. You also want to make sure to rebase against master, we recently moved to go mod.
return loadRSAPublicKeyFromDisk(config.JWT.Keyfile), nil | ||
default: | ||
return nil, unauthorizedError("Invalid Signing Method: %s", signMethod) | ||
} |
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.
token.Method
will give you the signing method the JWT uses. Consider also checking if that matches - error messages for mismatch conditions would be great.
Please also check if Keyfile or Secret are empty and return an error if they should be present.
panic(e.Error()) | ||
} | ||
return key | ||
} |
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.
Please do not panic on errors. They should always be returned from the function so the caller can decide to handle errors.
Secret string `json:"secret" required:"true"` | ||
Method string `envconfig:"SIGNING_METHOD" json:"method"` | ||
Secret string `envconfig:"SECRET" json:"secret"` | ||
Keyfile string `envconfig:"KEYFILE" json:"keyfile"` |
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.
Since this service has support for a multi instance mode it should be possible to have a different singing key for every instance. The settings of an instance are persisted in the database and therefore cannot be loaded from a file dynamically. It would be great if there also was an option to pass in the PEM-encoded key as a string.
See these files for a similar implementation in gotrue
:
GITGATEWAY_JWT_SECRET="CHANGE-THIS! VERY IMPORTANT!" | ||
GITGATEWAY_JWT_SIGNING_METHOD="HS256" # [HS256|RS256] | ||
GITGATEWAY_JWT_SECRET="CHANGE-THIS! VERY IMPORTANT!" # HS256 | ||
#GITGATEWAY_JWT_KEYFILE="/path/to/keyfile.pub" # RS256 |
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.
If you would like to test for backwards compat, discard this change, so the tests run on a previous config where method did not exist.
Closes Issue #32
- Summary
This adds the RS256 Signing Method to the valid Parser methods in
api/auth.go
.There are two new properties on the JWTConfiguration struct:
Method
andKeyfile
.Secret
is no longer required, since the RS256 method will be looking at theKeyfile
property. TheKeyfile
should be a path to a public keyfile.Since
Method
is a new property, it is not required, so as to maintain backwards compatibility.api/auth.go
defaults to HS256 when that property is not present.- Motivation
I'm using a non-GoTrue authentication service which does not currently support HMAC signing of access tokens - only RSA.
- Test plan
Existing instances of Git Gateway should continue to function normally upon update.
Using RS256:
.env
key.pub
- Description for the changelog
Allow for tokens to be signed with RS256
- A picture of a cute animal (not mandatory but encouraged)