# RDS PostgreSQL

PostgreSQL databases are open-source relational database management systems emphasizing extensibility and SQL compliance. AWS enables developers to create cloud-hosted PostgreSQL databases.

Through this integration, Apono helps you securely manage access to your AWS RDS for PostgreSQL instances.

***

## Prerequisites

<table><thead><tr><th width="212">Item</th><th>Description</th></tr></thead><tbody><tr><td><strong>Apono Connector</strong></td><td><p>On-prem <a href="https://docs.apono.io/docs/apono-connector-for-aws">connection</a> with network access to your AWS RDS for PostgreSQL instances<br><br><strong>Minimum Required Version</strong>: 1.5.3<br><br>Use the following steps to <a href="../apono-connector-for-aws/updating-a-connector-in-aws">update an existing connector</a>.</p><p><strong>NOTE</strong>: When installing the Apono connector with CloudFormation, the AWS RDS database policy is automatically created.</p><p>If you do not use CloudFormation, you must create the following policy and assign it to the Apono connector role.</p><pre data-overflow="wrap"><code>{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "rds-db:connect",
            "Resource": "arn:aws:rds-db:*:*:dbuser:*/apono_connector",
            "Effect": "Allow"
        }
    ]
}
</code></pre></td></tr><tr><td><strong>PostgreSQL Info</strong></td><td><p>Information for the database instance to be integrated:</p><ul><li>Instance ID</li><li>Database Name</li></ul></td></tr><tr><td><strong>AWS Tag</strong></td><td><p>(Optional) Metadata label assigned to AWS resources<br><br>Adding an AWS tag, enables Apono to discover and add resources on your behalf.<br><br>When <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Tagging.html#Tagging.HowTo">adding an AWS tag</a>, use the following information:</p><ul><li><strong>Tag key</strong>: <em>apono-secret</em></li><li><strong>Value</strong>: (<a href="../../../connectors-and-secrets/apono-integration-secret#aws">AWS Secret</a>)</li></ul></td></tr></tbody></table>

***

### Create an AWS RDS PostgreSQL user

You must create a user in your AWS RDS PostgreSQL instance for the Apono connector and grant that user permissions to your databases.

Follow these steps to create a user and grant it database permissions:

1. Create a new user with either Built-in authentication or IAM authentication.

{% hint style="warning" %}
You can use only one authentication option on the RDS instance at a time.
{% endhint %}

{% tabs %}
{% tab title="Built-in Authentication" %}
Built-in authentication identifies a user through a username and password.

```sql
CREATE USER apono_connector WITH PASSWORD 'secret_passwd';
```

Be sure to select a strong password for the user.
{% endtab %}

{% tab title="IAM authentication" %}
After [enabling IAM](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Enabling.html) on your RDS instance, create an `AWSAuthenticationPlugin` user for the Apono connector. `AWSAuthenticationPlugin` is an AWS-provided plugin that works seamlessly with IAM to authenticate your users.

To create the user, run the following commands from your Postgre client.

```sql
CREATE USER apono_connector;
GRANT rds_iam TO apono_connector;
```

{% endtab %}
{% endtabs %}

2. From your preferred client tool, grant `rds_superuser` access to the user.

```sql
ALTER USER apono_connector WITH CREATEROLE;
GRANT rds_superuser TO apono_connector;
```

<table><thead><tr><th width="283">Permission</th><th>Description</th></tr></thead><tbody><tr><td><strong>ALTER USER apono_connector WITH CREATEROLE;</strong></td><td>Allows Apono connector to create, alter, and drop user roles</td></tr><tr><td><strong>GRANT rds_superuser TO apono_connector;</strong></td><td>Assigns the RDS superuser role to the Apono connector, providing comprehensive permissions for database management</td></tr></tbody></table>

3. (IAM authentication only) Create and attach the following IAM policy to your identity center permissions set or role.

```
{
     "Version": "2012-10-17",
     "Statement": [
         {
             "Effect": "Allow",
             "Action": [
                 "rds-db:connect"
             ],
             "Resource": [
                 "arn:aws:rds-db:*:*:dbuser:*/${SAML:sub}"
             ]
         },
         {
             "Effect": "Allow",
             "Action": [
                 "rds:DescribeDBInstances"
             ],
             "Resource": [
                 "arn:aws:rds:*:*:db:*"
             ]
         }
     ]
 }
```

4. (Built-in authentication only) [Create an AWS secret](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret#aws) with the credentials from step **1**.

{% hint style="info" %}
When using IAM authentication, **a secret does not need to be created**.

The service account and its permissions are managed through IAM roles and policies. The service account is used to authenticate the PostgreSQL instance instead of a secret.
{% endhint %}

***

### Integrate Amazon RDS for PostgreSQL

<figure><img src="https://1094436629-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv6MBfUGvblSdAz31yJXm%2Fuploads%2Fgit-blob-0df9ae87224076dc0c6e64ed27c666089a1eef51%2FIntegrate-aws-rds-postgresql-1.png?alt=media" alt="" width="563"><figcaption><p>AWS RDS PostgreSQL</p></figcaption></figure>

{% hint style="success" %}
You can also use the steps below to integrate with Apono using Terraform.

In step **11**, instead of clicking **Confirm**, follow the **Are you integrating with Apono using Terraform?** guidance.
{% endhint %}

Follow these steps to complete the integration:

1. On the [**Catalog**](https://app.apono.io/catalog?search=aws+rds+postgresql) tab, click **AWS RDS PostgreSQL**. The **Connect Integration** page appears.
2. Under **Discovery**, click one or more resource types to sync with Apono.

{% hint style="info" %}
Apono automatically discovers and syncs all the instances in the environment. After syncing, you can manage **Access Flows** to these resources.
{% endhint %}

3. Click **Next**. The **Apono connector** section expands.
4. From the dropdown menu, select a connector. Choosing a connector links Apono to all the services available on the account where the connector is located.

{% hint style="info" %}
If the desired connector is not listed, click **+ Add new connector** and follow the instructions for creating an [AWS connector](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws).
{% endhint %}

5. Click **Next**. The **Integration Config** section expands.
6. Define the **Integration Config** settings.

   <table><thead><tr><th width="210">Setting</th><th>Description</th></tr></thead><tbody><tr><td><strong>Integration Name</strong></td><td>Unique, alphanumeric, user-friendly name used to identify this integration when constructing an access flow</td></tr><tr><td><strong>Auth Type</strong></td><td><p>Authorization type for the MySQL service account user:</p><ul><li><strong>IAM Auth</strong>: IAM authentication</li><li><strong>User / Password</strong>: Built-in authentication</li></ul></td></tr><tr><td><strong>Region</strong></td><td>Location where the PostgreSQL database is deployed</td></tr><tr><td><strong>Instance ID</strong></td><td>ID of the PostgreSQL instance</td></tr><tr><td><strong>Database Name</strong></td><td>Name of the PostgreSQL database</td></tr><tr><td><strong>SSL Mode</strong></td><td><p>(Optional) Mode of Secure Sockets Layer (SSL) encryption used to secure the connection with the SQL database server</p><ul><li><strong>require</strong>: An SSL-encrypted connection must be used.</li><li><strong>allow</strong>: An SSL-encrypted or unencrypted connection is used. If an SSL encrypted connection is unavailable, the unencrypted connection is used.</li><li><strong>disable</strong>: An unencrypted connection is used.</li><li><strong>prefer</strong>: An SSL-encrypted connection is attempted. If the encrypted connection is unavailable, the unencrypted connection is used.</li><li><strong>verify-ca</strong>: An SSL-encrypted connection must be used and a server certification verification against the provided CA certificates must pass.</li><li><strong>verify-full</strong>: An SSL-encrypted connection must be used and a server certification verification against the provided CA certificates must pass. Additionally, the server hostname is checked against the certificate's names.</li></ul></td></tr><tr><td><strong>Enable Audit</strong></td><td>(Optional) Feature that allows Apono to ingest and aggregate session audit logs</td></tr></tbody></table>
7. Click **Next**. The **Secret Store** section expands.
8. [Associate the secret or credentials.](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret)

{% hint style="info" %}
A secret is **not** needed for IAM authentication.
{% endhint %}

9. Click **Next**. The **Get more with Apono** section expands.
10. Define the **Get more with Apono** settings.

    <table><thead><tr><th width="193">Setting</th><th>Description</th></tr></thead><tbody><tr><td><strong>Credential Rotation</strong></td><td>(Optional) Number of days after which the database credentials must be rotated<br><br>Learn more about the <a href="../../architecture-and-security/credentials-rotation-policy">Credentials Rotation Policy</a>.</td></tr><tr><td><strong>User cleanup after access is revoked (in days)</strong></td><td><p>(Optional) Defines the number of days after access has been revoked that the user should be deleted</p><p><br>Learn more about <a href="../../architecture-and-security/periodic-user-cleanup-and-deletion">Periodic User Cleanup &#x26; Deletion</a>.</p></td></tr><tr><td><strong>Custom Access Details</strong></td><td>(Optional) Instructions explaining how to access this integration's resources<br><br>Upon accessing an integration, a message with these instructions will be displayed to end users in the User Portal. The message may include up to <strong>400 characters</strong>.<br><br>To view the message as it appears to end users, click <strong>Preview</strong>.</td></tr><tr><td><strong>Integration Owner</strong></td><td><p>(Optional) Fallback approver if no <a href="../../access-flows/dynamic-access-management/resource-and-integration-owners">resource owner</a> is found<br><br>Follow these steps to define one or several integration owners:</p><ol><li>From the <strong>Attribute</strong> dropdown menu, select <strong>User</strong> or <strong>Group</strong> under the relevant identity provider (IdP) platform.</li><li>From the <strong>Value</strong> dropdown menu, select one or multiple users or groups.</li></ol><p><br><strong>NOTE</strong>: When <strong>Resource Owner</strong> is defined, an <strong>Integration Owner</strong> must be defined.</p></td></tr><tr><td><strong>Resource Owner</strong></td><td><p>(Optional) Group or role responsible for managing access approvals or rejections for the resource<br><br>Follow these steps to define one or several <a href="../../access-flows/dynamic-access-management/resource-and-integration-owners">resource owners</a>:</p><ol><li>Enter a <strong>Key name</strong>. This value is the name of the tag created in your cloud environment.</li><li>From the <strong>Attribute</strong> dropdown menu, select an attribute under the IdP platform to which the key name is associated.<br><br>Apono will use the value associated with the key (tag) to identify the resource owner. When you update the membership of the group or role in your IdP platform, this change is also reflected in Apono.</li></ol><p><br><strong>NOTE</strong>: When this setting is defined, an <strong>Integration Owner</strong> must also be defined.</p></td></tr></tbody></table>
11. Click **Confirm**.

<details>

<summary>💡Are you integrating with Apono using Terraform?</summary>

If you want to integrate with Apono using Terraform, follow these steps instead of clicking **Confirm**:

1. At the top of the screen, click **View as Code**. A modal appears with the completed Terraform configuration code.
2. Click to copy the code.
3. Make any additional edits.
4. Deploy the code in your Terraform.

Refer to [Integration Config Metadata](https://docs.apono.io/metadata-for-integration-config/integration-metadata/aws-rds-postgresql) for more details about the schema definition.

</details>

Now that you have completed this integration, you can [create access flows](https://docs.apono.io/docs/access-flows/access-flows) that grant permission to your RDS for PostgreSQL database.
