Private networking and Cloud Run (original) (raw)

This page discusses configuration options for including Cloud Run resources in your private network.

To get the most out of this content, you should have some familiarity with the following concepts:

To secure network traffic for their services and applications, many organizations use a private network on Google Cloud with perimeter controls to prevent data exfiltration. Your private network might have the following properties:

Unlike VMs, Cloud Run resources are not associated with any particular VPC network by default. This page explains how to incorporate Cloud Run resources into your private network.

Serverless networking narrative

To explore a range of common enterprise configurations for public and private networking, read our Serverless networking narrative.

This starting point introduces the following basic-to-advanced Cloud Run scenarios:

See the list of corresponding Terraform modules.

Receive requests from your private network

Receiving requests from your private network requires configuration based on the following conditions:

For example,receiving requests from VPC networksmight require different configuration thanreceiving requests from on-premises resources and other clouds.

Receive requests from other Cloud Run resources or App Engine

When your destination Cloud Run resource receives traffic from other Cloud Run resources or App Engine, and it uses the "internal" or "internal and load balancing" ingress setting, the traffic must use the VPC network to be considered internal.

To receive requests from other Cloud Run resources or App Engine, perform the following steps:

  1. Configure the source resource to use either Direct VPC egress or a connector.
  2. Make sure traffic to Cloud Run routes through the VPC network by using one of the following options:
    • Configure the source resource to route all traffic through the VPC network and enable Private Google Accesson the subnet associated with Direct VPC egress or the connector.
    • Set up Private Service Connector an internal Application Load Balancer to front your destination Cloud Run resource. With this configuration, you access Cloud Run by using internal IP addresses, so requests are routed through the VPC network.
    • Enable Private Google Access on the subnet associated with the _source_resource and configure DNSto resolve run.app URLs to the private.googleapis.com (199.36.153.8/30) or restricted.googleapis.com (199.36.153.4/30) ranges. Requests to these ranges are routed through the VPC network.

Receive requests from VPC networks

By default, only resources that have external IP addresses or useCloud NAT can directly access the internet and Google Cloud services such as Pub/Sub and Cloud Run. For other resources, there are a few options to enable the traffic path to Cloud Run:

Responses are returned by using the same path that the request went through.

Special considerations for Shared VPC

When using the internal setting with Cloud Run ingress controlsto enforce that all traffic must come from your private network, Shared VPC traffic is only recognized as "internal" in the following situations:

Special considerations for other VPC networks outside your project

When using the internal setting with Cloud Run ingress controlsto enforce that all traffic must come from your private network, traffic from other VPC networks outside your project is not recognized as "internal" except in the following situations:

Peering with a VPC network that is outside of your project doesn't allow traffic to be recognized as "internal."

Receive requests from other Google Cloud services

Requests to Cloud Run from Google Cloud services such as Pub/Sub stay within Google's network.

There are a few special considerations if you have configured Cloud Run ingress controls to only allow "internal" traffic:

Receive requests from on-premises resources or other clouds

There are multiple ways to privately receive requests from on-premises resources and other clouds.

Require requests to come from your private network

To prevent incoming traffic (ingress) from external sources, you specify a restrictive ingress setting. The most restrictive ingress setting is internal. With ingress set tointernal, your service only allows requests from your project, Shared VPC networks your project is attached to, and your VPC Service Controls perimeter. There are some limitations with this setting depending on where the requests come from. To learn about these limitations and how to navigate them, see the section Receive requests from your private network.

You can specify the ingress setting for each Cloud Run resource, or enforce the use of your preferred ingress setting for all Cloud Run resources in your organization.

Send requests to your private network

If your Cloud Run resource needs to access a resource on your private network, you configure a path for private requests to your network. The configuration depends on the final destination of the request.

Send requests to your VPC network

To send requests to a VPC network, you must configure Direct VPC egress or a Serverless VPC Access connector.Compare Direct VPC egress and VPC connectors. Review pricing to understand costs.

When Direct VPC egress or connectors are configured, the following considerations apply by default:

With requests routed using Direct VPC egress or connectors, responses return using the path that the request went through. Requests from your VPC network to Cloud Run are enabled by using other technologies and are not routed through Direct VPC egress or connectors, and responses to those requests are returned using the same path. To learn more about sending requests from your VPC network to Cloud Run, see Receive requests from VPC networks.

Sending requests to a VPC network outside of your project

To send requests to a VPC network outside of your project:

  1. For Shared VPC users, see Connect to a Shared VPC network.
  2. For other VPC networks, configure Direct VPC egress or a connector to connect to a VPC in your project.
    • Peered VPC networks: To send to a VPC that is peered to a VPC that uses VPC network egress, no additional configuration is required. However, the VMs in the subnet hosting VPC network egress must be able to reach the target VPC network.
    • Other VPC networks: For VPC networks outside of your project that are not part of the same Shared VPC environment or peered to your project VPC network, configurePrivate Service Connectafter setting up VPC network egress.

Send requests to other Cloud Run resources and Google Cloud services

Requests from one Cloud Run resource to another or to other Google Cloud services stay within Google's internal network and are subject to VPC Service Controls.

For requests to Cloud Run resources with restrictive ingress settings, additional configuration is required. SeeReceive requests from other Cloud Run resources or App Engine.

Send requests to on-premises resources and other clouds

To send requests to on-premises resources and other clouds through your private network, you must do the following:

  1. Make sure your VPC network is configured to privately route your traffic to the destination, such as through a VPN tunnel.
  2. Configure your service tosend requests to your VPC network.
  3. Require that all requests go to your VPC network.

Require that all requests go to your VPC network

To require that all requests from your Cloud Run resource go to your VPC network, specify the all-trafficVPC network egress setting. You can specify the egress setting for each Cloud Run resource that uses VPC network egress, or you can enforce the use of your preferred egress setting for all Cloud Run resources in your project, folder, or organization.

This is useful in the following situations:

  1. You want to set up astatic outbound IP addressfor your Cloud Run resource.
  2. You want to apply firewall rules for all egress from a Cloud Run resource.
  3. You want to send requests to on-premises resources and other clouds through your private network.

If your Cloud Run resource makes requests to final destinations outside of your VPC network, requiring that all requests go to your VPC network increases bandwidth use on configured Serverless VPC Access connectors and might increase costs accordingly. Connectors automatically scale out when traffic increases, but don't scale in if traffic decreases. Reviewpricing to understand costs.

Additional controls

What's next

To learn more about delivering low latency and high throughput using a direct network path, see Direct VPC egress with a VPC network.