⚡️(api) improve performance of HTTP basic auth#337
Conversation
b51674c to
94deb57
Compare
94deb57 to
2d8ac37
Compare
jmaupetit
left a comment
There was a problem hiding this comment.
That's wonderful and promising, wow!
Maybe you should also add python tests ensuring we hit the cache on subsequent requests?
There was a problem hiding this comment.
Seems good to me (I agree with comments by @jmaupetit concerning the default values). One suggestion:
Maybe only cache results with valid credentials to avoid the following situation:
a user (probably an admin in this situation) tries to connect with his credentials, then realizes they are not valid and proceeds to create an account with these credentials. The user would be locked out of the account for the next hour (probably without knowing why) as the credentials were cached as invalid.
This would not lead to a timing exploit or decrease performance for users.
For now, we are caching what's in the |
We would either need to do a timing test, or to activate with |
2d8ac37 to
67d9979
Compare
Maybe we could directly call the |
Good point concerning
My bad, I thought cachetools was also caching Exceptions 🙃 |
@Leobouloc We could probably remove |
65f9ad6 to
5e7ef64
Compare
My guess is that as long, as we are using a single file ( |
Leobouloc
left a comment
There was a problem hiding this comment.
Seems good to me. I left a few small suggestions.
5e7ef64 to
a9407a5
Compare
HTTP Basic auth implementation in Ralph is using the secure and standard bcrypt algorithm to hash/salt passwords before storing them. But this implementation comes with a performance cost, as each request has an overhead of almost 200ms. By LRU caching the HTTP auth credentials, we should greatly decrease the overhead of the vast majority of the requests.
Gitlint logs a warning when using a rule that uses a custom regex and `regex-style-search` option is not enabled. Now enabling this option to avoid the warning
a9407a5 to
454ecfd
Compare
Changes : - Cache the credentials file based on when it was last modified. - Also cache the users' decrypted data based on that information. Rationale : Right now, modifying the basic auth credentials file (adding a user, for instance) requires a server restart. This is because of caching at the credentials file level. Following the dicussion on [a previous PR](openfun#337 (comment)) we propose to add the last modified time of the credentials file to the chache key for the credentials file and the users' data both. If caching of the credentials file seems unnecessary (as was discussed in the above PR), it may be removed without breaking this feature.
Changes: - Cache the credentials file based on when it was last modified. - Also cache the users' decrypted data based on that information. Rationale: Right now, modifying the basic auth credentials file (adding a user, for instance) requires a server restart. This is because of caching at the credentials file level. Following the dicussion on [a previous PR] (openfun#337 (comment)) we propose to add the last modified time of the credentials file to the cache key for the credentials file and the users' data both. If caching of the credentials file seems unnecessary (as was discussed in the above PR), it may be removed without breaking this feature.
Changes: - Cache the credentials file based on when it was last modified. - Also cache the users' decrypted data based on that information. Rationale: Right now, modifying the basic auth credentials file (adding a user, for instance) requires a server restart. This is because of caching at the credentials file level. Following the dicussion on [a previous PR] (openfun#337 (comment)) we propose to add the last modified time of the credentials file to the cache key for the credentials file and the users' data both. If caching of the credentials file seems unnecessary (as was discussed in the above PR), it may be removed without breaking this feature.

Purpose
HTTP Basic auth implementation in Ralph is using the secure and standard bcrypt algorithm to hash/salt passwords before storing them.
But this implementation comes with a performance cost, as each request has an overhead of around 200ms.
Proposal
By LRU caching the HTTP auth credentials, we should greatly decrease the overhead of the vast majority of requests.
/whoami