snowflake-role-based-access

mermaid graph TB subgraph β€œHANDBOOK” HB[β€œπŸ“– RBAC_Framework_Handbook.md
- Architecture Overview
- Table Definitions
- Stored Procedures
- Usage Examples”] end

subgraph "DATABASE LAYER"
    META["πŸ—„οΈ adw_rbac_metadata<br/>---<br/>Stores permission<br/>mappings between<br/>tables and roles"]
    AUDIT["πŸ“Š adw_rbac_audit_log<br/>---<br/>Logs all RBAC<br/>operations with<br/>success/failure status"]
    VIEWS["πŸ‘οΈ VIEWS<br/>---<br/>vw_active_rbac<br/>vw_successful_ops<br/>vw_failed_ops<br/>vw_ops_summary"]
end

subgraph "UI LAYER"
    STREAMLIT["🎯 Streamlit App<br/>main.py<br/>---<br/>Interactive dashboard<br/>for RBAC management"]
end

subgraph "PAGES"
    PAGE1["πŸ“Š Dashboard<br/>- Overview stats<br/>- Permission charts"]
    PAGE2["πŸ“‹ Metadata Mgmt<br/>- View permissions<br/>- Edit entries"]
    PAGE3["πŸ“ Add Permission<br/>- New role grants<br/>- Bulk operations"]
    PAGE4["πŸ” Audit Log<br/>- Operation history<br/>- Error tracking"]
end

subgraph "DDL SCRIPTS"
    DDL1["adw_rbac_metadata.ddl<br/>- Table creation<br/>- 5 indexes<br/>- 1 view"]
    DDL2["adw_rbac_audit_log.ddl<br/>- Table creation<br/>- 5 indexes<br/>- 3 views"]
    DDL3["INSTALL_RBAC_METADATA.ddl<br/>- Master installer<br/>- Complete setup<br/>- Sample data"]
end

HB -->|Defines| META
HB -->|Defines| AUDIT
HB -->|Guides| DDL3

DDL1 -->|Creates| META
DDL2 -->|Creates| AUDIT
DDL3 -->|Orchestrates| DDL1
DDL3 -->|Orchestrates| DDL2

META -->|Powers| VIEWS
AUDIT -->|Powers| VIEWS

VIEWS -->|Data Source| STREAMLIT
META -->|CRUD Operations| STREAMLIT
AUDIT -->|Read Operations| STREAMLIT

STREAMLIT --> PAGE1
STREAMLIT --> PAGE2
STREAMLIT --> PAGE3
STREAMLIT --> PAGE4

PAGE2 -->|Updates| META
PAGE3 -->|Creates| META
PAGE4 -->|Reads| AUDIT

RBAC Framework - Data Flow & Integration

Components Overview

1. Documentation Layer πŸ“–

2. Database Layer πŸ—„οΈ

Core Tables (per Handbook)

Performance Features

3. DDL Scripts πŸ“

Deployment Strategy

  1. INSTALL_RBAC_METADATA.ddl (Recommended)
    • One-stop installation script
    • Creates database, schema, tables, indexes, views
    • Optional sample data
    • Complete setup in single execution
  2. Individual DDL Files (For reference)
    • adw_rbac_metadata.ddl: Metadata table only
    • adw_rbac_audit_log.ddl: Audit table only
    • Use for modular deployments or debugging

4. Streamlit UI Layer 🎯

Connection Points

Key Pages

Page Purpose Data Source
Dashboard Overview & statistics Both tables
Metadata Management View/edit permissions adw_rbac_metadata
Add Permission Create new grants Insert to adw_rbac_metadata
Audit Log Operation history adw_rbac_audit_log

Data Integration Points

Reading Data

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Streamlit App   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ SELECT
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Views (active)  │◄────── vw_active_rbac   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”œβ”€β”€β”€β”€β”€β–Ί Dashboard Visualizations
         β”œβ”€β”€β”€β”€β”€β–Ί Permission Tables
         └─────► Audit History

Writing Data

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Input (UI)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Streamlit App    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ INSERT/UPDATE
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ audit.adw_rbac_metadata      β”‚
β”‚ - New permissions added      β”‚
β”‚ - Status tracked             β”‚
β”‚ - Timestamps recorded        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


Data Flow Examples

Example 1: Grant New Permission

User β†’ Streamlit "Add Permission" Page
  ↓
User enters: Database, Schema, Table, Role, Permission
  ↓
INSERT INTO audit.adw_rbac_metadata
  β”œβ”€ database_name, schema_name, table_name
  β”œβ”€ role_name, permission_type
  β”œβ”€ effective_start_date, record_created_by
  └─ record_create_ts (current time)
  ↓
View refreshes showing new permission in Dashboard
  ↓
Permission ready for USP_GRANT_RBAC execution

Example 2: Review Audit Trail

User β†’ Streamlit "Audit Log" Page
  ↓
SELECT * FROM audit.vw_successful_rbac_operations
  β”œβ”€ operation_type (GRANT, REVOKE, DRY_RUN)
  β”œβ”€ execution_status (SUCCESS, FAILED)
  β”œβ”€ sql_statement (actual SQL executed)
  β”œβ”€ error_message (if failed)
  └─ record_create_ts (when it happened)
  ↓
Dashboard shows historical operations with filters
  ↓
User can drill down into specific operations

Example 3: Check Current Permissions

User β†’ Streamlit "Metadata Management" Page
  ↓
SELECT * FROM audit.vw_active_rbac_metadata
  β”œβ”€ Filters by current date (effective_start_date ≀ today)
  β”œβ”€ Excludes expired permissions (effective_end_date > today)
  └─ Shows only active records (record_status_cd = 'A')
  ↓
Dashboard displays active permission matrix

Update Sequence: Handbook β†’ Database β†’ UI

Step 1: Handbook Definition

Document what tables and columns are needed in the RBAC framework.

Step 2: DDL Creation

Create matching table structures in Snowflake:

-- INSTALL_RBAC_METADATA.ddl
CREATE TABLE audit.adw_rbac_metadata ( ... )
CREATE TABLE audit.adw_rbac_audit_log ( ... )

Step 3: UI Integration

Update Streamlit to reference handbook tables:

# main.py
st.session_state.metadata = pd.DataFrame({
    'rbac_id': [...],
    'database_name': [...],
    'schema_name': [...],
    # All columns from audit.adw_rbac_metadata
})

Step 4: Cross-Validation

All three layers now work together:


Alignment Checklist


Quick Reference: Table→View→UI Mapping

Handbook Table DDL File Database Object Streamlit Page
adw_rbac_metadata adw_rbac_metadata.ddl Table + View Metadata Management
adw_rbac_audit_log adw_rbac_audit_log.ddl Table + 3 Views Audit Log
β€” β€” vw_active_rbac_metadata Dashboard
β€” β€” vw_successful_rbac_operations Audit Log
β€” β€” vw_failed_rbac_operations Audit Log
β€” β€” vw_rbac_operations_summary Dashboard Stats

Installation Verification

After running DDL scripts, verify the complete chain:

-- 1. Verify tables exist and have correct structure
DESC TABLE audit.adw_rbac_metadata;
DESC TABLE audit.adw_rbac_audit_log;

-- 2. Verify views exist
SHOW VIEWS IN SCHEMA audit;

-- 3. Verify indexes exist
SHOW INDEXES ON TABLE audit.adw_rbac_metadata;

-- 4. Test views work
SELECT * FROM audit.vw_active_rbac_metadata;
SELECT * FROM audit.vw_successful_rbac_operations;

Then start Streamlit and verify the UI connects successfully:

streamlit run app/main.py

Complete Integration βœ… All layers are now aligned and ready for deployment!