What you will be able to do
- Explain when to create a custom role and who is allowed to create one
- Build a role hierarchy under SYSADMIN and predict which roles inherit which privileges
- Analyse what granting, revoking and transferring ownership of roles does to inherited access
- Grant the full chain of privileges (warehouse, database, schema, object) a role needs to query a table
1.Why and how to create custom roles
System-defined roles exist to manage the account. They aren't meant to carry access to business data. Snowflake advises against adding privileges to them. Its reason is that account-management privileges and entity-specific privileges shouldn't be mixed in one role. If a system role needs extra access, grant the privileges to a custom role and then grant that custom role to the system role.
Custom roles are also how you apply least privilege. Snowflake recommends creating custom roles that match your organisation's business functions, so that each one allows SQL actions on a narrow set of objects. USERADMIN, any role above it, or any role granted CREATE ROLE can create account-level custom roles. A database owner can create custom database roles.
A new role starts out isolated. It isn't assigned to any user and isn't granted to any other role. A role that nobody holds does nothing, so creating it is the first of four steps.
Checkpoint 1 of 5· Put it in order
Put Snowflake's custom role workflow in order
- 1.Grant the role to another role to create or add to a role hierarchy
- 2.Grant the role to the users who need those privileges
- 3.Grant a set of privileges to the role
- 4.Create a custom role
The configuration guide lists these four steps in this order. The last one is optional but highly recommended.
“Grant the role to another role to create or add to a role hierarchy.”Source: docs.snowflake.com
2.Role inheritance when granting and revoking
Granting one role to another builds a hierarchy. Privileges flow upward: every role above a role inherits that role's privileges. If r1 is granted to a parent role, and the parent is granted to SYSADMIN, then SYSADMIN holds everything r1 holds. That includes ownership. If a custom role owns objects, the roles above it own those objects indirectly and can manage them.
GRANT ROLE r1 TO ROLE sysadmin WITH GRANT OPTION;WITH GRANT OPTION does not control inheritance. A parent inherits the role with or without it. The option only lets the parent grant the role on to other roles.
A custom role that isn't connected to SYSADMIN leaves a gap. By default, not even ACCOUNTADMIN can modify or drop objects created by that role. Only roles with MANAGE GRANTS, which is SECURITYADMIN by default, can see those objects and change their grants. This is why the recommended design puts the top-most custom role under SYSADMIN.
Inheritance follows grants, not ownership. Owning a role lets you manage that role, but it doesn't give you the role's privileges. The only way to inherit them is to have the role granted to yours.
The same rule tells you what a revoke does. Parents get their privileges *through* the child, so removing a privilege from a child role also removes it from every role above that got it only through the child. Revoking the role grant itself, with REVOKE ROLE, cuts the whole branch off from the parent. A grant to PUBLIC needs particular care, because PUBLIC is automatically granted to every user and role. A privilege granted to PUBLIC reaches everyone until it is revoked from PUBLIC. Granting it to a narrower role afterwards doesn't remove that wide access. There is one limit on revoking: privileges that Snowflake granted to the system-defined roles can't be revoked. SECURITYADMIN can revoke any other grant through MANAGE GRANTS.
Checkpoint 2 of 5· Exam question
A company has 400 analysts who rotate between five business teams every few months. Security wants the lowest ongoing administrative effort and a clear audit trail when someone changes teams. Which design best meets this requirement?
Correct answer: D — Grant privileges to one role per team, then grant each role to its users and move people by revoking and granting the role.
- A. Incorrect. Per-user grants multiply the number of grants to maintain with every object and every team move, which is the overhead RBAC is designed to remove.
- B. Incorrect. One catch-all role breaks least privilege, and masking policies only hide column values; they do not stop access to tables the role can already read.
- C. Incorrect. Handing ownership to individuals scatters control across hundreds of users, and ownership moves with the person instead of with the team.
- D. Correct. Team roles hold the privileges once, and moving a person is a single GRANT ROLE and REVOKE ROLE pair, which is also easy to audit through grant history.
Checkpoint 3 of 5· Check yourself
Custom role ETL_RW creates several tables. It was never granted to any other role. Which role can modify or drop those tables by default?
Inheritance only flows through role grants. Until ETL_RW sits below ACCOUNTADMIN or SYSADMIN, neither of them holds its ownership of the tables.
“By default, not even the ACCOUNTADMIN role can modify or drop objects created by a custom role.”Source: docs.snowflake.com
3.Granting access to objects inside a database
Database objects sit inside containers: tables, views, functions and stages belong to a schema, and the schema belongs to a database. A privilege on the object alone isn't enough. The role also needs USAGE, or another privilege, on both the database and the schema that contain it. To run a query, it also needs USAGE on a warehouse for compute.
The documentation shows this with a read-only role. The role can query every table in d1.s1 but can't change data, create objects or drop tables:
GRANT USAGE
ON DATABASE d1
TO ROLE read_only;
GRANT USAGE
ON SCHEMA d1.s1
TO ROLE read_only;
GRANT SELECT
ON ALL TABLES IN SCHEMA d1.s1
TO ROLE read_only;
GRANT USAGE
ON WAREHOUSE w1
TO ROLE read_only;ON ALL TABLES only covers tables that exist now. Tables created later need a future grant:
GRANT SELECT ON FUTURE TABLES IN SCHEMA d1.s1 TO ROLE read_only;Checkpoint 4 of 5· Fill the gap
The read_only role already has SELECT on the tables and USAGE on the database and warehouse, but its queries still fail. Which privilege completes this grant?
GRANT ?
ON SCHEMA d1.s1
TO ROLE read_only;To reach an object, a role needs USAGE (or another privilege) on the schema that contains it as well as on the database. SELECT goes on the tables themselves.
Source: docs.snowflake.comSources3
4.Access roles and functional roles
Combining these grants with inheritance gives the pattern Snowflake recommends for matching access to business functions. Grant privileges on database objects and account objects, such as warehouses, to access roles. Then grant the access roles to functional roles that match job functions. A higher-level functional role can be the parent of lower-level ones when its job should include theirs. Finally, grant the top functional roles to SYSADMIN.
Take the documentation's example. An account has a fin database for payroll and an hr database for employee data. Accountants need read-write access to fin and read-only access to hr. Analysts need read-only access to both. You would build three access roles: fin read-write, fin read-only and hr read-only. Then you would grant the right combination to an accountant role and an analyst role. When a requirement changes, you change one grant between roles instead of re-granting privileges on many objects.
Checkpoint 5 of 5· Check yourself
How does Snowflake technically distinguish an access role from a functional role?
Both are ordinary roles. The split is a design convention for grouping privileges and assigning them to groups of users.
“There is no technical difference between an object access role and a functional role in Snowflake.”Source: docs.snowflake.com
Sources3
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.The role that owns another role automatically gets that role's privileges.Why is that wrong?
Owning a role only gives control over the role itself. To inherit its privileges, the role must be granted to yours as part of a role hierarchy.
Covered in Role inheritance when granting and revoking
2.GRANT SELECT ON ALL TABLES IN SCHEMA also covers tables created later.Why is that wrong?
It only covers tables that already exist. New tables need a separate GRANT ... ON FUTURE TABLES.
Covered in Granting access to objects inside a database
Practise it for real
Create a read-only custom role for schema d1.s1, connect it to the role hierarchy, and assign it to a user.
1.As USERADMIN, run CREATE ROLE read_only;
Why: USERADMIN, or a role with CREATE ROLE, can create custom roles.
You should see: The role exists, but no user or role holds it yet.
2.Grant USAGE on database d1, USAGE on schema d1.s1, SELECT on all tables in d1.s1, and USAGE on warehouse w1 to read_only.
Why: A query needs privileges on the database and schema that contain the table, plus a warehouse for compute.
You should see: SHOW GRANTS ON SCHEMA d1.s1 lists USAGE granted to READ_ONLY.
3.Run GRANT SELECT ON FUTURE TABLES IN SCHEMA d1.s1 TO ROLE read_only;
Why: ON ALL TABLES only covers tables that already exist.
You should see: Tables created later in d1.s1 are readable by read_only.
4.Grant read_only to SYSADMIN, then grant it to a user and set it as their default role.
Why: Connecting the role to SYSADMIN lets system administrators manage it, and the user grant puts it to use.
You should see: The user can query d1.s1 tables but cannot insert, create or drop objects.
Stuck? Get a nudge
If the user's query fails, check the container grants first: both the database and the schema need USAGE.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“we recommend creating custom roles that align with the business functions in your organization”
↩︎ Why and how to create custom roles“A grant that includes WITH GRANT OPTION also lets the recipient role grant that role to other roles.”
↩︎ Role inheritance when granting and revoking“grants the SELECT privilege on all existing tables only.”
↩︎ Exam trap 2“Grant the role to another role to create or add to a role hierarchy.”
↩︎ Checkpoint - 2.
“Although additional privileges can be granted to the system-defined roles, it is not recommended.”
↩︎ Why and how to create custom roles“By default, a newly-created role is not assigned to any user, nor granted to any other role.”
↩︎ Why and how to create custom roles“The privileges associated with a role are inherited by any roles above that role in the hierarchy.”
↩︎ Role inheritance when granting and revoking“if a custom role is not assigned to SYSADMIN through a role hierarchy, the system administrators cannot manage the objects owned by the role.”
↩︎ Role inheritance when granting and revoking“In addition, the privileges granted to these roles by Snowflake cannot be revoked.”
↩︎ Role inheritance when granting and revoking“Is granted the MANAGE GRANTS security privilege to be able to modify any grant, including revoking it.”
↩︎ Role inheritance when granting and revoking“Privilege inheritance is only possible within a role hierarchy.”
↩︎ Exam trap 1“A role owner (the role that has the OWNERSHIP privilege on the role) does not inherit the privileges of the owned role.”
↩︎ Prediction - 3.
“users must be granted USAGE or any other privilege on the container database and schema.”
↩︎ Granting access to objects inside a database“Grant access roles to functional roles to create a role hierarchy.”
↩︎ Access roles and functional roles“By default, not even the ACCOUNTADMIN role can modify or drop objects created by a custom role.”
↩︎ Checkpoint“There is no technical difference between an object access role and a functional role in Snowflake.”
↩︎ Checkpoint