To ensure that all database connections to an existing AlloyDB for PostgreSQL instance
use mutual TLS (mTLS) encryption and Identity and Access Management (IAM) authorization,
you can enforce connections through the AlloyDB Auth Proxy or
AlloyDB Language Connectors. You can also disable connector enforcement on an
instance at any time. For information about how to require connectors when you
create an instance, see
[Create a primary instance](https://docs.cloud.google.com/alloydb/docs/instance-primary-create.md.txt).

> [!NOTE]
> **Note:** For the primary instance in a Private Service Connect cluster, connector enforcement is only supported when there are no secondary instances.

AlloyDB instances accept connections on two TCP ports:

- Port `5432`, the default PostgreSQL port that applications use to
  connect to the instance. If you're using [managed connection
  pooling](https://docs.cloud.google.com/alloydb/docs/configure-managed-connection-pooling), the instance also
  listens on port `6432` for connections to the connection pool.

- Port `5433`, which connectors, including the AlloyDB Auth Proxy and
  AlloyDB Language Connectors, use to connect to the instance.

Applications connect to a chosen connector on the local host and port that the
connector listens on, and that connector communicates with your
AlloyDB instance on port `5433`.

## Enforce connectors on an instance

### Console

1. Go to the **Clusters** page.

   [Go to Clusters](https://console.cloud.google.com/alloydb/clusters)
2. Click a cluster in the **Resource name** column.
3. In the **Overview** page, go to the **Instances in your cluster** section, and click **Edit primary**.
4. In the **Edit primary instance** pane, expand **Advanced configuration options**.
5. Select **Enforce mTLS via AlloyDB connectors**.
6. Click **Update instance**.

### gcloud


To use the gcloud CLI, you can
[install and initialize](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt) the Google Cloud CLI, or you
can use [Cloud Shell](https://docs.cloud.google.com/shell/docs/using-cloud-shell.md.txt).

<br />

Use the [`gcloud alloydb instances update`](https://docs.cloud.google.com/sdk/gcloud/reference/alloydb/instances/update.md.txt)
command with the `--require-connectors` flag to enforce connector connections
on an AlloyDB instance:

```bash
gcloud alloydb instances update INSTANCE_ID \
    --region=REGION_ID \
    --cluster=CLUSTER_ID \
    --project=PROJECT_ID \
    --require-connectors
```

Replace the following:

- `INSTANCE_ID`: the ID of the instance that you're
  updating.

- `REGION_ID`: the region where the instance is
  located.

- `CLUSTER_ID`: the ID of the cluster where the
  instance is located.

- `PROJECT_ID`: the ID of the project where the
  cluster is located.

If the command returns an error message that includes the phrase
`invalid cluster state MAINTENANCE`, then the cluster is undergoing routine
maintenance. This state temporarily disallows instance reconfiguration.
After the cluster returns to a `READY` state, run the command again. To
check the cluster's status, see
[View cluster details](https://docs.cloud.google.com/alloydb/docs/cluster-view.md.txt).

## Disable connector enforcement on an instance

### Console

1. Go to the **Clusters** page.

   [Go to Clusters](https://console.cloud.google.com/alloydb/clusters)
2. Click a cluster in the **Resource name** column.
3. In the **Overview** page, go to the **Instances in your cluster** section, and click **Edit primary**.
4. In the **Edit primary instance** pane, expand **Advanced configuration options**.
5. Clear **Enforce mTLS via AlloyDB connectors**.
6. Click **Update instance**.

### gcloud


To use the gcloud CLI, you can
[install and initialize](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt) the Google Cloud CLI, or you
can use [Cloud Shell](https://docs.cloud.google.com/shell/docs/using-cloud-shell.md.txt).

<br />

Use the [`gcloud alloydb instances update`](https://docs.cloud.google.com/sdk/gcloud/reference/alloydb/instances/update.md.txt)
command with the `--no-require-connectors` flag to disable connector
enforcement on an AlloyDB instance:

```bash
gcloud alloydb instances update INSTANCE_ID \
    --region=REGION_ID \
    --cluster=CLUSTER_ID \
    --project=PROJECT_ID \
    --no-require-connectors
```

Replace the following:

- `INSTANCE_ID`: the ID of the instance that you're
  updating.

- `REGION_ID`: the region where the instance is
  located.

- `CLUSTER_ID`: the ID of the cluster where the
  instance is located.

- `PROJECT_ID`: the ID of the project where the
  cluster is located.

## What's next

- [AlloyDB Auth Proxy overview](https://docs.cloud.google.com/alloydb/docs/auth-proxy/overview.md.txt)

- [AlloyDB Language Connectors overview](https://docs.cloud.google.com/alloydb/docs/language-connectors-overview.md.txt)