This page explains how to access a Spanner database when you are a fine-grained access control user.
To learn about fine-grained access control, see About fine-grained access control.
As a fine-grained access control user, you must select a database role to use to execute SQL statements and queries, and to perform row operations on a database. Your role selection persists throughout your session until you change the role.
When you submit a query, DML, or row operation, Spanner checks authorization by using the following rules:
- Google Cloud console
Spanner first checks if you have database-level IAM permissions. If so, the Google Cloud console doesn't show a database role selector, and your session proceeds with your database-level permissions.
If you have only fine-grained access control privileges and no IAM database-level permissions, you must have been granted access to the
spanner_sys_reader
system role or one of its member roles. Select a role on the database Overview page so that your Google Cloud console session proceeds with the required privileges.
- Google Cloud SDK
If you specify a database role when you submit a query, DML, or a row operation, Spanner checks fine-grained access control privileges. If the check fails, Spanner does not check for database-level IAM permissions, and the operation fails.
If you don't specify a database role, Spanner checks database-level IAM permissions, and if the checks succeed, your session proceeds with your database-level permissions.
Use these methods to specify a database role when accessing a Spanner database:
Console
Select a database, and then on the database Overview page, click the Change database role (pencil) icon adjacent to the Current role field.
By default, when a fine-grained access control user logs in, this field has the value
public
. For information about thepublic
system role, see Fine-grained access control system roles.In the Change database role dialog, select another role from the list of available roles.
Click Update.
The Current role field shows the new role.
gcloud
Add the
--database-role
option to thegcloud spanner databases execute-sql
command, as follows:gcloud spanner databases execute-sql DATABASE_NAME \ --instance=INSTANCE_NAME \ --sql="SELECT * from TABLE_NAME;" \ --database-role=ROLE_NAME
Client libraries
C++
C#
Go
Java
Node.js
PHP
Python
Ruby