This page provides information about using private IP with Cloud SQL. For step-by-step instructions for configuring a Cloud SQL instance to use private IP, see Configuring private IP.
When you configure a Cloud SQL instance to use private IP, you use private services access. Private services access is implemented as a VPC peering connection between your VPC network and the underlying Google services VPC network where your Cloud SQL instance resides. Even though multiple ip ranges can be allocated, the IP range used for the private IP will always be done by Google. IP traffic using private services access is never exposed to the public Internet. Therefore, attack vectors are limited. Also, private IP can provide lower network latency than public IP.
You can use private services access to connect to:
Cloud SQL resources with access to a VPC network.
You can connect through private IP from any region. You can also connect through a Shared VPC between projects.
In the following example, the customer VPC network allocated the
address range for Google services and established a private connection that uses
the allocated range. Each Google service creates a subnet from the allocated
block to provision new resources in a given region, such as Cloud SQL
- The private connection is assigned the
10.240.0.0/16allocated range. From this allocation, Google services can create subnets where new resources are provisioned.
- On the Google services side of the private connection, Google creates a project for the customer. The project is isolated, meaning no other customers share it and the customer is billed for only the resources the customer provisions.
- Each Google service creates a subnet in which to provision resources. The
subnet's IP address range is typically a
/24CIDR block that is chosen by the service and comes from the allocated IP address range. You cannot modify the service producer's subnet. A service provisions new resources in existing regional subnets that were previously created by that service. If a subnet is full, the service creates a new subnet in the same region.
- VM instances in the customer's network can access service resources in any region if the service supports it. Some services might not support cross-region communication. For example, VM instances can only communicate with Cloud SQL instances that are in the same region. View the relevant service's documentation for more information.
- Egress costs for cross-regional traffic, where a VM instance communicates with resources in a different region, still apply.
- The Cloud SQL instance is assigned the IP address
10.240.0.2. In the Customer VPC network, requests with a destination of
10.240.0.2are routed to the private connection over to the service producer's network. After reaching the service network, the service network contains routes that direct the request to the correct resource.
- Traffic between VPC networks travels internally within Google's network, not through the public internet.
Allocated range reference
When you allocate an IP address range, you need to take into consideration the number of instances you plan to create. The number of usable hosts in a range depends on its subnet mask. For example:
|Subnet mask||Addresses||Usable hosts|
Requirements for Private IP
To use private IP, your network and application environment must meet the following requirements. In addition, setting up private IP for the first time requires extra IAM permissions.
Application environment requirements
- If you are connecting from GKE, you must be running GKE 1.8 or higher on a VPC-native cluster.
API and IAM requirements
- You must enable the Service Networking API for your project.
- In order to manage a private services access connection, the user should
have the following IAM permissions. If you don't have the required
permissions you can get insufficient-permissions errors.
If you are using a Shared VPC network, you also need to add your user to the host project and assign the same permissions to the user on the host project.
If you are using a Shared VPC network, you also need to enable this API for the host project.
Cloud SQL allocates a /24 subnet from the private services access IP range for each region. For example, placing MySQL instances in two regions requires that the allocated IP address range contain at least two available subnets of size /24.
Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. This way, all private clients can access the database without going through the Cloud SQL Auth proxy. Non-RFC 1918 address ranges must be configured as authorized networks.
Cloud SQL doesn't learn Non-RFC 1918 subnet routes from your VPC by default. You need to update the network peering to Cloud SQL to export any Non-RFC 1918 routes.
Traffic over private services access is provided with a certain level of encryption. For more information, see Google Cloud's virtual network encryption and authentication.
The Cloud SQL Auth proxy can be configured to connect using Private IP and provides authentication using IAM credentials and end to end encryption using a rotating SSL/TLS certificate.
If your security requirements mandate self-managed SSL/TLS certificates that you manage, see the instructions in Configuring SSL/TLS.
Creating one VPC network for each instance with a private IP address provides better network isolation than putting all instances in the "default" VPC network.
Overview of setting up private services access for your network
When you configure private IP connectivity for the first time on a specific VPC network, you need to perform a one-time procedure to set up private services access for Cloud SQL.
After you have established private services access, you can create a Cloud SQL instance configured to use private IP or configure private IP for an existing Cloud SQL instance. See Configuring private IP for step-by-step instructions.
Any time you change an established connection, you need to
vpc-peerings as well.
Quick reference for Private IP topics
When you manage Cloud SQL instances using private IP, some of the following topics could be of interest:
|Shared VPC networks||You can create Cloud SQL instances with private IP addresses in a Shared VPC network. However, you cannot assign a private IP address in a Shared VPC network to an existing Cloud SQL instance.|
|Regions||You can connect through private IP across regions.|
|Legacy networks||You cannot connect to the private IP of a Cloud SQL instance from a legacy network. Legacy networks do not support VPC network peering or private services access.|
|Removing a private IP||After you configure a Cloud SQL instance to use private IP, you cannot remove the private IP capability from that instance.|
|Public and private IP||You can use both public IP and private IP to connect to the same Cloud SQL instance. Neither connection method affects the other.|
|Existing Cloud SQL instances||You can configure an instance to use private IP at instance creation time. You can also configure an existing instance to use private IP. Configuring an existing instance to use private IP, or changing the network it is connected to, causes the instance to be restarted, resulting in a few minutes of downtime.|
|Static IP addresses||The private IP address of the Cloud SQL instance is static; it does not change.|
|Replicas||A replica inherits its private IP status from its primary instance. You can't configure private IP directly on a replica. If you're connecting to a replica using a private IP address, you don't need to create an additional VPC private connection for the replica as it is inherited from the primary instance.|
|The Cloud SQL Auth proxy||To connect to a Cloud SQL instance using private IP, the Cloud SQL Auth proxy
must be on a resource with access to the same VPC network as the
instance. If the instance has both IP types enabled, the Cloud SQL Auth proxy will default to
using the public IP. To ensure it is using private IP, the user needs to pass
|Serverless VPC Access||To connect from a serverless source, such as App Engine standard environment, App Engine flexible environment, Cloud Run, or Cloud Functions, your application or function connects directly to your instance through Serverless VPC Access without the Cloud SQL Auth proxy.|
|VPC Network Peering||A connection that uses private services access relies on a VPC Network
Peering. However, you do not create the VPC Network Peering explicitly, because
the peering is internal to Google Cloud. After you create the private
services access connection, you can see its underlying VPC Network Peering on
the VPC Network Peering page in the Cloud Console, but don't
delete it unless you want to
remove the private connection.
Learn more about VPC Network Peering.
|VPC Service Controls||VPC Service Controls improve your ability to mitigate the risk of data exfiltration. With VPC Service Controls, you create perimeters around the Cloud SQL instance. VPC Service Controls restrict access to resources within the perimeter from the outside. Only clients and resources within the perimeter can interact with one another. For more information, see the Overview of VPC Service Controls. Also review the Cloud SQL limitations when using VPC Service Controls. To use VPC Service Controls with Cloud SQL, see Configuring VPC Service Controls.|
|Transitive peering||Only directly peered networks can communicate. Transitive peering is not
supported. In other words, if VPC network N1 is peered with N2 and N3, but
N2 and N3 are not directly connected, VPC network N2 cannot communicate with
VPC network N3 over
VPC Network Peering.
Clients in one project can connect to Cloud SQL instances in multiple projects using Shared VPC networks.
|Moving Cloud SQL instances||Cloud SQL instances can only be moved between networks owned by the project in which they reside. Additionally, Cloud SQL instances can neither be moved between projects, nor can they be moved between networks hosted by different projects.|
- See how to configure private IP.
- Learn more about private services access.
- See how to configure private services access for Cloud SQL instances.
- Learn more about Cloud VPN.
- Learn more about VPC networks.
- Learn more about VPC Network Peering.
- Learn more about Shared VPC.
- Learn more about Cloud SQL Auth proxy.