Fix Redis fail-open behavior for auth revocation and throttling#20
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAuth and rate-limit middleware now fail closed on Redis errors: auth and auth-protected routes return HTTP 503 when blacklist or rate-limit checks fail. Swagger, handler docs, errors, tests, service logic, and router wiring were updated to reflect and enforce this behavior. Changes
Sequence DiagramsequenceDiagram
participant Client
participant RateLimit as RateLimit Middleware
participant Redis as Redis
participant JWTAuth as JWTAuth Middleware
participant Handler as Auth Handler
participant Service as Auth Service
Client->>RateLimit: Request /api/v1/auth/login
RateLimit->>Redis: IncrRateLimit()
alt Redis Available
Redis-->>RateLimit: Success
RateLimit->>JWTAuth: Next
else Redis Unavailable
Redis-->>RateLimit: Error
RateLimit-->>Client: 503 Service Unavailable
end
JWTAuth->>Redis: IsTokenBlacklisted(tokenID)
alt Blacklisted
Redis-->>JWTAuth: true
JWTAuth-->>Client: 401 Unauthorized
else Lookup Error
Redis-->>JWTAuth: Error
JWTAuth-->>Client: 503 Service Unavailable
else Not Blacklisted
Redis-->>JWTAuth: false
JWTAuth->>Handler: Proceed
Handler->>Service: Logout/ChangePassword...
Service->>Redis: BlacklistToken(tokenID)
alt Write Success
Redis-->>Service: Success
Service-->>Handler: OK
Handler-->>Client: 200/204 OK
else Write Failure
Redis-->>Service: Error
Service-->>Handler: ErrServiceUnavailable
Handler-->>Client: 503 Service Unavailable
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
/api/v1/auth/*rate limiting503via a shared service-unavailable error path instead of allowing protected/auth-sensitive traffic throughTesting
go test ./...make lintmake swagmake docker-builddocker compose up --build -dcurlflows for health/readiness, login, protected route access, logout revocation, Redis outage503behavior, and Redis recoverySummary by CodeRabbit