About the AlloyDB Auth proxy

This page describes the AlloyDB Auth proxy and summarizes the steps you take to use it to make authorized, encrypted connections to AlloyDB databases.

The AlloyDB Auth proxy provides these advantages over connecting clients directly to AlloyDB databases:

  • IAM-based connection authorization (AuthZ): The Auth proxy uses the credentials and permissions of an IAM principal to authorize connections to AlloyDB instances.

  • Secure, encrypted communication: The Auth proxy automatically creates, uses, and maintains a TLS 1.2 connection using a 256-bit AES cipher between your client and an AlloyDB instance to verify client and server identities and encrypt data traffic.

How to use the AlloyDB Auth proxy

To use the AlloyDB Auth proxy, you perform these steps:

  1. Download the AlloyDB Auth proxy client binary to your client host.
  2. Choose the IAM prinicipal you want the Auth proxy to use for authorization, make sure it has the required permissions, and make its credentials available on your client host.
  3. Gather connection information for the AlloyDB instance or instances you want to connect to.
  4. Start the Auth proxy client.
  5. Connect client applications to databases by opening local connections to the Auth proxy client.

See Connect using the AlloyDB Auth proxy for detailed instructions to perform these steps.

How the AlloyDB Auth proxy works

The AlloyDB Auth proxy works by having a local client running in the local environment. Your application communicates with the AlloyDB Auth proxy with the standard database protocol used by your database.

The AlloyDB Auth proxy uses a secure tunnel (TLS 1.2, 256-bit AES cipher) to communicate with its companion process running on the server. Each connection established through the AlloyDB Auth proxy creates one connection to the AlloyDB instance.

When an application connects to the AlloyDB Auth proxy, it checks whether an existing connection between it and the target AlloyDB instance is available. If a connection does not exist, it calls AlloyDB Admin APIs to obtain an ephemeral SSL certificate and uses it to connect to AlloyDB. Ephemeral SSL certificates expire in 24 hours. The AlloyDB Auth proxy refreshes these certificates before they expire.

While the AlloyDB Auth proxy can listen on any port, it creates outgoing or egress connections to your AlloyDB instance only on port 5433. Because the AlloyDB Auth proxy calls APIs through the domain name alloydb.googleapis.com, which does not have a fixed IP address, all egress TCP connections on port 443 must be allowed. If your client machine has an outbound firewall policy, make sure it allows outgoing connections to port 5433 on your AlloyDB instance's IP.

How the AlloyDB Auth proxy authorizes IAM principals

To authorize a client's connection to an AlloyDB instance, the Auth proxy client authenticates to Google Cloud using IAM principal credentials on the client, and then validates that the IAM principal has the Cloud AlloyDB Client (roles/alloydb.client) IAM role.

To locate the IAM credentials on the client, the Auth proxy client checks for each of the following items, using the first one it finds to attempt authentication to Google Cloud:

  1. Credentials supplied by the --credentials-file flag

    Use a service account to create and download the associated JSON key file, and set the --credentials-file flag to the path of the file when you start the Auth proxy client. The service account must have the Cloud AlloyDB Client (roles/alloydb.client) IAM role for the AlloyDB instance.

    To use this option on the command-line, invoke the alloydb-auth-proxy command with the --credentials-file flag set to the path and filename of a JSON credential file. The path can be absolute, or relative to the current working directory.

  2. Credentials supplied by the --token flag

    Create an access token and invoke the alloydb-auth-proxy command with the --token flag set to an OAuth 2.0 access token.

  3. Credentials supplied by an environment variable

    This option is similar to using the --credentials-file flag, except you specify the JSON credential file you set in the GOOGLE_APPLICATION_CREDENTIALS environment variable instead of using the --credentials-file flag.

  4. Credentials from an authenticated Google Cloud CLI client

    If you have installed the gcloud CLI and have authenticated with your personal account, the Auth proxy client can use the same account credentials. This method is especially helpful for getting a development environment up and running.

    If no account was selected for gcloud auth login, the Auth proxy client checks for an account that was selected for gcloud auth application-default login.

  5. Credentials associated with the Compute Engine instance

    If you are connecting to AlloyDB from a Compute Engine instance, the Auth proxy client can use the service account associated with the Compute Engine instance. If the service account has the Cloud AlloyDB Client (roles/alloydb.client) IAM role for the AlloyDB instance, the Auth proxy client authenticates successfully.

    If the Compute Engine instance is in the same project as the AlloyDB instance, the default service account for the Compute Engine instance has the necessary permissions for authenticating the AlloyDB. If the two instances are in different projects, you must add the Compute Engine instance's service account to the project containing the AlloyDB instance.

  6. Environment's default service account

    If the Auth proxy client cannot find credentials in any of the places covered earlier, it follows the logic documented in Authenticating as a service account. Some environment (such as Compute Engine, App Engine, and others) provide a default service account that your application can use to authenticate by default. If you use a default service account, it must have the Cloud AlloyDB Client (roles/alloydb.client) IAM role.

    For more information about Google Cloud's approach to authentication, see Authentication overview.