こちらのページで基本的な使い方を把握した Snowflake について、アクセス制御の設定を記載します。
参考資料: Access Control in Snowflake
Role Hierarchy and Privilege Inheritance
PUBLIC
role が grant されています。PUBLIC
role が grant されています。role は 0 個以上の privilege を持ちます。
CREATE ROLE myrole;
SHOW GRANTS TO ROLE myrole;
+------------+-----------+------------+------+------------+--------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|------------+-----------+------------+------+------------+--------------+--------------+------------|
+------------+-----------+------------+------+------------+--------------+--------------+------------+
暗黙的に grant されている、PUBLIC
role object に対する USAGE
privilege を含める場合は "1 個以上" と表現できます。
GRANT ROLE public TO ROLE myrole;
+----------------------------------------------------------------------------------------------+
| status |
|----------------------------------------------------------------------------------------------|
| Granting role PUBLIC has no effect. Every user and role has role PUBLIC implicitly granted. |
+----------------------------------------------------------------------------------------------+
PUBLIC
role object は特殊な role であり、通常は USAGE
privilege が SHOW GRANTS で確認できます。
CREATE ROLE myrole2;
GRANT ROLE myrole2 TO ROLE myrole;
SHOW GRANTS TO ROLE myrole;
+-------------------------------+-----------+------------+---------+------------+--------------+--------------+--------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-----------+------------+---------+------------+--------------+--------------+--------------|
| 2021-09-20 03:11:34.605 -0700 | USAGE | ROLE | MYROLE2 | ROLE | MYROLE | false | ACCOUNTADMIN |
+-------------------------------+-----------+------------+---------+------------+--------------+--------------+--------------+
関連資料:
Role Hierarchy and Privilege Inheritance
MANAGE GRANTS
privilege を持ちます。CREATE USER
と CREATE ROLE
privilege を持ちます。上記の USAGE 関係が確認できます。
SHOW GRANTS ON ROLE securityadmin;
+-------------------------------+-----------+------------+---------------+------------+--------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-----------+------------+---------------+------------+--------------+--------------+------------|
| 2021-09-11 02:19:20.752 -0700 | USAGE | ROLE | SECURITYADMIN | ROLE | ACCOUNTADMIN | true | |
+-------------------------------+-----------+------------+---------------+------------+--------------+--------------+------------+
SHOW GRANTS ON ROLE sysadmin;
+-------------------------------+-----------+------------+----------+------------+--------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-----------+------------+----------+------------+--------------+--------------+------------|
| 2021-09-11 02:19:20.753 -0700 | USAGE | ROLE | SYSADMIN | ROLE | ACCOUNTADMIN | true | |
+-------------------------------+-----------+------------+----------+------------+--------------+--------------+------------+
SHOW GRANTS ON ROLE useradmin;
+-------------------------------+-----------+------------+-----------+------------+---------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-----------+------------+-----------+------------+---------------+--------------+------------|
| 2021-09-11 02:19:20.750 -0700 | USAGE | ROLE | USERADMIN | ROLE | SECURITYADMIN | true | |
+-------------------------------+-----------+------------+-----------+------------+---------------+--------------+------------+
USERADMIN
と SECURITYADMIN
の privilege 一覧です。
SHOW GRANTS TO ROLE useradmin;
+-------------------------------+-------------+------------+----------+------------+--------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-------------+------------+----------+------------+--------------+--------------+------------|
| 2021-09-11 02:19:20.762 -0700 | CREATE ROLE | ACCOUNT | XXX12345 | ROLE | USERADMIN | true | |
| 2021-09-11 02:19:20.761 -0700 | CREATE USER | ACCOUNT | XXX12345 | ROLE | USERADMIN | true | |
+-------------------------------+-------------+------------+----------+------------+--------------+--------------+------------+
SHOW GRANTS TO ROLE securityadmin;
+-------------------------------+----------------------+------------+-----------+------------+---------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+----------------------+------------+-----------+------------+---------------+--------------+------------|
| 2021-09-11 02:19:20.766 -0700 | APPLY SESSION POLICY | ACCOUNT | XXX12345 | ROLE | SECURITYADMIN | true | |
| 2021-09-11 02:19:20.766 -0700 | MANAGE GRANTS | ACCOUNT | XXX12345 | ROLE | SECURITYADMIN | true | |
| 2021-09-11 02:19:20.750 -0700 | USAGE | ROLE | USERADMIN | ROLE | SECURITYADMIN | true | |
+-------------------------------+----------------------+------------+-----------+------------+---------------+--------------+------------+
参考情報: SHOW GRANTS
補足: ORGADMIN
は ACCOUNTADMIN
の更に上位の role です。
SHOW ROLES;
+-------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+-------+-----------------------------------------------------------------------------------+
| created_on | name | is_default | is_current | is_inherited | assigned_to_users | granted_to_roles | granted_roles | owner | comment |
|-------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+-------+-----------------------------------------------------------------------------------|
| 2021-09-11 02:19:20.691 -0700 | ACCOUNTADMIN | Y | Y | N | 1 | 0 | 2 | | Account administrator can manage all aspects of the account. |
| 2021-09-10 11:51:15.004 -0700 | ORGADMIN | N | N | N | 0 | 0 | 0 | | Organization administrator can manage organizations and accounts in organizations |
| 2021-09-11 02:19:20.668 -0700 | PUBLIC | N | N | Y | 0 | 0 | 0 | | Public role is automatically available to every user in the account. |
| 2021-09-11 02:19:20.708 -0700 | SECURITYADMIN | N | N | Y | 0 | 1 | 1 | | Security administrator can manage security aspects of the account. |
| 2021-09-11 02:19:20.721 -0700 | SYSADMIN | N | N | Y | 0 | 1 | 0 | | System administrator can create and manage databases and warehouses. |
| 2021-09-11 02:19:20.737 -0700 | USERADMIN | N | N | Y | 0 | 1 | 0 | | User administrator can create and manage users and roles |
+-------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+-------+-----------------------------------------------------------------------------------+
user に grant して利用します。
GRANT ROLE orgadmin TO USER admin;
補足: Custom Role の設計例
OWNERSHIP
privilege が付与されます。
OWNERSHIP
privilege を持つ role を current role としている user は、その object に対する grant または revoke 操作が可能です。
<privileges>
… TO ROLE
OWNERSHIP
privilege を有します。OWNERSHIP
privilege は他の role に移動させることが可能です。すべての privilege は object に対応しています。一見すると object と関係のなさそうな CREATE ROLE
, CREATE USER
, CREATE WAREHOUSE
, CREATE DATABASE
という名称の privilege が存在しますが、これらに対応する object は ACCOUNT です。
SHOW GRANTS ON account;
(または SHOW GRANTS ON account XXX12345;)
+-------------------------------+--------------------------------+------------+----------+------------+---------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+--------------------------------+------------+----------+------------+---------------+--------------+------------|
| 2021-09-11 02:19:20.780 -0700 | APPLY MASKING POLICY | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.772 -0700 | CREATE ACCOUNT | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.787 -0700 | CREATE CREDENTIAL | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.784 -0700 | CREATE DATA EXCHANGE LISTING | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.773 -0700 | CREATE INTEGRATION | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.769 -0700 | CREATE SHARE | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.778 -0700 | EXECUTE MANAGED TASK | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.777 -0700 | EXECUTE TASK | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.771 -0700 | IMPORT SHARE | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.779 -0700 | MONITOR EXECUTION | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.782 -0700 | MONITOR SECURITY | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.769 -0700 | MONITOR USAGE | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.771 -0700 | OVERRIDE SHARE RESTRICTIONS | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:20.784 -0700 | PURCHASE DATA EXCHANGE LISTING | ACCOUNT | XXX12345 | ROLE | ACCOUNTADMIN | true | |
| 2021-09-11 02:19:21.917 -0700 | CREATE DATABASE | ACCOUNT | XXX12345 | ROLE | APPADMIN | true | |
| 2021-09-11 02:19:21.918 -0700 | CREATE INTEGRATION | ACCOUNT | XXX12345 | ROLE | APPADMIN | true | |
| 2021-09-11 02:19:21.916 -0700 | CREATE ROLE | ACCOUNT | XXX12345 | ROLE | APPADMIN | true | |
| 2021-09-11 02:19:21.915 -0700 | CREATE USER | ACCOUNT | XXX12345 | ROLE | APPADMIN | true | |
| 2021-09-11 02:19:20.766 -0700 | APPLY SESSION POLICY | ACCOUNT | XXX12345 | ROLE | SECURITYADMIN | true | |
| 2021-09-11 02:19:20.766 -0700 | MANAGE GRANTS | ACCOUNT | XXX12345 | ROLE | SECURITYADMIN | true | |
| 2021-09-11 02:19:20.768 -0700 | CREATE DATABASE | ACCOUNT | XXX12345 | ROLE | SYSADMIN | true | |
| 2021-09-11 02:19:20.767 -0700 | CREATE WAREHOUSE | ACCOUNT | XXX12345 | ROLE | SYSADMIN | true | |
| 2021-09-11 02:19:20.762 -0700 | CREATE ROLE | ACCOUNT | XXX12345 | ROLE | USERADMIN | true | |
| 2021-09-11 02:19:20.761 -0700 | CREATE USER | ACCOUNT | XXX12345 | ROLE | USERADMIN | true | |
+-------------------------------+--------------------------------+------------+----------+------------+---------------+--------------+------------+
補足: ACCOUNT object は特殊であり、MANAGE GRANTS
privilege を持つ SECURITYADMIN であっても、例えば CREATE DATABASE
privilege を grant することはできません。
SHOW GRANTS TO ROLE sysadmin;
→ privilege: CREATE DATABASE, granted_on: ACCOUNT
SHOW GRANTS TO ROLE securityadmin;
→ privilege: MANAGE GRANTS, granted_on: ACCOUNT
USE ROLE securityadmin;
CREATE ROLE myrole;
GRANT CREATE DATABASE ON ACCOUNT TO ROLE myrole;
→ Grant not executed: Insufficient privileges.
関連資料:
Access Control Privileges
GRANT <privileges>
… TO ROLE
MUST_CHANGE_PASSWORD
を true に設定することが強く推奨されます。MINS_TO_BYPASS_MFA
は MFA 設定済みの user について、一時的に MFA の利用を強制しないようにするための設定です。
初期パスワードの変更を強制する設定で user を create する例です。
CREATE USER myuser
PASSWORD = 'abc123'
DEFAULT_ROLE = SYSADMIN
MUST_CHANGE_PASSWORD = true;
GRANT ROLE SYSADMIN TO USER myuser;
パスワードを連続して 5 回間違えると 15 分間 lock されます。unlock したい場合は以下のコマンドを利用します。
ALTER USER myuser SET MINS_TO_UNLOCK = 0;
参考資料: