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

Persistent API keys #414

Open
gctucker opened this issue Nov 16, 2023 · 2 comments
Open

Persistent API keys #414

gctucker opened this issue Nov 16, 2023 · 2 comments

Comments

@gctucker
Copy link
Contributor

gctucker commented Nov 16, 2023

At the moment, a user can login and get a JWT token. These tokens aren't stored in the database and have a baked-in expiry time. They're used for temporary sessions, typically by web browsers. This is fine and we'll definitely need this kind of tokens, but it's not designed to be used for automation tools that use the API continuously such as pipeline services.

In addition to the JWT, we should create another kind of tokens which we might call "API access keys". These would be stored in the database and could be revoked by the user. They may also have an expiry date and scopes to fine-tune the operations that can be performed with them. This is how most web APIs work, with persistent credentials for this kind of use-case. I don't think fastapi-users can support both, but it can support one or the other:

https://fastapi-users.github.io/fastapi-users/10.0/configuration/authentication/

In our particular case, I would like to suggest that we use the persistent API keys as a way to get a temporary JWT token. So a user can interactively login with a username / password interactive form or non-interactively by sending an access token. Then a short-lived JWT token is generated (say, valid for 1h) and when it expires a new one needs to be generated.

@gctucker
Copy link
Contributor Author

On a side note, JWT have variable length depending on what they contain. They are self-contained, and as such can have some arbitrary data. Some systems such as LAVA can keep tokens for third-party services such as the API in this case, to handle callbacks, but there is a maximum length for storing such tokens. As a result, storing JWT in LAVA databases has proven to be challenging in the past (that's why the early access deployment has a very short user name kci among other things). So having a fixed-sized API access token format for this kind of use-cases will avoid such issues in the future.

@gctucker gctucker changed the title Persistent API tokens Persistent API keys Jan 9, 2024
@gctucker
Copy link
Contributor Author

gctucker commented Jan 9, 2024

Based on the fastapi-users documentation, it seems the best approach would probably be to have multiple authentication backends available: JWT and "database" for API keys, and maybe cookies for the new web dashboard later on as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant