Snowflake
Architecture
- Snowflake Architecture
- Multi-Cluster Architecture
- Shared Disk and MPP Processing
- Virtual Warehouses
- Zero-Copy Cloning
Data Storage & Management
Data Loading & Integration
QueryProcessing & Optimization
- Query Caching
- Query Profile & Optimization
- Materialized Views
- Adaptive Query Execution
- Query Acceleration Service
SQL & Analytics Features
Performance Optimization
- Auto-Suspend & Auto-Resume
- Multi-Cluster Warehouses
- Pruning & Partitioning
- Storage Optimization
- Result Set Reuse
Security & Access Control
❄️ Snowflake Role-Based Access Control (RBAC) – Managing Permissions via User Roles
In any enterprise data platform, data security and access management are critical. You don’t want every user to access everything — you need controlled access based on roles and responsibilities.
That’s where Role-Based Access Control (RBAC) in Snowflake comes in.
RBAC in Snowflake allows administrators to grant and manage privileges to roles, and then assign those roles to users. This design ensures:
- Centralized management of permissions,
- Reduced human error, and
- Better security compliance.
In short:
Users don’t own permissions — roles do.
❄️ What is Role-Based Access Control (RBAC) in Snowflake?
RBAC is a security model that restricts access based on the roles assigned to users rather than directly assigning privileges to individual users.
In Snowflake:
- Privileges (permissions) are granted to roles.
- Roles are then granted to users or other roles.
This hierarchy creates a role graph that defines who can access what.
⚙️ Snowflake RBAC Components
Component | Description |
---|---|
User | Represents a person or service account. |
Role | A collection of privileges. |
Privilege | A specific permission, like SELECT or CREATE TABLE. |
Object | A database entity (table, schema, warehouse, etc.) |
Grant | The act of assigning a privilege to a role or user. |
🧩 ** Snowflake RBAC Model**
✅ Key Idea: RBAC separates “who” (users) from “what” (permissions), with roles acting as the bridge.
🧠 How RBAC Works in Snowflake
- Create a Role → Define a job function (e.g.,
ANALYST_ROLE
). - Grant Privileges → Assign permissions (e.g.,
SELECT
on schema). - Assign Role to User → Give users the appropriate roles.
- Activate Role → The user switches roles using
USE ROLE
.
Snowflake automatically maintains a hierarchical structure — meaning a role can inherit privileges from another role.
🧩 Example 1 – Basic RBAC Setup
Let’s walk through a simple RBAC configuration.
-- Step 1: Create a new roleCREATE ROLE analyst_role;
-- Step 2: Grant usage and select privilegeGRANT USAGE ON DATABASE sales_db TO ROLE analyst_role;GRANT USAGE ON SCHEMA sales_db.public TO ROLE analyst_role;GRANT SELECT ON ALL TABLES IN SCHEMA sales_db.public TO ROLE analyst_role;
-- Step 3: Assign role to userGRANT ROLE analyst_role TO USER john_doe;
-- Step 4: User activates the roleUSE ROLE analyst_role;
-- Step 5: Query the tableSELECT * FROM sales_db.public.orders;
✅ Result:
john_doe
can now query tables in the sales_db.public
schema but cannot modify them.
🧩 Example 2 – Role Hierarchies and Inheritance
Snowflake allows roles to inherit privileges from other roles, forming a role hierarchy.
-- Create base rolesCREATE ROLE reader_role;CREATE ROLE writer_role;
-- Assign privilegesGRANT SELECT ON DATABASE sales_db TO ROLE reader_role;GRANT INSERT, UPDATE ON DATABASE sales_db TO ROLE writer_role;
-- Create parent roleCREATE ROLE data_engineer_role;
-- Grant base roles to parentGRANT ROLE reader_role TO ROLE data_engineer_role;GRANT ROLE writer_role TO ROLE data_engineer_role;
-- Assign parent role to userGRANT ROLE data_engineer_role TO USER jane_doe;
✅ Result:
jane_doe
inherits privileges from both reader_role
and writer_role
.
No need to duplicate grants — it’s modular and scalable.
🧩 Example 3 – Managing Warehouse Access via Roles
RBAC can also control compute access.
-- Create role for computeCREATE ROLE compute_role;
-- Grant warehouse privilegesGRANT USAGE ON WAREHOUSE analytics_wh TO ROLE compute_role;
-- Grant role to analystsGRANT ROLE compute_role TO ROLE analyst_role;
✅ Result:
Analysts can now use the analytics_wh
warehouse without being able to alter it.
🧠 ** Role Inheritance Flow**
✅ Key Insight: Inherited roles simplify administration and align with real organizational structures.
⚙️ Built-in Roles in Snowflake
Snowflake provides a few default system roles out of the box:
Role | Description |
---|---|
ACCOUNTADMIN | Full control of the account. |
SECURITYADMIN | Manages users and roles. |
SYSADMIN | Manages databases, schemas, and warehouses. |
PUBLIC | Default role with minimal access. |
✅ Best practice:
Never use ACCOUNTADMIN
for daily operations. Use custom roles instead.
🧩 Example 4 – Creating a Secure Role Hierarchy
A real-world hierarchy might look like this:
-- Step 1: Create rolesCREATE ROLE finance_reader;CREATE ROLE finance_writer;CREATE ROLE finance_admin;
-- Step 2: Grant privilegesGRANT SELECT ON SCHEMA finance_db.public TO ROLE finance_reader;GRANT INSERT, UPDATE, DELETE ON SCHEMA finance_db.public TO ROLE finance_writer;GRANT ROLE finance_reader TO ROLE finance_admin;GRANT ROLE finance_writer TO ROLE finance_admin;
-- Step 3: Assign to userGRANT ROLE finance_admin TO USER alice;
-- Step 4: Alice uses her roleUSE ROLE finance_admin;
✅ Result:
Alice inherits both read and write permissions through finance_admin
.
🧠 Best Practices for Snowflake RBAC
Practice | Description |
---|---|
🧩 Least Privilege Principle | Grant only the permissions a user needs. |
🧠 Use Role Hierarchies | Combine similar roles under one parent role. |
🧰 Use Custom Roles | Avoid assigning system roles directly to users. |
🧾 Document Roles | Keep a catalog of roles and privileges. |
🔒 Regular Audits | Periodically review role grants and access. |
🧩 Example 5 – Auditing Role Assignments
You can check who has which roles using:
SHOW GRANTS OF ROLE analyst_role;
SHOW GRANTS TO USER john_doe;
Or analyze all grants:
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES;
✅ Purpose: This helps ensure compliance and prevents privilege creep.
💡 How to Remember RBAC Concepts for Exams and Interviews
Concept | Easy Memory Trick |
---|---|
RBAC = Role Before Access | Always assign access to roles, not users. |
User → Role → Privilege | “URP” → Remember this chain! |
Hierarchies | Think of it as family inheritance. |
Least Privilege | “Give only what’s needed.” |
Grant Flow | User inherits from role, not the other way. |
💡 Mnemonic:
“In Snowflake, roles own the keys — users just borrow them.”
🧠 ** How Access Flows**
📘 Why Learning RBAC Is Important
Reason | Description |
---|---|
🔒 Security | Prevents unauthorized access. |
🧠 Governance | Supports compliance with data regulations. |
💼 Scalability | Easy to onboard/offboard users in large teams. |
💰 Cost Optimization | Avoids accidental usage of high-credit warehouses. |
🎓 Exam Relevance | Frequently tested in SnowPro Core and Advanced exams. |
🧩 Best Practice | Foundation of secure Snowflake architecture. |
🧩 Example 6 – Combining RBAC with Object Ownership
Snowflake uses ownership-based control along with RBAC. Each object has an owner role, which can transfer ownership.
-- Check ownershipSHOW GRANTS ON TABLE sales_db.public.orders;
-- Transfer ownershipGRANT OWNERSHIP ON TABLE sales_db.public.orders TO ROLE data_engineer_role REVOKE CURRENT GRANTS;
✅ Result: Ownership control ensures that even with roles, object management remains secure.
🧮 RBAC vs DAC (Discretionary Access Control)
Feature | RBAC | DAC |
---|---|---|
Control Type | Centralized | Decentralized |
Assignment | Roles control privileges | Object owners grant privileges |
Scalability | Highly scalable | Difficult to manage in large orgs |
Snowflake Uses | RBAC (with Ownership for DAC-like features) | ❌ Not default |
🧠 Snowflake RBAC Interview Questions
- What is RBAC in Snowflake?
- How does Snowflake handle role inheritance?
- What’s the difference between
ACCOUNTADMIN
and custom roles? - How do you check which roles a user has?
- What’s the least privilege principle?
- Can a user have multiple roles in Snowflake?
- What’s the command to switch roles in Snowflake?
✅ Quick Recall:
RBAC = Roles Build Access Control.
🧩 Example 7 – Switching Between Roles
A user can switch roles during a session:
USE ROLE analyst_role;SELECT CURRENT_ROLE();
USE ROLE sysadmin;SELECT CURRENT_ROLE();
✅ Benefit: Allows a single user to perform different tasks securely based on their active role.
🧠 ** Multi-Role User Scenario**
✅ Result: Mike can switch between analytical and engineering tasks without compromising access controls.
💡 Real-World Use Case
Imagine a company with the following setup:
- Analysts need read-only access to data.
- Data Engineers need to build and modify tables.
- Finance Team needs access to financial data only.
With RBAC:
- You create
analyst_role
,data_engineer_role
,finance_role
. - Grant each role specific privileges.
- Assign roles to users.
- Auditing and compliance become effortless.
✅ Impact:
- Simplified access management.
- Enhanced security.
- Quick onboarding/offboarding.
🧠 Memory Flowchart
💡 Simple Memory Tip:
“CRAGU” – Create → Role → Assign → Grant → Use.
🧾 Common Mistakes to Avoid
Mistake | Why It’s Wrong |
---|---|
Directly granting privileges to users | Hard to manage and audit. |
Using ACCOUNTADMIN for daily work | Risky — over-privileged. |
Not revoking unused roles | Security vulnerability. |
Forgetting role hierarchy | Leads to privilege confusion. |
No documentation | Chaos in large teams. |
🧩 Example 8 – Revoking Privileges
When users leave or change teams, revoke roles easily:
REVOKE ROLE analyst_role FROM USER john_doe;
✅ Result: Immediate removal of access without affecting others.
🧠 Best Practice Diagram
🧩 Example 9 – Role and Privilege Reporting
To view complete role relationships:
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES;SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_USERS;
✅ Result: Provides a full map of role-to-user and privilege-to-role assignments.
🧠 Why RBAC Matters for Data Engineers
Benefit | Explanation |
---|---|
🧠 Control | Centralized access management for all data layers. |
🧩 Compliance | Meets GDPR, HIPAA, and SOC 2 standards. |
⚙️ Automation | Easily managed via Terraform or DBT scripts. |
📈 Scalability | Ideal for enterprise-grade governance. |
🏁 Conclusion
Snowflake RBAC is the cornerstone of secure and scalable access management. By assigning privileges to roles — not directly to users — you ensure:
- Simplified administration,
- Stronger security, and
- Streamlined compliance.
For any data engineer, mastering RBAC means mastering the backbone of Snowflake governance.
🌟 Final Thought
“In Snowflake, access belongs to roles, not people — that’s the secret to security and scalability.”