<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Saurabh Kumar</title>
    <description>The latest articles on Forem by Saurabh Kumar (@saurabhkr).</description>
    <link>https://forem.com/saurabhkr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3755862%2F78fd10fb-fda6-4691-b9f7-f88068adf49f.jpg</url>
      <title>Forem: Saurabh Kumar</title>
      <link>https://forem.com/saurabhkr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/saurabhkr"/>
    <language>en</language>
    <item>
      <title>Secure Access to Private IP AlloyDB with Identity-Aware Proxy (IAP) and Auth Proxy🔒</title>
      <dc:creator>Saurabh Kumar</dc:creator>
      <pubDate>Mon, 16 Feb 2026 05:43:55 +0000</pubDate>
      <link>https://forem.com/saurabhkr/secure-access-to-private-ip-alloydb-with-identity-aware-proxy-iap-and-auth-proxy-21o0</link>
      <guid>https://forem.com/saurabhkr/secure-access-to-private-ip-alloydb-with-identity-aware-proxy-iap-and-auth-proxy-21o0</guid>
      <description>&lt;p&gt;Need to access a private AlloyDB instance securely from your local machine? In this guide, I'll show you how to use &lt;strong&gt;Identity-Aware Proxy (IAP)&lt;/strong&gt; combined with &lt;strong&gt;AlloyDB Auth Proxy&lt;/strong&gt; to create a secure connection to your private AlloyDB instance-all with just your &lt;code&gt;gcloud&lt;/code&gt; command and zero public IPs required.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;Imagine you have an AlloyDB instance sitting in a private subnet-no public IP, no direct internet access. This is great for security, but how do you connect to it for development, debugging, or administration tasks? Traditional approaches often involve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting up VPNs &lt;/li&gt;
&lt;li&gt;Exposing databases to the internet (security risk)&lt;/li&gt;
&lt;li&gt;Complex networking configurations&lt;/li&gt;
&lt;li&gt;Managing multiple access points&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;There's a better way!&lt;/strong&gt; Google Cloud's &lt;strong&gt;&lt;a href="https://docs.cloud.google.com/iap/docs/concepts-overview" rel="noopener noreferrer"&gt;IAP (Identity-Aware Proxy)&lt;/a&gt;&lt;/strong&gt; combined with &lt;strong&gt;AlloyDB Auth Proxy&lt;/strong&gt; lets you securely access your database using identity-based authentication, leveraging Google's enterprise-grade security infrastructure. IAP eliminates the need for VPNs by providing secure, authenticated access to private resources through Google's identity system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We'll Build
&lt;/h2&gt;

&lt;p&gt;By the end of this tutorial, you'll have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A private VPC with AlloyDB instance (no public IP)&lt;/li&gt;
&lt;li&gt;A secure jumphost VM (no public IP) accessible only via IAP&lt;/li&gt;
&lt;li&gt;AlloyDB Auth Proxy running on the jumphost for secure database connections&lt;/li&gt;
&lt;li&gt;Local access to AlloyDB through an encrypted IAP tunnel&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Challenge&lt;/li&gt;
&lt;li&gt;What We'll Build&lt;/li&gt;
&lt;li&gt;Architecture Overview&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;
Step 1: Set Up Network Infrastructure

&lt;ul&gt;
&lt;li&gt;Create VPC and Subnet&lt;/li&gt;
&lt;li&gt;Configure Firewall Rules for IAP&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Step 2: Create Service Account&lt;/li&gt;

&lt;li&gt;Step 3: Provision the Jumphost VM&lt;/li&gt;

&lt;li&gt;Step 4: Set Up Cloud NAT&lt;/li&gt;

&lt;li&gt;

Step 5: Provision AlloyDB

&lt;ul&gt;
&lt;li&gt;Enable Private Services Access&lt;/li&gt;
&lt;li&gt;Create AlloyDB Cluster and Instance&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Step 6: Access the Jumphost via IAP

&lt;ul&gt;
&lt;li&gt;Verify Internet Access&lt;/li&gt;
&lt;li&gt;Test Direct AlloyDB Connection&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Step 7: Install and Run AlloyDB Auth Proxy

&lt;ul&gt;
&lt;li&gt;Download and Install&lt;/li&gt;
&lt;li&gt;Run the Auth Proxy&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Step 8: Connect from Your Local Machine&lt;/li&gt;

&lt;li&gt;Step 9: Grant Access to Team Members&lt;/li&gt;

&lt;li&gt;Security Best Practices&lt;/li&gt;

&lt;li&gt;

Troubleshooting

&lt;ul&gt;
&lt;li&gt;"Network is unreachable" during apt update&lt;/li&gt;
&lt;li&gt;IAP SSH connection fails&lt;/li&gt;
&lt;li&gt;AlloyDB connection refused&lt;/li&gt;
&lt;li&gt;Port forwarding not working&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Cost Optimization Tips&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;li&gt;References&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────┐         ┌──────────────────────────────────────────┐
│   Your      │  IAP    │          Private VPC                     │
│   Local     │  Tunnel │  ┌──────────────┐         ┌─────────────┐│
│   Machine   │ ────────┼─►│   Jumphost   │  Auth   │   AlloyDB   ││
│             │         │  │     VM       │ ──────► │  Instance   ││
│             │         │  │  (Private)   │  Proxy  │  (Private)  ││
└─────────────┘         │  └──────────────┘         └─────────────┘│
                        └──────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Google Cloud Project with billing enabled&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gcloud&lt;/code&gt; CLI installed and authenticated&lt;/li&gt;
&lt;li&gt;PostgreSQL client installed (for local connections)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial, we'll use IAP's TCP forwarding feature to securely connect to a private VM (jumphost) that has no public IP address. This jumphost will then connect to your AlloyDB instance, which is also in a private network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Set Up Network Infrastructure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create VPC and Subnet
&lt;/h3&gt;

&lt;p&gt;First, let's create a custom VPC network for our private resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud compute networks create restricted-access-vpc &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--subnet-mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;custom &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--bgp-routing-mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;regional
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvndzv5ifgu3l1bv5hsnm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvndzv5ifgu3l1bv5hsnm.png" alt="VPC Configuration" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a subnet within this VPC:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud compute networks subnets create private-apps-us-south1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--network&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;restricted-access-vpc &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--range&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10.10.0.0/24 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-south1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcyiwzep2c8bp3y9048r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcyiwzep2c8bp3y9048r.png" alt="Subnet Configuration" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure to provision your AlloyDB instance in the same VPC where your jumphost VM will be located.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Configure Firewall Rules for IAP
&lt;/h3&gt;

&lt;p&gt;IAP uses specific IP ranges to connect to your VMs. These IP ranges are managed by Google and are used exclusively by IAP services. We need to allow these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud compute firewall-rules create allow-iap-access &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--network&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;restricted-access-vpc &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--allow&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tcp:22,tcp:3389 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--source-ranges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;35.235.240.0/20 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Allow IAP to access jumphost VM"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This firewall rule allows IAP to connect to VMs without public IPs for SSH access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3w5jz34dmqvid4a5673.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3w5jz34dmqvid4a5673.png" alt="Firewall Rules Configuration" width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create Service Account
&lt;/h2&gt;

&lt;p&gt;The jumphost VM needs permissions to access AlloyDB. Let's create a service account with the necessary roles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create service account&lt;/span&gt;
gcloud iam service-accounts create alloydb-jumphost-sa &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--display-name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"AlloyDB Jumphost Service Account"&lt;/span&gt;

&lt;span class="c"&gt;# Grant AlloyDB Client role&lt;/span&gt;
gcloud projects add-iam-policy-binding PROJECT_ID &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:alloydb-jumphost-sa@PROJECT_ID.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/alloydb.client"&lt;/span&gt;

&lt;span class="c"&gt;# Grant Service Usage Consumer role (required for AlloyDB access)&lt;/span&gt;
gcloud projects add-iam-policy-binding PROJECT_ID &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:alloydb-jumphost-sa@PROJECT_ID.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/serviceusage.serviceUsageConsumer"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;PROJECT_ID&lt;/code&gt; with your actual Google Cloud project ID.&lt;/p&gt;

&lt;p&gt;
  &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdi6l2i3r1bre646tsl4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdi6l2i3r1bre646tsl4k.png" alt="Service Account Permissions" width="800" height="530"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Provision the Jumphost VM
&lt;/h2&gt;

&lt;p&gt;Now, let's create the jumphost VM &lt;strong&gt;without a public IP address&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud compute instances create iap-jumphost-vm &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--zone&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-south1-b &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--machine-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;e2-micro &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--subnet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;private-apps-us-south1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--no-address&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--service-account&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;alloydb-jumphost-sa@PROJECT_ID.iam.gserviceaccount.com &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--scopes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://www.googleapis.com/auth/cloud-platform &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--image-family&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ubuntu-2204-lts &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--image-project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ubuntu-os-cloud &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--preemptible&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--no-address&lt;/code&gt;: No external IP for maximum security&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--service-account&lt;/code&gt;: Attach the service account with AlloyDB permissions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--subnet&lt;/code&gt;: Use the subnet created in Step 1&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--preemptible&lt;/code&gt;: Cost optimization for testing (optional)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhb1bhftu0t1jj8n9w1e0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhb1bhftu0t1jj8n9w1e0.png" alt="Service Account Mounted on Jumphost VM" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Set Up Cloud NAT
&lt;/h2&gt;

&lt;p&gt;Since our VM has no public IP, we need Cloud NAT for outbound internet access (to download packages, etc.):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create Cloud Router&lt;/span&gt;
gcloud compute routers create nat-router &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--network&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;restricted-access-vpc &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-south1

&lt;span class="c"&gt;# Create Cloud NAT Gateway&lt;/span&gt;
gcloud compute routers nats create nat-gateway &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--router&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nat-router &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-south1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--nat-all-subnet-ip-ranges&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--auto-allocate-nat-external-ips&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select &lt;strong&gt;NAT type: Public&lt;/strong&gt; and create the Cloud Router attached to your VPC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjv6x3bvme0sgzrhpc56o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjv6x3bvme0sgzrhpc56o.png" alt="Cloud NAT Configuration" width="800" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Provision AlloyDB
&lt;/h2&gt;

&lt;p&gt;Provision your AlloyDB cluster and instance in the same VPC as your jumphost VM. Make sure to configure Private Services Access (PSA) for AlloyDB to connect to Google-managed services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvgzg38uu6hjgmecfk7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvgzg38uu6hjgmecfk7h.png" alt="AlloyDB Config" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1v2ta3kzy0r0jz9js8l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1v2ta3kzy0r0jz9js8l.png" alt="AlloyDB Cluster Credentials" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpd3wi1orvobv2g6uusc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpd3wi1orvobv2g6uusc.png" alt="Private Services Access (PSA) Configuration" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Access the Jumphost via IAP
&lt;/h2&gt;

&lt;p&gt;Now for the magic! This is where IAP comes into play. We'll connect to your private VM using IAP's TCP forwarding feature:&lt;/p&gt;

&lt;p&gt;Get the SSH command from the Google Cloud Console VM UI and use it to connect via IAP. The command will automatically include the &lt;code&gt;--tunnel-through-iap&lt;/code&gt; flag, which tells &lt;code&gt;gcloud&lt;/code&gt; to route your connection through IAP instead of requiring a public IP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr9cv0ajh272oq0bum2o5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr9cv0ajh272oq0bum2o5.png" alt="SSH Connection using IAP" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Simple and secure access through Google's identity verification and IAP tunneling. IAP handles all the authentication and encryption automatically—you just need to be authenticated with &lt;code&gt;gcloud&lt;/code&gt; and have the proper IAM permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Verify Internet Access
&lt;/h3&gt;

&lt;p&gt;Once connected, test that Cloud NAT is working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this works, you're all set! If not, double-check your Cloud NAT configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Direct AlloyDB Connection
&lt;/h3&gt;

&lt;p&gt;From the jumphost VM, you can test direct connection to AlloyDB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install PostgreSQL client&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;postgresql-client-common postgresql-client &lt;span class="nt"&gt;-y&lt;/span&gt;

&lt;span class="c"&gt;# Connect to AlloyDB (use the private IP from AlloyDB instance details)&lt;/span&gt;
psql &lt;span class="nt"&gt;-h&lt;/span&gt; 10.48.0.2 &lt;span class="nt"&gt;-p&lt;/span&gt; 5432 &lt;span class="nt"&gt;-U&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx0iuc398szmibd5m22e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjx0iuc398szmibd5m22e.png" alt="Database Connection from Jumphost VM" width="800" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Install and Run AlloyDB Auth Proxy
&lt;/h2&gt;

&lt;p&gt;The AlloyDB Auth Proxy provides secure, authenticated connections to your AlloyDB instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Download and Install
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Download the latest version from GitHub&lt;/span&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; alloydb-auth-proxy https://github.com/GoogleCloudPlatform/alloydb-auth-proxy/releases/latest/download/alloydb-auth-proxy.linux.amd64

&lt;span class="c"&gt;# Make it executable&lt;/span&gt;
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x alloydb-auth-proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the Auth Proxy
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./alloydb-auth-proxy &lt;span class="s2"&gt;"projects/PROJECT_ID/locations/REGION/clusters/CLUSTER_NAME/instances/INSTANCE_NAME"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--address&lt;/span&gt; &lt;span class="s2"&gt;"0.0.0.0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--port&lt;/span&gt; 5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./alloydb-auth-proxy &lt;span class="s2"&gt;"projects/pocs-487506/locations/us-east1/clusters/dev-alloydb-primary/instances/dev-alloydb-primary-primary"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--address&lt;/span&gt; &lt;span class="s2"&gt;"0.0.0.0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--port&lt;/span&gt; 5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the connection URI with your AlloyDB instance details. You can find the connection URI in the AlloyDB instance details in the Google Cloud Console. The proxy will now listen on port 5432.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fff91geght1x2qmqoee4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fff91geght1x2qmqoee4u.png" alt="AlloyDB Auth Proxy Running" width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Connect from Your Local Machine
&lt;/h2&gt;

&lt;p&gt;This is where it all comes together! From your &lt;strong&gt;local machine&lt;/strong&gt;, establish an SSH connection with port forwarding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Open a new terminal&lt;/strong&gt; and run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud compute ssh iap-jumphost-vm &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--zone&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-south1-b &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--tunnel-through-iap&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--ssh-flag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"-L 5432:localhost:5432"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command does two important things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Connects via IAP&lt;/strong&gt; (&lt;code&gt;--tunnel-through-iap&lt;/code&gt;): Creates a secure, authenticated tunnel through IAP to your private jumphost VM&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port Forwarding&lt;/strong&gt; (&lt;code&gt;-L 5432:localhost:5432&lt;/code&gt;): Forwards traffic from your local port 5432 to the jumphost's port 5432, where the AlloyDB Auth Proxy is listening&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The IAP tunnel ensures that all traffic is encrypted and authenticated before reaching your private network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtsnlvipupbhfl38lfuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtsnlvipupbhfl38lfuz.png" alt="SSH Connection with Port Forwarding" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, in &lt;strong&gt;another terminal&lt;/strong&gt; (keep the SSH session running), connect to AlloyDB as if it were local:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-h&lt;/span&gt; localhost &lt;span class="nt"&gt;-p&lt;/span&gt; 5432 &lt;span class="nt"&gt;-U&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw59a9b4kbp4r4jixgh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw59a9b4kbp4r4jixgh65.png" alt="Local Connection to AlloyDB" width="800" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🎉 &lt;strong&gt;Success!&lt;/strong&gt; You're now connected to your private AlloyDB instance from your local machine through a secure IAP tunnel!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Grant Access to Team Members
&lt;/h2&gt;

&lt;p&gt;To allow other users to access the jumphost via IAP, grant them the necessary IAM roles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# IAP-secured Tunnel User role&lt;/span&gt;
gcloud projects add-iam-policy-binding PROJECT_ID &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"user:USER_EMAIL"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/iap.tunnelResourceAccessor"&lt;/span&gt;

&lt;span class="c"&gt;# Compute Instance Admin role (for SSH)&lt;/span&gt;
gcloud projects add-iam-policy-binding PROJECT_ID &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"user:USER_EMAIL"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/compute.instanceAdmin.v1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;USER_EMAIL&lt;/code&gt; with the email address of the user who needs access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Best Practices
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No External IPs&lt;/strong&gt;: Keep all resources private—no public-facing endpoints&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAP Authentication&lt;/strong&gt;: Leverage Google's identity verification—no shared keys or passwords&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Least Privilege&lt;/strong&gt;: Grant only necessary permissions to service accounts and users&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Isolation&lt;/strong&gt;: Use private VPCs with controlled firewall rules&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Audit Logging&lt;/strong&gt;: Enable Cloud Audit Logs to monitor access&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;h3&gt;
  
  
  "Network is unreachable" during apt update
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure Cloud NAT is properly configured and attached to your VPC&lt;/li&gt;
&lt;li&gt;Verify the NAT gateway is in the same region as your subnet&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  IAP SSH connection fails
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Check firewall rules allow IAP source ranges (&lt;code&gt;35.235.240.0/20&lt;/code&gt;) - this is the IP range that IAP uses to connect to your VMs&lt;/li&gt;
&lt;li&gt;Verify you have the &lt;code&gt;roles/iap.tunnelResourceAccessor&lt;/code&gt; IAM role - this role is required to use IAP's TCP forwarding feature&lt;/li&gt;
&lt;li&gt;Ensure the firewall rule is properly configured for your VPC&lt;/li&gt;
&lt;li&gt;Make sure you're authenticated with &lt;code&gt;gcloud auth login&lt;/code&gt; and have the correct project selected&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AlloyDB connection refused
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure Auth Proxy is running on the jumphost&lt;/li&gt;
&lt;li&gt;Verify service account has &lt;code&gt;roles/alloydb.client&lt;/code&gt; role&lt;/li&gt;
&lt;li&gt;Check AlloyDB instance is in the same VPC as the jumphost&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Port forwarding not working
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Confirm Auth Proxy is listening on &lt;code&gt;0.0.0.0:5432&lt;/code&gt; (not just &lt;code&gt;127.0.0.1&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Verify SSH command includes correct port forwarding flags&lt;/li&gt;
&lt;li&gt;Keep the SSH session running while connecting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cost Optimization Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;preemptible instances&lt;/strong&gt; for development/testing (saves up to 80%)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop the jumphost VM&lt;/strong&gt; when not in use&lt;/li&gt;
&lt;li&gt;Consider &lt;strong&gt;e2-micro&lt;/strong&gt; instances for light workloads&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete Cloud NAT&lt;/strong&gt; if outbound internet access isn't needed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This setup provides enterprise-grade security for accessing AlloyDB while maintaining ease of use. The combination of IAP tunneling, private networking, and AlloyDB Auth Proxy ensures that your database remains completely isolated from the public internet while still being accessible to authorized users.&lt;/p&gt;

&lt;p&gt;The beauty of this approach is its simplicity: just run a &lt;code&gt;gcloud&lt;/code&gt; command, and you have a secure tunnel to your private database. &lt;strong&gt;IAP (Identity-Aware Proxy)&lt;/strong&gt; handles authentication and encryption using your Google Cloud identity, while AlloyDB Auth Proxy manages secure database connections—all working together seamlessly with Google Cloud's identity-aware security infrastructure. No VPN clients, no complex networking, just secure, identity-based access to your private resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.cloud.google.com/iap/docs/using-tcp-forwarding" rel="noopener noreferrer"&gt;IAP TCP Forwarding Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.cloud.google.com/alloydb/docs/auth-proxy/connect" rel="noopener noreferrer"&gt;AlloyDB Auth Proxy Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.cloud.google.com/iap/docs/using-tcp-forwarding#grant-permission" rel="noopener noreferrer"&gt;Granting IAP Access&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you found this helpful, feel free to share your thoughts or questions in the comments below. Have you tried this setup? What challenges did you face? Let's discuss!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>cloud</category>
      <category>googlecloud</category>
      <category>alloydb</category>
    </item>
  </channel>
</rss>
