This page describes how to enable VPC Service Controls on a Cloud SQL project. Before you begin, review Overview of VPC Service Controls. Also review the Cloud SQL limitations when using VPC Service Controls.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Compute Engine API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.Enable the Service Networking API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- Add the Identity and Access Management (IAM) roles to the user or service account you are using to set up and administer VPC Service Controls. See IAM Roles for Administering VPC Service Controls.
- Review limitations when using VPC Service Controls with Cloud SQL.
- Optionally, add an organization policy that restricts public IP on instances in projects that use that policy. See Connection organization policies and Configuring the organization policy.
Configure the Virtual Private Cloud (VPC) network
Perform the steps in Setting up private connectivity to Google APIs and services.
Configure DNS for Artifact Registry
Cloud SQL instances require access to Artifact Registry (pkg.dev
and *.pkg.dev) to download essential service agent container
images during instance creation and maintenance. When using
VPC Service Controls, you must route requests for Artifact Registry
domains to the restricted virtual IP (VIP) range
(199.36.153.4/30).
To route Artifact Registry traffic to the restricted VIP, configure Cloud DNS private DNS zones:
Create a dedicated private managed DNS zone for the
pkg.dev.domain:gcloud dns managed-zones create ZONE_NAME \ --project=PROJECT_ID \ --description="DESCRIPTION" \ --dns-name=pkg.dev. \ --networks=NETWORK_NAME \ --visibility=private
Replace the following:
ZONE_NAME: a name for the DNS zone (for example,pkg-dev-private).PROJECT_ID: the ID of the Google Cloud project that hosts your VPC network.DESCRIPTION: a description of the zone (for example,Private DNS zone for Artifact Registry).NETWORK_NAME: the name of your VPC network.
Start a DNS transaction:
gcloud dns record-sets transaction start \ --project=PROJECT_ID \ --zone=ZONE_NAME
Add an
Arecord forpkg.dev.pointing to the restricted VIP range (199.36.153.4/30):gcloud dns record-sets transaction add \ 199.36.153.4 199.36.153.5 199.36.153.6 199.36.153.7 \ --name=pkg.dev. \ --type=A \ --ttl=300 \ --zone=ZONE_NAME \ --project=PROJECT_ID
Add a
CNAMErecord mapping wildcard subdomains (*.pkg.dev.) topkg.dev.:gcloud dns record-sets transaction add "pkg.dev." \ --name="*.pkg.dev." \ --type=CNAME \ --ttl=300 \ --zone=ZONE_NAME \ --project=PROJECT_ID
Run the transaction:
gcloud dns record-sets transaction execute \ --zone=ZONE_NAME \ --project=PROJECT_ID
Enable VPC Service Controls for private services access
When a Cloud SQL instance uses private IP (private services access), its
underlying resources run in a peered service producer VPC
network (servicenetworking). If your VPC network
exports custom broad routes (such as 0.0.0.0/0,
0.0.0.0/1, or 128.0.0.0/2) over the private services
access peering connection, those routes can override Google API routes in the
producer network and block Artifact Registry access.
To configure the service producer network with private DNS zones (including
pkg.dev) and a route to the restricted VIP
(199.36.153.4/30), enable VPC Service Controls on the peering
connection:
gcloud services vpc-peerings enable-vpc-service-controls \ --network=NETWORK_NAME \ --project=PROJECT_ID \ --service=servicenetworking.googleapis.com
For more information, see gcloud services vpc-peerings enable-vpc-service-controls and Configure hybrid connectivity in the VPC documentation.
Disallow or disable public IP for Cloud SQL instances
To constrain data within the VPC for your Cloud SQL project, don't allow connections to Cloud SQL instances from public IPs. IP-based connections bypass VPC Service Controls. You must also disable public IP for new and existing Cloud SQL instances within the VPC.
To either disallow or disable public IP on Cloud SQL instances:
- Organization administrators can apply organization policies that disallow creating new instances with public IP. See Configure the organization policy.
- Users who create Cloud SQL instances can configure the instances to use private IP instead of public IP. See Disable public IP.
Create a service perimeter
During this procedure, you select the Cloud SQL projects that you want the VPC service perimeter to protect.
To create a service perimeter, follow the instructions in Creating a service perimeter.
Add more instances to the service perimeter
To add existing Cloud SQL projects to the perimeter, follow the instructions in Updating a service perimeter.
Add Cloud SQL and Cloud Storage APIs
To mitigate the risk of your data being exfiltrated from Cloud SQL, for example, using Cloud SQL import or export APIs, you must restrict both the Google Cloud SQL Admin API and the Google Cloud Storage API.
To add Cloud SQL and Cloud Storage APIs as restricted services:
Console
In the Google Cloud console navigation menu, click Security, and then click VPC Service Controls.
On the VPC Service Controls page, in the table, click the name of the service perimeter that you want to modify.
Click EDIT.
On the Edit VPC Service Perimeter page, click ADD SERVICES.
Add Cloud SQL Admin API and Cloud Storage API.
Click Save.
gcloud
gcloud access-context-manager perimeters update PERIMETER_ID \ --policy=POLICY_ID \ --add-restricted-services=sqladmin.googleapis.com,storage.googleapis.com
Where:
- PERIMETER_ID is the ID of the perimeter or the fully qualified identifier for the perimeter.
- POLICY_ID is the ID of the access policy.
For reference information, see access-context-manager perimeters update.
Create an access level
Optionally, to permit external access to protected resources inside a perimeter, you can use access levels. Access levels apply only to requests for protected resources coming from outside the service perimeter. You can't use access levels to give protected resources or VMs permission to access data and services outside the perimeter.
See Allowing access to protected resources from outside a perimeter.