Prerequisites¶
This section outlines the prerequisites for setting up the Discovery scanning feature for GCP Cloud SQL PostgreSQL.
Make sure you have installed and configured the base Privacera Discovery before proceeding with the setup. For more information, see Discovery.
| Prerequisites | Description |
|---|---|
| Instance Connection Name | The connection name of the Cloud SQL PostgreSQL instance, in the format <project-id>:<region>:<instance-name>. |
| Database Name | The PostgreSQL database to be scanned. |
| Service Account | The Google Cloud service account used to connect to the database. |
| IAM Database User | The Cloud SQL IAM database user of the service account. For PostgreSQL, this is the service account email without the .gserviceaccount.com suffix, for example <sa-name>@<project-id>.iam. |
Here are some of the prerequisites for setting up the Discovery scanning feature for GCP Cloud SQL PostgreSQL:
- The Cloud SQL PostgreSQL instance must have a private IP in a VPC network that is reachable from the GKE cluster where Privacera is deployed.
-
The Cloud SQL Admin API and the IAM Service Account Credentials API must be enabled in the Google Cloud project.
Enable the required APIs
Bash -
IAM database authentication must be enabled on the instance by setting the
cloudsql.iam_authenticationdatabase flag toon.Enable IAM database authentication
Bash Warning
The
--database-flagsoption replaces all existing database flags on the instance. If other flags are already set, include them in the same command. -
Identify the service account to be used for connecting to the database. The recommendation is to create a dedicated service account and allow the Discovery and Portal pods to impersonate it. To allow impersonation, grant the Service Account Token Creator role (
roles/iam.serviceAccountTokenCreator) on the dedicated service account to the Workload Identity used by the Discovery and Portal pods.Grant the Service Account Token Creator role
Bash If the Discovery and Portal pods use different identities, run the command for each identity.
Info
Alternatively, if the Kubernetes service accounts of the Discovery and Portal pods are already annotated with a Google service account (
iam.gke.io/gcp-service-account), you can use that service account directly and skip the impersonation setup. Do not add or change this annotation only for Cloud SQL access, as it changes the identity used by Discovery for all Google Cloud services, such as Bigtable, Cloud Storage, and Pub/Sub. -
Grant the Cloud SQL Client (
roles/cloudsql.client) and Cloud SQL Instance User (roles/cloudsql.instanceUser) roles to the service account.Grant the Cloud SQL roles
-
Add the service account to the instance as an IAM database user, and grant it read permission on the schemas to be scanned.
Create the IAM database user and grant permissions
Bash Run the following for each schema to be scanned, for example
public:SQL To include tables created later, also run:
Replace the following placeholders
<project-id>: The Google Cloud project ID where the Cloud SQL instance is created.
<instance-name>: The name of the Cloud SQL PostgreSQL instance.
<sa-name>: The name of the service account used to connect to the database.
<database-name>: The PostgreSQL database to be scanned.
<schema-name>: The schema to be scanned, for example public.
<table-owner-role>: The role that creates the tables in the schema.
<privacera-pod-identity>: The identity of the Discovery and Portal pods, for example serviceAccount:<privacera-gsa>@<project-id>.iam.gserviceaccount.com, or principal://iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/<project-id>.svc.id.goog/subject/ns/<namespace>/sa/<ksa-name>.