-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(infra): Add IAM support for Redis #5265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR introduces IAM authentication support for Redis ElastiCache to complement the existing PostgreSQL IAM authentication pattern in the codebase. The implementation adds a new configuration flag USE_REDIS_IAM_AUTH
that allows Redis connections to use AWS IAM roles instead of password-based authentication.
The changes span four key areas:
- Configuration: Adds the
USE_REDIS_IAM_AUTH
environment variable flag inapp_configs.py
- Redis Connection Handling: Updates
redis_pool.py
to create IAM-aware connection pools that disable password auth and enforce SSL when IAM is enabled - IAM Authentication Module: Introduces
iam_auth.py
containing functions for token generation, SSL configuration, and credential management - Celery Integration: Modifies
base.py
to exclude passwords from broker URLs when IAM authentication is active
The implementation follows the same architectural pattern as the existing PostgreSQL IAM authentication (USE_IAM_AUTH
), maintaining consistency across the codebase. When USE_REDIS_IAM_AUTH
is enabled, Redis connections are configured to use SSL and IAM credentials from AWS, while traditional password authentication is bypassed. This enables secure integration with AWS ElastiCache clusters that are configured for IAM authentication, eliminating the need for hardcoded Redis passwords and leveraging AWS IAM policies for access control.
Confidence score: 1/5
- This PR has critical implementation flaws that will cause authentication failures in production
- Score reflects fundamental issues with the IAM token generation logic that doesn't align with AWS ElastiCache IAM authentication mechanisms
- Pay close attention to
backend/onyx/redis/iam_auth.py
- the core authentication logic needs complete revision as it attempts to use cluster names as tokens rather than generating proper IAM auth tokens
4 files reviewed, 6 comments
d71014e
to
e9f1d3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 issues found across 4 files
React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
host=host, | ||
port=port, | ||
db=db, | ||
password=None, # No password with IAM auth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IAM auth requires an AUTH token (SigV4) and username; setting password=None means no authentication will be performed, causing connection failures with ElastiCache Redis IAM.
Prompt for AI agents
Address the following comment on backend/onyx/redis/redis_pool.py at line 209:
<comment>IAM auth requires an AUTH token (SigV4) and username; setting password=None means no authentication will be performed, causing connection failures with ElastiCache Redis IAM.</comment>
<file context>
@@ -192,6 +196,28 @@ def create_pool(
# Using ConnectionPool is not well documented.
# Useful examples: https://github.com/redis/redis-py/issues/780
+
+ # Handle IAM authentication
+ if USE_REDIS_IAM_AUTH:
+ # For IAM authentication, we don't use password
+ # and ensure SSL is enabled
+ ssl_context = create_redis_ssl_context_if_iam()
</file context>
e9f1d3f
to
8dd7f31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR adds IAM authentication support for Redis ElastiCache to match the existing PostgreSQL IAM authentication capabilities in the codebase. The changes introduce a new configuration variable USE_REDIS_IAM_AUTH
that enables IAM-based authentication for Redis connections.
The implementation adds four key components:
-
Configuration: A new
USE_REDIS_IAM_AUTH
environment variable inapp_configs.py
that follows the same pattern as the existingUSE_IAM_AUTH
for PostgreSQL -
IAM Authentication Module: A new
iam_auth.py
file in the Redis directory that provides functions for configuring IAM authentication parameters and creating SSL contexts -
Celery Integration: Updates to the Celery broker configuration to conditionally exclude password authentication when IAM auth is enabled
-
Redis Pool Integration: Modifications to both synchronous and asynchronous Redis connection creation to support IAM authentication by removing password-based auth and enabling SSL
The approach mirrors the existing PostgreSQL IAM authentication pattern by creating separate configuration paths for IAM versus traditional authentication methods. When IAM authentication is enabled, the system removes password-based authentication and ensures SSL is properly configured for secure connections to AWS ElastiCache.
Confidence score: 1/5
- This PR is not safe to merge and will cause Redis connection failures in production
- Score reflects fundamental flaws in IAM authentication implementation - the code only removes passwords and enables SSL but doesn't implement actual AWS Signature V4 authentication tokens required by ElastiCache IAM
- Pay close attention to
backend/onyx/redis/iam_auth.py
andbackend/onyx/redis/redis_pool.py
as they contain incomplete IAM authentication logic that will fail silently
4 files reviewed, no comments
""" Manual approach: Generate URLs for all your projects to check OAuth clients. Requires no additional installations - just built-in Python libraries. """ def main(): print("Since we can't easily list projects without gcloud,") print("let's generate URLs manually.") print() # Ask user for project IDs print("Enter your GCP project IDs (one per line, press Enter twice when done):") projects = [] while True: project = input().strip() if not project: if projects: # If we have at least one project and get empty line break else: continue projects.append(project) if not projects: print("No projects entered.") return print(f"\nFound {len(projects)} projects.") print("Here are the direct URLs to check for OAuth 2.0 Client IDs:") print() # Generate URLs for each project for project in projects: url = f"https://console.cloud.google.com/apis/credentials?project={project}" print(f"Project: {project}") print(f"URL: {url}") print() # Save to file with open('oauth_check_urls.txt', 'w') as f: f.write("OAuth Client Check URLs\n") f.write("=" * 30 + "\n\n") for project in projects: url = f"https://console.cloud.google.com/apis/credentials?project={project}" f.write(f"Project: {project}\n") f.write(f"URL: {url}\n\n") print(f"URLs also saved to: oauth_check_urls.txt") print("\nInstructions:")
8dd7f31
to
966ddbc
Compare
Description
[Provide a brief description of the changes in this PR]
Adding in IAM support for Redis to match Postgresql
How Has This Been Tested?
[Describe the tests you ran to verify your changes]
Still working on testing this.
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.