-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
Token authentication very slow > 5s #684
Comments
Friendly ping @lepture Is there any context I can provide? Do you have any hints for me what could cause this behavior? I would be happy to do further debugging to track this down. |
Another friendly ping @lepture This behavior is really bugging me. I would love to get some guidance on how to debug this further. |
If the behavior varies depending on the silicon and is affected by the version of You might try generating a flamegraph to see where it's hanging. My gut feeling is this is not a bug in authlib, but I could be wrong. |
This seems not a thing that Authlib can solve. |
I like the suggestion about the entropy, as that is something I have wondered about too. Do you by chance have any suggestions what the best way to check this could be? I thought that docker provides the kernel randomness in the containers too (since the kernel is shared). Do you happen to know if this is not the case? |
I will be looking into the flame graph, that could help. However the runtime environment is.... kind of hard to reach, so I'm not yet sure if that is really possible. |
@lepture Regarding what could be done by Authlib: Perhaps reloading and verifying the key from disk less frequently (i.e. on every request). That would probably help, as the key does not need to be verified for each request. |
@dwt is it related with docker? If you run outside docker, will it be that slow? |
This is running in Podman, outside of Podman it seemed fast. |
Do you have to generate the RSA key every time? Can you cache the key like: _cached_keys = {}
def get_rsa_key(name: str):
if name in _cached_keys:
return _cached_keys[name]
key = _generate_rsa_key(name)
_cached_keys[name] = key
return key |
According to cryptography
|
Closed, since we can't fix it in Authlib. |
Thanks for trying! |
Regarding the caching: I would like to. These keys are read from the filesystem on each request - and that is slow because of the check in cryptography. Caching them so they are only re-read when they change on disk would probably solve this problem perfectly fine. That might be something that authlib can actually do to speed this up. |
Describe the bug
When authenticating against a oidc server written with Authlib 1.3.2 generating the token for the client is really slow. Depending on the runtime context this can take more than 5s.
Error Stacks
To Reproduce
When running this on my arm machine (apple silicon) this is fast as in < .2 seconds. On a xeon virtual machine, running in Podman this however takes > 5s when executed via the code path in rsa_key.py.
The strange thing is, that this reproduction in isolation, is fast there too (<.2s) but when run in the full project this call to
numbers.private_key()
reliably takes more than 5 seconds.Expected behavior
numbers.private_key()
should always be fast.Environment:
Additional context
I do not understand what kind of difference in the environment is the reason, but this behavior feels really weird. Especially since I can reliably reproduce this when running inside the application, but not when running the above reproduction independently (inside the same docker container on the same system)
Inspired by this bug in cryptography I tried downgrading to cryptography < 37 - and that restores the missing speed in the application.
This is my current workaround, but of course using such a really old version of openssl (1.1.1) is a bad idea long term.
The text was updated successfully, but these errors were encountered: