An enterprise-grade Snowflake data platform reference implementation featuring a medallion (Bronze β Silver β Gold) architecture with full security, observability, and governance controls β aligned to the CIS Snowflake Foundations Benchmark.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA SOURCES β
β SQL Server (Legacy) AWS S3 (Files) Snowflake Native β
ββββββββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββββββββ¬βββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BRONZE LAYER (RAW_DB) β
β Raw, unmodified ingestion β schema-on-read, immutable β
β β’ Snowpipe for S3 auto-ingest β’ External stages β
β β’ ADF / Fivetran for SQL Server β’ Full audit metadata β
ββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β dbt (validation + type casting)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SILVER LAYER (FOUNDATION_DB) β
β Cleansed, validated, conformed β single source of truth β
β β’ Null checks / referential integrity β’ SCD Type 2 snapshots β
β β’ Standardised column naming β’ PII masking applied β
ββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β dbt (business logic + aggregations)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GOLD LAYER (ANALYTICS_DB) β
β Curated, domain-oriented data products β
β β’ Customer 360 β’ Revenue summary β
β β’ Product performance β’ Row-level security enforced β
ββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CONSUMPTION LAYER β
β Microsoft Power BI (SAML/OAuth + AD group RLS) β
β Data Science / ML workloads Ad-hoc SQL (analysts) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
snowflake-medallion/
βββ docs/
β βββ architecture/
β β βββ security-model.md # RBAC hierarchy, masking, RLS, audit
β β βββ cis_benchmark_compliance.md # CIS Snowflake Benchmark control mapping
β β βββ multi_account_architecture.md # Multi-account topology guide
β β βββ cortex_ai.md # Cortex AI layer: governance + capabilities
β βββ runbooks/
β βββ onboarding.md # New developer setup guide
β βββ incident-response.md # 5 incident playbooks (data loss, pipeline, etc.)
β βββ environment_promotion.md # How to promote changes dev β staging β prod
βββ infrastructure/
β βββ snowflake/
β βββ account_setup/
β β βββ 01_databases.sql # Databases and schemas
β β βββ 02_warehouses.sql # Warehouse sizing and auto-suspend
β β βββ 03_roles.sql # RBAC role hierarchy and grants
β β βββ 04_users.sql # Service accounts and human user templates
β β βββ 05_network_policies.sql # Network rules + IP allowlisting (CIS 2.1/2.2)
β β βββ 06_password_policies.sql # Strong password + session timeout (CIS 1.3/1.4)
β β βββ 07_scim_integration.sql # Azure AD SCIM provisioning (CIS 1.6)
β β βββ 08_authentication_policies.sql # SSO-only humans, key-pair-only services, MFA
β βββ security/
β β βββ 01_object_tags.sql # DATA_SENSITIVITY, PII_CATEGORY, COMPLIANCE_SCOPE tags
β β βββ 02_data_classification.sql # Auto-classification profiles + manual log
β β βββ 03_column_masking_policies.sql # PII dynamic masking (email, phone, name, DOB, IP, ...)
β β βββ 04_row_access_policies.sql # Domain isolation, tenant, regional residency RLS
β β βββ 05_managed_access_schemas.sql # Prevent privilege escalation (CIS 3.5)
β β βββ 06_cis_compliance_checks.sql # Audit queries for every CIS control
β β βββ 07_trust_center.sql # Trust Center access + CIS Benchmarks scanner package
β βββ monitoring/
β β βββ 01_resource_monitors.sql # Credit consumption alerts per warehouse
β β βββ 02_audit_logging.sql # Audit views over SNOWFLAKE.ACCOUNT_USAGE
β β βββ 03_alerts.sql # Operational alerts (freshness, DQ, DDL)
β β βββ 04_privileged_access_alerts.sql # Security alerts (CIS 5.3/6.1/6.2)
β βββ integrations/ # S3 storage integration, Snowpipe, SQL Server
β βββ backup/ # Time travel config, cross-region replication
β βββ multi_account/
β β βββ 01_organizations_setup.sql # Snowflake Organizations + account provisioning
β β βββ 02_cross_account_sharing.sql # Secure Data Sharing between accounts
β β βββ 03_account_replication.sql # Failover Groups for HA/DR
β βββ cortex/
β βββ 00_cortex_governance.sql # CORTEX_USER hygiene, model allowlist, AI cost alert
β βββ 01_semantic_views.sql # Semantic models for Cortex Analyst / Intelligence
β βββ 02_cortex_search.sql # Search service over platform runbooks/docs
β βββ 03_anomaly_monitoring.sql # ML anomaly detection on credit spend
β βββ 04_document_ai_ingestion.sql # AI_PARSE_DOCUMENT bronze pattern for PDFs
βββ dbt/
β βββ dbt_project.yml
β βββ profiles.yml.example # Connection template (copy to ~/.dbt/profiles.yml)
β βββ packages.yml # dbt_utils, dbt_expectations, audit_helper, elementary
β βββ models/
β β βββ bronze/
β β β βββ sources.yml # Source definitions with freshness checks
β β β βββ sqlserver/ # brz_sqlserver_{customers,orders,order_items,products}
β β β βββ s3/ # brz_s3_{events,transactions}
β β βββ silver/
β β β βββ customers/ # slv_customers
β β β βββ orders/ # slv_orders, slv_order_items
β β β βββ products/ # slv_products
β β β βββ events/ # slv_events
β β βββ gold/
β β βββ marketing/ # gld_customer_360
β β βββ finance/ # gld_revenue_summary
β β βββ operations/ # gld_product_performance
β βββ seeds/
β β βββ _seeds.yml # Seed column types, tests, and documentation
β β βββ ref_data_domains.csv # Business domain definitions and PBI role mappings
β β βββ ref_country_regions.csv # ISO country β GDPR/CCPA/residency zone mapping
β βββ macros/ # audit_columns, generate_schema_name, safe_cast_*, etc.
β βββ snapshots/ # snp_customers (SCD Type 2)
β βββ tests/singular/ # Business-rule tests across all layers
βββ powerbi/
β βββ saml_oauth_setup.md # Azure AD SSO + OAuth integration guide
β βββ row_level_security/
β βββ rls_snowflake_setup.sql # Applies row access + masking policies to gold tables
β βββ rls_policies.md # AD group β role β data access matrix
βββ scripts/
βββ setup/
β βββ bootstrap.sh # Ordered, role-aware execution of all infra scripts
βββ utilities/
βββ clone_for_dev.sh # Zero-copy dev/test clones from production schemas
βββ cost_report.sql # Credit consumption and storage cost queries
| Tool | Version | Notes |
|---|---|---|
| Snowflake account | Enterprise edition or higher | Business Critical for Failover Groups |
| Python | 3.11+ | Use pyenv to manage versions |
| dbt-snowflake | 1.8.x | See dbt/packages.yml for exact constraint |
Snowflake CLI (snow) |
3.x | For running infrastructure scripts (SnowSQL is legacy; bootstrap.sh supports both) |
| AWS CLI | 2.x | Required for S3 storage integration setup |
| Azure CLI | latest | Required for Azure AD / SAML SSO + SCIM configuration |
git clone https://github.com/your-org/snowflake-medallion.git
cd snowflake-medallion
cp .env.example .env
# Edit .env with your Snowflake account identifier and credential pathsEach script specifies its required role in the header comment. The bootstrap script handles role switching automatically:
chmod +x scripts/setup/bootstrap.sh
./scripts/setup/bootstrap.sh --env dev --account <your-account>
# For production (requires explicit confirmation):
./scripts/setup/bootstrap.sh --env prod --account <your-prod-account>Or run individual phases manually (examples use Snowflake CLI with a named
connection β snow connection add β swap in snowsql -f if still on SnowSQL):
# Account setup (databases, warehouses, roles, users, network policies,
# password/session policies, SCIM, authentication policies)
snow sql -f infrastructure/snowflake/account_setup/01_databases.sql
# ... through 08_authentication_policies.sql
# Security controls (tags, masking, row access, managed access, Trust Center)
snow sql -f infrastructure/snowflake/security/01_object_tags.sql
# ... through 07_trust_center.sql
# Monitoring and alerting (resource monitors, audit views, operational + security alerts)
snow sql -f infrastructure/snowflake/monitoring/01_resource_monitors.sql
# ... through 04_privileged_access_alerts.sql
# External integrations (S3, Snowpipe, SQL Server)
snow sql -f infrastructure/snowflake/integrations/01_storage_integration_s3.sql
snow sql -f infrastructure/snowflake/integrations/02_external_stages.sql
snow sql -f infrastructure/snowflake/integrations/03_sqlserver_integration.sqlAfter bootstrapping, verify your CIS compliance posture (and enable the Trust
Center's CIS Benchmarks scanner package β see
infrastructure/snowflake/security/07_trust_center.sql):
snow sql -f infrastructure/snowflake/security/06_cis_compliance_checks.sqlcd dbt
pip install "dbt-snowflake~=1.8.0"
cp profiles.yml.example ~/.dbt/profiles.yml
# Edit ~/.dbt/profiles.yml with your Snowflake credentials
dbt deps # install packages (dbt_utils, dbt_expectations, elementary)
dbt debug # verify connection
dbt seed # load reference data (data domains, country/GDPR mapping)
dbt run # run all models
dbt test # run data quality testsSee docs/runbooks/onboarding.md for the full developer onboarding guide including RSA key-pair setup and per-developer schema isolation.
After dbt has created the gold tables, apply Snowflake RLS and masking policies:
snowsql -f powerbi/row_level_security/rls_snowflake_setup.sqlThen follow powerbi/saml_oauth_setup.md to configure the Azure AD app registration and Snowflake OAuth security integration.
| Model | Grain | Source |
|---|---|---|
slv_customers |
One row per customer | SQL Server via Fivetran |
slv_orders |
One row per order | SQL Server via Fivetran |
slv_order_items |
One row per order line item | SQL Server via Fivetran |
slv_products |
One row per product | SQL Server via Fivetran |
slv_events |
One row per web/app event | S3 via Snowpipe |
| Model | Domain | Description |
|---|---|---|
gld_customer_360 |
Marketing | Customer profile + lifetime order metrics + RFM segmentation |
gld_revenue_summary |
Finance | Daily revenue roll-up by product category, country, and channel |
gld_product_performance |
Operations | Product scorecard: velocity, margin, return rate, fulfilment speed |
Gold models include a DATA_DOMAIN column used as the anchor for Snowflake Row Access
Policies. Power BI users see only the rows for their AD group's domain.
| Seed | Description |
|---|---|
ref_data_domains |
Business domain definitions, owning teams, and Power BI role mappings |
ref_country_regions |
ISO 3166-1 country β region, GDPR/CCPA applicability, and data residency zone |
This implementation enforces least-privilege RBAC aligned to the CIS Snowflake Foundations Benchmark:
| Role | Purpose |
|---|---|
LOADER_ROLE |
Service account for data ingestion (Fivetran / ADF / Snowpipe) |
TRANSFORMER_ROLE |
dbt service account β reads bronze, writes silver/gold |
DATA_ENGINEER_ROLE |
Platform engineers β full read across all layers, DDL in DEV_DB |
DATA_ANALYST_ROLE |
Business analysts β read gold + silver |
DATA_SCIENTIST_ROLE |
ML/DS team β read gold + silver, can create dev schemas |
POWERBI_ROLE |
Power BI gateway service account β read all of ANALYTICS_DB |
POWERBI_MARKETING_ROLE |
PBI users in AD group PBI_MARKETING (RLS: Marketing rows only) |
POWERBI_FINANCE_ROLE |
PBI users in AD group PBI_FINANCE (RLS: Finance rows only) |
POWERBI_OPERATIONS_ROLE |
PBI users in AD group PBI_OPERATIONS (RLS: Operations rows only) |
Key controls applied at every layer:
- Network policies β IP allowlisting per service account and per human user population (CIS 2.1/2.2)
- Password policy β 14-char minimum, 90-day rotation, 5-attempt lockout (CIS 1.3)
- Session policy β 60-minute idle timeout for users, 30-minute for privileged accounts (CIS 1.4)
- SCIM provisioning β Azure AD lifecycle management for automated deprovisioning (CIS 1.6)
- Key-pair authentication β all service accounts; no passwords (CIS 1.5)
- Managed access schemas β prevents schema owners from escalating object access (CIS 3.5)
- Dynamic column masking β PII columns (email, phone, name, DOB) masked per role (CIS 4.3)
- Row access policies β domain isolation, tenant isolation, regional data residency (CIS 4.4)
- Object tags β PII category and compliance scope (
GDPR,PCI_DSS, etc.) on all sensitive columns - Security alerts β ACCOUNTADMIN usage, network policy changes, role/user changes (CIS 5.3/6.x)
See docs/architecture/security-model.md for the full model and docs/architecture/cis_benchmark_compliance.md for the complete CIS control mapping.
For organisations that require environment isolation, business unit separation, or cross-region
disaster recovery, this repo includes a multi-account layer under infrastructure/snowflake/multi_account/:
| Script | Purpose |
|---|---|
01_organizations_setup.sql |
Snowflake Organizations setup, account provisioning, org-level cost views |
02_cross_account_sharing.sql |
Secure Data Sharing between accounts (gold tables, reference data, monitoring) |
03_account_replication.sql |
Failover Groups for cross-region HA/DR (RPO: 10 min, RTO: ~5 min) |
Common topologies:
- Account-per-environment (recommended):
<ORG>-DEV/<ORG>-STAGING/<ORG>-PROD - Account-per-BU:
<ORG>-FINANCE/<ORG>-MARKETING/<ORG>-SHARED-SERVICES - Hub-and-spoke: PROD hub shares gold data to dedicated Analytics and Data Science accounts
See docs/architecture/multi_account_architecture.md for a detailed guide on choosing a topology and configuring each pattern.
This repo does not ship CI workflow files (earlier GitHub Actions workflows were removed). The recommended execution model is native to Snowflake:
dbt Projects on Snowflake
runs dbt Core natively inside Snowflake β no external runner, and the
SVC_DBT_TRANSFORMER key never leaves your secrets manager:
-- One-time: deploy the dbt/ directory as a DBT PROJECT object
-- (from a Snowsight Workspace connected to this git repo, or via `snow dbt deploy`)
-- Nightly production run, scheduled with a serverless task:
CREATE OR ALTER TASK FOUNDATION_DB.PUBLIC.TASK_DBT_NIGHTLY
SCHEDULE = 'USING CRON 0 4 * * * UTC'
AS
EXECUTE DBT PROJECT FOUNDATION_DB.PUBLIC.SNOWFLAKE_MEDALLION
ARGS='build --target prod';For PR validation, run snow dbt execute (or dbt build --target ci) against
the ci target β it builds everything in an ephemeral TEST_DB schema named
after the run (see dbt/profiles.yml.example).
Deploy infrastructure changes from any runner (or a developer machine) with
key-pair auth via scripts/setup/bootstrap.sh, or per-script:
snow sql -f infrastructure/snowflake/security/03_column_masking_policies.sql \
--temporary-connection --account "$SNOWFLAKE_ACCOUNT" \
--user "$SNOWFLAKE_USER" --private-key-file "$SNOWFLAKE_PRIVATE_KEY_PATH" \
--role SECURITYADMINIf you prefer GitHub Actions/GitLab CI, wrap those two commands in a workflow β
use a self-hosted runner with a stable egress IP so the service-account
network policy can stay tight (see 05_network_policies.sql), and never
allowlist shared hosted-runner IP ranges.
All models include dbt tests for:
not_nullanduniqueon all primary keysrelationships(referential integrity across layers)accepted_valueson all categorical/status columnsdbt_utils.expression_is_trueon financial amounts (non-negative)dbt_expectations.expect_column_values_to_be_betweenon timestamps and rates
Custom singular tests:
test_gold_revenue_no_negativeβ no negative revenue in the gold finance layertest_silver_no_orphan_ordersβ orphan order rate below 1%test_customer_360_completenessβ all active customers present in the gold 360 view
Test failures are stored in MONITORING_DB.DATA_QUALITY and trigger the
ALERT_DBT_TEST_FAILURES Snowflake alert within 30 minutes.
An optional, governance-first Cortex AI layer lives under
infrastructure/snowflake/cortex/ β run 00_cortex_governance.sql before
anything else in it (Snowflake grants CORTEX_USER to PUBLIC by default; the
script revokes it, pins a model allowlist, sets the cross-region posture, and
adds an AI-spend budget alert). Capabilities included:
| Capability | What you get |
|---|---|
| Semantic views + Cortex Analyst | Governed NL Q&A over gld_revenue_summary / gld_customer_360 (RLS-aware, PII excluded from the semantic model) |
| Cortex Search | "Ask the runbooks" retrieval service over docs/ for on-call engineers and agents |
| ML anomaly detection | Learned baseline on daily credit spend replaces static cost thresholds |
| Document AI ingestion | AI_PARSE_DOCUMENT bronze pattern extending the medallion to PDFs/DOCX |
| AISQL in dbt | Opt-in gold/ai model using AI_CLASSIFY to fill missing product categories (enable_ai_enrichment var) |
| Agents / Snowflake Intelligence | Assembly guidance for domain-scoped agents over the semantic views + search service |
See docs/architecture/cortex_ai.md for the full design, guardrails checklist, and cost model.
This template is designed to satisfy all applicable controls in the CIS Snowflake Security Foundations Benchmark v1.0. The implementation status of each control is documented in docs/architecture/cis_benchmark_compliance.md.
Run the compliance check script after bootstrapping to verify your posture:
snowsql -a <your-account> \
-r ACCOUNTADMIN \
-f infrastructure/snowflake/security/06_cis_compliance_checks.sqlThe final query in the script returns a single-row dashboard showing the count of gaps across the key CIS sections. All values should be 0.
See CONTRIBUTING.md for branching strategy, PR process, naming conventions, and SQL style guide.
See docs/runbooks/environment_promotion.md for the full process of promoting changes from development through to production.
Credentials must never be committed. Use <PLACEHOLDER> tokens for any
org-specific values in SQL scripts, and run a secret scanner (e.g. gitleaks
or GitHub secret scanning / push protection) on the repository.