To set up private network access so that traffic runs within a Google Cloud network, you must configure the project that owns the VPC network, the Service Directory project, and the Google Cloud service project that you are using. These three projects could be the same or separate.
- Network project is the project of the VPC network.
- Service Directory project is the project of the Service Directory service. This project may be a service project in the Shared VPC network of the network project.
- Google Cloud service project is the project with the configuration that is invoking private network access. For example, a Google Cloud service configuration.
Permissions required for this task
To perform this task, you must have been granted the following permissions and IAM roles.
Before you begin
This procedure assumes that you have completed the following steps.
- Enable the APIs that you want to access through the APIs & services page in the Google Cloud Console, including the Service Directory API.
- VM instances in a VPC network must have a private IP address.
- For on-premises hosts, you must have an existing Cloud VPN tunnel or an Cloud Interconnect connection to your VPC network.
Configuring the network project
Follow these steps to configure the network project.
- Create or use an existing VPC network. Both auto and custom mode VPC networks are supported. Legacy networks are not supported.
If the destination target is a Compute Engine VM, or an internal load balancer backend, you must allow ingress through the VPC firewall for private network access. The targets must allow TCP ingress from
188.8.131.52/19on the appropriate port (port
Grant the Identity and Access Management (IAM) Service Directory network access to the Google Cloud service project. Note that the Google Cloud project must be in the VPC Service Controls perimeter of the Google Cloud service and Service Directory project for
To learn more about VPC Service Controls, see Overview of VPC Service Controls.
Configuring the Service Directory project
Follow these steps to configure the Service Directory project.
- Create a virtual machine (VM) or an internal load balancer in the VPC network.
- Create a Service Directory service pointing at the VM or internal load balancer that you created in the VPC network.
- Grant the IAM Service Directory network access to the Google Cloud service account. For more information about roles and permissions, see Service Directory permissions and roles.
Creating an endpoint with private network access
To create an endpoint with private network access configured, do the following.
- Go to the Service Directory namespaces page in the Google Cloud Console.
Go to the Service Directory namespaces page
- Click a namespace.
- Click a service.
- Click more_vert and click Add endpoint.
- Provide an Endpoint name.
- Enter an IPv4 IP address, such as
- Enter a Port number, such as
- To enable private network access, click Choose from the list to choose from a list of available networks under Associated VPC network.
- You can also provide a specific project ID and the network name by choosing Specify by a project and network name.
- Click Create.
gcloud beta service-directory endpoints create
command with the project ID and the network path specified.
gcloud beta service-directory endpoints create ENDPOINT_NAME --project=PROJECT_ID \ --location=REGION \ --namespace=NAMESPACE_NAME \ --service=SERVICE_ID \ --address=IP_ADDRESS \ --port=PORT_NUMBER \ --network=NETWORK_PATH
Replace the following:
ENDPOINT_NAME: a name for the endpoint that you're creating in your service, such as
PROJECT_ID: the ID of the project
REGION: the Google Cloud region containing the namespace
NAMESPACE_NAME: the name that you gave the namespace, such as
SERVICE_ID: the ID of the service
IP_ADDRESS: the IP address of the endpoint, such as
PORT_NUMBER: the ports that the endpoints are running on, typically
NETWORK_PATH: the URL to the network, such as
Configuring the Google Cloud service project
- Enable the Google Cloud service API.
- Configure your Google Cloud service using the Service Directory service that you created in the network project.
- If you are using VPC Service Controls, make sure that the VPC Service Controls perimeter allows Service Directory to access the network project and the Service Directory project.
This section provides example use cases to configure private network access.
Calling an HTTP endpoint when a VPC network, VM, and Service Directory are in the same project
You can set up a Google Cloud product to call an HTTP endpoint on your VM. This traffic must not transit over the public internet.
In this set up, you have a project with a VPC network, a VM, a Service Directory service, and the Google Cloud service in the same project.
To set up your Google Cloud product using private network access, follow these steps.
Set up your network and target network
- Create a project, such
- Create a VPC network,
- Grant proxy access to ingress to
VPC-1or to the subnet or VM.
- Allow ingress from
- Set it up to run the service on port
- If you prefer using HTTPS, make sure that you have installed a public key infrastructure (PKI) transport layer security (TLS) certificate.
- Create a Service Directory service
- Create an endpoint in
SD-1with internal IP address of
projects/project-number/global/networks/my-network. For detailed instructions, see Creating an endpoint with private network access configured.
Grant the Google Cloud service account the following IAM roles:
Optionally, you can set up
VM-2, and add
Set up a Google Cloud product
- Configure Google Cloud product configuration
CONFIG-1, such as, "Cloud Scheduler, call me every minute".
- Set up an HTTP request.
- Specify that request should go over private networking, such as through
- (Optional) Configure Certificate Authority Service settings.
Now, the Google Cloud product can invoke the HTTP request
Calling an HTTP endpoint when a VPC network, VM, and Service Directory are in different projects
In this example configuration, you want to set up a Google Cloud service, such as Events, Tasks, or Pub/Sub, to call an HTTP endpoint on your VM. In this example, the Service Directory project, the network project and the Google Cloud service projects are different. This traffic must not transit over the public internet. Optionally, this API invocation must respect the VPC Service Controls perimeter.
In this case, the Google Cloud service project's configuration enables egress to a Google Cloud service project VM, which resides in the network project's VPC network.
The Google Cloud service project might be different from the producer project. Both projects' VPC Service Controls perimeters are used.
Create a network project
Make sure that you have the following IAM permissions:
servicedirectory.services.resolvefor the messaging service
servicedirectory.networks.accessfor the network
Note the following:
- The Service Directory project and network project need not be connected, but they must be part of the same VPC Service Controls.
- The firewall and IAM are disabled by default on the network and the service.
To create the network project, follow these steps.
- Create a VPC network,
Enable the VPC network firewall.
If using VPC Service Controls, the VPC Service Controls perimeter allows Service Directory to connect to the Google Cloud service project and the Service Directory project.
Configure the Service Directory project
- Create a VM or internal load balancer in the VPC network.
- Create a Service Directory service that points at the VM or internal load balancer in the VPC network.
- Grant IAM Service Directory
service readaccess to the Google Cloud service project messaging service.
- If using VPC Service Controls, the VPC Service Controls perimeter allows Service Directory to connect to the Google Cloud service project and the Service Directory project.
Configure the Google Cloud service project
- Enable the API for the messaging service that you are using.
- Configure the messaging service
PUSHusing the Service Directory service from the Service Directory project.
- If using VPC Service Controls, the VPC Service Controls perimeter allows Service Directory to connect to the network project and the Service Directory project.
- Configure a Service Directory endpoint.
- To get an overview of Service Directory, see the Service Directory overview.
- To learn more about Private Service Connect, see Private Service Connect.
- To find solutions for common issues that you might encounter when using Service Directory, see Troubleshooting.