Solving Cloud Run Custom Domain Error: “Caller is not authorized to administer the domain”
Introduction
When setting up a custom domain for Cloud Run using Terraform or the gcloud command, you may encounter the following error:
Error: Error waiting to create DomainMapping: resource is in failed state "Ready:False",
message: Caller is not authorized to administer the domain example.com.
If you own example.com, you can obtain authorization by verifying ownership of the domain,
or any of its parent domains, via the Webmaster Central portal:
https://www.google.com/webmasters/verification/verification?domain=This error commonly occurs in CI/CD pipelines or when using Service Accounts for automated deployments, and the solution isn’t always obvious. This article provides a detailed explanation of how to resolve it.
TL;DR
You need to grant domain ownership permissions to your Service Account.
- Verify your domain in Google Search Console
- Add your Service Account’s email address as an “Owner”
- Re-run Terraform/gcloud
Root Cause
This error occurs in the following scenarios:
1. Domain verified with personal account, but executing with Service Account
2. Automated deployment via CI/CD (e.g., GitHub Actions)
# .github/workflows/deploy.yml
- name: Deploy to Cloud Run
run: terraform apply -auto-approve
# ↑ Fails because it runs with Service Account3. Deployment across multiple projects or environments
- Development: Set up with personal account ✅
- Production: Set up with Service Account ❌
Solution
Step 1: Verify Domain Ownership
First, verify domain ownership with your personal Google account.
- Go to Google Search Console
- Click “Add property” → Select “Domain”
- Enter your domain name (e.g.,
example.com) - Add the TXT record to your DNS
- Complete verification
Step 2: Identify Your Service Account Email
# Check the Service Account used by Terraform
gcloud config get-value account# List Service Accounts in your project
gcloud iam service-accounts list# Example output:
# NAME EMAIL
# terraform-sa terraform-sa@my-project.iam.gserviceaccount.com
# github-actions github-actions@my-project.iam.gserviceaccount.com
Step 3: Add Service Account as Owner
Important: This is the most commonly overlooked step
- Open Google Search Console
- Select your verified domain property
- Click “Settings” in the left menu
- Click “Users and permissions”
- Click the “Add user” button
- Enter your Service Account email address
Example: terraform-sa@my-project.iam.gserviceaccount.com - Set permission level to “Owner” (critical!)
- Click “Add”
Step 4: Verify and Re-execute
The permission takes effect immediately after being added.
# For Terraform
terraform plan
terraform apply
# For gcloud
gcloud run domain-mappings create \
--service=my-service \
--domain=example.com \
--region=asia-northeast1Terraform Configuration Example
resource "google_cloud_run_domain_mapping" "default" {
location = var.region
name = var.custom_domain
metadata {
namespace = var.project_id
}
spec {
route_name = google_cloud_run_service.default.name
}
# Handle dependencies
depends_on = [
google_cloud_run_service.default
]
}Troubleshooting
1. Error persists after adding permissions
# Verify the correct Service Account is being used
gcloud auth list
# Execute with the current account
gcloud run domain-mappings create \
--service=my-service \
--domain=example.com \
--region=asia-northeast1 \
--impersonate-service-account=SERVICE_ACCOUNT_EMAIL2. Using subdomains
Verifying the parent domain covers all subdomains:
- Verify
example.com→ Can usesubdomain.example.com - Verify
example.com→ Can useapi.example.com
You can also verify subdomains individually if needed.
3. Using the same domain across multiple projects
You need to add each project’s Service Account as an owner in Search Console.
# Project A Service Account
sa-project-a@project-a.iam.gserviceaccount.com
# Project B Service Account
sa-project-b@project-b.iam.gserviceaccount.com
# Add both as owners in Search ConsoleSummary
The “Error waiting to create DomainMapping” error is caused by the Service Account lacking domain ownership permissions.
Key points to remember:
- Domain verification is per user account — Not automatically shared with other users or Service Accounts
- Search Console permission grant is required — Separate from IAM permissions
- “Owner” level permission is necessary — “Full access” is insufficient
- Verifying the parent domain is more convenient — Applies to all subdomains