示例 - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

示例

以下示例向用户 fred 授予对 SALES 表的 SELECT 权限。

grant select on table sales to fred;

以下示例向用户 fred 授予对 QA_TICKIT schema 中所有表的 SELECT 权限。

grant select on all tables in schema qa_tickit to fred;

以下示例向用户组 QA_USERS 授予对 schema QA_TICKIT 的全部 schema 权限。Schema 权限包括 CREATE 和 USAGE。USAGE 向用户授予访问 schema 中对象的权限,但不授予对这些对象的 INSERT 或 SELECT 之类的权限。单独授予对每个对象的权限。

create group qa_users; grant all on schema qa_tickit to group qa_users;

以下示例向组 QA_USERS 中的所有用户授予对 QA_TICKIT schema 中的 SALES 表的所有权限。

grant all on table qa_tickit.sales to group qa_users;

以下示例向组 QA_USERS 和 RO_USERS 中的所有用户授予对 QA_TICKIT 架构中的 SALES 表的所有权限。

grant all on table qa_tickit.sales to group qa_users, group ro_users;

以下示例向组 QA_USERS 中的所有用户授予对 QA_TICKIT schema 中的 SALES 表的 DROP 权限。

grant drop on table qa_tickit.sales to group qa_users;>

以下命令序列说明,具有对 schema 的访问权限并不表示授予对 schema 中的表的权限。

create user schema_user in group qa_users password 'Abcd1234'; create schema qa_tickit; create table qa_tickit.test (col1 int); grant all on schema qa_tickit to schema_user; set session authorization schema_user; select current_user; current_user -------------- schema_user (1 row) select count(*) from qa_tickit.test; ERROR: permission denied for relation test [SQL State=42501] set session authorization dw_user; grant select on table qa_tickit.test to schema_user; set session authorization schema_user; select count(*) from qa_tickit.test; count ------- 0 (1 row)

以下命令序列说明,具有对视图的访问权限并不意味着具有对基础表的访问权限。虽然名为 VIEW_USER 的用户已被授予 VIEW_DATE 的所有权限,但该用户无法从 DATE 表中选择数据。

create user view_user password 'Abcd1234'; create view view_date as select * from date; grant all on view_date to view_user; set session authorization view_user; select current_user; current_user -------------- view_user (1 row) select count(*) from view_date; count ------- 365 (1 row) select count(*) from date; ERROR: permission denied for relation date

以下示例向用户 cust_name 授予对 cust_phone 表的 cust_profileuser1 列的 SELECT 权限。

grant select(cust_name, cust_phone) on cust_profile to user1;

以下示例向 cust_name 组授予对 cust_phonecust_contact_preference 列的 SELECT 权限,并授予对 cust_profile 表的 sales_group 列的 UPDATE 权限。

grant select(cust_name, cust_phone), update(cust_contact_preference) on cust_profile to group sales_group;

下面的示例演示如何使用 ALL 关键字向 cust_profile 组授予对 sales_admin 表的三列的 SELECT 和 UPDATE 权限。

grant ALL(cust_name, cust_phone,cust_contact_preference) on cust_profile to group sales_admin;

以下示例向用户 cust_name 授予对 cust_profile_vw 视图的 user2 列的 SELECT 权限。

grant select(cust_name) on cust_profile_vw to user2;

授予数据共享 USAGE 权限的示例

以下示例显示了 GRANT 数据共享对特定数据库或基于数据共享创建的 schema 的使用权限。此 USAGE 权限不会将使用权限授予不是从指定数据共享创建的数据库。您只能将针对数据共享的权限 GRANT 或 REVOKE ALTER 或 SHARE 给用户和用户组。

以下示例将对 salesshare 数据共享的 USAGE 权限授予指定的命名空间。

GRANT USAGE ON DATASHARE salesshare TO NAMESPACE '13b8833d-17c6-4f16-8fe4-1a018f5ed00d';

以下示例将对 sales_db 的 USAGE 权限授予 Bob。

GRANT USAGE ON DATABASE sales_db TO Bob;

以下示例将对 sales_schema 的 USAGE 权限授予 Analyst_group

GRANT USAGE ON SCHEMA sales_schema TO GROUP Analyst_group;

授予 ASSUMEROLE 权限的示例

下面是授予 ASSUMEROLE 权限的示例。

以下示例显示了 REVOKE 语句,超级用户可以在集群上运行一次该语句,以便为用户和组启用 ASSUMEROLE 权限。然后,超级用户向用户和组授予相应命令的 ASSUMEROLE 权限。有关为用户和组启用 ASSUMEROLE 权限的信息,请参阅有关授予 ASSUMEROLE 权限的使用说明

revoke assumerole on all from public for all;

以下示例向用户 reg_user1 授予 IAM 角色 Redshift-S3-Read 的 ASSUMEROLE 权限来执行 COPY 操作。

grant assumerole on 'arn:aws:iam::123456789012:role/Redshift-S3-Read' to reg_user1 for copy;

以下示例向用户 reg_user1 授予 IAM 角色链 RoleARoleB 的 ASSUMEROLE 权限来执行 UNLOAD 操作。

grant assumerole on 'arn:aws:iam::123456789012:role/RoleA,arn:aws:iam::210987654321:role/RoleB' to reg_user1 for unload;

以下是使用 IAM 角色链 RoleARoleB 执行 UNLOAD 命令的示例。

unload ('select * from venue limit 10') to 's3://companyb/redshift/venue_pipe_' iam_role 'arn:aws:iam::123456789012:role/RoleA,arn:aws:iam::210987654321:role/RoleB';

以下示例向用户 reg_user1 授予 IAM 角色 Redshift-Exfunc 的 ASSUMEROLE 权限来创建外部函数。

grant assumerole on 'arn:aws:iam::123456789012:role/Redshift-Exfunc' to reg_user1 for external function;

以下示例向用户 reg_user1 授予 IAM 角色 Redshift-model 的 ASSUMEROLE 权限来创建机器学习模型。

grant assumerole on 'arn:aws:iam::123456789012:role/Redshift-ML' to reg_user1 for create model;

授予 ROLE 权限的示例

下面的示例将向 user1 授予 sample_role1。

CREATE ROLE sample_role1; GRANT ROLE sample_role1 TO user1;

以下示例使用 WITH ADMIN OPTION 将 sample_role1 授予 user1,为用户 1 设置当前会话,而 user1 将 sample_role1 授予 user2。

GRANT ROLE sample_role1 TO user1 WITH ADMIN OPTION; SET SESSION AUTHORIZATION user1; GRANT ROLE sample_role1 TO user2;

下面的示例将向 sample_role2 授予 sample_role1。

GRANT ROLE sample_role1 TO ROLE sample_role2;

下面的示例将向 sample_role3 和 sample_role4 授予 sample_role2。然后尝试将 sample_role3 授予 sample_role1。

GRANT ROLE sample_role2 TO ROLE sample_role3; GRANT ROLE sample_role3 TO ROLE sample_role2; ERROR: cannot grant this role, a circular dependency was detected between these roles

下面的示例将向 sample_role1 授予 CREATE USER 系统权限。

GRANT CREATE USER TO ROLE sample_role1;

下面的示例将向 user1 授予系统定义角色 sys:dba

GRANT ROLE sys:dba TO user1;

下面的示例尝试将循环依赖关系中的 sample_role3 授予 sample_role2。

CREATE ROLE sample_role3; GRANT ROLE sample_role2 TO ROLE sample_role3; GRANT ROLE sample_role3 TO ROLE sample_role2; -- fail ERROR: cannot grant this role, a circular dependency was detected between these roles