Skip to content

Commit 8dd7f31

Browse files
committed
--amend
""" 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:")
1 parent 2c049e1 commit 8dd7f31

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

backend/onyx/background/celery/configs/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
from onyx.configs.app_configs import REDIS_SSL
1313
from onyx.configs.app_configs import REDIS_SSL_CA_CERTS
1414
from onyx.configs.app_configs import REDIS_SSL_CERT_REQS
15+
from onyx.configs.app_configs import USE_REDIS_IAM_AUTH
1516
from onyx.configs.constants import OnyxCeleryPriority
1617
from onyx.configs.constants import REDIS_SOCKET_KEEPALIVE_OPTIONS
1718

1819
CELERY_SEPARATOR = ":"
1920

2021
CELERY_PASSWORD_PART = ""
21-
if REDIS_PASSWORD:
22+
if REDIS_PASSWORD and not USE_REDIS_IAM_AUTH:
2223
CELERY_PASSWORD_PART = ":" + urllib.parse.quote(REDIS_PASSWORD, safe="") + "@"
2324

2425
REDIS_SCHEME = "redis"

backend/onyx/configs/app_configs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@
231231
except ValueError:
232232
POSTGRES_POOL_RECYCLE = POSTGRES_POOL_RECYCLE_DEFAULT
233233

234+
# RDS IAM authentication - enables IAM-based authentication for PostgreSQL
234235
USE_IAM_AUTH = os.getenv("USE_IAM_AUTH", "False").lower() == "true"
235236

237+
# Redis IAM authentication - enables IAM-based authentication for Redis ElastiCache
238+
# Note: This is separate from RDS IAM auth as they use different authentication mechanisms
239+
USE_REDIS_IAM_AUTH = os.getenv("USE_REDIS_IAM_AUTH", "False").lower() == "true"
236240

237241
REDIS_SSL = os.getenv("REDIS_SSL", "").lower() == "true"
238242
REDIS_HOST = os.environ.get("REDIS_HOST") or "localhost"

backend/onyx/redis/iam_auth.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Redis IAM Authentication Module
3+
4+
This module provides Redis IAM authentication functionality for AWS ElastiCache.
5+
Unlike RDS IAM auth, Redis IAM auth relies on IAM roles and policies rather than
6+
generating authentication tokens.
7+
8+
Key functions:
9+
- configure_redis_iam_auth: Configure Redis connection parameters for IAM auth
10+
- create_redis_ssl_context_if_iam: Create SSL context for secure connections
11+
"""
12+
13+
import ssl
14+
from typing import Any
15+
16+
17+
def configure_redis_iam_auth(
18+
connection_kwargs: dict[str, Any], host: str, port: str, region: str
19+
) -> None:
20+
"""
21+
Configure Redis connection parameters for IAM authentication.
22+
23+
For ElastiCache with IAM, we:
24+
1. Remove the password (not needed with IAM)
25+
2. Ensure SSL is enabled
26+
3. Set up proper SSL context (defaults to system CA certificates)
27+
"""
28+
# Remove password as it's not needed with IAM authentication
29+
if "password" in connection_kwargs:
30+
del connection_kwargs["password"]
31+
32+
# Ensure SSL is enabled for IAM authentication
33+
connection_kwargs["ssl"] = True
34+
35+
# Create SSL context using system CA certificates by default
36+
# This works with AWS ElastiCache without requiring additional CA files
37+
ssl_context = ssl.create_default_context()
38+
ssl_context.check_hostname = True
39+
ssl_context.verify_mode = ssl.CERT_REQUIRED
40+
connection_kwargs["ssl_context"] = ssl_context
41+
42+
43+
def create_redis_ssl_context_if_iam() -> ssl.SSLContext | None:
44+
"""Create an SSL context for Redis IAM authentication using system CA certificates."""
45+
# Use system CA certificates by default - no need for additional CA files
46+
ssl_context = ssl.create_default_context()
47+
ssl_context.check_hostname = True
48+
ssl_context.verify_mode = ssl.CERT_REQUIRED
49+
return ssl_context

backend/onyx/redis/redis_pool.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from redis.client import Redis
1515
from redis.lock import Lock as RedisLock
1616

17+
from onyx.configs.app_configs import AWS_REGION_NAME
1718
from onyx.configs.app_configs import REDIS_AUTH_KEY_PREFIX
1819
from onyx.configs.app_configs import REDIS_DB_NUMBER
1920
from onyx.configs.app_configs import REDIS_HEALTH_CHECK_INTERVAL
@@ -25,8 +26,11 @@
2526
from onyx.configs.app_configs import REDIS_SSL
2627
from onyx.configs.app_configs import REDIS_SSL_CA_CERTS
2728
from onyx.configs.app_configs import REDIS_SSL_CERT_REQS
29+
from onyx.configs.app_configs import USE_REDIS_IAM_AUTH
2830
from onyx.configs.constants import FASTAPI_USERS_AUTH_COOKIE_NAME
2931
from onyx.configs.constants import REDIS_SOCKET_KEEPALIVE_OPTIONS
32+
from onyx.redis.iam_auth import configure_redis_iam_auth
33+
from onyx.redis.iam_auth import create_redis_ssl_context_if_iam
3034
from onyx.utils.logger import setup_logger
3135
from shared_configs.configs import DEFAULT_REDIS_PREFIX
3236
from shared_configs.contextvars import get_current_tenant_id
@@ -186,12 +190,43 @@ def create_pool(
186190
ssl_cert_reqs: str = REDIS_SSL_CERT_REQS,
187191
ssl: bool = False,
188192
) -> redis.BlockingConnectionPool:
193+
"""
194+
Create a Redis connection pool with appropriate SSL configuration.
195+
196+
SSL Configuration Priority:
197+
1. IAM Authentication (USE_REDIS_IAM_AUTH=true): Uses system CA certificates
198+
2. Regular SSL (REDIS_SSL=true): Uses custom SSL configuration
199+
3. No SSL: Standard connection without encryption
200+
201+
Note: IAM authentication automatically enables SSL and takes precedence
202+
over regular SSL configuration to ensure proper security.
203+
"""
189204
"""We use BlockingConnectionPool because it will block and wait for a connection
190205
rather than error if max_connections is reached. This is far more deterministic
191206
behavior and aligned with how we want to use Redis."""
192207

193208
# Using ConnectionPool is not well documented.
194209
# Useful examples: https://github.com/redis/redis-py/issues/780
210+
211+
# Handle IAM authentication
212+
if USE_REDIS_IAM_AUTH:
213+
# For IAM authentication, we don't use password
214+
# and ensure SSL is enabled with proper context
215+
ssl_context = create_redis_ssl_context_if_iam()
216+
return redis.BlockingConnectionPool(
217+
host=host,
218+
port=port,
219+
db=db,
220+
password=None, # No password with IAM auth
221+
max_connections=max_connections,
222+
timeout=None,
223+
health_check_interval=REDIS_HEALTH_CHECK_INTERVAL,
224+
socket_keepalive=True,
225+
socket_keepalive_options=REDIS_SOCKET_KEEPALIVE_OPTIONS,
226+
connection_class=redis.SSLConnection,
227+
ssl_context=ssl_context, # Use IAM auth SSL context
228+
)
229+
195230
if ssl:
196231
return redis.BlockingConnectionPool(
197232
host=host,
@@ -363,7 +398,17 @@ async def get_async_redis_connection() -> aioredis.Redis:
363398
"socket_keepalive_options": REDIS_SOCKET_KEEPALIVE_OPTIONS,
364399
}
365400

366-
if REDIS_SSL:
401+
# Handle SSL configuration with clear priority:
402+
# 1. IAM Authentication (takes precedence, handles SSL automatically)
403+
# 2. Regular SSL (only when IAM auth is disabled)
404+
if USE_REDIS_IAM_AUTH:
405+
# IAM authentication handles SSL configuration automatically
406+
# This ensures proper security with system CA certificates
407+
configure_redis_iam_auth(
408+
connection_kwargs, REDIS_HOST, REDIS_PORT, AWS_REGION_NAME
409+
)
410+
elif REDIS_SSL:
411+
# Regular SSL configuration (only when not using IAM auth)
367412
ssl_context = ssl.create_default_context()
368413

369414
if REDIS_SSL_CA_CERTS:

0 commit comments

Comments
 (0)