-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
API tokens using JWT #1772
Comments
+1 |
What other solutions are you envisioning that would allow Kong nodes to be aware of your consumer's credentials (signing the tokens) all the while not storing them in the database at the same time?
We would welcome contributions for this, but at the same time, such a contribution would need to find an elegant way of dealing with this issue across the entire code base, providing a proper DB encryption for all secrets stored in both Cassandra and Postgres. This is on our TODO list.
That is correct. Contributions welcomed :) |
PS: at the same time, you can use RS256 to sign your tokens, for which Kong will only require you to store the public key in the DB. |
Avoiding DB access for fetching secret : I was hoping it would be more like nginx plus jwt token support. In this case, a single secret is needed on server side as configuration. The configuration is loaded on server startup and no db access for fetching secret. The jwt plugin for caddy also has similar implementation where secret is configured using a environment variable Avoiding DB access for fetching consumer details : The To draw parallels in kong, the flow in kong could be as follows
$ export JWT_SECRET=e71829c351aa4242c2719cbfbe671c09
$ kong start
// Claim payload for creating token
{
"sub": "7bce93e1-0a90-489c-c887-d385545f8f4b", // consumer id
"username": "john_doe",
"customid": "1234"
} // Request for creating JWT token for consumer
$ curl -X POST http://kong:8001/consumers/{consumer}/jwt
HTTP/1.1 201 Created
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI3YmNlOTNlMS0wYTkwLTQ4OWMtYzg4Ny1kMzg1NTQ1ZjhmNGIiLCJ1c2VybmFtZSI6ImpvaG5fZG9lIiwiY3VzdG9taWQiOiIxMjM0In0.V7DGbqOPS_MlZOnL_jyFYIH-mxAe-e1l3uuhYgr0vGM"
}
Security aspectNone of the consumer tokens are stored in DB, hence no need for encryption / hashing. This assumes the secret for creating token is safe guarded on server side, which would be a minimum requirement even when encryption / hashing mechanism is used for storing sensitive data in DB. So no DB access at all?Yes*, only If blacklisting tokens is not needed. @thibaultcha Thanks for suggesting RS256 |
Reading this post, should I assume that there is no blacklisting of JWT supported by Kong? |
@endeepak exposing consumer metadata as http headers (one http header for one consumer attribute) might be problematic if you start having a big enough claim payload. Would be nice if kong expose the base64 encoded string that we just need to decode and deal with it. What do you think? |
@endeepak, I would suggest using RS256 encryption, requiring you only to store only the public key of your users for validation. Very safe, as you do not have knowledge of the private key of your caller and you do not have to communicate any secrets to the users. |
I am closing this as using an asymmetric signature algorithm should be the preferred way to go. |
Context:
We are planning to expose our APIs to our application users similar to Github api keys. We need rate limiting etc which are implemented beautifully in kong. Our use case can be achieved easily with key auth plugin, but couple of concerns there
The JWT spec seems to solve both of these problems (assuming secret used for signing token is safe)
Problem:
The current JWT plugin seems to generate new pair of issuer field (iss / called as key there) and secret per consumer for signing. These values are stored in DB
Question:
What is the recommended way achieve use case like Github api keys with JWT in kong?
The text was updated successfully, but these errors were encountered: