Skip to content

Key Redis rate limiter by Metron username instead of API token - #276

Merged
bpepple merged 1 commit into
mainfrom
fix-redis-key
Oct 2, 2026
Merged

bpepple merged 1 commit into
mainfrom
fix-redis-key

Conversation

@bpepple

@bpepple bpepple commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

metron-tagger keyed the shared Redis rate-limit state by a hash of the API token. Each mokkari-based app usually has its own token, so metron-tagger never shared a limit with other apps on the same Metron account. This PR keys it by the Metron username instead, the same way Barda does.

Changes

  • talker.py: Talker passes the configured user to RedisRateLimiter, including when authenticating with an API token. If no username is set, it warns and falls back to the local HeaderPacedRateLimiter. Removes _redis_account() and the token hashing.
  • cli.py: Switching from password to token auth now keeps metron.user and removes only the password, so migrated users still have the username Redis needs.
  • README.md: The Redis FAQ says user is required even with token auth. The section on sharing with other mokkari software now says to use the Metron username as the account.
  • Tests: Removed the _redis_account tests. Added a test that a token user's limiter is keyed by username. The no-username test now covers a token with no username, and the CLI migration test expects the username to be kept.

Compatibility with other apps

  • Barda: It also keys by the raw username with mokkari's default key_prefix, so both apps use mokkari:ratelimit:{<username>}:* and share one limit.
  • Desaad It also keys by the raw username with mokkari's default key_prefix, so both apps use mokkari:ratelimit:{<username>}:* and share one limit.

Summary

metron-tagger keyed the shared Redis rate-limit state by a hash of the API token. Each mokkari-based app usually has its own token, so metron-tagger never shared a limit with other apps on the same Metron account. This PR keys it by the Metron username instead, the same way Barda does.

Changes

  • talker.py: Talker passes the configured user to RedisRateLimiter, including when authenticating with an API token. If no username is set, it warns and falls back to the local HeaderPacedRateLimiter. Removes _redis_account() and the token hashing.
  • cli.py: Switching from password to token auth now keeps metron.user and removes only the password, so migrated users still have the username Redis needs.
  • README.md: The Redis FAQ says user is required even with token auth. The section on sharing with other mokkari software now says to use the Metron username as the account.
  • Tests: Removed the _redis_account tests. Added a test that a token user's limiter is keyed by username. The no-username test now covers a token with no username, and the CLI migration test expects the username to be kept.

Compatibility with other apps

  • Barda: It also keys by the raw username with mokkari's default key_prefix, so both apps use mokkari:ratelimit:{<username>}:* and share one limit.
  • desaad: It also keys by the raw username with mokkari's default key_prefix, so both apps use mokkari:ratelimit:{<username>}:* and share one limit.

Upgrade note

Users who already switched to token auth had user removed from their settings. To use the Redis limiter, they need to add it back to the [metron] section of settings.ini:

[metron]
user = your-metron-username
redis_url = redis://localhost:6379/0

Each app using mokkari's RedisRateLimiter usually has its own API token, so keying the shared rate-limit state by a hash of the token meant metron-tagger never shared a limit with other apps on the same account. Use the Metron username as the account name instead, matching Barda.

- Talker passes the configured `user` to RedisRateLimiter even when authenticating with an API token. If no username is set, it warns and falls back to the local rate limiter.
- Switching from password to token auth now keeps `metron.user` and removes only the password, so migrated users still have the username Redis needs.
- Update the README's Redis FAQ and the tests.

Users who already switched to token auth lost their username. They need to add `user` back to the [metron] section of settings.ini to use the Redis limiter.
@bpepple bpepple self-assigned this Oct 2, 2026
@bpepple bpepple added the bug Something isn't working label Oct 2, 2026
@bpepple
bpepple merged commit 3a083b1 into main Oct 2, 2026
11 checks passed
@bpepple
bpepple deleted the fix-redis-key branch October 2, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant