Module 17 · Lesson 12 of 12Detailed study · about 43 min

Snowflake Access Control Lab: Test RBAC, Denials and Revocation

Create an isolated RBAC setup for analysts, engineers and developers. Reproduce a missing schema grant, test allowed and denied actions, revoke access and verify a secure client session.

Agree the access rules before creating any roles

Maple Market wants Ana to read two orders, Ravi to load orders, and Dev to create tables in a separate sandbox. Mira approves who may read production reporting data. Write the two expected order rows down first. Order 101 has an amount of 40.00 and order 102 has 60.00. The live exercise uses fabricated data only.

Confirm that M17_ACCESS_LAB and the three role names are unused. Have the identity owner provision three isolated test users using the existing approved strong authentication path. In the commands, M17_ANALYST_USER, M17_ENGINEER_USER and M17_DEVELOPER_USER stand for those Snowflake usernames. Have the warehouse owner provide M17_LAB_WH or agree the replacement name before starting. Confirm no unexpected direct, inherited, secondary or PUBLIC privileges apply to the test objects.

Use separate connections for administration and each test user. Run each expected-denial statement by itself and note the approximate error class. A denied statement can stop a batch, and error wording can vary. Use an existing approved client profile and treat all output as account data.

Decisions to prove in the lab
Test identityAllowedDenied
AnalystRead the approved report after the missing grant is fixedInsert into the reporting table
EngineerLoad ordersRead orders through the write-only role
DeveloperCreate a table in DEV_SANDBOXRead reporting orders

Reproduce the failure and change exactly one grant

Start with the model. Then, for approved live practice, create the account roles and the schema and table. Give the database role SELECT on the report. Grant it to the analyst account role, which gets implicit database USAGE. Leave out schema USAGE for the first test. In the analyst connection, select M17_ANALYST with secondary roles inactive. The reporting SELECT should fail even though SHOW GRANTS shows the table grant.

The schema owner adds USAGE on REPORTING to REPORT_READER. Run the same statement again from the analyst identity. With no other change, it should return 101 for 40.00 and 102 for 60.00. Next show that the engineer can insert and the developer can create inside the sandbox. Run the denial tests in the stated sessions.

Prove the connection and remove the intended access path

From the approved lab network, use an existing secure connection profile for the analyst. An SSO profile for a supported client can open the organization’s browser sign-in. Use your approved MFA flow and inspect CURRENT_USER and CURRENT_ROLE. Keep connection secrets outside the worksheet and evidence log. If the client cannot connect, collect the error and review the network or authentication lesson before editing grants.

Use the schema owner to revoke SELECT from REPORT_READER, then repeat the analyst query. It should fail. If it succeeds, look for an alternate grant path before celebrating the earlier result. Capture current grants, role context and the allowed and denied actions. Remove the dedicated lab database and roles only after the lab owner confirms the names and tests are complete. Keep the supplied warehouse and have the identity owner retire temporary users or memberships.

Predict the five checkpoints before running the lab

This capstone checks access from three actual test identities. The RBAC guide builds the role model in one worksheet. Here each job uses its own session, which tests identity assignment and effective privileges as a separate deployment check. Run the existing numbered SQL blocks in order. Use the same exact analyst statement at each checkpoint.

Expected evidence in a completed rollout
CheckpointWho testsExpected result
Before the repairAnalystSELECT denied although table SELECT exists.
After schema USAGEAnalystOrders 101 and 102.
Rollback of sample loadEngineer then analystOne insert acknowledged. After rollback the report still contains only 101 and 102.
Development boundaryDeveloperDEV_CHECK created. The report read fails.
After SELECT is revokedAnalystThe original report read fails again.

Check the transaction and document a safe release decision

After the engineer rollback and before revoking SELECT, rerun this summary in the isolated analyst session. The table should still contain two rows with total 100. Order 103 should be absent. If it remains, stop and check whether the INSERT and ROLLBACK ran in the same connection and transaction. Close the test sessions after verification.

Record the query ID, identity, role, expected outcome and observed outcome for each checkpoint. If a prohibited query works, check PUBLIC, direct user grants, inherited membership and which object the query selected. Repair only the proven source of extra access. Keep the grant evidence in the deployment ticket and pair revocation with the same original read.

SQL · configuration template
USE ROLE M17_ANALYST;
USE SECONDARY ROLES NONE;
USE WAREHOUSE M17_LAB_WH;
SELECT COUNT(*) AS order_count, SUM(amount) AS sales,
       SUM(IFF(order_id = 103, 1, 0)) AS test_orders
FROM M17_ACCESS_LAB.REPORTING.ORDERS;

Learn role-based access control and role design →

Explain the design in an interview

Name the rule, then explain how you would prove it.

How do you prove a security deployment is ready?

I test a permitted read and a forbidden action in each actual job identity. I record the same query before and after the targeted grant or revocation so there is a clear cause for the difference.

What would you do if the developer’s forbidden SELECT succeeded?

I would stop release, capture the active role and full object name, then trace inherited or PUBLIC access and any direct grant. I would correct the actual path and rerun the whole affected test.

Words used in this lesson
Test identity
A scoped, approved account user used to verify a role’s real behavior.
Positive check
An operation the design expects to succeed.
Negative check
An operation the design expects to be denied.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Snowflake Access Control Lab: Test RBAC, Denials and Revocation

Analyst session
SELECT exists
Missing schema USAGE

Observe the first denial

The analyst can sign in and holds SELECT, but cannot reach the reporting schema.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Observe the first denial

    The analyst can sign in and holds SELECT, but cannot reach the reporting schema.

    Analyst session → SELECT exists → Missing schema USAGE

  2. Change one grant and retest

    Add schema USAGE. The analyst reads two rows. The engineer writes and the developer creates only where authorized.

    Schema USAGE granted → Two report rows → Denial checks

  3. Prove revocation

    Remove the lab’s table grant and verify the same analyst read is denied again.

    Revoke table SELECT → Same analyst session → Read denied

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Read the fixture and expected results with no account. For live practice, use an approved disposable account, a dedicated lab warehouse and pre-provisioned test identities. Use the exact lab names only after the administrator confirms they are unused. The role and object statements create and remove lab resources. A live run can incur usage.

Step 1 · Check the fictional access test plan

SQL · runnable example
WITH tests AS (
  SELECT column1 AS trial, column2 AS role_name, column3 AS operation,
         column4 AS should_succeed
  FROM VALUES ('1 Before schema grant', 'ANALYST_BEFORE', 'READ', FALSE),
              ('2 After schema grant', 'ANALYST', 'READ', TRUE),
              ('3 Analyst insert', 'ANALYST', 'INSERT', FALSE),
              ('4 Engineer insert', 'ENGINEER', 'INSERT', TRUE),
              ('5 Engineer read', 'ENGINEER', 'READ', FALSE),
              ('6 Developer creates table', 'DEVELOPER', 'CREATE', TRUE),
              ('7 Developer reads reporting', 'DEVELOPER', 'READ', FALSE),
              ('8 After SELECT revoke', 'ANALYST_REVOKED', 'READ', FALSE)
),
requirements AS (
  SELECT column1 AS operation, column2 AS privilege
  FROM VALUES ('READ', 'DB_USAGE'), ('READ', 'REPORT_USAGE'),
              ('READ', 'ORDER_SELECT'), ('INSERT', 'DB_USAGE'),
              ('INSERT', 'REPORT_USAGE'), ('INSERT', 'ORDER_INSERT'),
              ('CREATE', 'DB_USAGE'), ('CREATE', 'DEV_USAGE'),
              ('CREATE', 'DEV_CREATE')
),
effective_grants AS (
  SELECT column1 AS role_name, column2 AS privilege
  FROM VALUES ('ANALYST_BEFORE', 'DB_USAGE'), ('ANALYST_BEFORE', 'ORDER_SELECT'),
              ('ANALYST', 'DB_USAGE'), ('ANALYST', 'REPORT_USAGE'),
              ('ANALYST', 'ORDER_SELECT'),
              ('ENGINEER', 'DB_USAGE'), ('ENGINEER', 'REPORT_USAGE'),
              ('ENGINEER', 'ORDER_INSERT'),
              ('DEVELOPER', 'DB_USAGE'), ('DEVELOPER', 'DEV_USAGE'),
              ('DEVELOPER', 'DEV_CREATE'),
              ('ANALYST_REVOKED', 'DB_USAGE'), ('ANALYST_REVOKED', 'REPORT_USAGE')
),
outcomes AS (
  SELECT t.trial, t.should_succeed,
         COUNT(DISTINCT g.privilege) = COUNT(DISTINCT r.privilege) AS can_act
  FROM tests AS t
  JOIN requirements AS r ON r.operation = t.operation
  LEFT JOIN effective_grants AS g
    ON g.role_name = t.role_name AND g.privilege = r.privilege
  GROUP BY t.trial, t.should_succeed
)
SELECT trial,
       CASE WHEN can_act THEN 'Allowed' ELSE 'Denied' END AS modeled_result,
       CASE WHEN can_act = should_succeed THEN 'Matches plan'
            ELSE 'Investigate' END AS check_result
FROM outcomes
ORDER BY trial;

What to expect and why

The fixture assumes lab warehouse access and uses flattened effective data grants. Each required privilege has one row. A LEFT JOIN keeps a requirement visible when no grant matches it. COUNT compares the matched privileges with all requirements. Test an unintended developer access path by adding REPORT_USAGE and ORDER_SELECT for DEVELOPER. The developer read should now show Allowed and Investigate.

Expected result for the supplied input (not live output)
TRIALMODELED_RESULTCHECK_RESULT
1 Before schema grantDeniedMatches plan
2 After schema grantAllowedMatches plan
3 Analyst insertDeniedMatches plan
4 Engineer insertAllowedMatches plan
5 Engineer readDeniedMatches plan
6 Developer creates tableAllowedMatches plan
7 Developer reads reportingDeniedMatches plan
8 After SELECT revokeDeniedMatches plan

Step 2 · Create roles and assign the approved test users

SQL · runnable example
USE ROLE USERADMIN;

CREATE ROLE M17_ANALYST;
CREATE ROLE M17_ENG;
CREATE ROLE M17_DEV;

GRANT ROLE M17_ANALYST TO ROLE SYSADMIN;
GRANT ROLE M17_ENG TO ROLE SYSADMIN;
GRANT ROLE M17_DEV TO ROLE SYSADMIN;

GRANT ROLE M17_ANALYST TO USER M17_ANALYST_USER;
GRANT ROLE M17_ENG TO USER M17_ENGINEER_USER;
GRANT ROLE M17_DEV TO USER M17_DEVELOPER_USER;

What to expect and why

The authorized role administrator runs this once with unused names and pre-provisioned identities. Each user receives one lab job role. A delegated role can perform the same actions if it holds the required create and grant authority.

Step 3 · Set up the reporting and development boundaries

SQL · runnable example
USE ROLE SYSADMIN;
USE WAREHOUSE M17_LAB_WH;

CREATE DATABASE M17_ACCESS_LAB;
CREATE SCHEMA M17_ACCESS_LAB.REPORTING WITH MANAGED ACCESS;
CREATE SCHEMA M17_ACCESS_LAB.DEV_SANDBOX;

CREATE TABLE M17_ACCESS_LAB.REPORTING.ORDERS (
  order_id NUMBER NOT NULL,
  amount NUMBER(10, 2) NOT NULL
);

INSERT INTO M17_ACCESS_LAB.REPORTING.ORDERS (order_id, amount)
VALUES (101, 40.00), (102, 60.00);

CREATE DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;

GRANT SELECT ON TABLE M17_ACCESS_LAB.REPORTING.ORDERS
  TO DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;
GRANT DATABASE ROLE M17_ACCESS_LAB.REPORT_READER TO ROLE M17_ANALYST;

GRANT USAGE ON DATABASE M17_ACCESS_LAB TO ROLE M17_ENG;
GRANT USAGE ON SCHEMA M17_ACCESS_LAB.REPORTING TO ROLE M17_ENG;
GRANT INSERT ON TABLE M17_ACCESS_LAB.REPORTING.ORDERS TO ROLE M17_ENG;

GRANT USAGE ON DATABASE M17_ACCESS_LAB TO ROLE M17_DEV;
GRANT USAGE, CREATE TABLE ON SCHEMA M17_ACCESS_LAB.DEV_SANDBOX TO ROLE M17_DEV;

What to expect and why

SYSADMIN must be authorized to use the approved warehouse and owns the new lab objects. The analyst account role receives implicit database USAGE through REPORT_READER. REPORTING schema USAGE is deliberately absent. Warehouse usage is a separate grant in the next step.

Step 4 · Give the job roles access to lab compute

SQL · runnable example
GRANT USAGE ON WAREHOUSE M17_LAB_WH TO ROLE M17_ANALYST;
GRANT USAGE ON WAREHOUSE M17_LAB_WH TO ROLE M17_ENG;
GRANT USAGE ON WAREHOUSE M17_LAB_WH TO ROLE M17_DEV;

What to expect and why

Run as the approved lab warehouse owner or another grant-authorized role. The three job roles can use this warehouse. Each role still needs the correct object privileges for its own SQL.

Step 5 · Run the analyst read before and after the schema grant

SQL · runnable example
USE ROLE M17_ANALYST;
USE SECONDARY ROLES NONE;
USE WAREHOUSE M17_LAB_WH;

SELECT order_id, amount
FROM M17_ACCESS_LAB.REPORTING.ORDERS
ORDER BY order_id;

What to expect and why

With the analyst test identity, the first read should fail because REPORTING.USAGE is missing. If it succeeds, stop and audit alternate permissions. After the administrator runs Step 6, run the same SELECT in this connection. The rows shown are expected after the correction.

Expected result for the supplied input (not live output)
ORDER_IDAMOUNT
10140.00
10260.00

Step 6 · Correct the missing schema grant

SQL · runnable example
USE ROLE SYSADMIN;

GRANT USAGE ON SCHEMA M17_ACCESS_LAB.REPORTING
  TO DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;

SHOW GRANTS TO DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;

What to expect and why

Use the separate administrator connection. Confirm the managed schema owner has granted USAGE. Return to the analyst connection and repeat the SELECT in Step 5. It should now return two rows.

Step 7 · Compare analyst and engineer writes, then test development

SQL · excerpt
-- In the analyst test session, run these one at a time.
BEGIN TRANSACTION;
INSERT INTO M17_ACCESS_LAB.REPORTING.ORDERS VALUES (103, 25.00);
ROLLBACK;

-- In the engineer test session, use these commands in order.
USE ROLE M17_ENG;
USE SECONDARY ROLES NONE;
USE WAREHOUSE M17_LAB_WH;
BEGIN TRANSACTION;
INSERT INTO M17_ACCESS_LAB.REPORTING.ORDERS VALUES (103, 25.00);
ROLLBACK;

-- Separately in the engineer test session, expect a denial.
SELECT order_id FROM M17_ACCESS_LAB.REPORTING.ORDERS ORDER BY order_id;

-- In the developer test session, switch role and warehouse before trying each action.
USE ROLE M17_DEV;
USE SECONDARY ROLES NONE;
USE WAREHOUSE M17_LAB_WH;
CREATE TABLE M17_ACCESS_LAB.DEV_SANDBOX.DEV_CHECK (id NUMBER);
SELECT order_id FROM M17_ACCESS_LAB.REPORTING.ORDERS ORDER BY order_id;

What to expect and why

The analyst INSERT should fail and the engineer INSERT should report one row inserted. Execute ROLLBACK in each session even if the preceding outcome differs from the plan. The engineer SELECT is denied. The developer can create DEV_CHECK and the reporting read is denied.

Step 8a · Test the approved CLI connection profile

Terminal · configuration template
snow connection test --connection <approved_lab_profile>

What to expect and why

Use a profile prepared by the identity owner. If it uses browser-based SSO, a supported local CLI profile uses the EXTERNALBROWSER authenticator. Complete the approved browser sign-in, then verify the account and user reported by the client. Run the next SQL in that same approved connection context.

Step 8b · Verify the approved client session

SQL · runnable example
SELECT CURRENT_USER() AS connected_user,
       CURRENT_ROLE() AS primary_role,
       CURRENT_SECONDARY_ROLES() AS secondary_roles,
       CURRENT_WAREHOUSE() AS warehouse_name;

What to expect and why

Use the analyst’s approved secure client profile, then select M17_ANALYST and M17_LAB_WH and run the session checks from Step 5. Expect the analyst identity and role. Run the same permitted query from that client and verify the two rows. Compare the exact user and role fields with the worksheet test.

Step 9 · Revoke the report grant and retest

SQL · runnable example
USE ROLE SYSADMIN;

REVOKE SELECT ON TABLE M17_ACCESS_LAB.REPORTING.ORDERS
  FROM DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;

SHOW GRANTS TO DATABASE ROLE M17_ACCESS_LAB.REPORT_READER;

What to expect and why

The schema owner removes only table SELECT. Confirm that the explicit SELECT disappeared while schema USAGE remains. The database role relationship still supplies database USAGE. Run Step 5 again from the analyst test identity. It should fail.

Step 10 · Retire the disposable objects with their owners

SQL · excerpt
-- Only the approved disposable database and lab roles.
USE ROLE SYSADMIN;
DROP DATABASE M17_ACCESS_LAB;

USE ROLE USERADMIN;
DROP ROLE M17_ANALYST;
DROP ROLE M17_ENG;
DROP ROLE M17_DEV;

What to expect and why

Run after all tests and only once the lab owners confirm the exact resources created here. Dropping the database removes its contained lab objects and database role. The identity administrator reviews the temporary user memberships and handles test-identity retirement. Retain the supplied warehouse.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

What should happen after only table SELECT is revoked from the analyst’s one approved grant path?

Try it yourself

Add the two unintended developer reporting grants as described in Step 1. Then write the first two grant paths you would inspect in a real incident.

Compare your reasoning

The developer read shows Allowed and Investigate. Check M17_DEV’s grants and inherited roles, followed by direct user grants, active secondary roles and PUBLIC as applicable.

Connect this lesson to the learning path

Official sources and curriculum

Module 17 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab