Database Roles and IAM Authentication¶
Overview¶
Amazon Aurora DSQL supports authentication using both IAM roles and IAM users. You can use either method to authenticate and access Aurora DSQL databases.
IAM Identity Types¶
IAM Roles¶
An IAM role is an identity within your AWS account that has specific permissions but is not associated with a specific person. Using IAM roles provide temporary security credentials. You can temporarily assume an IAM role in several ways:
- By switching roles in the AWS Console
- By calling a CLI or AWS API operation
- By using a custom URL
After assuming a role, you can access Aurora DSQL using the role's temporary credentials. For more information about methods for using roles, see IAM Identities in the IAM user guide.
IAM Users¶
An IAM user is an identity within your AWS account that has specific permissions and is associated with a single person or application. IAM users have long-term credentials such as passwords and access keys that can be used to access Aurora DSQL.
Note: To run SQL commands with IAM authentication, you can use either IAM role ARNs or IAM user ARNs in the examples below.
Database Role Types¶
Aurora DSQL supports two types of database roles:
Admin Role¶
- Aurora DSQL automatically creates a predefined
adminrole for you in your Aurora DSQL cluster - You can't modify the
adminrole - When you connect to your database as
admin, you can issue SQL to create new database-level roles
Custom Roles¶
- You create and manage custom roles using SQL commands in your database
- Custom roles must be associated with your IAM roles to allow IAM identities to connect to your database
Working with Custom Database Roles¶
Authorizing Database Roles to Connect to Your Cluster¶
-
Create an IAM role and grant connection authorization with the IAM policy action:
dsql:DbConnect -
Grant cluster access permissions - The IAM policy must also grant permission to access the cluster resources. Use a wildcard (
*) or follow the instructions for using IAM condition keys with Aurora DSQL.
Authorizing Database Roles to Use SQL in Your Database¶
You must use an IAM role with authorization to connect to your cluster.
Step-by-step process:
-
Connect to your Aurora DSQL cluster using a SQL utility with the
admindatabase role and an IAM identity that is authorized for IAM actiondsql:DbConnectAdmin -
Create a new database role with the
WITH LOGINoption:CREATE ROLE example WITH LOGIN; -
Associate the database role with the IAM role ARN:
AWS IAM GRANT example TO 'arn:aws:iam::012345678912:role/example'; -
Grant database-level permissions to the database role:
GRANT USAGE ON SCHEMA myschema TO example; GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA myschema TO example;
For more information, see PostgreSQL GRANT and PostgreSQL Privileges in the PostgreSQL documentation.
Viewing IAM to Database Role Mappings¶
To view the mappings between IAM roles and database roles, query the sys.iam_pg_role_mappings system table:
SELECT * FROM sys.iam_pg_role_mappings;
Example output:
iam_oid | arn | pg_role_oid | pg_role_name | grantor_pg_role_oid | grantor_pg_role_name
---------+----------------------------------------+-------------+--------------+---------------------+----------------------
26398 | arn:aws:iam::012345678912:role/example | 26396 | example | 15579 | admin
(1 row)
This table shows all the mappings between IAM roles (identified by their ARN) and PostgreSQL database roles.
Revoking Database Authorization from an IAM Role¶
To revoke database authorization, use the AWS IAM REVOKE operation:
AWS IAM REVOKE example FROM 'arn:aws:iam::012345678912:role/example';
Authentication Process Flow¶
For Admin Role¶
- IAM Authentication: Generate temporary authentication token using IAM identity with
dsql:DbConnectAdminpermission - Database Connection: Use token as password to connect with
adminrole - Database Operations: Perform administrative tasks, create custom roles
For Custom Role¶
- Role Creation: Admin creates custom database role with
CREATE ROLE example WITH LOGIN - IAM Association: Admin associates role with IAM identity using
AWS IAM GRANT - Permission Granting: Admin grants specific database permissions to custom role
- IAM Authentication: User generates token using IAM identity with
dsql:DbConnectpermission - Database Connection: User connects using custom role and token
Authorization Process Flow¶
Database-Level Authorization¶
- Connect as admin: Use admin role to connect to cluster
- Create custom roles: Issue SQL commands to create new database-level roles
- Grant permissions: Use PostgreSQL GRANT commands to assign specific permissions
- Associate with IAM: Use
AWS IAM GRANTto link database roles with IAM identities
Cluster-Level Authorization¶
- Managed through IAM policies
- Use
dsql:DbConnectAdminfor admin role access - Use
dsql:DbConnectfor custom role access
Best Practices¶
Security Recommendations¶
- Use custom database roles for production applications instead of admin role
- Grant minimal necessary permissions to custom roles
- Regularly review and audit role mappings using
sys.iam_pg_role_mappings - Use temporary IAM roles when possible for enhanced security
Permission Management¶
- You can't manage permissions of the predefined
admindatabase role - Modifications to privileges take effect on the next transaction after Aurora DSQL successfully commits the modification transaction
- Use PostgreSQL standard commands for managing custom role permissions