Access Google APIs through endpoints
This document explains how to use Private Service Connectendpoints to connect to Google APIs. Instead of sending API requests to thepublicly available IP addresses for service endpoints such asstorage.googleapis.com, you can send the requests to the internal IP addressof an endpoint.
You can also use Private Service Connect toaccess services inanother VPC networkand topublish services.
Roles
The followingIAM roles providethe permissions needed to perform the tasks in this guide.
| Task | Roles |
|---|---|
| Create an endpoint | All of the following roles: Compute Network Admin ( roles/compute.networkAdmin),Service Directory Editor ( roles/servicedirectory.editor), andDNS Administrator ( roles/dns.admin) |
| Configure Private Google Access (optional) | Compute Network Admin (roles/compute.networkAdmin) |
Before you begin
ReadAbout connecting to Google APIs by usingendpointsfor more information, including DNS configuration andlimitations.
Private Service Connect does not automatically enable any API.You must separatelyenable the Google APIs youneed to use from theAPIs & services page inthe Google Cloud console.
You mustenabletheCompute Engine API in your project.
You mustenabletheService DirectoryAPI in your project.
You mustenable theCloud DNS API in your project.
You must choose an IP address to use for the endpoint. For information aboutwhat IP addresses you can use, seeIP address requirements.
Egress firewall rules must permit traffic to theendpoint. The default firewallconfiguration for a VPC network permits this traffic, because itcontains an implied allow egress rule. Verify that you have not created a higherpriority egress rule that blocks the traffic.
Virtual machine (VM) instances without an external IP address assigned mustuse a subnet withPrivate Google Accessenabled to access Google APIs and services usingan endpoint.
A VM with an external IP address can access Google APIs and services usingendpoints even ifPrivate Google Access is disabled for its subnet. Connectivity to theendpoint stays within Google's network.
If your VPC network does not contain anyendpoints, check if a Cloud DNSprivate zone exists for
p.googleapis.com. If the zone exists, delete it beforeyou create the endpoint. If you don'tdelete it, creation of the Service Directory DNS zone used forPrivate Service Connect fails. For more information,seetroubleshooting.Endpoints are not accessible frompeered VPC networks.
Enable Private Google Access for a subnet
VMs without an external IP address assigned must be connected to a subnet withPrivate Google Access enabled to access Google APIs and services usingan endpoint.
If the VM has more than one interface, connect the interface that is configuredwith a default route (usuallynic0).
The source IP address of packets sent from the VM must match the VM interface'sprimary internal IPv4 address or an internal IPv4 address from an alias IP range.
To enable Private Google Access on a subnet, follow these steps.
Console
In the Google Cloud console, go to theVPC networks page.
Click the name of the network that contains the subnet for which you needto enable Private Google Access.
Click the name of the subnet. TheSubnet details page is displayed.
ClickEdit.
In thePrivate Google Access section, selectOn.
ClickSave.
gcloud
Determine the name and region of the subnet. To list the subnets for aparticular network, use the following command:
gcloud compute networks subnets list --filter=NETWORK_NAME
Run the following command to enable Private Google Access:
gcloud compute networks subnets updateSUBNET_NAME \--region=REGION \--enable-private-ip-google-access
Verify that Private Google Access is enabled by running thiscommand:
gcloud compute networks subnets describeSUBNET_NAME \--region=REGION \--format="get(privateIpGoogleAccess)"
Replace the following:
SUBNET_NAME: the name of the subnetREGION: the region for the subnetNETWORK_NAME: the name of the VPCnetwork that contains the subnet
Terraform
You can use theTerraformresourceto enable Private Google Access on a subnet.
resource "google_compute_network" "network" { project = var.project # Replace this with your project ID in quotes name = "tf-test" auto_create_subnetworks = false}resource "google_compute_subnetwork" "vpc_subnetwork" { project = google_compute_network.network.project name = "test-subnetwork" ip_cidr_range = "10.2.0.0/16" region = "us-central1" network = google_compute_network.network.id private_ip_google_access = true}To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
Create an endpoint
After you have chosen an IP address thatmeets the requirements,you can create an endpoint.
An endpoint connects to Google APIs andservices using a global forwarding rule. Each forwarding rule counts toward theper VPC network quota forPrivate Service Connect.
You can't update an endpoint for Google APIs and services after it is created.If you need to update an endpoint for Google APIs and services, delete theendpoint, and then create a new one.
Permissions required for this task
To perform this task, you must have been granted the following permissionsor one of the following IAM roles.
Permissions for the gcloud CLI and the API
compute.globalForwardingRules.pscCreatecompute.globalForwardingRules.createcompute.networks.usecompute.globalAddresses.useservicedirectory.namespaces.createservicedirectory.namespaces.associatePrivateZonedns.managedZones.create
Permissions for the Google Cloud console
compute.forwardingRules.listcompute.globalForwardingRules.listcompute.networks.listcompute.backendBuckets.listcompute.backendServices.listcompute.instanceGroupManagers.listcompute.targetPools.listcompute.targetSslProxies.listcompute.targetTcpProxies.listcompute.urlMaps.list
Roles
SeeRoles for role information.
Console
In the Google Cloud console, go to thePrivate Service Connect page.
Click theConnected endpoints tab.
ClickConnect endpoint.
ForTarget, select thetarget API bundlethat you want to use:
- All Google APIs
- VPC-SC
ForEndpoint name, enter a name for the endpoint.
Select aNetwork for the endpoint.
Select anIP Address for the endpoint.
The IP address mustmeet these requirements.
If you need a new IP address, you can create one:
- ClickCreate IP address.
- Enter aName andDescription for the IP address.
- Enter theIP address you want to use and clickSave .
If aService Directory region is not already configured for thisVPC network, select the region you want to use.
All endpoints that are used to access Google APIs and services in a givenVPC network use the sameService Directoryregion.
If aService Directory namespace is not already configured for thisVPC network, configure the namespace you want to use:
To use an automatically assigned namespace, click theNamespacedrop-down menu and select the automatically assigned namespace.
To select an existing namespace that is used in another network, clicktheNamespace drop-down menu and select a namespace from the list. Thelist displays all namespaces in the project. You must select a namespacethat is used only for endpoints thatare used to access Google APIs.
To create a new namespace, click theNamespace drop-down menu andclickCreate namespace. Enter the namespace and clickCreate.
All endpoints that you use to access Google APIs and services in a givenVPC network use the sameService Directorynamespace.
ClickAdd endpoint.
gcloud
Reserve a global internal IP address to assign to the endpoint.
gcloud compute addresses createADDRESS_NAME \ --global \ --purpose=PRIVATE_SERVICE_CONNECT \ --addresses=ENDPOINT_IP \ --network=NETWORK_NAME
Replace the following:
ADDRESS_NAME: the name to assign to thereserved IP address.ENDPOINT_IP: the IP address to reserve for theendpoint.The IP address mustmeet these requirements.
NETWORK_NAME: the name of the VPCnetwork for the endpoint.
Create a forwarding rule to connect the endpoint to Google APIs andservices.
gcloud compute forwarding-rules createENDPOINT_NAME \ --global \ --network=NETWORK_NAME \ --address=ADDRESS_NAME \ --target-google-apis-bundle=API_BUNDLE \ [ --service-directory-registration=REGION_NAMESPACE_URI ]
Replace the following:
ENDPOINT_NAME: the name to assign to the endpoint.The name must be a string of 1-20 characters,containing only lower-case letters and numbers. The name must start witha letter.NETWORK_NAME: the name of the VPCnetwork for the endpoint.ADDRESS_NAME: the name of the reserved address onthe associated network.API_BUNDLE: the bundle of APIs to makeavailable using the endpoint. See thelist of supportedAPIs.Use
all-apisto give access to all supported APIs.Use
vpc-scto restrict access to Google APIs that supportVPC Service Controls.
REGION_NAMESPACE_URI: the URI of theService Directory region or namespacethat you want to use. This URI must reference the same project that youare creating the endpoint in.You can define a region only with
projects/PROJECT_NAME/locations/REGION.You can define a region and namespace with
projects/PROJECT_NAME/locations/REGION/namespaces/NAMESPACE.
If you you omit
--service-directory-registrationcompletely, or seta region without a namespace, the following occurs:If a region or namespace is already configured for thisVPC network, those defaults are used.
If a region is not configured, the region is set to
us-central1.If a namespace is not configured, a system-generated namespace isassigned.
API
Reserve a global internal IP address to assign to the endpoint.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses{"name":ADDRESS_NAME,"address":ENDPOINT_IP,"addressType": "INTERNAL","purpose": PRIVATE_SERVICE_CONNECT,"network":NETWORK_URL}Replace the following:
PROJECT_ID: your project ID.ADDRESS_NAME: the name to assign to thereserved IP address.ENDPOINT_IP: the IP address to reserve for theendpoint.The IP address mustmeet these requirements.
NETWORK_URL: the VPC network for theendpoint. Use thenetwork.listmethod orgcloudcompute networks list --urito find the URLs of your networks.
Create a forwarding rule to connect the endpoint to Google APIs andservices.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules{ "IPAddress":ADDRESS_URL, "network":NETWORK_URL, "name":ENDPOINT_NAME, "target":API_BUNDLE, "serviceDirectoryRegistrations : [ { "service_directory_region":REGION, "namespace": "NAMESPACE" } ],}Replace the following:
PROJECT_ID: your project ID.ENDPOINT_NAME: the name to assign to the endpoint.The name must be a string of 1-20 characters, containing only lower-caseletters and numbers. The name must start with a letter.NETWORK_URL: the VPC network for theendpoint. Use thenetwork.listmethod orgcloudcompute networks list --urito find the URLs of your networks.ADDRESS_URL: the URL of the reserved address on theassociated network. Use theglobalAddresses.listmethod orgcloudcompute addresses list --urito find the URLs of your reservedaddresses.API_BUNDLE: the bundle of APIs to make availableusing the endpoint. See thelist of supported APIs.Use
all-apisto give access to all supported APIs.Use
vpc-scto restrict access to Google APIs that supportVPC Service Controls.
REGION: theService Directoryregion you want to use. For example,us-central1.If you omitREGION, and a region is already configuredfor this VPC network, that region is used. If a region isnot configured, the region is set tous-central1.NAMESPACE: the name of theService Directory namespacethat you want to use. If you omitNAMESPACE, and anamespace is already configured for this VPC network, thatnamespace is used. If a namespace is not configured, a system-generatednamespace is assigned.
Terraform
You can use the following Terraformresources to create an endpoint:
resource "google_compute_global_address" "default" { project = google_compute_network.network.project name = "global-psconnect-ip" address_type = "INTERNAL" purpose = "PRIVATE_SERVICE_CONNECT" network = google_compute_network.network.id address = "10.3.0.5"}resource "google_compute_global_forwarding_rule" "default" { project = google_compute_network.network.project name = "globalrule" target = "all-apis" network = google_compute_network.network.id ip_address = google_compute_global_address.default.id load_balancing_scheme = ""}Verify that the endpoint is working
Create a VM instance in the VPC network wherePrivate Service Connect is configured. Run the followingcommand on the VM to verify that the Private Service Connectendpoint is working. Endpointsdon't respond to ping (ICMP) requests.
curl -vENDPOINT_IP/generate_204
ReplaceENDPOINT_IP with the IP address of theendpoint.
If the endpoint is working, you see an HTTP204 response code.
List endpoints
You can list all configured endpoints.
Permissions required for this task
To perform this task, you must have been granted the following permissionsor one of the following IAM roles.
Permissions for the gcloud CLI and the API
compute.globalForwardingRules.list
Permissions for the Google Cloud console
compute.forwardingRules.listcompute.globalForwardingRules.listcompute.networks.listcompute.backendBuckets.listcompute.backendServices.listcompute.instanceGroupManagers.listcompute.targetPools.listcompute.targetSslProxies.listcompute.targetTcpProxies.listcompute.urlMaps.list
Roles
SeeRoles for role information.
Console
In the Google Cloud console, go to thePrivate Service Connect page.
Click theConnected endpoints tab.
The endpoints are displayed.
gcloud
gcloud compute forwarding-rules list \--filter --global
The output is similar to the following:
NAME REGION IP_ADDRESS IP_PROTOCOL TARGETRULEIP TCP all-apis
Get information about an endpoint
You can view all the configuration details of anendpoint.
Permissions required for this task
To perform this task, you must have been granted the following permissionsor one of the following IAM roles.
Permissions for the gcloud CLI and the API
compute.globalForwardingRules.get
Permissions for the Google Cloud console
compute.forwardingRules.listcompute.globalForwardingRules.listcompute.networks.listcompute.backendBuckets.listcompute.backendServices.listcompute.instanceGroupManagers.listcompute.targetPools.listcompute.targetSslProxies.listcompute.targetTcpProxies.listcompute.urlMaps.list
Roles
SeeRoles for role information.
Console
In the Google Cloud console, go to thePrivate Service Connect page.
Click theConnected endpoints tab.
The endpoints aredisplayed.
Click the endpoint that youwant to view details for.
gcloud
gcloud compute forwarding-rules describe \ENDPOINT_NAME --global
Label an endpoint
You can manage labels for endpoints. Seelabeling resources for more information.
Permissions required for this task
To perform this task, you must have been granted the following permissionsor one of the following IAM roles.
Permissions
compute.globalForwardingRules.pscSetLabelscompute.globalForwardingRules.setLabels
Roles
SeeRoles for role information.
Delete an endpoint
You can delete an endpoint.
Permissions required for this task
To perform this task, you must have been granted the following permissionsor one of the following IAM roles.
Permissions for the gcloud CLI and the API
compute.globalForwardingRules.pscDeletecompute.globalForwardingRules.deleteservicedirectory.namespaces.deletedns.managedZones.delete
Permissions for the Google Cloud console
compute.forwardingRules.listcompute.globalForwardingRules.listcompute.networks.listcompute.backendBuckets.listcompute.backendServices.listcompute.instanceGroupManagers.listcompute.targetPools.listcompute.targetSslProxies.listcompute.targetTcpProxies.listcompute.urlMaps.list
Roles
SeeRoles for role information.
Console
In the Google Cloud console, go to thePrivate Service Connect page.
Click theConnected endpoints tab.
Select the endpoint that you want todelete, and clickDelete.
gcloud
gcloud compute forwarding-rules delete \ENDPOINT_NAME --global
ReplaceENDPOINT_NAME with the name of the endpoint that you wantto delete.
Use an endpoint
To use an endpoint, you send requests to aDNS hostname that resolves to the IP address of the endpoint.
You can use the automatically created
p.googleapis.comDNS names if youcan configure your clients to use a custom endpoint and ifp.googleapis.comDNS records are created for the APIs and services that you want to use. For moreinformation, seeUsep.googleapis.comDNS names.For example, if your endpoint name is
xyz, DNS records are created forstorage-xyz.p.googleapis.com,compute-xyz.p.googleapis.com, and othercommonly used APIs in the API bundle.You can create DNS records by using the default DNS names if you are using aclient that hasn't been configured to use a custom endpoint, or if a
p.googleapis.comDNS record does not exist for the service that you want touse. For more information, seeCreate DNS records by using default DNS names.For example, create DNS records for
storage.googleapis.com,compute.googleapis.com, or*.gke.goog.
storage.googleapis.com) or the service'sSERVICE-ENDPOINT.p.googleapis.com DNS name,if available. ForSERVICE-ENDPOINT.p.googleapis.com names, theSERVICEpart of the name must match the service, though any value forENDPOINT can be used.Usep.googleapis.com DNS names
When you create an endpoint,Service Directory creates DNS records for commonly used APIs andservices that are available using the endpoint. DNS records are created only forAPIs and services that have default DNS names that end withgoogleapis.com,and only for a subset of those APIs and services.
The DNS records are created in ap.googleapis.com private zone. The recordspoint to the endpoint IP address, and use this format:SERVICE-ENDPOINT.p.googleapis.com
For example, if your endpoint name isxyz, DNS records are created forstorage-xyz.p.googleapis.com,compute-xyz.p.googleapis.com, and other supported APIs.
Clients that can be configured to use a custom endpoint can use thep.googleapis.com DNS names to send requests to anendpoint.
See the documentation for your client or client library for information aboutconfiguring it to use custom endpoints. For example:
Python: you can configure
api_endpointinClientoptions.Go: you can configure
WithEndpointinClientOptions..NET: you can configure
Endpointinthe client's builder class.gcloud: you can configure
api_endpoint_overridesin thegcloud CLI.
Create DNS records by using default DNS names
You need to create DNS records to direct the default DNS names for APIs andservices to your endpoint in thesecircumstances:
Your client or application cannot be configured to use a
p.googleapis.comDNS name.You need to access a supported service, but there is no automatically created
p.googleapis.comDNS name for that service.
To create DNS records that point to your Private Service Connectendpoint, follow these instructions:
Create a DNS zone for the domain you need to use (for example,
googleapis.comorgcr.io). Considercreating a Cloud DNS privatezone for this purpose.In this DNS zone:
Create an
Arecord for the domain (zone) name itself; for example,googleapis.comorgcr.io. Point thisArecord to the IP address of theendpoint. If you're usingCloud DNS, seeadding a record.Create a
CNAMErecord for all of the additional domain's possible hostnames by using an asterisk and a dot followed by the domain (zone) name; forexample,*.googleapis.comor*.gcr.io. Point thisCNAMErecord to theArecord in the same zone. For example, point*.googleapis.comtogoogleapis.comor point*.gcr.iotogcr.io.
Access the endpoint from on-premises hosts
If your on-premises network is connected to a VPC network, youcan use Private Service Connect to access Google APIs andservices from on-premises hosts by using the internal IP address of theendpoint.
Your on-premises network must be connected to a VPC networkusing either Cloud VPN tunnels or VLAN attachments forCloud Interconnect.
The endpoint must be in the VPC network that is connected to youron-premises network.
The on-premises network must have appropriate routes for the endpoint.Configure aCloud Router custom routeadvertisementto announce routes for the endpoint on the BGP session that manages routesfor the Cloud VPN tunnel or VLAN attachment.
- If your on-premises network uses equal-cost multi-path (ECMP) routing todistribute traffic to Private Service Connect endpoints,you must ensure that all packets for a single TCP connection are routedthrough the same Cloud VPN tunnel or VLAN attachment. Ifpackets for an established TCP connection are routed over multiplepaths, you might experience intermittent TCP resets (RSTs).To help prevent resets, configure your on-premises peer routers tomaintain consistent next hop destinations.
You must configure on-premises systems so that they can make queries to yourprivate DNS zones.
If you've implemented the private DNS zones using Cloud DNS,complete the following steps:
Create aninbound server policy in theVPC network to which your on-premises network connects.
Identify theinbound forwarder entrypoints, in the regions whereyour Cloud VPN tunnels and VLAN attachments are located, in theVPC network to which your on-premises network connects.
Configure on-premises systems and on-premises DNS name servers toforward theDNS names for the Private Service Connectendpoints to an inbound forwarder entry point in thesame region as the Cloud VPN tunnel or VLAN attachment thatconnects to the VPC network.
Troubleshooting
The following sections contain information about resolving issues withPrivate Service Connect endpoints that are used to access GoogleAPIs.
Private DNS zone creation fails
When you create an endpoint, aService Directory DNS zone is created. Zone creation can failfor these reasons:
You haven't enabled the Cloud DNS API in your project.
You don't have the required permissions to create aService Directory DNS zone.
A DNS zone with the same zone name exists in this VPC network.
A DNS zone for
p.googleapis.comalready exists in this VPCnetwork.
Conflicting zones might exist because a previousdeletionfailed.
To create the Service Directory DNS zone, do the following:
Verify that the Cloud DNS API isenabled in your project.
Verify that you have the required permissions to create theService Directory DNS zone:
dns.managedZones.createservicedirectory.namespaces.associatePrivateZone
Create a Service Directory DNSzonebacked by the Service Directory namespace associated with yourendpoint.
Use the following values when you create the zone:
Zone name: Use the same zone name that the system used during the failedcreation attempt. The error message displays what zone name was used.
DNS name:
p.googleapis.com.(include the trailing dot).Service Directory namespace:Find the Service Directorynamespace for the Private Service Connectendpoint you created, and use this namespace when you create theService Directory DNS zone.
The Service Directory namespace has the following format:
goog-psc-NETWORK_NAME-NETWORK_ID.
Private DNS zone deletion fails
When you delete the last endpoint in aVPC network, the associated Service Directoryconfiguration including the DNS zone is deleted.
This deletion can fail for these reasons:
You don't have the required permissions to delete the DNS zone.
The zone contains user-defined DNS entries that were not created byService Directory.
To resolve this issue, do the following:
Verify that you have the
dns.managedZones.deletepermission. For moreinformation, seeAccess Control in theCloud DNS documentation.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.