Skip to content

feat(grants): support SEMANTIC VIEW privileges (CREATE / SELECT ON ALL|FUTURE)#38

Open
GClunies wants to merge 2 commits into
datacoves:mainfrom
GClunies:snowcap-30
Open

feat(grants): support SEMANTIC VIEW privileges (CREATE / SELECT ON ALL|FUTURE)#38
GClunies wants to merge 2 commits into
datacoves:mainfrom
GClunies:snowcap-30

Conversation

@GClunies

Copy link
Copy Markdown
Contributor

Summary

Semantic views are the backbone of Cortex Analyst, but granting a role access to them required manual SQL. This registers SEMANTIC VIEW as a grants-only resource type following the CORTEX SEARCH SERVICE precedent (#18) — pure data-driven registration (enum member, SemanticViewPriv, SchemaPriv.CREATE_SEMANTIC_VIEW, PRIVS_FOR_RESOURCE_TYPE + RESOURCE_SCOPES entries), no concrete resource class and zero type-specific branching in the generic grant/fetch/SQL paths.

Closes #30

Changes

  • CREATE SEMANTIC VIEW schema privilege: priv: CREATE SEMANTIC VIEW / on: schema db.schema
  • Object grants: priv: SELECT|REFERENCES|MONITOR / on: semantic view db.schema.name (on_semantic_view= in Python)
  • Bulk/future grants via the uniform on: forms: all semantic views in schema … / future semantic views in schema … (on_all_*/on_future_* kwargs stay rejected repo-wide by design — a test pins the redirect)
  • Fix (pre-existing, surfaced by review): drop_grant's ALL branch rendered invalid SQL — missing FROM <role> and singular object type — so removing any on: all … grant failed at apply time; now mirrors the FUTURE branch
  • Tests: 12 new unit tests (first coverage of a multi-word plural through the ALL/FUTURE parser), live grant.sql fixture line, strengthened test_revoke_all_grant, and a --snowflake-gated integration round-trip test
  • Docs: grant.md examples, snowflake-permissions.md schema-scoped note, new resources/semantic_view.md + mkdocs nav

Before release (manual)

CI runs unit tests only (--ignore=tests/integration), so the new integration test collects-and-skips. Against a live test account (enterprise, if standard lacks the feature), run pytest tests/integration/test_grant_patterns.py --snowflake or manually confirm: SHOW GRANTS round-trips a semantic-view grant with zero plan drift, and GRANT SELECT ON ALL|FUTURE SEMANTIC VIEWS IN SCHEMA … executes.

Follow-up candidates (pre-existing, out of scope)

  • tests/fixtures/sql/future_grant.sql is silently skipped by get_sql_fixtures (filename doesn't resolve to a resource class) — the whole file is dead coverage
  • grant_yaml reconstructs bulk-grant on: strings in a singular, keyword-less form the parser wouldn't re-accept

GClunies added 2 commits July 16, 2026 23:14
Semantic views are the backbone of Cortex Analyst, but granting a role
access to them required manual SQL. Register SEMANTIC VIEW as a
grants-only resource type following the CORTEX SEARCH SERVICE precedent
(datacoves#18): enum member, SemanticViewPriv (SELECT/REFERENCES/MONITOR/
OWNERSHIP/ALL), SchemaPriv.CREATE_SEMANTIC_VIEW, and a SchemaScope
registration — no concrete resource class, no type-specific branching.

Supported forms:
  - priv: CREATE SEMANTIC VIEW / on: schema db.schema
  - priv: SELECT / on: semantic view db.schema.name (on_semantic_view=)
  - on: all|future semantic views in schema db.schema

Fetch/plan round-trip is covered at unit level (GrantedPrivilege
typing, SQL fixture parse) plus a --snowflake-gated integration test;
that test only runs against a live account, which CI does not do —
verify live before release.

Closes datacoves#30
drop_grant's GrantType.ALL branch omitted the mandatory FROM clause and
passed items_type singular, producing invalid SQL like
'REVOKE SELECT ON ALL TABLE IN SCHEMA db.schema' for every resource
type. Removing any 'on: all ...' grant from YAML would fail at apply
time. Mirror the FUTURE branch: pluralize+uppercase the object type and
append FROM <to_type> <to>. Strengthen test_revoke_all_grant from a
substring check (which hid the bug) to full-statement equality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(grants): support SEMANTIC VIEW privileges (CREATE / SELECT ON ALL|FUTURE)

1 participant