Skip to content

feat: opt-in AWS IAM authentication for PostgreSQL (RDS) and Redis/Valkey (ElastiCache) - #1029

Open
nimish-ks wants to merge 9 commits into
mainfrom
feat--aws-iam-auth-postgres-valkey
Open

nimish-ks wants to merge 9 commits into
mainfrom
feat--aws-iam-auth-postgres-valkey

Conversation

@nimish-ks

Copy link
Copy Markdown
Member

Lets the backend authenticate to Amazon RDS and ElastiCache with short-lived IAM tokens instead of static passwords, using the ambient AWS credentials (e.g. an ECS task role).

Opt-in, no new configuration. IAM auth is used only when no password is set and the host is an AWS endpoint:

  • DATABASE_PASSWORD unset + DATABASE_HOST ending in .rds.amazonaws.com
  • REDIS_USER set, REDIS_PASSWORD unset + REDIS_HOST ending in .cache.amazonaws.com (TLS replication-group endpoints)

Region comes from the standard AWS_DEFAULT_REGION. Password authentication is unchanged: the settings diff is additions only, and with a password set the resulting DATABASES, CACHES and RQ_QUEUES are identical to before.

How: a thin subclass of Django's PostgreSQL backend sets the password to an RDS auth token at connect time; a redis-py CredentialProvider does the same for ElastiCache and is passed to the cache and RQ queues. Tokens are signed locally and only checked when a connection opens.

Testing: unit tests for both token paths and provider pickling; settings verified under both configurations.

…lkey (ElastiCache)

When no password is configured and the host is an Amazon RDS or ElastiCache
endpoint, log in with short-lived IAM tokens signed from the ambient AWS
credentials. Password authentication is unchanged.
… a dedicated role

When set, the instance/machine role first assumes AWS_INTEGRATION_ROLE_ARN and
target roles are assumed from it, so the role integrations trust can stay
separate from the role the application runs as. Unset, behaviour is unchanged;
AWS_INTEGRATION_ACCESS_KEY_ID/SECRET still take precedence.
nimish-ks and others added 3 commits September 21, 2026 21:24
Password-based setups resolve exactly as before, IAM only switches on for
passwordless RDS/ElastiCache endpoints, tokens are signed per connection and
fail loudly without region or credentials, and AWS_INTEGRATION_ROLE_ARN is
strictly opt-in with integration access keys still taking precedence.
The signer only holds weak references into the session's event hooks. The
session was a local in _signer(), so once it was garbage-collected every new
Redis connection failed with ReferenceError. Long-running RQ workers hit this
on staging; the regression test forces a collection between connections.
@nimish-ks nimish-ks self-assigned this Sep 22, 2026
nimish-ks and others added 4 commits September 24, 2026 19:30
- Redis IAM is now opt-in via REDIS_IAM_CACHE_NAME (the replication group
  ID). The group can't be derived reliably from the endpoint (older endpoint
  formats, custom DNS names), and explicit opt-in means a passwordless
  ElastiCache user is never switched to IAM by accident.
- IAM tokens are only sent over TLS: Redis IAM refuses to start without
  REDIS_SSL, and Postgres uses IAM only when DATABASE_SSL is on.
- Dynamic secrets that use their own access keys no longer build an STS
  client, so they don't depend on the AWS_INTEGRATION_ROLE_ARN hop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant