Skip to main content

Authentication Flow

The gateway uses two independent auth mechanisms in sequence:

  1. Worker → cf-proxy: X-Internal-Auth-Token (shared secret)
  2. cf-proxy → Cloud Run: GCP identity token (OIDC, from instance metadata)

Why two auth layers?

  • X-Internal-Auth-Token guards the tunnel ingress from traffic that bypasses the Worker (e.g. direct requests to the internal hostname). CF Access apps were removed from internal hostnames because Cloudflare strips CF-Access-* headers from same-zone Worker subrequests, making service token auth unworkable there.
  • The GCP identity token lets Cloud Run enforce that only the gateway VM SA can invoke the service — no other caller can forge this token.

Token material

SecretSource (at deploy time)Consumer
INTERNAL_AUTH_TOKENrandom_password in iac-api-gateway/gateway/secrets.tfWorker (via CF Secrets Store) + cf-proxy (via GCP SM)
GCP identity tokenInstance metadata server (runtime)cf-proxy → Cloud Run
CF tunnel tokencloudflare_zero_trust_tunnel_cloudflared_token in secrets.tfcloudflared on the VM