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

[auth] Add JWT Signing #1871

Closed
humphd opened this issue Mar 5, 2021 · 8 comments
Closed

[auth] Add JWT Signing #1871

humphd opened this issue Mar 5, 2021 · 8 comments
Assignees
Labels
area: back-end type: enhancement New feature or request type: security Security concerns
Milestone

Comments

@humphd
Copy link
Contributor

humphd commented Mar 5, 2021

We need to include JWT signing so our tokens can be verified with a public key. Right now we only use a secret from the env. We'll have to figure out how to generate, store, and pass the public/private keys into the container from staging/prod, similar to what we do now with certs for SSL and nginx.

@humphd humphd added type: enhancement New feature or request type: security Security concerns labels Mar 5, 2021
@yuanLeeMidori yuanLeeMidori self-assigned this Mar 9, 2021
@izhuravlev
Copy link
Contributor

Looking into this:
image

@joelazwar
Copy link
Contributor

joelazwar commented Feb 1, 2022

Working on this right now. Wondering if you could clear up a few questions I have regarding this issue.

I've written the code to sign and verify the tokens with the RSA algorithm to use public and private keys and the e2e tests seem to work (JWT.io link) Currently trying to figure out how to generate and store the keys.

One question I have though, is do we generate a new public/private key pair everytime a use logs in/ register?

My understanding is that we'll have a fixed value of the pair, keeping the private key in a concealed place(environment variable?) and the public key is shared for verifying the JWTs.

As for generation, I used a website to generate (there are a couple) the private/public keys.

Would appreciate your (and anyone else's) advice on this, still learning about JWTs cc @humphd

@humphd
Copy link
Contributor Author

humphd commented Feb 1, 2022

We'll need to generate a bunch of new key pairs for development, staging, production. We'd pass these in via env variables, so your code can expect to read them from process.env somehow, and we'll have to update the docker configs to forward these variables into the container at runtime.

We'll also need to expose a JWKS endpoint on our sso (formerly auth) server, so all the miroservices can get the signing keys to validate the signed tokens they receive. This bit can be done behind the scenes in Satellite, so microservices don't have to worry about it.

@humphd
Copy link
Contributor Author

humphd commented Feb 1, 2022

In Satellite we do it here https://github.com/Seneca-CDOT/satellite/blob/3b0833360a91527df2fac7726fee806d289e8588/src/service-token.js#L19, and we need to upgrade this to use something like https://github.com/auth0/node-jwks-rsa/tree/61b5740b3846f74fa6d631be6712405700d9c163/examples/express-demo

@humphd
Copy link
Contributor Author

humphd commented Feb 1, 2022

https://sometimes-react.medium.com/jwks-and-node-jose-9273f89f9a02 is useful, as is https://github.com/DinoChiesa/Apigee-JWT-with-JWKS (see his video explanation).

NOTE: because all of our microservices are run together, we could also share this via env variables too vs. having them download via a URI.

@aserputov aserputov modified the milestones: 2.6 Release, 2.7 Release Feb 2, 2022
@joelazwar
Copy link
Contributor

joelazwar commented Feb 2, 2022

thanks for the references, their really informative. But I still haven't fully grasped JWKS endpoints and Satellite fully just yet.

So we need to expose an endpoint on our sso server like "/auth/jwks" so that our microservices can grab a JWKS to use to authenticate their JWTs. Versus the alternative which is to put the keys in an env variable.

If we use the first approach, we'd change the Satellite.isAuthenticated() method to be like the example you mentioned above where it grabs the JWKS from the sso server endpoint. Then passes the signing keys back to the microservices to use to validate.

The alternative is just to share the key via env variable and make the changes in Satellite.isAuthenticated() to verify with the key.

But that's all in satellite's area. So the changes in our SSO service would include modifying the JWT to be signed with private keys, and add the endpoint to give out the JWKS.

Please correct me where I'm wrong.

@humphd
Copy link
Contributor Author

humphd commented Feb 2, 2022

You've got it. The sso service will sign the JWTs, and also have an endpoint for getting the JWKS. The Satellite code will be updated with middleware to automatically do the verification step using the key it downloads from the sso service (on startup). Almost all of this will be invisible and automatic inside Satellite.

@humphd
Copy link
Contributor Author

humphd commented Feb 18, 2022

I'm going to call this "done" based on @joelazwar's work in #2957. We can file more as we go.

@humphd humphd closed this as completed Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end type: enhancement New feature or request type: security Security concerns
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants