README
¶
AlloyDB Auth Proxy
The AlloyDB Auth Proxy is the recommended way to connect to AlloyDB. It provides:
- Secure connections — TLS 1.3 encryption and identity verification, independent of the database protocol
- IAM-based authorization — controls who can connect to your AlloyDB instances using Google Cloud IAM
- No certificate management — no SSL certificates, firewall rules, or IP allowlisting required
- IAM database authentication — optional support for automatic IAM DB authentication
Note: The proxy does not configure the network. You must ensure it can reach your AlloyDB instance (e.g., by running the proxy inside the same VPC as your AlloyDB instance).
If you're using Go, Python, or Java, consider using the language connectors instead—they embed the same functionality directly in your process:
| Language | Connector |
|---|---|
| Go | alloydb-go-connector |
| Python | alloydb-python-connector |
| Java | alloydb-java-connector |
Quickstart
Get connected in five steps.
1. Install the proxy
Pick your platform below, or see all installation options.
Linux (amd64)
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.linux.amd64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Mac (Apple Silicon)
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.darwin.arm64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Mac (Intel)
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.darwin.amd64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Windows (x64)
Invoke-WebRequest -Uri "https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0/alloydb-auth-proxy-x64.exe" -OutFile "alloydb-auth-proxy.exe"
Container image
docker pull gcr.io/alloydb-connectors/alloydb-auth-proxy:1.18.0
2. Authenticate
The proxy uses Application Default Credentials (ADC) by default. Set them up with gcloud:
gcloud auth application-default login
In Google-managed environments (Cloud Run, GKE, Compute Engine), ADC is available automatically—no additional setup needed.
3. Find your instance URI
gcloud alloydb instances describe INSTANCE_NAME \
--region=REGION \
--cluster=CLUSTER_NAME \
--format='value(name)'
The URI has the form:
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
4. Start the proxy
Binary (Linux / Mac)
# By default, the proxy connects over Private Service Access—a private
# connection within the same VPC as your AlloyDB instance. Add --public-ip
# if your instance has a public IP and you are not connecting from within
# the VPC.
./alloydb-auth-proxy projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
Binary (Windows)
.\alloydb-auth-proxy.exe projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
Container image
# Mounts your local gcloud credentials into the container
docker run --rm \
-v "$HOME/.config/gcloud:/gcloud" \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcloud/application_default_credentials.json \
-p 1.18.0.1:5432:5432 \
gcr.io/alloydb-connectors/alloydb-auth-proxy:1.18.0 \
--address 1.18.0.0 \
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
You should see output like:
Authorizing with Application Default Credentials
Listening on 127.0.0.1:5432
The proxy has started successfully and is ready for new connections!
5. Connect
In a separate terminal, connect with any Postgres client:
psql "host=127.0.0.1 port=5432 user=DB_USER dbname=DB_NAME"
Table of contents
- Installation
- Authentication
- Usage
- Running behind a SOCKS5 proxy
- Observability
- Reference
- Support policy
- Contributing
Installation
Binary
Download the latest binary for your OS and architecture from releases.
Linux amd64
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.linux.amd64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Linux 386
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.linux.386" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Linux arm64
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.linux.arm64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Mac (Intel)
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.darwin.amd64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Mac (Apple Silicon)
URL="https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0"
wget "$URL/alloydb-auth-proxy.darwin.arm64" -O alloydb-auth-proxy
chmod +x alloydb-auth-proxy
Windows x64
Invoke-WebRequest -Uri "https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0/alloydb-auth-proxy-x64.exe" -OutFile "alloydb-auth-proxy.exe"
Windows x86
Invoke-WebRequest -Uri "https://storage.googleapis.com/alloydb-auth-proxy/v1.18.0/alloydb-auth-proxy-x86.exe" -OutFile "alloydb-auth-proxy.exe"
Container image
Container images are available from Artifact Registry:
gcr.io/alloydb-connectors/alloydb-auth-proxyus.gcr.io/alloydb-connectors/alloydb-auth-proxyeu.gcr.io/alloydb-connectors/alloydb-auth-proxyasia.gcr.io/alloydb-connectors/alloydb-auth-proxy
[!NOTE] These images were migrated from Google Container Registry (deprecated) to Artifact Registry, which is why they still use the
gcr.ionaming prefix.
Each image is tagged with the proxy version. Available tag variants:
| Tag | Base image |
|---|---|
VERSION |
distroless (default, non-root, minimal) |
VERSION-alpine |
Alpine |
Use Alpine or Debian variants when you need a shell or debugging tools.
# Pull a specific version (recommended over :latest)
docker pull gcr.io/alloydb-connectors/alloydb-auth-proxy:1.18.0
Pin to a specific version tag and use CI automation to keep it updated.
Running with Docker:
docker run --rm \
-v "$HOME/.config/gcloud:/gcloud" \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcloud/application_default_credentials.json \
-p 127.0.0.1:5432:5432 \
gcr.io/alloydb-connectors/alloydb-auth-proxy:1.13.11 \
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE \
--address 0.0.0.0
Build from source
Requires the latest version of Go.
Using go install
go install github.com/GoogleCloudPlatform/alloydb-auth-proxy@latest
The binary is placed in $GOPATH/bin or $HOME/go/bin.
Using the Makefile
If you have cloned the repository, you can use the provided Makefile to build the binary.
Build the binary for your current OS and architecture (defaults to linux/amd64):
make build-binary
To build for a specific OS and architecture, pass TARGETOS and TARGETARCH:
TARGETOS=darwin TARGETARCH=arm64 make build-binary
The binary will be created in the bin/binary/ directory as alloydb-auth-proxy.<os>.<arch> (e.g., alloydb-auth-proxy.linux.amd64).
Build your own container
You can build and push your own container image using the provided Dockerfiles.
These Dockerfiles require go to build the binaries outside docker, and docker buildx
to correctly set the build platform and target architecture.
If you don't have a registry to push to, you can set up an Artifact Registry in Google Cloud.
You should use the Makefile to build the container images to ensure that the go binaries are built and ready before the docker build:
# Build default container image (alloydb-auth-proxy:latest)
make build-image
# Build Alpine container image (alloydb-auth-proxy:latest-alpine)
make build-image-alpine
To build multi-arch images (requires docker buildx):
# Build multi-arch default container image
make build-image-multi-default
# Build multi-arch Alpine container image
make build-image-multi-alpine
Using internal mirrors
To use an internal registry proxy for the base image when building the Alpine images, use the REGISTRY_PROXY variable with make (applies to build-image-alpine and build-image-multi-alpine):
make build-image-alpine REGISTRY_PROXY=<Reference_To_Internal_Proxy>
make build-image-multi-alpine REGISTRY_PROXY=<Reference_To_Internal_Proxy>
Authentication
The proxy uses Application Default Credentials (ADC) by default and this is the recommended approach for most use cases. ADC automatically picks up credentials from the environment—no flags needed:
# One-time setup on a developer machine
gcloud auth application-default login
In Google-managed environments (Cloud Run, GKE, Compute Engine), ADC is already available and requires no additional configuration.
For less-common scenarios, the proxy also accepts explicit credentials via flags:
| Flag | Description |
|---|---|
--credentials-file PATH |
Path to a service account key JSON file |
--token TOKEN |
An OAuth2 Bearer token |
--login-token TOKEN |
A separate OAuth2 Bearer token for IAM database authentication login |
Required IAM roles for any principal connecting through the proxy:
roles/alloydb.client(Cloud AlloyDB Client)roles/serviceusage.serviceUsageConsumer(Service Usage Consumer)
See Roles and Permissions in AlloyDB for details.
Service account impersonation is also supported:
./alloydb-auth-proxy \
--impersonate-service-account=SA@PROJECT.iam.gserviceaccount.com \
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
For delegation chains, supply a comma-separated list where the first entry is the target and each subsequent entry is a delegate:
./alloydb-auth-proxy \
--impersonate-service-account=TARGET_SA,DELEGATE_SA \
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
Usage
All examples below assume valid credentials are present. Replace
INSTANCE_URI with the full instance path:
projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE
Basic usage
# Listens on 127.0.0.1:5432 using private IP
./alloydb-auth-proxy INSTANCE_URI
Multiple instances
# First instance: 127.0.0.1:5432, second: 127.0.0.1:5433
./alloydb-auth-proxy INSTANCE_URI_1 INSTANCE_URI_2
Custom address and port
# Listen on all interfaces, port 6000
./alloydb-auth-proxy --address 0.0.0.0 --port 6000 INSTANCE_URI
Public IP
./alloydb-auth-proxy --public-ip INSTANCE_URI
Write endpoints (DNS)
Pass an AlloyDB write endpoint DNS name (whose TXT record holds the target instance URI) instead of an instance URI:
./alloydb-auth-proxy my-endpoint.global.alloydb-psa.goog
Write endpoint DNS names only resolve from within the VPC network of the cluster. The proxy re-checks the TXT record every 30 seconds; when it points to a different instance (for example, after a switchover or failover), the proxy closes existing connections to the old instance so clients reconnect to the new primary.
Auto IAM Authentication
Lets the proxy supply the IAM principal's OAuth2 token as the database password—no password prompt needed for the client.
./alloydb-auth-proxy --auto-iam-authn INSTANCE_URI
Per-instance configuration
Override address, port, or other settings for individual instances using a
query-string appended to the instance URI (wrap in quotes to protect & from
the shell):
./alloydb-auth-proxy \
'INSTANCE_URI_1?address=0.0.0.0&port=6000' \
'INSTANCE_URI_2?address=127.0.0.1&port=7000&auto-iam-authn=true'
Unix sockets
# All instances use a Unix socket under /run/alloydb
./alloydb-auth-proxy --unix-socket /run/alloydb INSTANCE_URI
# Per-instance path (Postgres appends .s.PGSQL.5432 automatically)
./alloydb-auth-proxy 'INSTANCE_URI?unix-socket-path=/path/to/socket'
By default, Unix sockets and their parent directories are created with 0700
(owner-only) permissions so that other OS users on the same host cannot connect
to the proxy's listener. If you intentionally need to share the socket across
OS users or container UIDs (for example, in a multi-container pod), pass
--unix-socket-mode (e.g., --unix-socket-mode 0770 or
--unix-socket-mode 0777; in a config file, specify it as a quoted octal
string such as unix-socket-mode = "0770").
[!WARNING] Widening
--unix-socket-mode(such as0777) on a multi-tenant host allows any local OS user who can access the socket to connect through the proxy's encrypted tunnel—and when--auto-iam-authnis enabled, to authenticate to the database as the proxy's IAM principal without supplying a password.
Config file
Instead of flags, you can supply a TOML, YAML, or JSON config file:
./alloydb-auth-proxy --config-file config.toml
Example config.toml:
instance-uri = "projects/PROJECT/locations/REGION/clusters/CLUSTER/instances/INSTANCE"
auto-iam-authn = true
debug-logs = true
Multiple instances:
instance-uri-0 = "INSTANCE_URI_1"
instance-uri-1 = "INSTANCE_URI_2"
Environment variables
Every flag has an environment variable equivalent using the
ALLOYDB_PROXY_ prefix (uppercase, underscores):
# Equivalent to --structured-logs
ALLOYDB_PROXY_STRUCTURED_LOGS=true ./alloydb-auth-proxy INSTANCE_URI
# Single instance via env var
ALLOYDB_PROXY_INSTANCE_URI=INSTANCE_URI ./alloydb-auth-proxy
# Multiple instances via env vars
ALLOYDB_PROXY_INSTANCE_URI_0=INSTANCE_URI_1 \
ALLOYDB_PROXY_INSTANCE_URI_1=INSTANCE_URI_2 \
./alloydb-auth-proxy
Running behind a SOCKS5 proxy
ALL_PROXY=socks5://localhost:8000 \
HTTPS_PROXY=socks5://localhost:8000 \
./alloydb-auth-proxy INSTANCE_URI
ALL_PROXY routes TCP traffic to AlloyDB (supports socks5 and socks5h).
Use socks5h to route DNS lookups through the proxy. HTTPS_PROXY routes
HTTP(S) traffic to the AlloyDB Admin API (optional).
Observability
Health checks
Enable HTTP health check endpoints (useful for Kubernetes probes):
./alloydb-auth-proxy --health-check INSTANCE_URI
| Endpoint | Returns 200 when... |
|---|---|
/startup |
Proxy has finished starting up |
/readiness |
Proxy is started, has available connections, and can reach all instances |
/liveness |
Always 200 — if unresponsive, restart the proxy |
Configure address and port with --http-address and --http-port (default:
localhost:9090).
Prometheus metrics
./alloydb-auth-proxy --prometheus INSTANCE_URI
# Metrics available at http://localhost:9090/metrics
Use --prometheus-namespace to set a custom namespace prefix.
Cloud Monitoring and Cloud Trace
./alloydb-auth-proxy --telemetry-project=PROJECT_ID INSTANCE_URI
Use --disable-metrics or --disable-traces to opt out of either. Use
--telemetry-prefix to customize the Cloud Monitoring metric prefix.
Supported metrics:
| Metric | Description |
|---|---|
alloydbconn/dial_latency |
Distribution of dialer latencies (ms) |
alloydbconn/open_connections |
Current number of open AlloyDB connections |
alloydbconn/dial_failure_count |
Number of failed dial attempts |
alloydbconn/refresh_success_count |
Successful certificate refresh operations |
alloydbconn/refresh_failure_count |
Failed certificate refresh operations |
Debug logging
./alloydb-auth-proxy --debug-logs INSTANCE_URI
Logs internal certificate refresh operations. Useful when diagnosing unexpected proxy behavior.
Admin server (pprof / graceful shutdown)
The admin server runs on localhost:9091 and is disabled by default.
# Enable Go profiler at /debug/pprof/
./alloydb-auth-proxy --debug INSTANCE_URI
# Enable graceful shutdown via POST /quitquitquit
./alloydb-auth-proxy --quitquitquit INSTANCE_URI
Change the port with --admin-port. See the pprof documentation for
profiler usage.
Reference
Run ./alloydb-auth-proxy --help for full flag documentation, or browse the
rendered docs in docs/cmd.
Commonly used flags:
| Flag | Default | Description |
|---|---|---|
-a, --address |
127.0.0.1 |
Address for instance listeners |
-p, --port |
5432 |
Starting port; subsequent instances increment |
-i, --auto-iam-authn |
false | Enable Auto IAM Authentication |
-c, --credentials-file |
Path to service account key JSON | |
-t, --token |
OAuth2 Bearer token | |
--login-token |
Separate token for IAM database authentication login | |
--public-ip |
false | Connect via public IP |
--psc |
false | Connect via Private Service Connect; falls back to the automatic PSC DNS name if the manual one is unreachable |
-u, --unix-socket |
Directory for Unix socket listeners | |
--unix-socket-mode |
0700 |
File permissions (octal) for Unix sockets and directories |
--lazy-refresh |
false | Refresh certs on-demand (for throttled CPUs) |
--health-check |
false | Enable /startup, /liveness, /readiness |
--prometheus |
false | Enable Prometheus /metrics endpoint |
--structured-logs |
false | Emit logs in LogEntry JSON format |
--max-connections |
0 (unlimited) | Maximum simultaneous connections |
--config-file |
Path to TOML/YAML/JSON config file |
Support policy
This project follows semantic versioning. We release a new version monthly with features, bug fixes, and security updates. If no new features are added, we still release a PATCH version with updated dependencies. We recommend always using the latest version.
Contributing
Contributions are welcome. See the CONTRIBUTING document for details.
This project is released with a Contributor Code of Conduct. By participating, you agree to abide by its terms.