Skip to content

root: in-process per-IP rate throttle - #23015

Merged
BeryJu merged 2 commits into
goauthentik:mainfrom
ryanpesek:local-anon-rate-throttle
Jul 6, 2026
Merged

BeryJu merged 2 commits into
goauthentik:mainfrom
ryanpesek:local-anon-rate-throttle

Conversation

@ryanpesek

Copy link
Copy Markdown
Contributor

Why

DRF's stock AnonRateThrottle uses Django's default cache to track
per-IP request counters. With authentik's default cache backed by
PostgreSQL (django_postgres_cache), every API request that hits the
throttle machinery issues a cache.get + cache.set against PG just
to make the throttle decision. Under flood conditions this adds DB
load instead of reducing it — the protective layer becomes an amplifier.

What

  • New LocalAnonRateThrottle(AnonRateThrottle) subclass with
    cache = caches["throttle"].
  • New throttle cache alias in CACHES backed by LocMemCache with
    MAX_ENTRIES=10000
  • DEFAULT_THROTTLE_CLASSES points at the new subclass.

Tests

5 tests: throttle uses the throttle cache alias, the alias is backed
by LocMemCache, MAX_ENTRIES is sufficiently above the default 300,
throttle writes are isolated from the default PG cache, and
DEFAULT_THROTTLE_CLASSES references the new subclass.


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

@ryanpesek
ryanpesek requested a review from a team as a code owner June 11, 2026 19:12
@netlify

netlify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 666dc74
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a3e670f298d6f0008d09319
😎 Deploy Preview https://deploy-preview-23015--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 666dc74
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a3e670f7ceba800084740f4
😎 Deploy Preview https://deploy-preview-23015--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 666dc74
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a3e670f4e7d5f000899f92f
😎 Deploy Preview https://deploy-preview-23015--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.24%. Comparing base (c870bc5) to head (666dc74).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23015      +/-   ##
==========================================
- Coverage   93.28%   93.24%   -0.05%     
==========================================
  Files        1037     1039       +2     
  Lines       60556    60582      +26     
  Branches      400      400              
==========================================
  Hits        56490    56490              
- Misses       4066     4092      +26     
Flag Coverage Δ
conformance 36.33% <15.38%> (-0.01%) ⬇️
e2e 41.56% <15.38%> (-0.01%) ⬇️
integration 32.30% <15.38%> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 92.27% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.30% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@gergosimonyi gergosimonyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. @rissson can you think of a reason not to?

@rissson rissson added backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 labels Jun 26, 2026
@rissson rissson changed the title In-process per-IP rate throttle root: in-process per-IP rate throttle Jun 29, 2026
@rissson

rissson commented Jun 29, 2026

Copy link
Copy Markdown
Member

Seems reasonable to me. @rissson can you think of a reason not to?

I cannot. We probably want to call this out in release notes however. @BeryJu thoughts?

@rissson
rissson requested a review from BeryJu June 29, 2026 13:20
@BeryJu
BeryJu merged commit 3cd80c7 into goauthentik:main Jul 6, 2026
107 checks passed
BeryJu pushed a commit that referenced this pull request Jul 7, 2026
root: in-process per-IP rate throttle (#23015)

route DRF anonymous throttle through a per-worker LocMem cache

Co-authored-by: Ryan Pesek <[email protected]>
gergosimonyi added a commit that referenced this pull request Jul 21, 2026
route DRF anonymous throttle through a per-worker LocMem cache

Co-authored-by: Ryan Pesek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants