[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Fine-grained access control overview\n\nSpanner fine-grained access control combines the benefits of\n[Identity and Access Management](/iam/docs) (IAM) with\nSQL role-based access control. With fine-grained access control, you define\ndatabase roles, grant privileges to the roles, and create\nIAM policies to grant permissions on database roles to\nIAM principals. This page describes how to use fine-grained access control\nwith Spanner for GoogleSQL-dialect databases and PostgreSQL-dialect databases.\n\nAs an administrator, you must enable fine-grained access control for individual IAM\nprincipals. Principals\nfor whom fine-grained access control is enabled (\"fine-grained access control users\") must assume a database\nrole to access Spanner resources.\n\nResource access for users who are are not fine-grained access control users is governed\nby IAM database-level roles.\nFine-grained access control is fully compatible and can co-exist with existing\nIAM database-level access control. You can use it to access\nindividual database objects. To control access to the entire database, use\n[IAM roles](/spanner/docs/iam).\n| **Note:** Spanner relies on IAM for identity management rather than managing user credentials within the database.\n\nWith fine-grained access control, you can control access to tables, columns, views, and\nchange streams.\n\nTo manage fine-grained access control, you use the following DDL\nstatements:\n\n- `CREATE` and `DROP` statements for creating and dropping database roles. Database roles are collections of privileges. You can create up to 100 roles for a database.\n- `GRANT` and `REVOKE` statements to grant and revoke privileges to and from\n database roles. Privileges include `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and\n `EXECUTE`. Privilege names\n correspond to the like-named SQL statements. For example, a role with the\n `INSERT` privilege can execute the `INSERT` SQL statement on the tables that\n are specified in the `GRANT` statement.\n\n The following DDL statements grant `SELECT` on table `employees`\n to the `hr_rep` database role. \n\n ### GoogleSQL\n\n CREATE ROLE hr_rep;\n GRANT SELECT ON TABLE employees TO ROLE hr_rep;\n\n ### PostgreSQL\n\n CREATE ROLE hr_rep;\n GRANT SELECT ON TABLE employees TO hr_rep;\n\n For more information on privileges, see\n [Fine-grained access control privileges reference](/spanner/docs/fgac-privileges).\n- `GRANT` statements for granting roles to other roles to create hierarchies of\n roles, with privilege inheritance.\n\nUse cases\n---------\n\nThe following are sample use cases for fine-grained access control:\n\n- An HR information system that has roles for sales compensation analyst, sales management, and HR analyst, each with different access levels on the data. For example, compensation analysts and sales management shouldn't see social security numbers.\n- A ride-sharing application with different service accounts and privileges for riders and drivers.\n- A ledger that permits `SELECT` and `INSERT` operations but not `UPDATE` and `DELETE` operations.\n\nSpanner resources and their privileges\n--------------------------------------\n\nThe following is a list of Spanner resources and the [fine-grained access control\nprivileges](/spanner/docs/fgac-privileges) that you can grant for them.\n\nSchemas\n: You can grant the `USAGE` privilege on schemas to specific database roles. For\n a non-default schema, database roles must have the `USAGE` privilege to access\n the database objects. The privilege check looks like the following:\n\nDo you have `USAGE` on the schema?\n\nNo: Reject access.\n\nYes: Do you also have the appropriate rights on the table?\n\nNo: Reject access.\n\nYes: You can access the table.\n| **Note:** You can use `ALL` to bulk grant privileges on all objects that use the same type in the schema. If you later add objects, you must grant privileges to the new objects as you add them.\n\nTables\n: You can grant the `SELECT`, `INSERT`, `UPDATE`, and `DELETE` privileges on\n tables to database roles. For interleaved tables, a privilege granted on the\n parent table doesn't propagate to the child table.\n\nColumns\n: You can grant `SELECT`, `INSERT`, and `UPDATE` on a subset of columns in a\n table. The privilege is then valid only for those columns. `DELETE` is not\n permitted at the column level.\n\nViews\n: You can grant `SELECT` privilege on a view. Only `SELECT` is supported for\n views. Spanner supports both invoker's rights views and definer's\n rights views. If you create a view with invoker's rights, to query the view, the\n database role or user needs the `SELECT` privilege on the view, and also the\n `SELECT` privilege on the underlying objects referenced in the view. If you\n create a view with definer's rights, to query the view, the database role or\n user only needs the `SELECT` privilege on the view. For more information, see\n [Views overview](/spanner/docs/views).\n\nChange streams\n: You can grant `SELECT` on change streams. You must also grant `EXECUTE` on the\n read function associated with a change stream. For information,\n see [Fine-grained access control for change streams](/spanner/docs/fgac-change-streams).\n\nSequences\n: You can grant `SELECT` and `UPDATE` on sequences. For information,\n see [Fine-grained access control for sequences](/spanner/docs/fgac-sequences).\n\nModels\n: You can grant `EXECUTE` on models. For information,\n see [Fine-grained access control for models](/spanner/docs/fgac-models).\n\nFine-grained access control system roles\n----------------------------------------\n\nFine-grained access control has predefined *system roles* for each database.\nLike user-defined database roles, system roles can control access to\nSpanner resources.\n\nFor example, a fine-grained access control user needs to be granted the `spanner_sys_reader`\nsystem role to access Key Visualizer, and needs the `spanner_info_reader` system\nrole to be able to see unfiltered results when querying the\n`INFORMATION_SCHEMA` tables.\n\nFor more information, see [Fine-grained access control system roles](/spanner/docs/fgac-system-roles).\n\nDatabase role hierarchies and inheritance\n-----------------------------------------\n\nYou can create hierarchies of database roles, where child roles\ninherit the privileges of parent roles. Child roles are known as *members* of\nthe parent role.\n\nFor example, consider the following `GRANT` statements: \n\n### GoogleSQL\n\n GRANT SELECT ON TABLE employees TO ROLE pii_access;\n GRANT ROLE pii_access TO ROLE hr_manager, hr_director;\n\n### PostgreSQL\n\n GRANT SELECT ON TABLE employees TO pii_access;\n GRANT pii_access TO hr_manager, hr_director;\n\n`hr_manager` and `hr_director` are members of role `pii_access`, and inherit the\n`SELECT` privilege on table `employees`.\n\n`hr_manager` and `hr_director` can also have members, and those members would\ninherit the `SELECT` privilege on `employees`.\n\nThere are no limits on the depth of role hierarchies, but query performance\nmight degrade with deep and wide role hierarchy structures.\n\nBackup and restore\n------------------\n\nSpanner [backups](/spanner/docs/backup) include database role\ndefinitions. When a database is restored from backup, database roles\nare re-created with their granted privileges. However, IAM\npolicies are not a part of database backups, so you must re-grant access to\ndatabase roles to principals in the restored database.\n\nOverview of setting up fine-grained access control\n--------------------------------------------------\n\nThe following are the high-level steps that you take to begin\nsecuring data with fine-grained access control. For details, see\n[Configure fine-grained access control](/spanner/docs/configure-fgac).\n\nYou must be granted the `roles/spanner.admin` or\n`roles/spanner.databaseAdmin` IAM roles to perform these tasks.\n\n1. Create database roles and grant privileges to the roles.\n2. Optional: Create role hierarchies with inheritance by granting roles to other roles.\n3. Perform these steps for each principal who is to be a fine-grained access control user:\n 1. Enable fine-grained access control for the principal. The principal is then automatically granted the `public` database role, which has no privileges by default. This is a one-time operation for each principal.\n 2. Grant IAM permissions on one or more database roles to the principal.\n 3. After the principal is granted all required database roles, if the principal has database-level IAM roles, consider revoking the database-level roles so that the principal's access control is managed by only one method.\n\nLimitations\n-----------\n\n- Export operations don't export database roles and privileges, and import operations can't import them. You must manually set up roles and privileges after your import is complete.\n- The **Data** tab on the **TABLE** page in the Google Cloud console is not available for fine-grained access control users.\n\nWhat's next\n-----------\n\n- [Access a database with fine-grained access control](/spanner/docs/access-with-fgac)\n- [Fine-grained access control for change streams](/spanner/docs/fgac-change-streams)\n- [Configure fine-grained access control](/spanner/docs/configure-fgac)\n- [Fine-grained access control privileges reference](/spanner/docs/fgac-privileges)\n- [Fine-grained access control system roles](/spanner/docs/fgac-system-roles)\n- [GoogleSQL `GRANT` and `REVOKE` statements](/spanner/docs/reference/standard-sql/data-definition-language#grant_and_revoke_statements)\n- [PostgreSQL `GRANT` and `REVOKE` statements](/spanner/docs/reference/postgresql/data-definition-language#grant_and_revoke_statements)\n- [Fine-grained access control for sequences](/spanner/docs/fgac-sequences)\n- [Fine-grained access control for models](/spanner/docs/fgac-models)"]]