IAM database authentication replaces the static database password in your application's configuration with a short-lived token issued to the workload's cloud identity, so there is no long-lived database secret to leak, rotate or forget. This guide explains how the model works and walks through enabling it on Amazon RDS and Aurora, Azure SQL and Google Cloud SQL, then covers the identity design, authorisation, logging and migration steps that decide whether the change actually reduces risk.
The wider picture of database credentials, including vaulting, dynamic secrets and privileged access, is covered in the Database Credential and Access Security Guide. If you are not ready to remove passwords yet, see How to rotate database credentials without downtime. The three platforms are covered in alphabetical order, each in its own section, and the page does not rank them.
Key takeaways
- IAM database authentication moves the trust decision from "who knows the password" to "which cloud identity is this workload", so the database credential becomes a non-human identity governed in your cloud IAM.
- Tokens are short-lived. Amazon RDS documents a 15 minute token lifetime, and Google Cloud documents that OAuth 2.0 access tokens used for manual Cloud SQL login are valid for one hour. Applications must fetch tokens at connection time, not at start-up.
- Login rights and data rights are separate. Each platform still needs a database user or principal with explicit grants; cloud IAM alone does not give access to tables.
- Run workloads with attached identities (instance profiles or IAM roles for workloads, managed identities, attached service accounts) so the workload holds no static cloud credential either.
- Close the password path once migration is done. Otherwise an old password or administrator account remains a bypass.
- Check logging. AWS documents that CloudWatch and CloudTrail do not log IAM authentication, and Cloud SQL Data Access audit logs are off by default.
How IAM database authentication works
The pattern is the same on all three platforms:
- The workload runs with a cloud identity, ideally one attached to the compute resource so there is no stored key.
- At connection time, the workload or a connector library uses that identity to obtain a short-lived token from the cloud provider.
- The workload presents the token to the database in place of a password, over TLS.
- The database validates the token with the provider and maps the identity to a database user or principal.
- The database's own permission system (grants, roles, schema ownership) decides what that user can do.
Two consequences shape every design decision. First, the strength of the scheme is the strength of the cloud identity: anything that can act as the workload's role, managed identity or service account can log in to the database. Second, the database user still exists and still holds privileges, so database permission hygiene does not go away.
The security gains over a stored password are real: no secret in configuration files, environment variables or code; no shared password reused across services; access granted and revoked centrally in IAM; and tokens that expire on their own if stolen. AWS frames the use case simply: consider IAM database authentication "when you don't want to manage usernames and passwords directly in your application code."
Amazon RDS and Aurora
AWS documents IAM database authentication for MariaDB, MySQL and PostgreSQL engines. Each token has a lifetime of 15 minutes. Platform-level security for these engines is covered in the Amazon RDS and Aurora Security Guide.
Step 1: enable it on the instance or cluster
Turn on IAM database authentication on the DB instance or cluster through the console, CLI or your infrastructure as code. Plan capacity: AWS notes that IAM authentication requires compute on the database instance and that you should have between 300 and 1000 MiB of extra memory for reliable connectivity. It is not supported for RDS on Outposts.
Step 2: create the database user
For MariaDB and MySQL:
CREATE USER 'orders_svc' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';ALTER USER 'orders_svc'@'%' REQUIRE SSL;
For PostgreSQL:
CREATE USER orders_svc;GRANT rds_iam TO orders_svc;
The user name must match the IAM policy resource and must match its case in the database. On PostgreSQL, AWS warns that once rds_iam is granted to a user, including the master user, IAM authentication takes precedence over password authentication. Do not grant it to the master user unless you intend that. RDS for PostgreSQL also does not support enabling IAM and Kerberos authentication at the same time.
Step 3: grant rds-db:connect to the workload role
The IAM action is rds-db:connect, and the resource identifies one database account on one instance:
arn:aws:rds-db:region:account-id:dbuser:DbiResourceId/db-user-name
Note that the resource uses the instance's resource ID, not its name, and that the rds-db: prefix is distinct from the rds: management API prefix. AWS also documents wildcard forms such as dbuser:*/* (every account on every instance in the account and Region) and dbuser:*/jane_doe (that user name on any instance). Avoid both in production. A wildcard instance with a common user name like app lets one service's role log in to every database that has an app user.
Step 4: generate a token in the application
Use the AWS SDK's token generator or aws rds generate-db-auth-token, then connect with the token as the password over TLS. Points from the AWS documentation that cause real outages:
- Generate the token against the instance endpoint. A custom Route 53 DNS record cannot be used to generate the token.
- Tokens are generally about 1 KB or larger. Make sure the driver or tool does not truncate them.
- If the token was created from temporary credentials, those credentials must still be valid when the connection is made.
- Not all IAM global condition context keys are supported in the policy.
Step 5: confirm your logging
AWS states that "CloudWatch and CloudTrail don't log IAM authentication" and do not track generate-db-auth-token calls. Token generation is a local signing operation, so you will not see a CloudTrail event per login. Rely on database engine logs for connection auditing, and on IAM configuration monitoring for who holds rds-db:connect.
Azure SQL
For Azure SQL Database, Azure SQL Managed Instance and SQL Server on Azure VMs, the equivalent is Microsoft Entra authentication. Platform-level controls are covered in the Azure SQL and Cosmos DB Security Guide.
Step 1: set a Microsoft Entra administrator
Microsoft Entra authentication requires a Microsoft Entra administrator on the logical server or managed instance. Only one identity can be the admin at a time, so assign a group rather than a person. The admin is the first account that can create other Entra logins and users and is a member of db_owner in every user database, so treat it as a privileged role. Removing the Entra admin disables all Entra-based connections, even for existing users.
Step 2: give the workload a managed identity
Assign a system-assigned or user-assigned managed identity to the app service, function, container app, VM or AKS workload. Microsoft describes managed identity authentication as token-based and passwordless and recommends it over a service principal with a client secret, which it says "isn't recommended because of the risk associated with passwords that can be guessed and leaked." For Kubernetes workloads, see the AKS Workload Identity Guide.
Step 3: create a database principal for the identity
Connect as the Entra admin and create a contained database user mapped to the identity:
CREATE USER [orders-svc-identity] FROM EXTERNAL PROVIDER;ALTER ROLE db_datareader ADD MEMBER [orders-svc-identity];
Contained users are portable with the database. Server-level logins (CREATE LOGIN ... FROM EXTERNAL PROVIDER) are also available. Microsoft cautions that a contained user and a login with the same name are not linked and can produce undefined behaviour, so pick one model and use it consistently.
Microsoft states that Entra authentication for Azure SQL does not integrate with Azure RBAC for data access. An Azure role on the server does not let an identity query data; the identity must exist as a principal in the database.
Step 4: connect with a token
Use a driver that supports Entra authentication and choose the managed identity method, or the Entra Default method, which scans credential caches on the machine. Microsoft notes that only access tokens issued by Microsoft Entra ID are accepted, and recommends a connection timeout of 30 seconds.
Step 5: turn on Microsoft Entra-only authentication
With Microsoft Entra-only authentication enabled, all other methods are disabled, including the SQL server administrator and every SQL authentication account, and Windows authentication on Managed Instance. This is the switch that actually removes database passwords. Enable it once all applications and operational tooling use Entra.
Other limits worth planning for: principals in more than 2048 Entra security groups cannot log in, functions such as SUSER_NAME() return NULL for Entra principals, and failover groups need an Entra admin on both primary and secondary servers.
Google Cloud SQL
Cloud SQL offers IAM database authentication for PostgreSQL, MySQL and SQL Server, with engine-specific documentation for each. The steps below follow the PostgreSQL documentation. Platform-level controls are covered in Google Cloud SQL Security.
Step 1: enable the instance flag
Set cloudsql.iam_authentication on the instance. Google documents that it is required for both IAM database authentication and IAM group authentication, is on by default for instances created in the console, and that disabling it removes access for IAM users already added.
Step 2: grant the login permission
The permission that allows login is cloudsql.instances.login, included in the Cloud SQL Instance User predefined role. The console also prompts for the Cloud SQL User role. Bindings apply project-wide by default, so use a dedicated project per environment, or an IAM condition, to stop one service's account from logging in to every instance in the project.
Step 3: add the IAM user to the instance
Add the user or service account as an IAM database user with gcloud, the API or the console. For service accounts, Cloud SQL truncates the .gserviceaccount.com suffix, giving a database user name of the form [email protected]. The resulting name must be 63 characters or fewer, and user names must be lowercase.
You can also manage access through Cloud Identity groups. Members inherit login permission and database privileges from the group, and Cloud SQL creates a database account for each member on first login. Google documents a limit of 200 IAM groups per instance, that an account cannot be added both individually and through a group on the same instance, and that membership changes can take about 15 minutes to propagate.
Step 4: grant database privileges
Login access does not grant table or database privileges. Use standard PostgreSQL GRANT statements for the new user, for example GRANT SELECT, INSERT ON orders TO "[email protected]";.
Step 5: connect with automatic or manual token handling
- Automatic IAM database authentication (Google's recommended option) uses a Cloud SQL connector, either the Cloud SQL Auth Proxy or the Go, Java or Python connector, which requests and refreshes the token. The application supplies only the IAM database user name.
- Manual IAM database authentication passes the principal's email as the user name and an OAuth 2.0 access token as the password. Those tokens are valid for one hour, so long-running applications must refresh them.
Logins must use SSL. There is a per-instance login quota of 12,000 per minute, counting successful and failed attempts, which matters for connection storms. Context-aware access blocks connector-based IAM login, in which case connect directly to the instance.
Step 6: enable audit logging
Cloud Audit Logs Data Access logs are off by default. Turn them on for Cloud SQL to record IAM logins, and budget for the logging cost.
Setting names at a glance
The table lists each platform's own names for the main settings, with no ranking implied.
| Setting | Amazon RDS and Aurora | Azure SQL | Google Cloud SQL |
|---|---|---|---|
| Feature switch | IAM database authentication on the instance or cluster | Microsoft Entra administrator, then Microsoft Entra-only authentication | cloudsql.iam_authentication flag |
| Cloud permission to log in | rds-db:connect | Database principal created FROM EXTERNAL PROVIDER | cloudsql.instances.login (Cloud SQL Instance User role) |
| Database mapping | AWSAuthenticationPlugin or rds_iam | Contained user or Entra login | IAM database user or IAM group |
| Workload identity | IAM role for the compute resource | Managed identity | Attached service account |
Designing the identities behind database access
The database credential is now a cloud identity, so apply non-human identity governance to it.
- One identity per service per environment. Do not share a role, managed identity or service account across services, or you lose attribution and blast radius control. The Cloud Workload Identity Guide covers the identity models in depth.
- No static keys behind the token. If the workload authenticates to the cloud with a stored access key, client secret or service account key file, you have moved the password rather than removed it. Use attached identities or federation.
- Least privilege on both layers. Scope the cloud permission to the specific database user and instance, and scope database grants to the specific schemas and operations.
- Separate humans from workloads. Engineers should connect with their own identities, through groups, with read-only defaults and time-bound elevation for writes. Do not let people assume the application's identity to debug.
- Protect the administrator path. The RDS master user, the Azure Entra admin and Cloud SQL built-in administrative users are break-glass accounts. Vault their credentials or restrict them to a privileged group, and alert on use.
- Clean up. AWS reminds you that removing a mapped user should be followed by
DROP USERin the database. The same applies on all platforms: deprovision the database principal when the identity is retired.
Migrating from passwords
- Inventory. List every application, job, report and tool that connects to each database and the credential it uses.
- Enable alongside passwords. Turn on IAM authentication without removing password authentication.
- Create new users. Create a new IAM-mapped database user for each service with the same grants as its current user, rather than converting the existing one, so you can roll back.
- Update connection code. Fetch a token per new connection and configure connection pools to refresh credentials, because pooled connections opened with an expired token cannot be re-established.
- Cut over and watch. Deploy, confirm the old user is no longer used from database logs, then disable or drop it.
- Close the password path. On Azure SQL, enable Microsoft Entra-only authentication. On RDS and Cloud SQL, remove remaining password users or restrict them to vaulted break-glass use.
- Revoke old secrets. Delete the old passwords from secret stores, CI variables and configuration repositories, and rotate any that cannot be removed yet.
Common failure patterns
- Wildcard connect permissions.
rds-db:connectondbuser:*/*, or a project-wide Cloud SQL login role, so one compromised workload reaches every database. - Static keys behind the token. The application uses an access key, client secret or key file to mint database tokens.
- Token fetched once at start-up. Connections fail after 15 minutes or one hour when the pool opens new connections with the expired token.
- Passwords left enabled. IAM authentication is added but the old application password and SQL admin accounts remain usable.
- Over-privileged database users. The new IAM user is given owner rights "to make it work".
- Single-person Entra admin. One engineer is the Azure SQL Entra admin, creating a privileged single point of failure.
- Assumed logging. Teams expect CloudTrail or default Cloud Audit Logs to record every database login.
- Token truncation. A driver or proxy truncates the token and authentication fails intermittently.
Practitioner checklist
- IAM database authentication is enabled on every production instance that supports it.
- Each service uses its own attached workload identity, with no static cloud key behind it.
- Cloud permissions name a specific instance and database user, with no wildcard user or instance in production.
- Database grants for IAM-mapped users follow least privilege and are reviewed with other access.
- Applications request a token per new connection and connection pools refresh credentials.
- All IAM logins use TLS, and drivers are tested for token size.
- Azure SQL Entra admin is a group, and Microsoft Entra-only authentication is enabled after migration.
- Administrator and break-glass password accounts are vaulted, restricted and alerted on.
- Database engine logs and, on Cloud SQL, Data Access audit logs capture logins.
- Retired identities trigger removal of the matching database principal.
Standards and references
- AWS: IAM database authentication for MariaDB, MySQL and PostgreSQL
- AWS: Creating and using an IAM policy for IAM database access
- AWS: Creating a database account using IAM authentication
- Microsoft: Microsoft Entra authentication for Azure SQL
- Google Cloud: IAM authentication for Cloud SQL for PostgreSQL
- NIST: SP 800-53 Rev. 5 (IA-5 Authenticator Management, AC-6 Least Privilege)
- OWASP: Secrets Management Cheat Sheet
- MITRE ATT&CK: Valid Accounts: Cloud Accounts (T1078.004)
Related NHI Mgmt Group resources: Database Credential and Access Security Guide · How to rotate database credentials without downtime · Cloud Workload Identity Guide · Amazon RDS and Aurora Security Guide