Repository navigation
feat!: log in as a Redis ACL user with connection.username - #49
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
BREAKING CHANGE: a hand-written connection object now needs a username attribute (None for the default user); without it the factories raise AttributeError.
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.
Closes #48
RedisConnectionSettingsgainsusername: str | None = None, andbuild_base_redis_kwargspasses it to redis-py next topassword, so every client the factories build — sync and asyncio, single node and cluster — logs in as that ACL user.Why this matters beyond "can't use ACL users"
On master, an ACL user's password in
connection.passworddoes not just fail. Againstredis:7-alpinewith anopassdefault user:AUTH <password> called without any password configured for the default user.HELLO 3 AUTH default <password>, the server accepts it, and the client runs asdefaultwith full access —GET other:xandFLUSHDBboth succeed.Breaking change
username: str | Noneis a member ofRedisConnectionProtocol, and the kwargs builder readssettings.connection.usernamedirectly.BaseRedisSettingsusers get the field with aNonedefault and see no difference. A hand-written connection object (as in the README and the configuration guide) now needsusername = None; without it the factories raiseAttributeError. Those examples are updated. The README one also lackedclient_nameandprotocol, so it already failed before this change.Pre-1.0 with
bump-minor-pre-major,feat!still releases as 0.4.0. The only sibling that depends on the kit, idempotency-kit (>=0.2.0, no cap), builds its settings fromBaseRedisSettings.Docs
The configuration guide gets an "ACL Users" section with a rule that works with the kit. The rule in the issue (
-@all +@read +@write) is not enough, each point below checked on a live server:health_check_intervalsendPING, so+ping;client_nameneeds+client|setname, anddb != 0needs+select; without them every connection fails;+@writestill allowsFLUSHDB/FLUSHALL(a key pattern does not stop a command with no key), so-@dangerous;SCANstill lists other apps' key names;-scanif they are private.docs/agents.mdgets the new field and the updated hand-written example.Tests
mask_redis_kwargs, the sync and asyncio factories passing it toRedisandRedisCluster, the default, andREDIS__CONNECTION__USERNAMEread through an app-level settings model;tests/integration/test_redis_acl.py): an ACL user limited to~app:*under the documented rule canSET app:x, getsNoPermissionErroronGET other:xandFLUSHDB(RESP2 and RESP3, async; RESP2 sync), and passescheck_async_redis_healthwith and without the write probe.With master's
utils.pyswapped back in, the 10 tests that go through the kwargs fail; with the fix all pass.make checkis clean;make testgives 185 passed, coverage 99.66%; the docs build passes.CHANGELOG is left to release-please; the
!puts the break under BREAKING CHANGES.