Symptom
A dashboard or downstream job fails with Object 'ANALYTICS.MARTS.FCT_ORDERS' does not exist or not authorized shortly after the dbt job finishes. Someone runs GRANT SELECT ... by hand, it works, and the next dbt run breaks it again. A variant: access survives normal runs but disappears after dbt run --full-refresh, or after a new model is added.
The cause is almost always that dbt rebuilt the object and nothing told Snowflake to put the privileges back.
Why dbt drops privileges
| Materialization | What dbt runs | Effect on existing grants |
|---|---|---|
view | CREATE OR REPLACE VIEW every run | New object; manual grants are gone unless copied |
table | CREATE OR REPLACE TABLE ... AS SELECT every run | Same as view |
incremental | MERGE/INSERT into the existing table | Grants kept, except on --full-refresh or the first build |
snapshot | MERGE into the existing table | Grants kept unless the snapshot table is recreated |
A manual GRANT lives on one object version. When CREATE OR REPLACE builds a new one, that grant is gone. Three things can put privileges on the new object:
- dbt's
grantsconfig, applied after each build. copy_grants: true, which makes Snowflake copy privileges from the object being replaced.- Snowflake future grants on the schema or database, applied when the object is created.
If none of these are in place, the reader role loses access on every rebuild.
Checks
1. What grants are on the object now
SHOW GRANTS ON TABLE analytics.marts.fct_orders;
SHOW GRANTS ON VIEW analytics.marts.v_orders;
Note the created_on of the object (SHOW TABLES LIKE 'FCT_ORDERS' IN SCHEMA analytics.marts;). If it matches the last dbt run, the object was replaced.
2. What dbt actually ran
dbt writes the grant and revoke statements it issues to logs/dbt.log. Search for the model:
Select-String -Path .\logs\dbt.log -Pattern "fct_orders" | Select-String -Pattern "grant|revoke|create or replace"
Or check Snowflake directly for statements from the dbt user:
SELECT start_time, query_type, LEFT(query_text, 200) AS sql_text
FROM snowflake.account_usage.query_history
WHERE user_name = 'DBT_SVC'
AND start_time > DATEADD(hour, -24, CURRENT_TIMESTAMP())
AND (query_text ILIKE '%fct_orders%')
AND (query_type IN ('GRANT', 'REVOKE', 'CREATE_TABLE_AS_SELECT', 'CREATE_VIEW'))
ORDER BY start_time;
ACCOUNT_USAGE views have some latency. For the last few minutes, use TABLE(information_schema.query_history_by_user(...)) instead.
A REVOKE issued by dbt means the model has a grants config that doesn't include the role. dbt makes grants match the config exactly.
3. Future grants and managed access on the schema
SHOW FUTURE GRANTS IN SCHEMA analytics.marts;
SHOW FUTURE GRANTS IN DATABASE analytics;
SHOW SCHEMAS LIKE 'MARTS' IN DATABASE analytics; -- options column shows MANAGED ACCESS
Two traps here:
- If a schema has any future grants for an object type, Snowflake applies those and ignores the database-level future grants for that type. A database-level
GRANT SELECT ON FUTURE TABLEScan look correct and still never fire. - In a managed access schema, the object owner (the dbt role) can't grant privileges unless it owns the schema or has
MANAGE GRANTS. dbt's grant statements then fail with insufficient privileges.
Symptom → cause → fix
| Symptom | Cause | Fix |
|---|---|---|
| Access lost after every run on a view/table model | No grants config, no copy_grants, no future grants | Add grants config (below) |
Access lost only after --full-refresh | Incremental table recreated | grants config or copy_grants: true |
| Access lost on new models only | Future grants missing or overridden at schema level | Add schema-level future grants |
Manual grant removed by dbt (REVOKE in log) | Model's grants config omits that role | Add the role to config, or use +select to add instead of replace |
dbt run fails on GRANT | Managed access schema, dbt role isn't schema owner | Give dbt role ownership of the schema or MANAGE GRANTS, or let future grants do it |
| Grants to a database role not applied correctly | dbt grants fully supports account roles only on Snowflake | Grant via hook or future grants for database roles |
Fix 1: declare grants in dbt (preferred)
Put grants next to the models so every build applies them.
# dbt_project.yml
models:
analytics:
marts:
+grants:
select: ['reporter', 'bi_service']
staging:
+grants:
select: ['data_engineer']
Per model, in the model's SQL file:
{{ config(materialized='table', grants={'select': ['reporter', 'finance_analyst']}) }}
By default a more specific config replaces the inherited list, so the model above loses bi_service. To add to the inherited list instead, prefix the privilege with +:
{{ config(grants={'+select': ['finance_analyst']}) }}
Rules worth knowing:
- dbt only manages grants on nodes that have a
grantsconfig. Remove the config and dbt leaves existing grants alone. select: []tells dbt to revoke allSELECTgrants on that node.- If a role is granted manually and not in the config, dbt revokes it on the next build. Agree that the config is the source of truth before you roll this out.
Apply it to one model first and check:
dbt run --select fct_orders
SHOW GRANTS ON TABLE analytics.marts.fct_orders;
Warning
Rolling out
grantsconfig across a whole project can revoke access that people currently rely on, because dbt removes any grantee not in the config. Export current grants first (SHOW GRANTS ON SCHEMA ...and per object) and add every legitimate role to the config before the first run.
Fix 2: copy_grants on Snowflake
copy_grants makes Snowflake keep the existing privileges (except ownership) when dbt runs CREATE OR REPLACE.
# dbt_project.yml
models:
analytics:
+copy_grants: true
The default is false. On recent dbt-snowflake versions, dbt adds IGNORE GRANTS to the rebuild when copy_grants is false, so privileges are dropped deliberately; on older versions the behaviour depends on the account's defaults. Check your adapter's release notes for the exact version.
copy_grants keeps whatever grants already exist, including manual ones nobody tracks. Use it as a safety net alongside grants config, not as the only control. When both are set, the copied grants are applied first and dbt's grants config then makes the final list match the config.
Fix 3: future grants for anything dbt creates
Future grants cover new models that nobody has added to the config yet. A platform admin sets them once per schema:
USE ROLE securityadmin;
GRANT USAGE ON DATABASE analytics TO ROLE reporter;
GRANT USAGE ON SCHEMA analytics.marts TO ROLE reporter;
GRANT SELECT ON FUTURE TABLES IN SCHEMA analytics.marts TO ROLE reporter;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA analytics.marts TO ROLE reporter;
-- Existing objects are not covered by future grants; grant them once
GRANT SELECT ON ALL TABLES IN SCHEMA analytics.marts TO ROLE reporter;
GRANT SELECT ON ALL VIEWS IN SCHEMA analytics.marts TO ROLE reporter;
Set future grants at the schema level when the schema already has any. Otherwise the database-level ones are ignored for that object type.
Tip
Don't forget
USAGEon the database and schema. dbt'sgrantsconfig only grants on the model object itself. WithoutUSAGEon the containers, the reader still sees "does not exist or not authorized".
Prevent it next time
- Keep reader grants in
dbt_project.ymlat folder level, and review changes to them like code. - Add schema-level future grants for each consumer role, so new models are readable before anyone remembers to update the config.
- Add a post-deploy check that fails the job if a key role can't read the marts:
-- run as the reporter role after dbt finishes
USE ROLE reporter;
SELECT COUNT(*) FROM analytics.marts.fct_orders LIMIT 1;
- Grant BI tools a functional role (
reporter) rather than individual users, so the config list stays short. - Before a
--full-refreshin production, check that the model hasgrantsorcopy_grantsset.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get