Configure private services access (original) (raw)

Private services access is a private connection between your VPC network and a network owned by Google or a third party. Google or the third party, entities who are offering services, are also known as service producers. The private connection enables VM instances in your VPC network and the services that you access to communicate exclusively by using internal IP addresses. VM instances don't need internet access or external IP addresses to reach services that are available through private services access.

To use private services access, you do the following:

For information about other private access options, see Private access options for services.

Before you begin

To establish a private connection, complete the following prerequisites:

Permissions

Project owners and IAM members with the Compute Network Admin role(roles/compute.networkAdmin) can create allocated IP address ranges and manage private connections.

For more information about Compute Engine roles, see Compute Engine IAM roles and permissions.

Choose an IP address range for the allocated range

Creating an allocated range reserves an IP address range for use by the service producer. Consider the following when you choose a range for your allocation:

Create an allocated range

The following steps describe how to create an allocated IP address range.

When a Google service allocates a range on your behalf, the service uses the following format to name the allocation:google-managed-services-CONSUMER_NETWORK_NAME. If this allocation exists, Google services use the existing one instead of creating another one. You can use the same naming convention that Google uses to signal to other users or Google services that an allocation for Google already exists.

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that will connect to a service producer.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Allocated IP ranges for services tab.
  5. Click Allocate IP range.
  6. Enter a Name and Description for the allocated range.
  7. Configure the IP address range for the allocation:
    • To specify a specific IP address range, select Custom and then enter a CIDR block, such as 192.168.0.0/16.
    • To let Google select an available range, select Automatic and then enter a prefix length, such as 16.
  8. Click Allocate to create the allocated range.

gcloud

To create an allocated range in your VPC network, use thegcloud compute addresses createcommand.

Replace the following:

Terraform

To create an allocated range in your VPC network, use thegoogle_compute_global_addressresource.

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

If you see an error about the compute.globalAddresses.list permission for the project, see Service account permissions.

List allocated IP address ranges

To list allocated IP address ranges, use thegcloud compute addresses list command.

gcloud compute addresses list --global --filter="purpose=VPC_PEERING"

Create a private connection

After you create an allocated range, you can create a private connection to a service producer. The private connection establishes aVPC Network Peering connection between your VPC network and the service producer's network.

Consider the following when you create a private connection:

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that will connect to a service producer.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Private connections to services tab.
  5. Click Create connection to create a private connection between your network and a service producer.
  6. For the Assigned allocation, select one or more existing allocated ranges that aren't being used by other service producers.
  7. Click Connect to create the connection.

gcloud

  1. Use thegcloud services vpc-peerings connect command.
    gcloud services vpc-peerings connect \
    --service=servicenetworking.googleapis.com \
    --ranges=RESERVED_RANGE_NAME \
    --network=VPC_NETWORK
    Replace the following:
    • RESERVED_RANGE_NAME: the name of one or more allocated ranges.
    • VPC_NETWORK: the name of your VPC network.
      The command initiates a long-running operation, returning an operation name.
  2. To check whether the operation was successful, use thegcloud services vpc-peerings operations describe command.
    gcloud services vpc-peerings operations describe \
    --name=OPERATION_NAME
    Replace OPERATION_NAME with the operation name that was returned from the previous step.

You can specify more than one allocated range when you create a private connection. For example, if a range has been exhausted, you can assign additional allocated ranges. The service uses IP addresses from all of the provided ranges in the order that you specified.

Terraform

To create a private connection, use thegoogle_service_networking_connection resource.

List private connections

After you create a private connection, you can list it to check that it exists. The list also shows the list of allocated ranges that are associated with each connection. For example, if you don't remember which allocated range you assigned to a connection, view the list to find out.

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that contains the connections.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Private connections to services tab to view all the network's private connections.

gcloud

Use thegcloud services vpc-peerings list command.

gcloud services vpc-peerings list
--network=VPC_NETWORK

Replace VPC_NETWORK with the name of your VPC network.

Modify a private connection

You can't modify an allocated range, but you can update a private connection to add or remove allocated ranges without disrupting traffic.

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that contains the connections.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Private connections to services tab to view all the network's private connections.
  5. Click a connection name in the list.
  6. In the Assigned allocation list, select the allocated ranges that you want to associate with the private connection. Clear the checkboxes for any allocated ranges that you want to remove from the private connection.
  7. Click OK.

gcloud

To add or remove assigned allocated IP address ranges on an existing private connection, use the gcloud services vpc-peerings update command.

gcloud services vpc-peerings update
--service=servicenetworking.googleapis.com
--ranges=RESERVED_RANGE_NAME
--network=VPC_NETWORK
[--force]

Replace the following:

Delete an allocated IP address range

Before you delete an allocated IP address range, checkif the range is in use by a private connection.

If the allocated IP address range is in use, firstmodify the private connection to remove the range. Then delete the allocated IP address range.

If you delete an allocated IP address that is in use, and you don't modify the private connection, the following applies:

To avoid these problems, always modify your private connections when you delete an in-use allocated IP address range.

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that contains the allocations to delete.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Allocated IP ranges for services tab.
  5. Select the allocation to delete.
  6. Click Release to return the allocated IP address range to network's pool of available internal IP addresses.
    If the allocated IP address range is still assigned to an existing connection, you must enter additional confirmation before you can release the allocation.
  7. Click Release again to confirm the deletion.

gcloud

Delete the allocation by specifying the name of your allocation.

gcloud compute addresses delete NAME
--global

ReplaceNAME with the name of the allocated range that you want to delete.

Delete a private connection

To delete a private connection, complete the procedure in this section. Don't attempt to delete a private connection by deleting its associated VPC Network Peering connection directly.

Before you delete a private connection, you must delete all the service instances that you access through the connection.

Console

  1. In the Google Cloud console, go to the VPC networks page.
    Go to VPC networks
  2. Select the VPC network that contains the connections to delete.
  3. Select the Private services access tab.
  4. On the Private services access tab, select the Private connection to services tab.
  5. Select the private connection to delete.
  6. Click Delete to delete.
  7. Click Delete again to confirm the deletion.

gcloud

To delete a private connection's VPC Network Peering connection, use thegcloud services vpc-peerings delete command.

gcloud services vpc-peerings delete
--service=servicenetworking.googleapis.com
--network=VPC_NETWORK

Replace VPC_NETWORK with the name of your VPC network.

Share private DNS zones with service producers

Cloud DNS private zones are private to your VPC network. If you want to let a service producer network resolve names from your private zone, you can configure DNS peering between the two networks.

When you configure DNS peering, you provide a VPC network and a DNS suffix. If the service producer needs to resolve an address with that DNS suffix, the service producer forwards those queries to your VPC network to be resolved.

These supported servicessupport DNS peering, with the exception of Cloud SQL.

If you want to enable DNS peering, you mustenable theCloud DNS API in your project.

Peer DNS with a service producer

gcloud

To set up DNS peering between your VPC network and the service provider network, use thegcloud services peered-dns-domains create command.

gcloud services peered-dns-domains create PEERING_NAME
--network=VPC_NETWORK
--dns-suffix=DNS_SUFFIX

Replace the following:

Terraform

To set up DNS peering between your VPC network and the service provider network, use thegoogle_service_networking_peered_dns_domain resource.

List DNS peering configurations

Delete a DNS peering configuration

gcloud

Use thegcloud services peered-dns-domains delete command.

gcloud services peered-dns-domains delete PEERING_NAME
--network=VPC_NETWORK

Replace the following:

Configure hybrid connectivity

By default, the service producer's network only learns the subnet routes from your VPC network. Therefore, any request that's not from a subnet IP range is dropped by the service producer.

To configure connectivity between your on-premises hosts and the service producer's network, do the following:

Troubleshooting

The following sections contain troubleshooting information for private services access.

How much of my allocation is being used?

When you create a private connection with a service producer, you allocate an IP address range for them to use. If you use multiple services from a service producer, each service reserves a chunk of IP addresses from that allocated range. You can check which services are using which IP addresses so that, for example, you can see which services are using large blocks of IP addresses and avoid IP address exhaustion.

To view the allocation ratio for your allocated ranges, use Network Analyzer. For more information, seePrivate services access IP address utilization summary.

Alternatively, to view which service is using a particular IP address range:

  1. List your private connections.
  2. Find the peering connection name that connects you to the relevant service producer.
  3. List the routes for your VPC network.
  4. Find the routes with a next hop that match the peering connection name. The destination range of the routes indicates which IP addresses each service is using.

IP address range exhaustion

For a given private connection, if you exhaust your allocated IP address space, Google Cloud returns this error: Failed to create subnetwork. Couldn't find free blocks in allocated IP ranges.

You might see this error because the allocated range isn't sufficient for your usage, or because a custom static or dynamic route is preventing the allocated range from being fully used. For more information about routing considerations, see Choose an IP address range for the allocated range.

You can expand the existing allocation or add new ones. The expanded allocation must be a contiguous IP address range that includes the existing range. We recommend expanding an allocation because there's no limit on the size of an allocation, but there is a limit on the number of allocations that you can create per project and per connection. For more information, seeStatic global internal IPv4 addressesandAllocated IP address ranges per private connection.

To expand an existing allocation:

  1. List your private connections and record the name of the allocated range you need to expand.
  2. Delete the existing allocated range that you want to expand.
  3. Create a new allocated range by using the same name as the deleted range. Specify an IP address range that includes the deleted IP address range. That way, existing peered resources that are using the old allocated range can continue to use the same IP addresses without colliding with resources in your VPC network. For example, if the previous allocated range was 192.168.0.0/20, create a new allocated range

To add allocated ranges to an existing private connection:

  1. Create a new allocated range. This range doesn't have to be contiguous with existing allocated ranges.
  2. Add the allocated range to the existing private connection.

Service account permissions

If you see an error about the compute.globalAddresses.list permission for a project when creating an allocated range, or if you experience errors such asError 400: Precondition check failed while creating, listing, or modifying private connections, it might be a problem with Identity and Access Management (IAM) roles for your Service Networking API service account. This service account is created automatically after you enable the Service Networking API. It can take time for the account to be provisioned and display on theIAM page.

Console

To ensure that the service account has the correct IAM role, do the following:

  1. In the Google Cloud console, go to the IAM page.
    Go to IAM
  2. Select the Include Google-provided role grants checkbox.
  3. In the Name column, find the Service Networking Service Agentprincipal, and then click Edit principalin the corresponding row.
  4. In the Role field, ensure that the Service Networking Service Agent role (roles/servicenetworking.serviceAgent) is present.
  5. If the Service Networking Service Agent role is not present, click either Add role orAdd another role.
  6. Click Select a role.
  7. In the Filter text box, enter Service Networking Service Agent.
  8. Select Service Networking Service Agent from the list, and then clickSave.

gcloud

To create a Service Networking API service account, use thegcloud projects add-iam-policy-binding command.

gcloud projects add-iam-policy-binding HOST_PROJECT_NAME
--member=serviceAccount:service-HOST_PROJECT_NUMBER@service-networking.iam.gserviceaccount.com
--role=roles/servicenetworking.serviceAgent

Replace the following:

Peering subnet route persists after updating allocated range

After you update the allocated IP address range of a private services connection, the old peering subnet route might still appear in the routing table of your VPC network. The route persists because the IP address range is still in use.

To resolve this issue, do the following:

The peering subnet route is removed automatically after the IP address range is no longer in use. There might be a delay between deleting the resource, and the service producer fully deleting the resource. For example, if the old IP address range is being used by a Cloud SQL instance, it can take up to four days for the service producer to fully delete your instance. The peering subnet route is removed after the deletion is complete.

Unable to create a new private connection

If you attempt to create a new private connection after deleting the VPC Network Peering connection associated with a previous private connection, Google Cloud might return an error. For troubleshooting information, see the following error messages.

To prevent this issue from happening, follow the procedure to delete a private connection instead of deleting the associated VPC Network Peering connection directly.