# AlloyDB

AlloyDB is a fully managed PostgreSQL-compatible database service on Google Cloud. It offers high performance, scalability, and reliability for demanding enterprise workloads.

Through this integration, Apono helps you securely manage access to your AlloyDB instance.

***

### Prerequisites

<table><thead><tr><th width="206">Item</th><th>Description</th></tr></thead><tbody><tr><td><strong>Apono Connector</strong></td><td><p>On-prem<a href="../apono-connector-for-gcp"> connection</a> serving as a bridge between your Google Cloud SQL MySQL databases and Apono<br></p><p><strong>Minimum Required Version</strong>: 1.6.4</p><p><br>Use the following steps to<a href="../apono-connector-for-gcp/updating-a-connector-in-google-cloud"> update an existing connector</a>.</p></td></tr><tr><td><strong>Allow Connector IP Access</strong></td><td><p>Allows the Apono connector to communicate with the AlloyDB instance</p><p>You must allow the connector IP range in the AlloyDB primary instance's IP allow list.</p></td></tr><tr><td><strong>API Services</strong></td><td><p>API services that must enabled:</p><ul><li>AlloyDB API</li><li>Compute Engine API</li><li>Service Networking API</li></ul><p>See <a href="https://cloud.google.com/service-usage/docs/enable-disable#console">Enabling and Disabling Services</a> for more information.</p></td></tr><tr><td><strong>AlloyDB Information</strong></td><td><p>Identifiers for AlloyDB resources:</p><ul><li>Primary Instance ID</li><li>Cluster ID</li></ul><p>See <a href="https://cloud.google.com/alloydb/docs/instance-view">View instance details</a> to learn how to obtain these identifiers.</p></td></tr></tbody></table>

***

### Assign roles to the Apono connector

Use the following tabs to assign roles to the Apono connector for either your [Google Project](#project) or [Google Organization](#organization).

{% tabs %}
{% tab title="Project" %}
Follow these steps to assign roles to the Apono connector:

1. In your shell environment, log in to Google Cloud and enable the API.

```sh
gcloud auth login
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable iam.googleapis.com
```

2. Set the environment variables.

```sh
export GCP_PROJECT_ID=<GOOGLE_PROJECT_ID>
export SERVICE_ACCOUNT_NAME=<SERVICE_ACCOUNT_NAME>
```

3. Assign roles to the connector.

{% code overflow="wrap" %}

```sh
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
    --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/alloydb.admin" \
    --project $GCP_PROJECT_ID

gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
    --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/serviceusage.serviceUsageConsumer" \
    --project $GCP_PROJECT_ID
```

{% endcode %}
{% endtab %}

{% tab title="Organization" %}
Follow these steps to assign roles to the Apono connector:

1. In your shell environment, log in to Google Cloud and enable the API.

```sh
gcloud alpha auth login
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable iam.googleapis.com
```

2. Set the environment variables.

```sh
export GCP_ORGANIZATION_ID=<GOOGLE_ORGANIZATION_ID>
export GCP_PROJECT_ID=<GOOGLE_PROJECT_ID>
export SERVICE_ACCOUNT_NAME=<SERVICE_ACCOUNT_NAME>
```

3. Assign roles to the connector.

{% code overflow="wrap" %}

```sh
gcloud organizations add-iam-policy-binding $GCP_ORGANIZATION_ID \
    --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/alloydb.admin"

gcloud organizations add-iam-policy-binding $GCP_ORGANIZATION_ID \
    --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/serviceusage.serviceUsageConsumer"
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### Create an AlloyDB user

You must create a user in your AlloyDB instance for the Apono connector and grant that user permissions.

Use the following steps to create a user for the Apono connector and grant it permissions:

1. Create a new user and grant permissions with either [Built-in Authentication](#built-in-authentication) or [IAM Authentication](#iam-authentication).

{% tabs %}
{% tab title="Built-in Authentication" %}
Run the following commands from your PostgreSQL client.

```sql
CREATE USER CONNECTOR_USERNAME WITH PASSWORD 'password';
GRANT alloydbsuperuser TO CONNECTOR_USERNAME;
```

{% endtab %}

{% tab title="IAM Authentication" %}

1. In the Google Cloud console, enable IAM authentication for your AlloyDB instance by setting the **alloydb.iam\_authentication** flag to **on**.\
   \ <img src="https://1094436629-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv6MBfUGvblSdAz31yJXm%2Fuploads%2Fgit-blob-4ad7b73e0e850b54d58e40243e7ceef6a685ae74%2Fimage%20(2)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original">
2. Run the following command to grant superuser privileges to the Apono connector user.

{% code overflow="wrap" %}

```sh
gcloud alloydb users set-superuser CONNECTOR_USERNAME_IAM_SA_EMAIL@[PROJECT_ID].iam \
--superuser=true \
--cluster=CLUSTER_ID \
--region=REGION_ID
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. (Built-in Authentication only) [Create a secret](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret) with the credentials from step **1**.

{% hint style="success" %}
When using IAM authentication, the service account and its permissions are managed through Google Cloud IAM roles and policies.

**A secret does not need to be created.**
{% endhint %}

***

### Integrate AlloyDB

{% 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=alloydb) tab, click **AlloyDB**. The **Connect Integration** page appears.
2. Under **Discovery**, select one or multiple resource types for Apono to discover in the instance.
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="success" %}
If the desired connector is not listed, click **+ Add new connector** and follow the instructions for creating a [connector for GCP](https://docs.apono.io/docs/gcp-environment/apono-connector-for-gcp).
{% endhint %}

5. Click **Next**. The **Integration Config** page appears.
6. Define the **Integration Config** settings.

<table><thead><tr><th width="205">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><a href="../../architecture-and-security/authentication-types">Authorization type</a> for the AlloyDB user:</p><ul><li><strong>User / Password</strong>: Apono-created local user credentials</li><li><strong>IAM Authentication</strong>: Cloud IAM authentication</li></ul></td></tr><tr><td><strong>Project ID</strong></td><td>ID of the project associated with the AlloyDB instance</td></tr><tr><td><strong>Location</strong></td><td>Location of the AlloyDB instance</td></tr><tr><td><strong>Primary Instance ID</strong></td><td>ID for the primary instance within the AlloyDB cluster</td></tr><tr><td><strong>Cluster ID</strong></td><td>ID for the AlloyDB cluster</td></tr><tr><td><strong>Port</strong></td><td><p>Port value for the database</p><p>By default, Apono sets this value to <em>5432</em>.</p></td></tr><tr><td><strong>Instance ID User Override (optional)</strong></td><td>Overrides the instance ID for the user</td></tr><tr><td><strong>Database Name</strong></td><td><p>Name of the database to integrate</p><p>By default, Apono sets this value to <em>postgre</em>.</p></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><p>Be sure to choose the SSL mode based on your AlloyDB primary instance <a href="https://cloud.google.com/alloydb/docs/instance-ssl">SSL mode configuration</a>:</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></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).
9. Click **Next**. The **Get more with Apono** section expands.
10. Define the **Get more with Apono** settings.

<table><thead><tr><th width="210">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/gcp-alloydb) 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 AlloyDB instance.
