-
Notifications
You must be signed in to change notification settings - Fork 48
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
Dynamically resolve key based on token #9
Comments
This would be very helpful and is well supported in the node-jsonwebtoken library on which this depends. |
@dschenkelman @bbrown Wouldn't a better solution be to use Hapi's pack system and also the ability to register multiple variations of the same auth schema? With Hapi you can create a pack of servers, giving you the ability to have server A setup with token auth key A, and then also have server B setup with token auth key B. |
@ryanfitz thanks for the suggestion, but unfortunately that would not work for us :( We have a scenario in which users can create an arbitrary number of applications, each with their own private key. Thus we have no way of telling up front the amount of servers we would need, and instead need information embedded in each JWT to figure out the key to be used. |
@ryanfitz Our situation is that we want to have each token signed with the particular user's secret. That way we can deactivate a particular user without having to change the common secret, which would kick everyone out of the application. |
@ryanfitz should I close this one? |
Would also like to see this PR merged.. |
Would it be better if the plugin had an optional setting that allowed us to pass in a function to do the key look up? So along with validateFunc() we could also pass in something like keyLookUp(decoded, callback) that takes the decoded token and a callback to return a key, otherwise just take the key directly from settings? |
@eventhough that's exactly what the PR does. Here's how it works: auth0#3 (comment) |
@dschenkelman totally understand that you want to support multi-tenant scenarios, but what is the advantage to having a dynamic key instead of including a session id (_jti_) inside the JWT which can be looked up after the JWT has been validated? The JWT.verify function is computed on the Hapi node so is fast (no network latency). |
@nelsonic I see what you mean and we address that in a different way (the DDoS). How would the session id work?
More info about what we are doing here. Not trying to promote, just provide more info without typing everything again. |
@dschenkelman using the JWT in your example you would lookup the jti (_unique token_) after the Even with good caching (memcache/redis) you are still forcing your app to do a lookup for all invalid requests instead of letting How are you mitigating against DDOS? (e.g. does your load-balancer limit requests/sec per IP?) |
@nelsonic there's something I don't understand, would you give the same secret to all users? How do you know which secret to use to verify? Regarding DDoS mitigation: something like that, sorry I can't provide a lot of details. |
The only "secret" we are giving users is the jti (inside the JWT payload) which we look up in redis after the JWT has been verified. I hope I haven't miss-understood the JWT (draft) spec ... I'm not the expert in this, but the &yet guys might be able to provide some insight:
// a unique key for each JWT
var jwt = require('jsonwebtoken');
db.get(uid, function(err, key) {
var token = jwt.sign({ foo: 'bar' }, key);
// callback(err, token);
} // one key to sign them all
var key = fs.readFileSync('private.key'); // get private key
var token = jwt.sign({ foo: 'bar' }, key); Unless the _dynamic key_ implementation allows _Perfect forward secrecy_ ...? (in which case I'm curious how...) |
Note that per user and per tenant can be different things, depending on the perspective. We have multiple tenants (one secret each) and each tenants has multiple users (same secret for all, it's the tenant's secret). If you use the same secret for all tenants (and share it with them as we do), then anyone can create a token with a valid signature. Thus, verifying the token is rendered useless since it gives you no information whatsoever (anyone could have generated it). You would be basically just trusting the |
I agree with @dschenkelman We have a similar use case trying to build a federated identity provider that issues JWTs by authenticating with multiple auth servers (ideally each one belongs to a different partner in the company). We would like to use different secrets to sign users data belonging to different partners. Our application will be accepting JWTs from the federated identity server for all the users (union of users belonging to all the partners). While verifying we would need to dynamically detect the respective partner (exists within the token payload) and use the respective public key. Could you please tell me if you have any plans to merge this functionality sometime in the coming weeks ? |
@dschenkelman / @ksck23 / @bbrown / @martinj in case you still need/want the dynamic keys feature, @eventhough added it to hapi-auth-jwt2 example usage: |
In order to easily support multi tenant scenarios, it would be useful to have optionally have a callback function take the JWT and return the key.
To keep the API simple the idea would be to keep the current behavior if
key
is not a function. Ifkey
is a function then this fragment would look like this:What do you think about it?
I'm working on a PR with the updated docs, implementation and tests.
The text was updated successfully, but these errors were encountered: