Back to Blog
securitySecurityVPNGCPCloud ArmorNetworking

Securing Internal Services with VPN & Cloud Armor on GCP

How we lock down internal tools to VPN-only access using Outline VPN and Cloud Armor. A complete guide to network security for private infrastructure.

Securing Internal Services with VPN & Cloud Armor on GCP

When we deployed Supabase Studio for our client, one requirement was non-negotiable: the database admin interface should never be accessible from the public internet.

But we also needed the team to access it from anywhere: coffee shops, home offices, airports. The solution was a VPN combined with Cloud Armor IP whitelisting.

This post shows how we built it.

The security model

Our approach has two layers:

  1. VPN: Team members connect through Outline VPN to get a known, static IP
  2. Cloud Armor: Only allows traffic from the VPN server's IP
How a request reaches Supabase Studio
Developer laptopVPN Server(Outline)Cloud ArmorSecurity PolicyLoad BalancerSupabaseStudioVPN tunnelStatic public IP:34.x.x.xWhitelist:34.x.x.x/32

This gives us:

  • Zero public exposure: even with the URL, you can't access it without VPN
  • Centralized access control: revoke VPN access, revoke all access
  • Per-person keys: each team member has their own access key, and Outline Manager shows how much data each one uses. It isn't an audit trail, though: Outline doesn't log who connected when. If the services behind it hold health data, HIPAA's audit controls need that record from somewhere else, as our Supabase HIPAA guide explains
  • Works anywhere: developers just need the Outline app

Part 1: Deploying Outline VPN

We chose Outline VPN for several reasons:

  • Created by Jigsaw (Google), battle-tested and secure
  • Uses the Shadowsocks protocol, which is harder to detect and block
  • Cross-platform clients: macOS, Windows, Linux, iOS, Android
  • Simple management: no complex configuration files
  • Open source: full transparency

The VPN component

Our Pulumi component for the VPN server:

export class Vpn extends pulumi.ComponentResource {
  public readonly instance: gcp.compute.Instance;
  public readonly staticIp: gcp.compute.Address;
  public readonly persistentDisk: gcp.compute.Disk;
  public readonly publicIp: pulumi.Output<string>;
 
  constructor(name: string, args: VpnArgs, opts?: pulumi.ComponentResourceOptions) {
    super("acme:components:Vpn", name, {}, opts);
 
    // Static IP that won't change
    this.staticIp = new gcp.compute.Address(
      `${args.name}-vpn-ip`,
      {
        name: `${args.name}-vpn-ip`,
        region: args.region,
      },
      { parent: this },
    );
 
    // Persistent disk for VPN state
    this.persistentDisk = new gcp.compute.Disk(
      `${args.name}-vpn-data`,
      {
        name: `${args.name}-vpn-data`,
        zone: `${args.region}-a`,
        size: 10,
        type: "pd-ssd",
      },
      { parent: this },
    );
 
    // The VM instance
    this.instance = new gcp.compute.Instance(
      `${args.name}-vpn`,
      {
        name: `${args.name}-vpn`,
        machineType: "e2-small",
        zone: `${args.region}-a`,
        tags: ["vpn-server", "allow-ssh"],
 
        bootDisk: {
          initializeParams: {
            image: "projects/cos-cloud/global/images/family/cos-stable",
            size: 20,
            type: "pd-ssd",
          },
        },
 
        attachedDisks: [
          {
            source: this.persistentDisk.selfLink,
            deviceName: `${args.name}-vpn-data`,
          },
        ],
 
        networkInterfaces: [
          {
            network: args.network.id,
            subnetwork: args.subnet.id,
            accessConfigs: [
              {
                natIp: this.staticIp.address,
              },
            ],
          },
        ],
 
        metadataStartupScript: startupScript,
      },
      { parent: this },
    );
 
    this.publicIp = this.staticIp.address;
  }
}

Key design decisions:

Static IP

The VPN needs a stable public IP. If it changes, our Cloud Armor rules would break. We reserve a static IP and attach it to the instance.

Persistent disk

Outline stores its configuration and access keys on disk. If the VM restarts, we don't want to lose everything. A separate persistent disk survives instance recreation.

Container-Optimized OS

We use Google's Container-Optimized OS (COS). It's minimal, auto-updating, and designed for running Docker containers, which suits Outline.

Small instance

e2-small (2 vCPU, 2 GB RAM) is plenty for a VPN server handling a small team. We can scale up if needed.

The startup script

The startup script does the work. It runs when the VM boots:

#!/bin/bash
set -euo pipefail
 
# Configuration
SHADOWBOX_DIR="/mnt/disks/outline"
STATE_DIR="${SHADOWBOX_DIR}/persisted-state"
CONTAINER_NAME="shadowbox"
API_PORT="8443"
ACCESS_KEY_PORT="443"
PUBLIC_HOSTNAME="vpn.example.com" # the VPN's DNS name or static IP
SB_IMAGE="quay.io/outline/shadowbox:stable"
 
# Mount persistent disk ("google-" followed by the disk's device name)
DATA_DISK="/dev/disk/by-id/google-acme-dev-vpn-data"
MOUNT_POINT="/mnt/disks/outline"
 
if ! mountpoint -q "${MOUNT_POINT}"; then
    # Format if new
    if ! blkid "${DATA_DISK}" > /dev/null 2>&1; then
        mkfs.ext4 -F "${DATA_DISK}"
    fi
 
    mkdir -p "${MOUNT_POINT}"
    mount "${DATA_DISK}" "${MOUNT_POINT}"
fi
 
# Create state directory
mkdir -p "${STATE_DIR}"
 
# Generate API prefix (random string for management URL)
if [ ! -f "${STATE_DIR}/api_prefix" ]; then
    head -c 16 /dev/urandom | base64 | tr '/+' '_-' > "${STATE_DIR}/api_prefix"
fi
SB_API_PREFIX=$(cat "${STATE_DIR}/api_prefix")
 
# Generate TLS certificate
if [ ! -f "${STATE_DIR}/shadowbox-selfsigned.crt" ]; then
    openssl req -x509 -nodes -days 36500 -newkey rsa:4096 \
        -subj "/CN=${PUBLIC_HOSTNAME}" \
        -keyout "${STATE_DIR}/shadowbox-selfsigned.key" \
        -out "${STATE_DIR}/shadowbox-selfsigned.crt"
fi
 
# Server settings, written once. Access keys use this hostname (without it,
# Outline asks ipinfo.io for the public IP), and every new key gets the port
# in portForNewAccessKeys.
if [ ! -s "${STATE_DIR}/shadowbox_server_config.json" ]; then
    echo "{\"hostname\":\"${PUBLIC_HOSTNAME}\",\"portForNewAccessKeys\":${ACCESS_KEY_PORT}}" \
        > "${STATE_DIR}/shadowbox_server_config.json"
fi
 
# What Outline Manager asks for when you add the server
CERT_SHA256=$(openssl x509 -in "${STATE_DIR}/shadowbox-selfsigned.crt" -noout -fingerprint -sha256 | cut -d= -f2 | tr -d :)
echo "{\"apiUrl\":\"https://${PUBLIC_HOSTNAME}:${API_PORT}/${SB_API_PREFIX}\",\"certSha256\":\"${CERT_SHA256}\"}" \
    > "${SHADOWBOX_DIR}/access.txt"
 
# Start Outline container, recreated on every boot once the disk is mounted.
# --mount (unlike -v) won't start it on an empty directory before that.
docker rm -f "${CONTAINER_NAME}" > /dev/null 2>&1 || true
docker run -d \
    --name "${CONTAINER_NAME}" \
    --restart always \
    --net host \
    --label com.centurylinklabs.watchtower.enable=true \
    --mount "type=bind,source=${STATE_DIR},target=${STATE_DIR}" \
    -e "SB_STATE_DIR=${STATE_DIR}" \
    -e "SB_API_PORT=${API_PORT}" \
    -e "SB_API_PREFIX=${SB_API_PREFIX}" \
    -e "SB_CERTIFICATE_FILE=${STATE_DIR}/shadowbox-selfsigned.crt" \
    -e "SB_PRIVATE_KEY_FILE=${STATE_DIR}/shadowbox-selfsigned.key" \
    "${SB_IMAGE}"

Key points:

  1. Idempotent: Checks if things exist before creating them, and recreates the container on every boot
  2. Persistent: All state is stored on the attached disk
  3. Self-healing: Container restarts automatically
  4. Secure: API prefix is random, TLS is always used

Firewall rules for VPN

The VPN server needs to accept connections:

this.firewallVpn = new gcp.compute.Firewall(
  `${args.name}-allow-vpn`,
  {
    name: `${args.name}-allow-vpn`,
    network: args.network.id,
    allows: [
      // Management API
      { protocol: "tcp", ports: ["8443"] },
      // VPN connections, on the access-key port
      { protocol: "tcp", ports: ["443"] },
      { protocol: "udp", ports: ["443"] },
    ],
    sourceRanges: ["0.0.0.0/0"],
    targetTags: ["vpn-server"],
  },
  { parent: this },
);

One port for every key

Outline doesn't give each access key its own port. Every new key uses the server's portForNewAccessKeys; if the config doesn't set one, Outline picks a random port on first start and keeps it (Outline's server code). Our startup script sets it to 443, so the firewall opens just that port, for TCP and UDP. If you change the port for new keys in Outline Manager, open the new one too.

Part 2: Cloud Armor security policy

Cloud Armor is GCP's web application firewall. We use it as an IP whitelist.

The security policy

const securityPolicy = new gcp.compute.SecurityPolicy(`${resourceName}-security-policy`, {
  name: `${resourceName}-security-policy`,
  description: "Allow only VPN traffic",
 
  rules: [
    // Default: deny all
    {
      action: "deny(403)",
      priority: 2147483647,
      match: {
        versionedExpr: "SRC_IPS_V1",
        config: {
          srcIpRanges: ["*"],
        },
      },
      description: "Default deny all",
    },
    // Allow VPN server
    {
      action: "allow",
      priority: 900,
      match: {
        versionedExpr: "SRC_IPS_V1",
        config: {
          srcIpRanges: [pulumi.interpolate`${vpnPublicIp}/32`],
        },
      },
      description: "Allow VPN server",
    },
  ],
});

Rule priorities

Lower numbers = higher priority. Our logic:

  1. Priority 900: Allow VPN server IP
  2. Priority 2147483647: Deny everything else (default rule)

Health checks need a firewall rule, not a Cloud Armor rule

GCP load balancers use health checks to determine if backends are healthy. If the probes can't reach the instances, the load balancer thinks all instances are down, and nothing works.

Cloud Armor can't help with that. It filters requests at the load balancer, at Google's edge, and the probes never pass through it: Google sends them straight to each instance's internal IP (health check docs). What lets them in is a VPC firewall rule. Google's firewall requirements for a global external Application Load Balancer list these sources:

  • 35.191.0.0/16: health check probes (IPv4)
  • 130.211.0.0/22 and 35.191.0.0/16: the load balancer's own requests to the backends (IPv4)
  • 2600:2d00:1:b029::/64 and 2600:2d00:1:1::/64: the same for IPv6 backends

Our backends only have IPv4 addresses, so one rule on the port they serve covers it:

this.firewallLb = new gcp.compute.Firewall(`${resourceName}-allow-lb`, {
  name: `${resourceName}-allow-lb`,
  network: this.vpc.id,
  direction: "INGRESS",
  allows: [{ protocol: "tcp", ports: ["8000"] }], // the port the instance group serves
  sourceRanges: ["35.191.0.0/16", "130.211.0.0/22"],
  targetTags: ["supabase-studio"],
});

Attaching to the backend service

The security policy attaches to the backend service:

this.backendService = new gcp.compute.BackendService(`${resourceName}-backend`, {
  name: `${resourceName}-backend`,
  protocol: "HTTP",
  portName: "http",
  healthChecks: this.healthCheck.id,
  securityPolicy: securityPolicy?.selfLink, // <-- Here
  backends: [
    {
      group: this.instanceGroupManager.instanceGroup,
      balancingMode: "UTILIZATION",
      capacityScaler: 1.0,
    },
  ],
});

Do VPN clients need a firewall rule?

No. Outline is a Shadowsocks proxy, not a VPN that hands out addresses. Clients don't get an IP inside your network; their traffic leaves through the Outline server. To Studio and everything else, it arrives from the server's static IP, which is exactly what the Cloud Armor policy above allows.

It also means Outline won't take VPN users to a private IP at all. Its server refuses connections to private ranges such as 10.0.0.0/8, and there's no setting to change that (Outline's server code). For services on private IPs, like the database, we use a bastion: a VM with a public IP that only accepts connections from the Outline server. It forwards a port per service to that service's private IP, each under its own DNS name, such as db.<domain> (how we connect to Cloud SQL). Identity-Aware Proxy is the other option.

Managing VPN access

Getting the management URL

After deployment, SSH into the VPN server:

gcloud compute ssh acme-dev-vpn --zone=europe-west2-a

Then read the access configuration:

cat /mnt/disks/outline/access.txt

You'll get something like:

{
  "apiUrl": "https://vpn.example.com:8443/a1b2c3d4e5f6",
  "certSha256": "ABCDEF1234..."
}

The startup script writes this file. certSha256 is the certificate's SHA-256 fingerprint in hex, without colons, the same form Outline's own install script writes.

Using Outline Manager

  1. Download Outline Manager for your OS
  2. Click "Add Server"
  3. Paste the JSON configuration
  4. Create access keys for team members

Distributing access

Each team member gets their own access key:

  1. In Outline Manager, click "Add Key"
  2. Name it (e.g., "Sarah's MacBook")
  3. Share the access key (a ss:// URL)
  4. Team member imports it into Outline Client

Revoking access

When someone leaves the team:

  1. Open Outline Manager
  2. Find their key
  3. Delete it

Access is revoked immediately. They can't connect to the VPN, so they can't access any internal services.

Additional hardening

SSH access control

Our VPN server has SSH enabled for management. We limit it:

this.firewallSsh = new gcp.compute.Firewall(`${resourceName}-allow-ssh`, {
  name: `${resourceName}-allow-ssh`,
  network: this.vpc.id,
  allows: [{ protocol: "tcp", ports: ["22"] }],
  sourceRanges: ["0.0.0.0/0"], // Consider restricting this
  targetTags: ["allow-ssh"],
});

For production, consider:

  • Restricting to specific IPs
  • Using Identity-Aware Proxy (IAP) for SSH
  • Disabling SSH entirely after setup

OS-level firewall

Container-Optimized OS has a restrictive firewall by default. Our startup script adds rules:

# Allow VPN ports
iptables -A INPUT -p tcp --dport 8443 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p udp --dport 443 -j ACCEPT

Automatic updates

COS updates automatically. For Outline, we run Watchtower:

docker run -d \
    --name watchtower \
    --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    nickfedor/watchtower \
    --cleanup --label-enable --interval 3600

This checks for Outline updates hourly and applies them automatically. We use nickfedor/watchtower, the image Outline's own install script now runs. With --label-enable, Watchtower only touches containers labelled com.centurylinklabs.watchtower.enable=true (Watchtower docs), which is why the startup script puts that label on shadowbox.

Testing the setup

Verify Cloud Armor is blocking

Without VPN, try accessing the service:

curl -I https://db.dev.example.com

Expected: HTTP/2 403 (Forbidden)

Verify VPN access works

  1. Connect to VPN via Outline Client
  2. Try again:
curl -I https://db.dev.example.com

Expected: HTTP/2 200 (OK) or a redirect

Check Cloud Armor logs

In GCP Console, go to Network Security → Cloud Armor and view the logs. You'll see:

  • Blocked requests with source IP and reason
  • Allowed requests from the VPN

This is useful for debugging and auditing.

Gotchas and lessons learned

  1. Health check IPs must be allowed. We initially denied all traffic and couldn't figure out why the load balancer showed all backends as unhealthy. The health check probes were being blocked. They're allowed in the VPC firewall, not in Cloud Armor, which never sees them.
  2. VPN IP must be static. If you use an ephemeral IP and the VM restarts, the IP changes, and Cloud Armor blocks everything (including the new VPN IP). Always use a reserved static IP.
  3. Outline keys share one port. Every new access key uses the same port. Fix it in the server config, as our startup script does, and the firewall only needs that port. If you change it in Outline Manager later, update the firewall rule and the host firewall to match.
  4. IPv6 health checks. If your backends have IPv6 addresses, the probes and the load balancer can reach them over IPv6 too, from 2600:2d00:1:b029::/64 and 2600:2d00:1:1::/64. Add those to the VPC firewall rule, not to Cloud Armor.
  5. Policy propagation takes time. After creating or updating a Cloud Armor policy, give it a few minutes to propagate. Testing immediately after might give misleading results.

Alternative approaches

IP-based access without VPN

If your team works from static IPs (offices), you could whitelist those directly:

srcIpRanges: [
  "203.0.113.0/24", // London office
  "198.51.100.0/24", // NYC office
],

But this doesn't work for remote teams.

Identity-Aware Proxy (IAP)

GCP's IAP is another option. It verifies identity at the load balancer level:

  • Works with Google accounts
  • No VPN needed
  • But: Requires browser-based access, doesn't work for all protocols

For Supabase Studio (a web app), IAP would work. We chose VPN because we also need access to the database for some tools, which we reach through the VPN and a bastion.

Tailscale / WireGuard

Tailscale and WireGuard are excellent alternatives to Outline. We chose Outline for its simplicity and cross-platform support, but the same Cloud Armor approach works with any VPN.

The complete picture

What this setup gives us:

  • Zero public exposure: services only accessible via VPN
  • Simple access management: add/remove via Outline Manager
  • Works anywhere: coffee shop, home, airport
  • Per-person access: one Outline key per team member
  • Layered security: VPN + Cloud Armor + VPC firewall rules
  • Low maintenance: auto-updates for both OS and VPN

For internal tools and admin interfaces, this is our go-to security pattern.


Want Supabase Studio and your database off the public internet? It's part of how we set up self-hosted Supabase on Google Cloud.

Sachin Mour
Founder of Pulore, ex-CTO at Hexis
Share:

Want Supabase on your own cloud?

We set up and run self-hosted Supabase on Google Cloud for teams that need control over their data: private networking, managed PostgreSQL, backups and monitoring, all defined as code. A new setup is a two-week, fixed-price project from $8,000.