Installing a Cloud SQL database
Install P0 on a Google Cloud SQL for PostgreSQL instance to grant just-in-time database access through a Cloud Run connector and GCP IAM database authentication.
Google Cloud SQL is a preview integration.
Follow this guide to install P0 on a Google Cloud SQL for PostgreSQL instance. P0 grants just-in-time, time-limited access to the instance using GCP IAM database authentication, reached through a P0-managed Cloud Run connector that runs inside your VPC.
Cloud SQL for MySQL is not yet supported. This integration manages PostgreSQL instances only.
How it works
P0 reaches your Cloud SQL instances through a connector: a Cloud Run service that P0 deploys into your project with direct access to the VPC your instances run on. The connector provisions database users and enforces access on P0's behalf.
When a user requests access to a Cloud SQL instance:
P0 provisions a dedicated IAM database user for that identity on the instance. P0 creates the user once, and it persists across requests.
After approval, P0 delegates the
roles/cloudsql.instanceUserrole to the requestor for the approved duration.The requestor connects to the instance as their IAM database user using GCP IAM database authentication.
When the access duration expires or an approver revokes access, P0 removes the delegated role. The IAM database user remains in place for future requests.
Prerequisites
Before you begin, ensure you have:
A P0 Google Cloud integration with IAM management installed on the project.
A VPC and subnetwork that your Cloud SQL instances run on.
Admin access to the Cloud SQL instance.
IAM database authentication enabled on the instance. Set the
cloudsql.iam_authenticationdatabase flag toon.Permissions to deploy a Cloud Run service, create IAM bindings, and reserve a Private Service Access range in the project.
These Google Cloud APIs enabled on the project:
compute,iam,run,servicenetworking, andsqladmin.
Private-IP Cloud SQL instances require a Private Service Access connection that peers a reserved internal IP range to servicenetworking.googleapis.com on the VPC. Establish this connection before you create the instance.
Install the GCP CloudSQL connector
Install the connector on the VPC that hosts your Cloud SQL instances. This step deploys the Cloud Run connector and grants it the roles it needs to manage database users.
Via the P0 app
Navigate to Integrations on p0.app and select the GCP CloudSQL integration.
Select the IAM management component.
Select the GCP project ID that hosts the VPC.
Enter the Subnetwork name that the connector should have direct VPC access to.
Click Next. P0 generates the connector's Cloud Run service name and service account, along with the Terraform to deploy them.
Apply the generated Terraform. It deploys the connector, grants the connector's service account the
roles/cloudsql.adminandroles/cloudsql.instanceUserroles, and grants P0's service account theroles/run.invokerrole on the connector.Click Next. P0 verifies that the connector is reachable, then completes the install.
Via the P0 Terraform provider
Ensure you have configured the P0 Terraform provider with the root
p0_gcpintegration andp0_gcp_iam_writeinstalled on the project.Use the
p0_gcp_cloudsql_stagedresource to stage the install. Staging generates the connector identifiers you need to deploy the connector.
Deploy the connector with the
p0-security/p0-connector/googlemodule, then grant the connector's service account the required Cloud SQL roles.
Register the connector's service account as an IAM database user on the instance.
Use the
p0_gcp_cloudsqlresource to complete the install. Creating it verifies that the connector is reachable.
Run
terraform initandterraform apply.
For a complete, runnable example that also enables the required APIs and provisions the VPC, subnetwork, Private Service Access range, and a sample instance, see the p0_gcp_cloudsql provider documentation.
Requesting access
Users request access to a Cloud SQL instance through the P0 app or a P0 notifier such as Slack. Select the GCP CloudSQL resource, choose the VPC and instance, and submit the request. After an approver grants the request, P0 provisions the requestor's IAM database user and delegates the roles/cloudsql.instanceUser role for the approved duration.
The requestor then connects to the instance as their IAM database user using GCP IAM database authentication.
The P0 CLI does not yet provide a Cloud SQL connection command. Request Cloud SQL access from the P0 app or a notifier.
Troubleshooting
P0 reports that it could not reach the connector during install. The connector's Cloud Run service can be briefly unreachable right after deployment. Wait a moment and click Next again to retry verification. If the error persists, confirm that:
The connector's Cloud Run service is deployed and running.
P0's service account holds the
roles/run.invokerrole on the connector service.Cloud Run has direct VPC access to the configured subnetwork.
Last updated