Configuring Amazon RDS with IAM Authentication
This article demonstrates how Amazon-based customers can set up their worker node configuration so that the worker node can access RBS databases using IAM-based authentication.
RDS Configuration
Connection Property Values
|
Property Name |
Description |
Value |
|---|---|---|
|
*Required |
Set to the database's connection URL. |
jdbc:postgresql://database-iam.hostname.us-east-1.rds.amazonaws.com:5431/ |
|
|
Connection using a .pem certificate |
false |
|
|
SSL enabled for this connection |
false |
|
|
Set to the given database user. |
db_user |
|
|
Provide the authentication token. |
getAuthenticationToken() |
To avoid using a key-secret pair or a regular username-password, you can generate an Authentication Token using the following properties:
|
Property Name |
Description |
Example Value |
|---|---|---|
|
|
Set to your RDS cluster region |
us-east-1 |
|
|
Set to your database information or endpoint. |
database-iam.hostname.us-east-1.rds.amazonaws.com |
|
|
Set to your given database user. |
postgres |
|
|
Set to your database port. |
5431 |
RDS Deployment
When creating a new database instance, you can choose to enable IAM database authentication. See Amazon RDS guidance here.
For any existing database instance:
-
In the AWS console, select Modify for the given database instance.
-
Go to Database Authentication to select Password and IAM Database authentication.
-
Click Continue.
-
Select when to apply modifications.
-
Click modify DB instance. If you choose the option, Apply immediately, AWS may take a few minutes to restart the database.
MariaDB and MYSQL
-
Connect to your database using a terminal or database manager.
-
Create a database user with the identifier for the AWS plugin.
CODECREATE USER db_user IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'; -
Grant all necessary permissions.
PostgreSQL
-
Connect to your database using a terminal or database manager.
-
Create a database user for connecting with IAM Auth:
CODECREATE USER db_user; -
Grant all necessary permissions, particularly
rds_iamfor use with IAM Auth.CODEGRANT rds_iam TO db_user;
Policy Creation
-
In the AWS console, go to Policies.
-
Create a new policy with the following JSON. Update our placeholders with your corresponding values.
-
<resource_id>and<db_user>can be replaced with wildcard * -
Resource ID is found in RDS > Databases > Database Instance > Configurationtab.
-
Add as many resources as desired and combinations for the ARN.
JSON{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "rds-db:connect" ], "Resource": [ "arn:aws:rds-db:<region>:<account_id>:dbuser:<resource_id>/<db_user>" ] } ] } -
Worker Node Configuration
-
In the AWs console, go to where the worker node is deployed.
-
In the cluster, go to the Compute tab.
-
Click the node group name in the Node groups section.
-
In the node group's Details section, click the link provided under Node IAM role ARN.
-
Go to to upload the policy you created in the previous steps.
OneTrust Vault Configuration
Example JSON of the vault entry with the required properties:
{
"port": "5431",
"hostname": "database-iam.hostname.us-east-1.rds.amazonaws.com",
"region": "us-east-1",
"db_user": "postgres",
"connectionUrl": "jdbc:postgresql://database-iam.hostname.us-east-1.rds.amazonaws.com:5431/"
}
Troubleshooting
Plugin Error
Cause: The AWS-provided plugin is not available for the current database instance.
ERROR 1524 (HY000): Plugin 'AWSAuthenticationPlugin' is not loaded
SSL Error
Cause: if SSL is on the RDS instance, the configurations must match.
Suppressed: org.postgresql.util.PSQLException: FATAL: pg_hba.conf rejects connection for host "38.140.48.10", user "postgres", database "postgres", SSL off
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:659)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:180)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:244)
... 84 common frames omitted
Add the following to the connection URL: ?sslmode-require, which should result in:
"connectionUrl": "jdbc:postgresql://database-iam.ccmqpelehavp.us-east-1.rds.amazonaws.com:5432/?sslmode=require"
Authentication Error
org.postgresql.util.PSQLException: FATAL: PAM authentication failed for user "db_user"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:659)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:180)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235)
Cause 1: User in database does not have the needed configuration.
Cause 2: Applied policy for the cluster role is incorrect.