This page provides information about Identity and Access Management (IAM) roles and permissions and how they're used with Cloud SQL instances.
IntroductionThis page focuses on aspects of IAM that are relevant specifically to Cloud SQL. For a detailed discussion of IAM and its features generally, see Identity and Access Management. In particular, see the Managing IAM Policies section. IAM lets you control who has access to the resources in your Google Cloud project. The set of access rules you apply to a resource is called an IAM policy. An IAM policy applied to your project defines the actions that users can take on all resources within your project.
Members are the "who" of IAM. Members can be individual users, groups, domains, or even the public as a whole. Members are assigned roles, which grant members the ability to perform actions in Cloud SQL as well as Google Cloud more generally. Each role is a collection of one or more permissions. Permissions are the basic units of IAM: each permission lets you perform a certain action. See IAM roles in Cloud SQL and IAM permissions in Cloud SQL for complete lists of all the roles and permissions available in Cloud SQL.
When you use an account to connect to a Cloud SQL instance, the account must have the Cloud SQL > Client role (roles/cloudsql.client
), which includes the permissions required for connecting.
You can add roles to an account in the Console on the IAM & Admin > IAM page, and see which permissions belong to which roles on the IAM & Admin > Roles page.
Cloud SQL uses service accounts for authentication between Cloud SQL and other Google Cloud products. Service accounts provide credentials
in JSON format, which you download from the Console and use for authentication in various scenarios.
For example: connecting from an application running in a
docker container.
Cloud SQL roles and permissions with Cloud SQL Auth ProxyIf you are connecting to a Cloud SQL instance from a Compute Engine instance using Cloud SQL Auth Proxy, you can use the default Compute Engine service account associated with the Compute Engine instance.
As with all accounts connecting to a Cloud SQL instance, the service account must have the Cloud SQL > Client role.
Cloud SQL roles and permissions with serverless optionsGoogle Cloud
serverless optionsinclude
App Engineand
Cloud Run.
Use a service account to authorize access from these options. The service account authorizes access to all Cloud SQL in a specific project. When you create an application or a Cloud Run functions, this service creates this account for you. You can find the account on the IAM & Admin > IAM page, with the appropriate suffix:
Serverless option Service account suffix App Engine @gae-api-prod.google.com.iam.gserviceaccount.com Cloud Run functions @appspot.gserviceaccount.com Cloud Run compute@developer.gserviceaccount.comAs with all accounts connecting to a Cloud SQL instance, the service account must have the
Cloud SQL > Clientrole.
Note: IfThe caller does not have permission Connection matched pg_hba.conf line 20: "local all +cloudsqliamuser cloudsql-iam-user"
error message appears when the service account connects to the instance, add the Cloud SQL Instance User role to the account. Cloud SQL roles and permissions with Cloud Storage
The import and export features in Cloud SQL work together. Exports write to Cloud Storage and imports read from there. For this reason, the service account you use for these operations needs both read and write permissions to Cloud Storage:
storage.objectAdmin
IAM role set in the project. You can find the instance's service account name in the Google Cloud console on your instance's Overview page.gcloud storage buckets add-iam-policy-binding
command to grant this IAM role to the service account for the bucket.When you use IAM group authentication, you create groups. You can then use the groups to manage access and database privileges to your Cloud SQL instances.
The following table lists the roles that are required to manage IAM group authentication.
Action Roles Create, view, and manage groups. roles/resourcemanager.organizationViewer
roles/logging.viewer
roles/resourcemanager.projectIamAdmin
roles/resourcemanager.folderIamAdmin
The administrator can grant Cloud SQL roles or give individual Cloud SQL permissions to each group. The members of each group inherit roles and permissions.
Cloud SQL roles and permissions for Dataplex Universal Catalog integrationTo provide access to Cloud SQL metadata on Dataplex Universal Catalog, you can grant a user the roles/cloudsql.schemaViewer
role or add the cloudsql.schemas.view
permission to a custom role.
For more information, see Manage Cloud SQL resources with Dataplex Universal Catalog.
Permission to access private Cloud SQL instancesWhen another Google Cloud service, such as BigQuery, needs to communicate with your Cloud SQL instance to access data and make queries against this data over a private connection, the service uses an internal path instead of the private IP addresses inside of the Virtual Private Cloud (VPC). Traffic can't be controlled or restricted with any VPC-level configurations, firewall rules, route policies, or cutting of the peering.
Instead, Cloud SQL offers a configuration flag on your instance to control whether to turn this internal path on or off for other Google Cloud services accessing your database.
Control and revoke the permissionWhen another Google Cloud service, such as BigQuery, tries to access your private Cloud SQL instance, it must provide a legitimate identity with the cloudsql.instances.connect
IAM permission.
Typically, there are two ways that a service can achieve this:
Using a service account. A service, such as BigQuery, can use a pre-configured service account to connect to a Cloud SQL instance. In this case, the service account must have sufficient IAM permissions.
For example, for the federated connection between BigQuery and Cloud SQL, a service account named service-{PROJECT_NUMBER}@gcp-sa-bigqueryconnection.iam.gserviceaccount.com
is created when the BigQuery connection API is activated. This service account has two Cloud SQL permissions: cloudsql.instances.connect
and cloudsql.instances.get
. BigQuery uses these permissions to access a private Cloud SQL instance through an internal path.
To control the permission for who can use this internal path, you can grant and revoke the IAM permissions to and from the user's IAM identity that the Google Cloud service, such as BigQuery, uses to connect to your Cloud SQL instance. For more information about granting and revoking permissions within BigQuery, see Setting up access to Cloud SQL.
Cloud SQL roles and permissions with other scenariosCloud SQL interacts with other Google Cloud products and tools. These interactions also require specific roles and permissions which can vary between scenarios. Cloud SQL documentation provides detailed information about these requirements for each case below:
The following sections show how to complete basic IAM tasks on projects.
To complete the following tasks, you must have the resourcemanager.projects.getIamPolicy
and resourcemanager.projects.setIamPolicy
IAM permissions.
For a list of roles associated with Cloud SQL, see IAM Roles.
ConsoleTo add a project-level IAM policy, use gcloud beta projects add-iam-policy-binding
.
To view the IAM policy of a project, use gcloud beta projects get-iam-policy
.
To remove a project-level IAM policy, use gcloud beta projects remove-iam-policy-binding
.
IAM, like any other administrative settings, requires active management to be effective. Before you make a resource accessible to other users, be sure you know what roles you want each of those people to play. Over time, changes in project management, usage patterns, and organizational ownership may require you to modify IAM settings on projects, especially if you manage Cloud SQL in a large organization or for a large group of users. As you evaluate and plan your access control settings, keep the following best practices in mind:
Use the principle of least privilege when granting access. The principle of least privilege is a security guideline for granting access to your resources. When you grant access based on the principle of least privilege, you give a user only the access they need to accomplish their assigned task.
Avoid granting roles with setIamPolicy
permission to people you do not know. Granting setIamPolicy
permission allows a user to change permissions and take control of data. You should use roles with setIamPolicy
permission only when you want to delegate administrative control over objects and buckets.
Be sure you delegate administrative control of your resources. You should be sure that your resources can still be managed by other team members should an individual with administrative access leave the group. Two common ways to achieve this are the following:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4