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

connectionURL

*Required

Set to the database's connection URL.

jdbc:postgresql://database-iam.hostname.us-east-1.rds.amazonaws.com:5431/

verifyServerCertificate

Connection using a .pem certificate

false

useSSL

SSL enabled for this connection

false

user

Set to the given database user.

db_user

password

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

region

Set to your RDS cluster region

us-east-1

hostname

Set to your database information or endpoint.

database-iam.hostname.us-east-1.rds.amazonaws.com

db_user

Set to your given database user.

postgres

port

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:

  1. In the AWS console, select Modify for the given database instance.

  2. Go to Database Authentication to select Password and IAM Database authentication.

  3. Click Continue.

  4. Select when to apply modifications.

  5. 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.

    CODE
    CREATE 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:

    CODE
    CREATE USER db_user;
  • Grant all necessary permissions, particularly rds_iam for use with IAM Auth.

    CODE
    GRANT rds_iam TO db_user;

Policy Creation

  1. In the AWS console, go to Policies.

  2. 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

  1. In the AWs console, go to Clusters > Select Cluster where the worker node is deployed.

  2. In the cluster, go to the Compute tab.

  3. Click the node group name in the Node groups section.

  4. In the node group's Details section, click the link provided under Node IAM role ARN.

  5. Go to Add Permissions > Attach Policies to upload the policy you created in the previous steps.

OneTrust Vault Configuration

Example JSON of the vault entry with the required properties:

JSON
{
    "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.

CODE
ERROR 1524 (HY000): Plugin 'AWSAuthenticationPlugin' is not loaded

SSL Error

Cause: if SSL is on the RDS instance, the configurations must match.

CODE
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:

CODE
"connectionUrl": "jdbc:postgresql://database-iam.ccmqpelehavp.us-east-1.rds.amazonaws.com:5432/?sslmode=require"

Authentication Error

CODE
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.