Skip to content

Prerequisites

This section outlines the prerequisites for setting up the Discovery scanning feature for GCP Cloud SQL MySQL.

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 MySQL instance, in the format <project-id>:<region>:<instance-name>.
Database Name The MySQL 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 MySQL, this is the service account name without @ and the domain, for example <sa-name>.

Here are some of the prerequisites for setting up the Discovery scanning feature for GCP Cloud SQL MySQL:

  • The Cloud SQL MySQL 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
    gcloud services enable sqladmin.googleapis.com iamcredentials.googleapis.com --project=<project-id>
    
  • IAM database authentication must be enabled on the instance by setting the cloudsql_iam_authentication database flag to on.

    Enable IAM database authentication
    Bash
    gcloud sql instances patch <instance-name> --database-flags=cloudsql_iam_authentication=on
    

    Warning

    The --database-flags option 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
    1
    2
    3
    gcloud iam service-accounts add-iam-policy-binding <sa-name>@<project-id>.iam.gserviceaccount.com \
      --member="<privacera-pod-identity>" \
      --role="roles/iam.serviceAccountTokenCreator"
    

    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
    Bash
    1
    2
    3
    4
    5
    6
    7
    gcloud projects add-iam-policy-binding <project-id> \
      --member="serviceAccount:<sa-name>@<project-id>.iam.gserviceaccount.com" \
      --role="roles/cloudsql.client"
    
    gcloud projects add-iam-policy-binding <project-id> \
      --member="serviceAccount:<sa-name>@<project-id>.iam.gserviceaccount.com" \
      --role="roles/cloudsql.instanceUser"
    
  • Add the service account to the instance as an IAM database user, and grant it read permission on the database to be scanned.

    Create the IAM database user and grant permissions
    Bash
    1
    2
    3
    gcloud sql users create <sa-name>@<project-id>.iam \
      --instance=<instance-name> \
      --type=cloud_iam_service_account
    
    SQL
    GRANT SELECT ON `<database-name>`.* TO '<sa-name>'@'%';
    

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 MySQL instance.

<sa-name>: The name of the service account used to connect to the database.

<database-name>: The MySQL database to be scanned.

<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>.