Repository navigation
Key Redis rate limiter by Metron username instead of API token - #276
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Talkerpasses the configuredusertoRedisRateLimiter, including when authenticating with an API token. If no username is set, it warns and falls back to the localHeaderPacedRateLimiter. Removes_redis_account()and the token hashing.cli.py: Switching from password to token auth now keepsmetron.userand removes only the password, so migrated users still have the username Redis needs.README.md: The Redis FAQ saysuseris required even with token auth. The section on sharing with other mokkari software now says to use the Metron username as theaccount._redis_accounttests. 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
key_prefix, so both apps usemokkari:ratelimit:{<username>}:*and share one limit.key_prefix, so both apps usemokkari: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:Talkerpasses the configuredusertoRedisRateLimiter, including when authenticating with an API token. If no username is set, it warns and falls back to the localHeaderPacedRateLimiter. Removes_redis_account()and the token hashing.cli.py: Switching from password to token auth now keepsmetron.userand removes only the password, so migrated users still have the username Redis needs.README.md: The Redis FAQ saysuseris required even with token auth. The section on sharing with other mokkari software now says to use the Metron username as theaccount._redis_accounttests. 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
key_prefix, so both apps usemokkari:ratelimit:{<username>}:*and share one limit.key_prefix, so both apps usemokkari:ratelimit:{<username>}:*and share one limit.Upgrade note
Users who already switched to token auth had
userremoved from their settings. To use the Redis limiter, they need to add it back to the[metron]section ofsettings.ini: