fix(queue): authenticate Redis connection when user/password are configured - #247
fix(queue): authenticate Redis connection when user/password are configured#247breken-ai wants to merge 1 commit into
Conversation
…igured The constructor accepts ?user/?password but getRedis() never called auth(), so every operation against a password-protected Redis failed with NOAUTH. Authenticate right after connect, using the ACL array form [user, password] when a username is set and the plain password form otherwise (phpredis >= 5.3). Null/empty-string checks keep the guard from treating valid edge-case credentials like "0" as unconfigured. An auth failure throws RedisException inside the existing connect retry loop, so misconfiguration fails loudly with bounded retries.
|
| if ($this->password !== null && $this->password !== '') { | ||
| // ACL form when a username is configured, plain password otherwise. | ||
| $hasUser = $this->user !== null && $this->user !== ''; | ||
| $redis->auth($hasUser ? [$this->user, $this->password] : $this->password); | ||
| } |
There was a problem hiding this comment.
Authentication Paths Lack Coverage
This authentication path has no observable behavioral coverage. The existing Redis test service has authentication disabled, so the suite cannot detect regressions in either password-only authentication or the new ACL username/password form. Add integration tests against an authenticated Redis instance that verify successful publish or consume behavior with each credential form and rejection of invalid credentials. Include the "0" credential case highlighted by this change rather than asserting the exact auth() arguments.
Knowledge Base Used: Messaging, queues, and NATS
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/queue/src/Queue/Connection/Redis.php
Line: 205-209
Comment:
**Authentication Paths Lack Coverage**
This authentication path has no observable behavioral coverage. The existing Redis test service has authentication disabled, so the suite cannot detect regressions in either password-only authentication or the new ACL username/password form. Add integration tests against an authenticated Redis instance that verify successful publish or consume behavior with each credential form and rejection of invalid credentials. Include the `"0"` credential case highlighted by this change rather than asserting the exact `auth()` arguments.
**Knowledge Base Used:** [Messaging, queues, and NATS](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/utopia-php/monorepo/-/docs/messaging-queue-nats.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Closing as superseded - the queue-side fix landed upstream in #260 (with appwrite/appwrite#13622 on the app side). @ChiragAgg5k's version is the one to keep. |
Same fix as the auto-closed utopia-php/queue#87 - the queue repo is a read-only mirror, so re-filing here.
packages/queue: theConnection\Redisconstructor has accepted?user/?passwordsince 2.0.x, butgetRedis()never callsauth()- the credentials are stored and ignored. Against a password-protected Redis (requirepassor ACL), every publish/consume fails withNOAUTH.Concrete downstream symptom: appwrite/appwrite#13554 - Appwrite's queue publisher pool passes host+port only, and even with credentials threaded through, this connection never authenticates. The app-side half is appwrite/appwrite#13588.
Fix
getRedis()calls$redis->auth()immediately afterconnect()when a password is configured:[$user, $password]when a username is set (phpredis >= 5.3)empty()), so edge-case but valid credentials like"0"are not droppedRedisExceptioninside the existing connect retry loop, so misconfiguration fails loudly with bounded retriesPrior art
utopia-php/queue#29 attempted this in January 2025 (thanks @kodejuice for the first pass) but stalled with no description and predates the constructor credentials entirely; this PR revives the approach against current
main, covering the ACL username form and the retry-loop failure semantics.Verification
Constructor signature, the
getRedis()connect/retry structure, and phpredisauth()forms all confirmed in source atmain(55dd5be); the monorepo file is byte-identical to the mirror's. Not run: no PHP runtime or live Redis in the author's environment - external red proof is the reporter's hourlyNOAUTHlog on appwrite/appwrite#13554 with every sibling pool authenticating.