Back to All Technical Blogs
GCP
Jan 22, 2025
7 min read

Custom Domain Mapping and Automated SSL Management for GCP Cloud Run & Cloud Storage

Sandip Basnet
Sandip Basnet
Senior Software Engineer & SRE

Custom Domain Mapping and Automated SSL Management for GCP Cloud Run & Cloud Storage

When launching production microservices on GCP Cloud Run or hosting static frontend assets on Google Cloud Storage (GCS), serving traffic under custom brand domain names (such as api.mycompany.com or assets.mycompany.com) is an essential branding and security requirement.

In this technical walkthrough, we cover both native Cloud Run Domain Mapping and Global Load Balancer Domain Mapping for Cloud Run services and GCS buckets, including zero-touch Google-managed SSL certificate provisioning.


Option 1: Native Cloud Run Domain Mapping

For straightforward single-region services, GCP Cloud Run provides built-in domain mapping:

  • Add Domain Mapping: In Google Cloud Console or gcloud CLI, map your custom domain api.example.com to your target Cloud Run service.
  • Domain Ownership Verification: Add the requested Google TXT record to your Cloud DNS or external registrar (e.g. Cloudflare, Route53, Namecheap).
  • Configure CNAME / ANAME Records: Update your DNS zone with the CNAME records provided by GCP pointing to ghs.googlehosted.com.
  • bashSnippet
    # Create Domain Mapping via gcloud CLI
    gcloud beta run domain-mappings create \
      --service=api-server \
      --domain=api.example.com \
      --region=us-central1

    Option 2: Cloud Storage (GCS) Custom Domain Mapping

    To serve static web assets, images, or single-page apps directly from a GCS bucket under cdn.example.com:

  • Name Bucket to Match Subdomain: Create a bucket named strictly matching the target domain (e.g., bucket name: cdn.example.com).
  • Set Bucket Access: Grant allUsers the Storage Object Viewer role or restrict via Cloud CDN.
  • DNS CNAME Entry: Point cdn.example.com to c.storage.googleapis.com in your DNS manager.

  • Automated TLS / SSL Certificate Provisioning

    Both Cloud Run Domain Mappings and GCP Load Balancers automatically issue and renew 90-day Let's Encrypt / Google Trust Services TLS certificates. Once DNS records propagate (typically 5 to 15 minutes), HTTPS is enforced automatically with zero manual certificate key rotations required.

    Topic Tags:GCPCloud RunCloud StorageCustom DomainSSLDNSDevOps
    View All