System-defined roles (ACCOUNTADMIN, SYSADMIN, etc.) in Snowflake - Time & Space Complexity
We want to understand how the time to check or assign system-defined roles changes as the number of users or roles grows.
How does the system handle these roles efficiently as more users or permissions are involved?
Analyze the time complexity of querying role grants for users.
-- List roles granted to a user
SHOW GRANTS TO USER some_user;
-- List users granted a system-defined role
SHOW GRANTS OF ROLE SYSADMIN;
-- Assign a system-defined role to a user
GRANT ROLE SYSADMIN TO USER some_user;
This sequence shows checking and assigning system-defined roles to users.
Look at the main operations that happen repeatedly when managing roles.
- Primary operation: Checking role grants involves scanning role assignments.
- How many times: Once per user or role queried, but can involve multiple role entries.
As the number of users or roles grows, the system checks more entries.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 users/roles | About 10 role checks |
| 100 users/roles | About 100 role checks |
| 1000 users/roles | About 1000 role checks |
Pattern observation: The number of checks grows roughly in direct proportion to the number of users or roles involved.
Time Complexity: O(n)
This means the time to check or assign system-defined roles grows linearly with the number of users or roles.
[X] Wrong: "Assigning a system-defined role is instant no matter how many users exist."
[OK] Correct: Even though the command is simple, the system must update and verify role assignments, which takes longer as more users or roles exist.
Understanding how role management scales helps you design secure and efficient access controls in cloud systems.
"What if we cached role assignments? How would the time complexity change when checking roles for many users?"
Practice
Solution
Step 1: Understand role privileges
ACCOUNTADMIN is designed to have full control over the Snowflake account, including all objects and user management.Step 2: Compare with other roles
SYSADMIN manages data objects, SECURITYADMIN manages users and roles, and PUBLIC has minimal default privileges.Final Answer:
ACCOUNTADMIN -> Option AQuick Check:
Full account control = ACCOUNTADMIN [OK]
- Confusing SYSADMIN with full control
- Thinking SECURITYADMIN manages data objects
- Assuming PUBLIC has admin privileges
Solution
Step 1: Recall Snowflake role switching syntax
The correct command to switch roles isUSE ROLE <role_name>;.Step 2: Verify options
Only USE ROLE SYSADMIN; matches the correct syntax exactly.Final Answer:
USE ROLE SYSADMIN; -> Option CQuick Check:
Switch role command = USE ROLE [OK]
- Using SET ROLE instead of USE ROLE
- Adding extra words like TO or SWITCH
- Missing semicolon at the end
USE ROLE SECURITYADMIN; CREATE USER test_user PASSWORD='Pass1234'; USE ROLE SYSADMIN; CREATE TABLE test_table(id INT);Which statement is true about the created objects?
Solution
Step 1: Analyze role privileges for user creation
SECURITYADMIN can create users, soCREATE USER test_usersucceeds.Step 2: Analyze role privileges for table creation
SYSADMIN manages data objects, soCREATE TABLE test_tablesucceeds.Final Answer:
Both test_user and test_table are created successfully. -> Option DQuick Check:
SECURITYADMIN creates users, SYSADMIN creates tables [OK]
- Assuming SYSADMIN can create users
- Assuming SECURITYADMIN can create tables
- Confusing role privileges
CREATE USER new_user PASSWORD='abc123'; while using the SYSADMIN role and get an error. What is the most likely cause?Solution
Step 1: Check role privileges for user creation
Only SECURITYADMIN or ACCOUNTADMIN can create users; SYSADMIN lacks this privilege.Step 2: Consider other options
Password complexity or syntax errors would cause different error messages; user existence would be a different error.Final Answer:
SYSADMIN role does not have privileges to create users. -> Option BQuick Check:
User creation requires SECURITYADMIN or ACCOUNTADMIN [OK]
- Blaming password complexity without checking error
- Assuming SYSADMIN can create users
- Ignoring role privilege boundaries
Solution
Step 1: Understand role responsibilities
SECURITYADMIN manages users and roles; SYSADMIN manages data objects; ACCOUNTADMIN has full control.Step 2: Match roles to admin tasks
Assign SECURITYADMIN to the admin handling users, SYSADMIN to the admin handling data, and keep ACCOUNTADMIN yourself for full control.Final Answer:
Assign SECURITYADMIN to user1, SYSADMIN to user2, ACCOUNTADMIN to yourself. -> Option AQuick Check:
Delegate roles by responsibility, keep ACCOUNTADMIN for full control [OK]
- Giving ACCOUNTADMIN to others unnecessarily
- Assigning PUBLIC role for admin tasks
- Mixing up role responsibilities
Ready to prove it?
Pass the test and this pattern moves unknown
