IAM authentication for LiteLLM's database and Redis on AWS

How to replace static database and Redis passwords in a self-hosted LiteLLM gateway with IAM token authentication on AWS, and what the Entra ID option changes on Azure.

On this page

Why LiteLLM's database and Redis credentials should not be static passwords

A LiteLLM gateway keeps its virtual keys, budgets and spend records in PostgreSQL, and it shares rate limits, router state and cache through Redis once more than one proxy instance runs. Those two data stores hold the access model for every model your organization exposes, so a static database or Redis password is a standing risk. The password sits in a configuration file or secret store, it is copied into deployment tooling, and it usually stays valid until someone remembers to rotate it. Replacing these passwords with short-lived IAM tokens removes the long-lived secret from the gateway entirely.

On AWS, IAM token authentication for Amazon RDS for PostgreSQL means the proxy requests a token from IAM and presents it as the database password, so access depends on the IAM role attached to the workload and on database users mapped to that role. LiteLLM turns this on with the documented setting IAM_TOKEN_DB_AUTH=True, and the matching Microsoft Entra ID option on Azure is AZURE_POSTGRESQL_AUTH=True. Teams usually need this when their security policy forbids stored database passwords, when they run several gateway pods that would otherwise share one credential, or when they must show auditors that database access is tied to a workload identity. Confirm with your database team whether your RDS engine version and parameter settings support IAM users before you commit to the design.

With these settings enabled, LiteLLM's writer and reader database connections refresh their tokens independently ahead of expiry, so a read replica connection does not depend on the writer connection's refresh cycle. Before you rely on this, confirm the token lifetime and refresh behavior against the LiteLLM read replica documentation, and plan a test where you rotate or revoke the IAM permission and observe how the gateway reconnects. ElastiCache also has IAM authentication documented by LiteLLM, which you should treat as a separate build step with its own verification.

How the gateway obtains and refreshes database tokens

The diagram starts with the LiteLLM proxy task or pod, which runs under an IAM role inside the VPC trust boundary. With IAM_TOKEN_DB_AUTH=True, the proxy requests short-lived tokens for the writer and reader RDS endpoints separately, and each connection pool refreshes its own token ahead of expiry. The ElastiCache connection follows the same role-based path. Check that the role has connect permissions on each database user and cache, and that no static passwords remain in configuration.

Token flow from the proxy task to RDS and ElastiCache inside the VPC.

Which authentication option fits which data store and cloud

This table compares static passwords with IAM-based token authentication for each data store and cloud in a LiteLLM deployment. Read each row as a question: what does this option remove, what must already exist, and when is it the right choice. The main takeaway is that IAM authentication removes stored database passwords, but it adds prerequisites in the cloud account and client configuration that must be confirmed before cutover.

OptionWhat it removesPrerequisitesWhen it fits
Static database password (PostgreSQL)Nothing. The password is stored in configuration or a secret and must be rotated by hand.A password in a secret manager, and a rotation process your team operates.Fallback during migration, or environments where IAM authentication is not yet available to the proxy.
RDS IAM token, writer endpointThe stored database password for the primary connection. LiteLLM generates short-lived tokens when IAM_TOKEN_DB_AUTH is True.An RDS PostgreSQL instance with IAM database authentication enabled, a database user granted rds_iam, and an IAM role attached to the proxy workload.Production writes on AWS where the proxy runs with an IAM role, such as on EKS or EC2.
RDS IAM token, reader endpointThe stored password for read replica connections. Writer and reader tokens refresh independently ahead of expiry.A read replica with the same IAM setup, plus the reader endpoint configured in LiteLLM's read replica settings.Deployments that use a read replica for reporting or read traffic. Confirm the replica supports IAM authentication in your region.
ElastiCache IAM auth (Redis)The static Redis auth token for the cluster connection.Confirm engine version and client support in your environment, the IAM policy for the ElastiCache user, and that LiteLLM's ElastiCache IAM setting is available in the release you run.Multi-instance deployments that share rate limits and router state on AWS. Confirm the Redis engine, TLS mode and client library before relying on it.
Microsoft Entra ID for Azure PostgreSQLThe stored password for Azure PostgreSQL. LiteLLM uses tokens when AZURE_POSTGRESQL_AUTH is True.An Azure Database for PostgreSQL server with Entra authentication enabled, a managed identity or service principal mapped to a database role, and token access for the workload.Azure-hosted gateways where workload identity is already managed in Entra ID.

What the AWS identity and network setup must provide first

Token-based authentication only works when the identity, database role, cache user and network path are all in place before LiteLLM starts. Each component below must be verified on its own, because a gap in any one of them shows up as a failed connection at go-live rather than a clear error.

IAM role attached to the workload

The LiteLLM pods or instances need an IAM role that they assume at runtime, so no long-lived access key sits in configuration. Confirm the role is attached to the actual compute identity (for example, a Kubernetes service account or instance profile) and that the trust policy allows only that workload. Check that the role is the same one your team reviews, not a shared administrative role.

rds-db:connect permission scoped to the user

The role needs the rds-db:connect action, and its resource ARN should name the specific database resource and the specific database user rather than a wildcard. A broad resource pattern lets any workload with the role connect as any database user. Ask your security team to review the ARN for both the writer and the reader endpoints if you run a read replica.

Database user mapped to IAM

The PostgreSQL role LiteLLM uses must be created for IAM authentication on the database side, so that RDS accepts a generated token instead of a stored password. Plan this as a one-time administrative step, record who approved it, and confirm that the role has only the privileges the proxy needs. Confirm the exact setup steps with AWS documentation for your engine version, since they are not covered by the LiteLLM settings alone.

ElastiCache user and IAM auth configuration

For Redis, the ElastiCache user must be configured for IAM authentication and mapped to the access rights LiteLLM needs for rate limits, router state and cache. Confirm the cache engine type and version support IAM auth before you design around it, and check the LiteLLM ElastiCache IAM documentation for the required settings. Keep a separate test user during validation so a misconfigured cache does not block the proxy from starting.

ElastiCache IAM docs

VPC routing and security groups

Token authentication does not remove the network path requirement. The proxy subnets must reach the database and cache endpoints on their ports, and security groups should allow only the LiteLLM workloads as sources. Verify routing from the actual runtime network, including any NAT, DNS resolution for private endpoints and the path used by read replicas, before you change any credentials.

PostgreSQL on a supported version line

Choose a PostgreSQL major version that is still within its support window when you go live and when you plan to upgrade. PostgreSQL 18 is the newest supported line in the supplied policy, and its final release is scheduled for November 14, 2030. Version 14 ends support on November 12, 2026, so an older target can force a major upgrade soon after launch. Confirm the version your RDS engine offers before you commit.

PostgreSQL versioning policy

How to switch LiteLLM from passwords to IAM tokens

This sequence replaces static database and Redis passwords with AWS IAM authentication, so the gateway proves its identity with short-lived tokens while the database and cache keep their access controls. Each step ends with a check that the change works before the next one starts.

  1. Create IAM-mapped database users and grants

    The database administrator creates a PostgreSQL role for the LiteLLM writer and another for the reader, configured to authenticate with IAM rather than a password. Grant each role only the privileges LiteLLM needs on its schema, and no superuser or schema ownership rights. Confirm the setup by connecting with a freshly generated IAM token from the gateway host and running a simple read and write test with each role. Both roles should connect and perform only their permitted operations.

  2. Attach a scoped IAM policy to the gateway role

    The cloud team attaches an IAM policy to the role the gateway runs under, allowing the rds-db:connect action only for the specific database resource and database user ARNs used by the writer and reader. Avoid wildcards on the database user name or the cluster so that a compromised gateway cannot connect as other users. Confirm the policy by generating a token with the AWS CLI from the gateway runtime, then checking that the same command fails for a user name outside the policy. Record the policy version in your change ticket.

  3. Enable IAM token authentication for writer and reader

    The platform engineer sets IAM_TOKEN_DB_AUTH to True in the LiteLLM environment, and configures the writer and reader connection settings so each one uses its own IAM user and endpoint. Because the writer and reader refresh tokens independently ahead of expiry, both connections must be defined separately in the configuration. Confirm the change by starting the proxy and checking the health endpoint and startup logs for successful connections to both the writer and the reader.

  4. Configure IAM authentication for ElastiCache

    The platform engineer follows the LiteLLM ElastiCache IAM documentation to set the cache connection to use IAM authentication, including the cache user, the replication group or cluster name and the region that the gateway uses. The ElastiCache user must be created in advance with an IAM-enabled access string that matches the policy. Confirm the setup by starting the proxy with a rate-limit or cache operation and checking that the Redis connection succeeds without a password. Also confirm that a connection attempt using an invalid IAM identity is refused.

  5. Remove static secrets from configuration and the secret manager

    The security team removes the old database passwords and the Redis auth token from the proxy configuration, environment variables, Kubernetes secrets and the secret manager, then rotates or revokes them at the database and cache so that the old credentials no longer work. Keep LITELLM_MASTER_KEY and the other values that LiteLLM still needs in the secret manager, and check the configuration files in source control for leftover credentials. Confirm completion by searching the repository, the deployment manifests and the running environment for the old passwords, and by verifying that connections with the retired credentials fail.

  6. Verify token refresh before expiry

    The operations team runs the proxy for longer than one token lifetime while generating steady request traffic, and watches the logs for the writer and reader refreshing their tokens before they expire. Include a restart test and a failover test on the reader, so that the proxy reconnects with fresh tokens and no request fails after the refresh window. Confirm the result by reviewing logs and error counts across at least one full refresh cycle, and by documenting the observed behavior against the token lifetime in your environment.

  7. Confirm virtual keys and spend still write

    The application owner creates a test virtual key, sends requests through it, and checks that the key's spend, budget counters and request logs appear in PostgreSQL through the writer. Then sends a request that is served by the reader and checks that the read path returns the key's budget status. Also confirm that rate limits are enforced through Redis and that the counters increase as expected. Close the sequence only when the key, the spend record and the rate-limit counter all update correctly under IAM authentication.

How token refresh behaves between the writer and the reader

With IAM_TOKEN_DB_AUTH=True set for AWS RDS IAM, LiteLLM refreshes the authentication tokens for its writer and reader database connections independently, each ahead of expiry. The practical consequence is that a failure on one endpoint does not necessarily stop the other, so monitoring and tests must check both the writer and the reader rather than assuming one reflects the other. Confirm with the LiteLLM read replica documentation, linked from the topic sources, which refresh timing and configuration keys apply to your release, since the refresh interval is not stated in the facts available to this page. Confirm too that the IAM role attached to the proxy carries rds-db:connect permission for both the writer and the reader database users.

A failed refresh usually shows up as authentication errors on new connections while existing connections keep working until they close, so the first signal is often a rising error rate in the proxy logs rather than an outage. Look for repeated database authentication failures naming the writer or reader endpoint, and check whether the failures start at a predictable point after deployment. Separate credential problems (expired or unauthorized IAM tokens, wrong database user mapped to the IAM role) from network problems (security group or route changes) before changing anything, because the fix differs. To test a rotation without downtime, change the IAM policy or role in a staging copy first, run a load test that opens and closes connections across the expected token lifetime, and confirm the writer and reader both reconnect cleanly.

If you place PgBouncer in front of PostgreSQL to pool connections, confirm how it interacts with token refresh before relying on it, because a pooler that holds long-lived server connections can keep old credentials in use longer than you expect. Old connections must age out: set connection lifetime limits in the pooler and in LiteLLM so that every connection is eventually re-established with a fresh token, and verify that the pool is not holding connections past the point where the IAM token was issued. Plan for an explicit cutover check after any change to the IAM role, and record the timestamp when old connections stop appearing in the database session view. Treat these lifetime settings as decisions to validate in your own environment with the PgBouncer documentation and your load test results.

Security and operational considerations after the switch

Removing static passwords moves the risk to IAM policy, logging and network placement. The cards below cover the controls that keep token-based access to the LiteLLM database and Redis narrow, visible and maintainable once it is live.

Least-privilege IAM policies

Scope the rds-db:connect permission to the specific database user and the specific writer or reader resource ARN, so the LiteLLM role cannot connect as other users or to other clusters. Keep separate roles for the writer and the reader if they use different database users. Confirm the policy in a non-production account by attempting a connection with a deliberately wrong user name and checking that it is refused. Check the ElastiCache policy against the user and replication group it actually needs.

Read replica docs

CloudTrail and database logs for token use

Confirm that CloudTrail records the IAM role that generates tokens and that the trail is delivered to storage the platform team cannot silently edit. Token generation does not show which query ran, so pair CloudTrail with PostgreSQL connection and statement logging on the RDS instance. Decide who reviews these records and how often, and alert on connection attempts from unexpected roles or source addresses.

Separating the master key from database access

The LITELLM_MASTER_KEY grants administrative control of the gateway and is a different credential from the database connection. Keep it in a secret manager with its own access policy, and do not let the database role or the application environment read it. Once IAM auth removes the database password, confirm the master key is still stored outside application configuration and rotated under a documented process.

PostgreSQL authentication and SCRAM background

IAM token login works through PostgreSQL's own authentication layer, so the server's pg_hba.conf rules decide which methods each client can use. PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM, which matters if any fallback password login remains enabled for administrators. Review the authentication rules on the database and remove methods that no client still needs.

PostgreSQL auth methods

Network placement of Redis and the database

Token auth does not restrict where connections come from. Place the RDS instance and the ElastiCache cluster in private subnets, limit their security groups to the LiteLLM workloads, and avoid public endpoints. Check that the reader endpoint is reachable only from the same workloads as the writer. Confirm that TLS is required for connections, since IAM tokens are sent over the connection.

Runbooks for IAM policy changes

Write a runbook for changing IAM policies, role trust and database user mappings before the switch goes live. Include who approves a change, how it is tested in staging, how to roll back, and how a failed token refresh shows up in LiteLLM logs. Schedule a periodic review of the policies so that permissions added for one project do not remain after it ends.

Questions buyers ask before outsourcing IAM auth for LiteLLM

Can our own team set up IAM authentication for LiteLLM without a partner?

Yes, if your team already runs RDS or ElastiCache, manages IAM roles and can test a change in a non-production account. The LiteLLM side is mostly configuration: setting IAM_TOKEN_DB_AUTH=True enables RDS IAM token authentication for the writer and reader connections, and LiteLLM documents IAM authentication for Amazon ElastiCache. The harder parts are the database-side role mapping, the IAM policies, and proving that token refresh holds up under load and during a failover. Teams without that AWS depth often outsource the build and keep the runbook in-house. Your own engineers can run the work once it is documented and tested.

What makes IAM auth work take longer or cost more?

Effort scales with the number of data stores, the number of environments, and how much secret tooling is already in place. Each PostgreSQL writer or reader endpoint needs its own role mapping and verification. Redis topology matters too: a single ElastiCache endpoint is simpler than a setup that depends on Sentinel or replicas, which the Redis Sentinel docs say needs at least three Sentinel instances for a robust deployment. Existing secret managers, change windows, and approval steps for production database changes also add time. Ask for the scope to list each store, environment, and window explicitly.

What do we need to give the team before the work starts?

The work needs IAM administrator access in the target AWS accounts, or a senior engineer who can create the IAM roles, policies and database users. It also needs network paths from the LiteLLM workloads to RDS, the reader endpoints and ElastiCache, plus a non-production environment that mirrors production's database engine and Redis topology. Expect to provide access to your current configuration, your secret tooling, and the people who approve production database changes. Confirm in writing who holds each approval and where test evidence will be stored.

How long does IAM authentication work take?

Duration depends on scope, and no fixed figure applies to every environment. A single gateway with one writer, one reader and one Redis endpoint in a test account is a much smaller job than several production accounts with replicas, failover testing and approval gates. Ask for milestones: discovery, a test environment build, a rehearsed cutover, a rollback test, and production rollout. Make sure the timeline names the change windows you can actually use, since those often set the calendar more than the technical work does.

Do we need LiteLLM Enterprise to remove static database passwords?

The supplied LiteLLM documentation describes the database-side settings for RDS and Entra ID authentication and the ElastiCache IAM option as configuration of the proxy itself, and it does not tie them to an Enterprise license. Enterprise adds features such as SSO and SCIM beyond the free limit, audit logs and secret manager integrations, which are separate controls. Confirm the exact feature set against the current LiteLLM documentation and your license terms before you commit, because the answer depends on the release you run.

What should a quote for this work include?

A quote should follow from a written scope and list what is in and out. Ask for the stores covered (writer, reader, and each ElastiCache endpoint), the environments, the IAM roles and policies to be created, the token refresh and failover tests, the rollback procedure, and the documentation handed over. Separate one-time build work from any recurring support or retainer, and state what the client must provide. Ask how changes after kickoff are priced and how retesting after a LiteLLM or PostgreSQL upgrade is handled.

Does IAM auth replace the need to rotate database credentials?

It removes the static database password from the LiteLLM configuration, so there is no long-lived secret to rotate for those connections. Token refresh replaces that job: LiteLLM refreshes the writer and reader tokens independently ahead of expiry. You still need IAM policies scoped to the right database users, monitoring for failed token refresh, and a plan for the database's own admin credentials. Ask your provider to show how a refresh failure appears in logs and alerts.

The matching Entra ID option on Azure

On Azure, the equivalent switch is AZURE_POSTGRESQL_AUTH=True. With it set, LiteLLM authenticates to Azure Database for PostgreSQL with a Microsoft Entra ID token instead of a stored password, and its writer and reader connections refresh their tokens independently ahead of expiry, the same pattern the RDS setting follows on AWS. The design decision is identity, not syntax: the gateway's workload identity must be granted database access through Entra ID, and the database server must be configured to accept Entra ID authentication. Confirm both in your own tenant before changing the LiteLLM configuration, because a token that cannot be issued to the right principal fails at connection time, not at deploy time.

Three things need confirmation before you rely on the Azure path. First, decide how the gateway gets its identity: a managed identity attached to the compute running the proxy is the usual choice, but confirm with your Azure team which identity type your hosting platform supports and that the same principal is registered as a database user. Second, check group mapping. If your Entra ID groups grant database roles, confirm how those groups map to PostgreSQL roles and who owns that mapping, since a group change in Entra ID should not silently widen LiteLLM's database permissions. Third, confirm the Redis position. The Azure-specific token setting documented for LiteLLM covers PostgreSQL, so verify with LiteLLM's current documentation and your Azure Cache for Redis configuration whether an Entra ID option is available for the cache before assuming the AWS ElastiCache pattern carries over.

Run the same verification steps on both clouds: confirm that the gateway starts with no database password in its environment or secret store, that the writer and reader connections both authenticate, and that a deliberately revoked identity loses access on its next token refresh. Test the failure path as well. If token issuance fails, the proxy should report the error clearly rather than fall back to a static password, so decide now whether any break-glass credential exists, where it is stored and who may use it. Document the outcome in the same runbook you use for AWS so that platform and security teams review one consistent control set across both clouds.

How DeployOpen scopes and delivers IAM hardening for LiteLLM

DeployOpen plans and implements IAM authentication for the PostgreSQL and Redis services behind a self-hosted LiteLLM gateway, inside your AWS accounts. Each step is agreed in writing, tested against your environment and documented so your own team can run and review the result.

How we scope

  • Inventory every LiteLLM database and Redis connection string, secret and consumer before any change is planned.
  • Agree in writing which RDS writer and reader endpoints, ElastiCache clusters and IAM roles are in scope.
  • Confirm the deployment platform, LiteLLM release line, and whether Entra ID is also in scope for Azure.

How we build

  • Create IAM roles and policies that allow only the database users and cache connections LiteLLM needs.
  • Configure token-based authentication for writer and reader connections, then verify token refresh before expiry.
  • Test failure paths, including expired tokens, revoked roles and replica failover, and record the results.

How we hand over

  • Deliver the IAM policy definitions, configuration changes and a runbook for rotating and reviewing access.
  • Document the verification evidence so your security and compliance reviewers can trace each control.
  • Walk your platform and security engineers through the setup and the operational checks they will own.

How we support

  • Fixed-scope engagements have deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer.
  • Post-handover changes, such as new replicas or LiteLLM upgrades, can be scoped as separate written work.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.