You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using Ory Network as our authentication provider, and Oathkeeper to protect our APIs.
Oathkeeper is configured with a cookie_session authenticator and uses the /sessions/whoami endpoint to check the cookie.
When a user makes a lot of calls to our API at the same time, Oathkeeper can sometimes return a 401 - Access credentials are invalid response, even when the cookie is valid.
I did a bit of digging with our OpenTelemetry instrumentation, and figured out that the /sessions/whoami endpoint is in fact returning a 429 status, because we're exceeding rate limiting.
I see two potential improvements:
Change the response status
Instead of returning a misleading 401 status, Oathkeeper should return another status code, like 429, so it can help the end-user understand what is happening.
Add cache to the check_session_url call
When a user performs a lot of calls in a small timeframe, it's not necessary to call the /sessions/whoami for all calls because the session cookie hasn't changed.
I suggest to add an optional caching mechanism to the cookie_session authenticator, it would solve this issue even with a low TTL (~1s)
This caching mechanism could be similar to the one found in the oauth2_client_credentials authenticator.
Reproducing the bug
Run Oathkeeper with a cookie_session authenticator linked to an Ory Network project.
Log-in and retrieve the session cookie
Write and run a script that sends 100 requests in parallel to the running Oathkeeper, with the session cookie
You should see a 401 at some point, even though the cookie is valid
This issue also shows that when we build an API on top of Oathkeeper & Ory Network, the rate-limiting of our API can't be better than Ory Network's rate-limiting on the whoami endpoint.
This is quite a big limitation ... I was suggesting to add a cache mechanism based on the session cookie, in order to avoid unnecessary requests to the whoami endpoint. If the TTL is low (~1s for instance), the security trade-off is acceptable.
Do you think that it would make sense to add this feature ? I see that it exists for other authenticators like oauth2_client_credentials.
In our case, we are trying to lift this limitation by creating our own whoami that has cache, but IMO it would be simpler to have it directly in oathkeeper
Preflight checklist
Ory Network Project
No response
Describe the bug
We're using Ory Network as our authentication provider, and Oathkeeper to protect our APIs.
Oathkeeper is configured with a
cookie_session
authenticator and uses the/sessions/whoami
endpoint to check the cookie.When a user makes a lot of calls to our API at the same time, Oathkeeper can sometimes return a
401 - Access credentials are invalid
response, even when the cookie is valid.I did a bit of digging with our OpenTelemetry instrumentation, and figured out that the
/sessions/whoami
endpoint is in fact returning a429
status, because we're exceeding rate limiting.I see two potential improvements:
Instead of returning a misleading
401
status, Oathkeeper should return another status code, like429
, so it can help the end-user understand what is happening.check_session_url
callWhen a user performs a lot of calls in a small timeframe, it's not necessary to call the
/sessions/whoami
for all calls because the session cookie hasn't changed.I suggest to add an optional caching mechanism to the
cookie_session
authenticator, it would solve this issue even with a low TTL (~1s)This caching mechanism could be similar to the one found in the
oauth2_client_credentials
authenticator.Reproducing the bug
cookie_session
authenticator linked to an Ory Network project.Relevant log output
No response
Relevant configuration
Version
latest
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Kubernetes
Additional Context
No response
The text was updated successfully, but these errors were encountered: