> [!WARNING]
>
> **Preview
> --- Ambient networking**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

Ambient networking brings a simplified resource networking experience built into
Cloud Run. It gives your resources a fully managed
data plane to remove the operational burden of building and maintaining
custom proxies. It also abstracts service mesh concepts, so you get advanced
networking features without learning or configuring a mesh.

When you enable ambient networking, traffic passes through unchanged by default
so that your existing HTTP and TCP traffic continues to work. Enabling ambient
networking on its own doesn't change how your resource behaves. As a
foundation, ambient networking lets you opt in to the capabilities described in
the following section.

## Use cases

Ambient networking is the foundation for advanced networking capabilities in
Cloud Run. After you enable ambient networking, you can opt in
to the following features:

- [Agent Gateway on Cloud Run](https://docs.cloud.google.com/run/docs/securing/agent-gateway-cloud-run.md.txt): govern agent traffic with access and security policies that your organization manages centrally.
- [Express links](https://docs.cloud.google.com/run/docs/configuring/express-links): route traffic to other Cloud Run services. The ambient sidecar injects the right credentials for you, so you can call a destination over plain HTTP and remove authentication code from your application.

## Architecture

Ambient networking runs a fully managed Envoy sidecar container inside each
container instance of your Cloud Run resource, alongside your
application container. The sidecar intercepts the instance's network traffic
and applies the routing and security policy that Cloud Run
distributes to it.
![An ambient sidecar container running alongside an application container
inside a container instance of a Cloud Run resource, with
traffic flowing from the sidecar to other Cloud Run
resources.](https://docs.cloud.google.com/static/run/docs/images/ambient-networking-architecture.svg) The ambient sidecar container intercepts traffic between your application container and the destinations that it calls (click to enlarge).

> [!NOTE]
> **Note:** The sidecar is fully managed by Google Cloud. You don't deploy, configure, or access it, and you don't need to define any service mesh resources. Because the sidecar shares your container instance's CPU and memory, see [Sidecar resource usage](https://docs.cloud.google.com/run/docs/configuring/ambient-networking.md.txt#resource-usage) to plan your resource limits.

### Sidecar resource usage

The managed Envoy sidecar shares the CPU and memory allocated to your
Cloud Run container instance. Enabling ambient networking
doesn't enforce a minimum CPU or memory increase beyond the second generation
execution environment requirements, and sidecar resource usage scales with
your workload.

Higher request rates, larger payloads, and concurrent streaming connections
increase sidecar CPU and memory usage. Larger routing and policy configurations
require more sidecar memory.

Because Cloud Run bills for your configured CPU and memory
limits, overprovisioning increases instance costs. To size your resource limits,
do the following:

1. Start with existing CPU and memory limits if your service already meets the second generation execution environment minimums.
2. Test your service and monitor container CPU and memory utilization in [Cloud Monitoring](https://docs.cloud.google.com/run/docs/monitoring.md.txt).
3. Increase your [CPU limit](https://docs.cloud.google.com/run/docs/configuring/services/cpu.md.txt) or [memory limit](https://docs.cloud.google.com/run/docs/configuring/services/memory-limits.md.txt) if you observe elevated utilization or latency. For large workloads, add up to an additional 1 vCPU and 1 GiB of memory.

### Ambient networking scopes

Ambient networking supports a global scope and a regional scope. The scope
determines whether the sidecar connects to a global or regional routing plane:

- **Regional (default)**: Cloud Run connects the sidecar to a regional routing plane, limiting routing and security policies to destinations within your service's region. This scope supports data residency (DRZ) requirements for data at rest, in use, and in transit. If you don't specify a scope, ambient networking uses the regional scope.
- **Global**: Cloud Run connects the sidecar to a global routing plane, allowing it to route traffic to destinations in any region.

Each feature that uses ambient networking requires a specific scope:

| Feature | Global scope | Regional scope |
|---|---|---|
| [Agent Gateway on Cloud Run](https://docs.cloud.google.com/run/docs/securing/agent-gateway-cloud-run.md.txt) | Not supported | Supported |
| [Express links](https://docs.cloud.google.com/run/docs/configuring/express-links) | Supported | Not supported |

## Limitations

The following limitations apply to ambient networking:

- Only Cloud Run services support ambient networking. Cloud Run jobs, worker pools, and instances aren't supported.
- UDP traffic isn't supported. Ambient networking only supports HTTP and TCP traffic.
- Inbound requests don't support [end-to-end HTTP/2](https://docs.cloud.google.com/run/docs/configuring/http2.md.txt). For details, see [Known issues](https://docs.cloud.google.com/run/docs/known-issues.md.txt#ambient-networking-http2).
- The regional scope doesn't support VPC networks that resolve `*.googleapis.com` to Private Google Access IP addresses. For details, see [Known issues](https://docs.cloud.google.com/run/docs/known-issues.md.txt#ambient-networking-regional-pga).
- The first generation [execution environment](https://docs.cloud.google.com/run/docs/configuring/execution-environments.md.txt) isn't supported. If you don't specify an execution environment, Cloud Run uses the second generation.
- Container instances take longer to start. For details, see [Known issues](https://docs.cloud.google.com/run/docs/known-issues.md.txt#ambient-networking-cold-start).

## Before you begin

1.


   Enable the Cloud Run, Network Services, and Traffic Director APIs, if any are not already enabled.


   **Roles required to enable APIs**


   To enable APIs, you need the `serviceusage.services.enable` permission. If you
   created the project, then you likely already have this permission through the
   Owner role (`roles/owner`). Otherwise, you can get this permission through the
   Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
   [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

   [Enable the APIs](https://console.cloud.google.com/apis/enableflow?apiid=run.googleapis.com,networkservices.googleapis.com,trafficdirector.googleapis.com)
2. Optional: Read [Sidecar resource usage](https://docs.cloud.google.com/run/docs/configuring/ambient-networking.md.txt#resource-usage) if
   you expect high traffic or large routing configurations. You don't need to
   increase your [CPU limit](https://docs.cloud.google.com/run/docs/configuring/services/cpu.md.txt) or
   [memory limit](https://docs.cloud.google.com/run/docs/configuring/services/memory-limits.md.txt)
   before enabling ambient networking, and you can adjust limits later based
   on observed utilization.

3. Read the Cloud Run
   [pricing](https://docs.cloud.google.com/run/pricing#networking) page for ambient networking
   sidecar usage. Billing for ambient features isn't enforced during Preview,
   but standard Cloud Run charges still apply for your
   configured container CPU and memory limits.

### Required roles


To get the permissions that
you need to configure and deploy Cloud Run services,

ask your administrator to grant you the
following IAM roles:

- [Cloud Run Developer](https://docs.cloud.google.com/iam/docs/roles-permissions/run.md.txt#run.developer) (`roles/run.developer`) on the Cloud Run service
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity


If you are deploying a [service](https://docs.cloud.google.com/run/docs/deploying-source-code.md.txt#required_roles)
or [function](https://docs.cloud.google.com/run/docs/deploy-functions.md.txt#required-roles) from source code, you
must also have additional roles granted to you on your project and
Cloud Build service account.

The Cloud Run resource's
[service identity](https://docs.cloud.google.com/run/docs/securing/service-identity.md.txt) must also have the
following roles:

- Traffic Director Client (`roles/trafficdirector.client`)
- Cloud Trace Agent (`roles/cloudtrace.agent`)

To grant these roles to the service identity, use gcloud:

```bash
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="serviceAccount:RUN_CLIENT_SA@PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/trafficdirector.client"

gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="serviceAccount:RUN_CLIENT_SA@PROJECT_ID.iam.gserviceaccount.com" \
    --role="roles/cloudtrace.agent"
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: your Google Cloud project ID.
- <var translate="no">RUN_CLIENT_SA</var>: the name of the service account attached to your Cloud Run service.

If the service identity lacks these roles, the Cloud Run
resource still deploys, but features that use ambient networking don't work.

For a list of IAM roles and permissions that are associated with
Cloud Run, see
[Cloud Run IAM roles](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt)
and [Cloud Run IAM permissions](https://docs.cloud.google.com/run/docs/reference/iam/permissions.md.txt).
If your Cloud Run service interfaces with
Google Cloud APIs, such as Cloud Client Libraries, see the
[service identity configuration guide](https://docs.cloud.google.com/run/docs/configuring/services/service-identity.md.txt).
For more information about granting roles, see
[deployment permissions](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt#additional-configuration)
and [manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

## Configure ambient networking

Configure ambient networking by using gcloud or a YAML file.

### gcloud

- To enable ambient networking on a new service, pass the
  `--ambient-networking` flag and, optionally, the
  `--ambient-scope` flag:

  ```bash
  gcloud beta run deploy SERVICE \
    --image=IMAGE_URL \
    --ambient-networking \
    --ambient-scope=SCOPE \
    --region=REGION
  ```
- To enable ambient networking on an existing service, pass the same flags
  to the `gcloud beta run services update` command, which
  deploys a new revision with ambient networking enabled:

  ```bash
  gcloud beta run services update SERVICE \
    --ambient-networking \
    --ambient-scope=SCOPE \
    --region=REGION
  ```
- To disable ambient networking, pass the
  `--no-ambient-networking` flag:

  ```bash
  gcloud beta run services update SERVICE \
    --no-ambient-networking \
    --region=REGION
  ```

Replace the following:

- <var translate="no">SERVICE</var>: the name of your Cloud Run service.
- `IMAGE_URL`: a reference to the container image, for example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry, the [repository](https://docs.cloud.google.com/artifact-registry/docs/repositories/create-repos.md.txt#docker) <var translate="no">REPO_NAME</var> must already be created. The URL follows the format of `LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG` .
- <var translate="no">SCOPE</var>: the [ambient networking scope](https://docs.cloud.google.com/run/docs/configuring/ambient-networking.md.txt#scopes), either `global` or `regional`.
- <var translate="no">REGION</var>: the region for your service.

### YAML

1. If you are creating a new service, skip this step.
   If you are updating an existing service, download its [YAML configuration](https://docs.cloud.google.com/run/docs/reference/yaml/v1.md.txt):

   ```bash
   gcloud run services describe SERVICE --format export > service.yaml
   ```
2. Add the `run.googleapis.com/ambient-networking` annotation and,
   optionally, the `run.googleapis.com/ambient-scope` annotation:

   ```yaml
   spec:
    template:
      metadata:
        annotations:
          run.googleapis.com/ambient-networking: 'true'
          run.googleapis.com/ambient-scope: SCOPE
   ```

   Replace <var translate="no">SCOPE</var> with the [ambient networking scope](https://docs.cloud.google.com/run/docs/configuring/ambient-networking.md.txt#scopes),
   either `global` or `regional`.
   To disable ambient networking, set `run.googleapis.com/ambient-networking`
   to `'false'` and remove the `run.googleapis.com/ambient-scope` annotation.
3. Create or update the service using the following command:

   ```bash
   gcloud run services replace service.yaml
   ```

   The `gcloud run services replace` command defaults to using `service.yaml` file if present.

## View ambient networking settings

To view the current ambient networking settings for your Cloud Run
service:

### Console

1. In the Google Cloud console, go to the Cloud Run **Services**
   page:

   [Go to Cloud Run](https://console.cloud.google.com/run/services)
2. Click the service to open the **Service details** page.

3. Click the **Networking** tab.

4. In the **Ambient networking** card, view the **Scope** setting.

### gcloud

1. Use the following command:

   ```bash
   gcloud beta run services describe SERVICE \
      --region=REGION \
      --format=yaml
   ```
2. Locate the `run.googleapis.com/ambient-networking` and
   `run.googleapis.com/ambient-scope` annotations in the returned
   configuration.

## What's next

- Learn about [Agent Gateway on Cloud Run](https://docs.cloud.google.com/run/docs/securing/agent-gateway-cloud-run.md.txt).
- Learn how to [configure Agent Platform features](https://docs.cloud.google.com/run/docs/ai/agent-platform-features.md.txt) for Cloud Run.
- Learn about [service-to-service authentication](https://docs.cloud.google.com/run/docs/authenticating/service-to-service.md.txt) in Cloud Run.
- Learn how to [trace requests](https://docs.cloud.google.com/run/docs/trace.md.txt) with Cloud Trace.
- Learn how to [configure express links](https://docs.cloud.google.com/run/docs/configuring/express-links) to connect and authenticate Cloud Run services with other Cloud Run services.