AwsRdsIamDatabasePasswordProvider 2.11.0.4.13.0.0-948

Bundle
org.apache.nifi | nifi-aws-nar
Description
Generates Amazon RDS IAM authentication tokens each time a JDBC connection is requested. The generated token replaces the database user password so that NiFi does not need to store long-lived credentials inside DBCP services.
Tags
aws, iam, jdbc, password, rds
Input Requirement
Supports Sensitive Dynamic Properties
false
  • Additional Details for AwsRdsIamDatabasePasswordProvider 2.11.0.4.13.0.0-948

    Summary

    AwsRdsIamDatabasePasswordProvider generates Amazon RDS IAM authentication tokens each time a JDBC connection is requested. The Controller Service implements the NiFi DatabasePasswordProvider API, so it can be referenced from DBCP controller services to avoid storing long-lived database passwords in NiFi.

    Usage

    1. Configure an AWSCredentialsProviderControllerService so the password provider can obtain AWS credentials (for example, using an IAM role or AssumeRoleWithWebIdentity).
    2. Create an AwsRdsIamDatabasePasswordProvider and reference the credentials provider service. Configure the AWS region. Host, port, and database user are inherited from the JDBC URL and “Database User” properties on the referencing DBCP service.
    3. Update the DBCP controller service to set the Database Password Provider property to the new IAM provider. The static Password property is ignored when a provider is configured.
    4. Ensure your JDBC URL enables TLS and includes the SSL parameters recommended by AWS (for example, ssl=true&sslmode=verify-full for PostgreSQL).

    Each time the DBCP service needs to create a physical JDBC connection, a fresh IAM token is generated and supplied as the password. Existing pooled connections remain valid until the database closes them, so standard NiFi pooling properties such as “Maximum Connection Lifetime” still apply.

    Example Setup

    PostgreSQL role and privileges

    Connect to the nifi database as a superuser and run:

    CREATE ROLE nifi_app LOGIN PASSWORD 'temporary';
    GRANT rds_iam TO nifi_app;
    
    GRANT CONNECT ON DATABASE nifi TO nifi_app;
    GRANT USAGE ON SCHEMA public TO nifi_app;
    GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO nifi_app;
    GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO nifi_app;
    
    ALTER DEFAULT PRIVILEGES IN SCHEMA public
      GRANT ALL PRIVILEGES ON TABLES TO nifi_app;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public
      GRANT ALL PRIVILEGES ON SEQUENCES TO nifi_app;
    

    IAM permissions

    Attach a policy like the following to your IAM role (for example myAuroraPostgresRole). Replace <region>, <account-id>, and <db-resource-id> with your values:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "rds-db:connect",
          "Resource": "arn:aws:rds-db:<region>:<account-id>:dbuser:<db-resource-id>/nifi_app"
        }
      ]
    }
    

    Ensure the role’s trust policy allows the NiFi host (EC2, EKS, etc.) to assume it.

    CLI verification

    Generate an IAM auth token and connect with psql:

    TOKEN=$(aws rds generate-db-auth-token \
      --hostname database-1-instance-1.ccfuwyso6lcz.us-east-1.rds.amazonaws.com \
      --port 5432 \
      --region us-east-1 \
      --username nifi_app)
    
    PGPASSWORD="$TOKEN" psql \
      "host=database-1-instance-1.ccfuwyso6lcz.us-east-1.rds.amazonaws.com \
       port=5432 user=nifi_app dbname=nifi \
       sslmode=verify-full sslrootcert=/path/to/rds-combined-ca-bundle.pem"
    

    When that works, configure NiFi’s DBCP service with:

    • Database Connection URL: jdbc:postgresql://database-1-instance-1.ccfuwyso6lcz.us-east-1.rds.amazonaws.com:5432/nifi?ssl=true&sslmode=verify-full
    • Database User: nifi_app
    • Database Password Provider: AwsRdsIamDatabasePasswordProvider

    NiFi will then mint IAM tokens automatically for each new JDBC connection.

    Connecting Through a Network Load Balancer in Front of an RDS Proxy

    When connecting through a Network Load Balancer (NLB) placed in front of an RDS Proxy, the JDBC URL must point to the NLB endpoint, but the IAM token must be signed for the RDS Proxy endpoint. By default, the token is generated using the hostname extracted from the JDBC URL, which causes authentication to fail.

    Use the optional Token Request Endpoint property to specify the RDS Proxy endpoint (hostname:port) for token signing while keeping the NLB endpoint in the JDBC URL for the actual TCP connection.

    CLI verification

    NLB_ENDPOINT="nlb-example.elb.us-east-1.amazonaws.com"
    RDS_PROXY_ENDPOINT="my-proxy.proxy-example.us-east-1.rds.amazonaws.com"
    
    TOKEN=$(aws rds generate-db-auth-token \
      --hostname "$RDS_PROXY_ENDPOINT" \
      --port 3306 \
      --region us-east-1 \
      --username nifi_app)
    
    mysql -h "$NLB_ENDPOINT" -P 3306 -u nifi_app --password="$TOKEN"
    

    When that works, configure NiFi’s DBCP service with:

    • Database Connection URL: jdbc:mysql://nlb-example.elb.us-east-1.amazonaws.com:3306/mydb
    • Database User: nifi_app
    • Database Password Provider: AwsRdsIamDatabasePasswordProvider
    • Token Request Endpoint: my-proxy.proxy-example.us-east-1.rds.amazonaws.com:3306
Properties