Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
roles/run.invoker
When running autonomous AI agents (such as Antigravity, Claude Code, OpenCode, or custom LangGraph runtimes) on Cloud Run and connecting them to Remote MCP (Model Context Protocol) servers that expose internal databases and operational tools, cloud engineers invariably hit a major pain point: auth boilerplate code polluting the codebase.
When implementing zero-trust access control with Google Cloud IAM, client services traditionally had to query the metadata server ( http://metadata.google.internal/... ) to fetch an OIDC ID token and append it to request headers as Authorization: Bearer <ID_TOKEN> .
http://metadata.google.internal/...
Authorization: Bearer <ID_TOKEN>
From a day-to-day engineering perspective, this setup came with several severe frictions:
https://my-mcp-backend-abc123-an.a.run.app
google-auth
google-auth-library
To resolve this issue once and for all by offloading authentication entirely to the infrastructure layer, Google Cloud introduced “Ambient Networking” and “Express Links” in Cloud Run in November 2026 (Preview).
▲ Overall architecture of autonomous AI agent mesh powered by Cloud Run Ambient Networking and Express Links
Ambient Networking is an infrastructure capability in Cloud Run that automatically injects a fully managed Envoy sidecar proxy inside container instances.
Developers do not need to write Envoy configuration files in their Dockerfiles or manage heavy Kubernetes-style sidecar manifests. With a single gcloud flag, a transparent proxy layer boots alongside the application container and intercepts ingress and egress traffic.
gcloud
Express Links leverage the managed Envoy sidecar of Ambient Networking as a data plane to fully automate routing and Google Cloud IAM authentication (OIDC ID token injection) between Cloud Run services .
The calling AI agent never needs to know the destination service’s physical URL or handle ID tokens. It simply issues plain HTTP requests to an abstract logical hostname, such as http://mcp-backend/mcp .
http://mcp-backend/mcp
The Envoy sidecar intercepts the request, obtains an OIDC ID token with the correct audience from the internal metadata server, injects the Authorization header, and upgrades the request to HTTPS before forwarding it to the destination service.
Authorization
https://*.a.run.app
http://mcp-backend
The sequence diagram below illustrates how traffic is transparently intercepted and forwarded securely without touching application-level auth code:
The decisive security advantage of this flow is that the ID token string never enters the calling agent container’s process space . Even if a prompt injection attack compromises the agent runtime or attempts a memory dump, lateral movement is contained because the token resides exclusively inside the isolated Envoy sidecar memory space.
Here is the exact procedure I executed to configure this architecture in a clean verification environment.
agent-worker
sa-agent@my-project.iam.gserviceaccount.com
mcp-filesystem
asia-northeast1
Update the calling service revision with --ambient-networking and --ambient-scope=global :
--ambient-networking
--ambient-scope=global
gcloud beta run services update agent-worker \ --region=asia-northeast1 \ --ambient-networking \ --ambient-scope=global \ --project=my-project
--matches-hostname
Next, create the Express Link routing resource using gcloud beta network-services express-links create .
gcloud beta network-services express-links create
A critical parameter here is the --matches-hostname flag . By default, an Express Link intercepts requests sent to the destination service’s deterministic URL ( https://mcp-filesystem-<PROJECT_NUMBER>.asia-northeast1.run.app ). Specifying --matches-hostname="mcp-backend" replaces that default deterministic URL mapping with an abstract custom logical hostname ( mcp-backend , specified without a scheme).
https://mcp-filesystem-<PROJECT_NUMBER>.asia-northeast1.run.app
--matches-hostname="mcp-backend"
mcp-backend
The 63-Character DNS Label Limit and Mandatory --matches-hostname : If the combined length of your destination Cloud Run service name and Google Cloud project number exceeds 63 characters , Express Link creation will fail with a DNS label length validation error unless --matches-hostname is configured. In microservice and Remote MCP architectures with descriptive service names, assigning a concise logical hostname via --matches-hostname is an essential production best practice.
gcloud beta network-services express-links create link-agent-to-mcp \ --location=global \ --source-services="//run.googleapis.com/projects/my-project/locations/asia-northeast1/services/agent-worker" \ --destination-services="//run.googleapis.com/projects/my-project/locations/asia-northeast1/services/mcp-filesystem" \ --matches-hostname="mcp-backend" \ --project=my-project
Inspecting the created Express Link via describe (or export ) confirms that sourceServices , destinationServices , and matchesHostname are active under locations/global :
describe
export
sourceServices
destinationServices
matchesHostname
locations/global
# gcloud beta network-services express-links describe link-agent-to-mcp --location=global name: "projects/my-project/locations/global/expressLinks/link-agent-to-mcp" sourceServices: - "//run.googleapis.com/projects/my-project/locations/asia-northeast1/services/agent-worker" destinationServices: - "//run.googleapis.com/projects/my-project/locations/asia-northeast1/services/mcp-filesystem" matchesHostname: - "mcp-backend" state: ACTIVE
Grant the calling service’s service account ( sa-agent ) permission to invoke the target service ( mcp-filesystem ):
sa-agent
gcloud run services add-iam-policy-binding mcp-filesystem \ --region=asia-northeast1 \ --member="serviceAccount:sa-agent@my-project.iam.gserviceaccount.com" \ --role="roles/run.invoker" \ --project=my-project
Previously, developers had to import google-auth-library and generate an ID token for every external invocation:
import { GoogleAuth } from 'google-auth-library'; import fetch from 'node-fetch'; const auth = new GoogleAuth(); const targetUrl = process.env.MCP_SERVER_URL!; // https://mcp-filesystem-abc123-an.a.run.app async function callMcpTool(method: string, params: Record<string, unknown>) { // 1. Retrieve OIDC ID token from GCP metadata server const client = await auth.getIdTokenClient(targetUrl); const headers = await client.getRequestHeaders(targetUrl); // 2. Attach Authorization header manually over HTTPS const response = await fetch(`${targetUrl}/mcp`, { method: 'POST', headers: { ...headers, 'Content-Type': 'application/json', 'Mcp-Method': method, }, body: JSON.stringify(params), }); return await response.json(); }
With Express Links in place, Google Cloud SDK dependencies are eliminated. A plain fetch call against the logical hostname is all that is required:
fetch
// No GoogleAuth library required! const MCP_ENDPOINT = 'http://mcp-backend/mcp'; // Abstract logical host mapped by Express Link async function callMcpTool(method: string, params: Record<string, unknown>) { // Token generation, header injection, and HTTPS upgrade are handled by the sidecar const response = await fetch(MCP_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Mcp-Method': method, }, body: JSON.stringify(params), }); return await response.json(); }
This drastically simplifies local mocking ( localhost:8080 ) and integration testing within CI/CD pipelines.
localhost:8080
▲ Real terminal verification log executing gcloud updates and testing Express Link routing on the remote PC
During initial testing, I encountered several specific pitfalls worth noting.
ENOTFOUND
In my first attempt, I only supplied --ambient-networking and omitted the scope flag (defaulting to regional ).
regional
Calling http://mcp-backend/mcp immediately crashed with a DNS failure:
FetchError: request to http://mcp-backend/mcp failed, reason: getaddrinfo ENOTFOUND mcp-backend at ClientRequest.<anonymous> (/app/node_modules/node-fetch/lib/index.js:1491:11) at Socket.emit (node:events:517:28) at emitErrorNT (node:internal/streams/destroy:151:8)
Root Cause and Fix : Express Links are currently managed as global resources under locations/global . The calling Cloud Run service must be deployed with --ambient-scope=global . Without it, Envoy does not intercept custom logical hostnames, causing the container’s standard Linux resolver to query external DNS and fail.
When configuring IAM, I initially attached roles/run.invoker to the target service’s own identity instead of the caller’s service account, resulting in 403 Forbidden :
403 Forbidden
HTTP/1.1 403 Forbidden content-type: text/html; charset=UTF-8 date: Wed, 27 Nov 2026 06:15:22 GMT content-length: 315 <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> Your client does not have permission to get URL <code>/mcp</code> from this server. </body></html>
Under Express Links, the caller service account ( sa-agent ) serves as the principal ( sub ) in the OIDC ID token . Always ensure roles/run.invoker is granted to the caller’s identity.
sub
For long-running MCP tool executions (such as large batch inference or deep reasoning cycles), relying on long-lived SSE connections can trigger timeouts on either the Cloud Run edge (300s default) or the Envoy proxy idle timeout. For production reliability, pair this architecture with stateless MCP protocols (such as MRTR - Multi Round-Trip Requests) rather than indefinite streaming connections.
I measured the operational overhead of running the managed sidecar in production:
512MiB
1GiB
2GiB
▲ Terminal verification log: reproducing scope mismatch (ENOTFOUND) and IAM principal errors (403 Forbidden), followed by a 1,000-request RTT benchmark via Express Links (+1.4ms mean overhead)
Cloud Run’s “Ambient Networking × Express Links” represents a major architectural milestone.
As enterprises scale from a handful of tools to hundreds of internal Remote MCP servers, requiring individual agents to handle authentication logic becomes untenable.
Delegating zero-trust authorization entirely to the ambient infrastructure layer allows developers to focus purely on business logic and agent capabilities. This is the gold standard for enterprise-grade autonomous AI agent service meshes.
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.