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

Allow for RS256 Token Signing #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrew-womeldorf
Copy link

@andrew-womeldorf andrew-womeldorf commented Mar 16, 2019

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 and Keyfile. Secret is no longer required, since the RS256 method will be looking at the Keyfile property. The Keyfile 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

GITGATEWAY_JWT_SIGNING_METHOD="RS256"
GITGATEWAY_JWT_KEYFILE="key.pub"

key.pub

-----BEGIN PUBLIC KEY-----
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
........
-----END PUBLIC KEY-----

- Description for the changelog
Allow for tokens to be signed with RS256

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Contributor

@mraerino mraerino left a 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)
}
Copy link
Contributor

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
}
Copy link
Contributor

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"`
Copy link
Contributor

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
Copy link
Contributor

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.

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.

2 participants