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.
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 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.
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.
Add the instance to PostgreSQL (new)
After the connector is installed, add each Cloud SQL instance to the PostgreSQL (new) integration. Each instance on the VPC gets its own entry.
Navigate to Integrations on p0.app and select the PostgreSQL (new) integration.
Select the Access management component and click Add instance.
Enter a unique identifier for the instance. This can be any value you like.
Choose GCP CloudSQL hosting.
Select the GCP VPC ID that hosts the instance. The list shows only VPCs where the GCP CloudSQL connector is fully installed.
Enter the CloudSQL instance name.
Click Next.
Apply the generated Terraform. It registers the connector's service account as an IAM database user on the instance.
Grant that database user the
cloudsqlsuperuserrole. With version 7.19.0 or later of the Google Terraform provider, add thedatabase_rolesline that P0 shows to the same resource. Otherwise, run thegcloud sql users assign-rolescommand that P0 shows.Click Next.
If desired, configure the port and default database.
Click Finish.
To let requestors request access to run specific SQL statements, also complete Enabling SQL statement access.
Enabling SQL statement access (optional)
By default, P0 grants role-based access to the instance. To also let requestors request access to run specific SQL statements, the connector's cloudsqlsuperuser role needs grant authority (WITH GRANT OPTION) on the tables and schemas you want P0 to manage. If you skip this section and a requestor asks for SQL statement access, P0 can't provision that request.
Set up table access, schema access, both, or neither, depending on what your requestors need to run.
Table access
To let requestors act on specific tables, first identify the roles that own tables in the schema:
Then, for each role that owns a table, connect as that role and grant cloudsqlsuperuser grant authority on its tables. The ALTER DEFAULT PRIVILEGES statement covers tables the role creates later:
Schema access
To let requestors perform schema-level actions on an existing schema, connect as the role that owns the schema and run the following once per schema you want P0 to manage. It grants cloudsqlsuperuser USAGE (to reference the schema's tables) and CREATE (to create new tables in it), with grant option. Run it again whenever you add a schema:
Once the database is connected, see Requesting PostgreSQL access to request and connect to it.
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.
The GCP VPC ID list is empty when adding the instance. The list shows only VPCs where the GCP CloudSQL connector install is complete. It does not read VPCs from your Google Cloud project, so granting P0 extra viewer roles does not add entries. Finish installing the GCP CloudSQL connector on the VPC, then add the instance again.
Last updated