EX-24: Row-Level Security (RLS) Regional Partitioning
Track: Security & Privacy • Difficulty: Intermediate • Mastery Points: 150 PTS
Business Problem Scenario
Under UK banking data privacy regulations, regional branch employees may only view account balances for customers registered within their assigned regional branch. Conversely, members of the national treasury team require unconstrained visibility across all branches for liquidity management. You must implement a row filter function in Unity Catalog that dynamically evaluates branch authorization against an authoritative mapping table.
Engineering Objective
Write the row filter function CREATE OR REPLACE FUNCTION gov.filter_branch_region(branch_id STRING). • Evaluation Logic: - Return true if current_user() is a member of 'national_treasury'. - OR return true if branch_id = (SELECT branch_id FROM gov.user_branch_mapping WHERE user_email = current_user()). - Else return false (fail-closed principle: unmapped users receive no row visibility). • Attachment Note: Attached via ALTER TABLE silver.core_accounts SET ROW FILTER gov.filter_branch_region ON (branch_id);. Key Concepts: - Row-Level Security (RLS): Automated table-level filter evaluating per-row visibility based on user session identity.
Target Table: silver.core_accounts & gov.user_branch_mapping (branch_id STRING, user_email STRING)
Verification & Architecture Insights
Row-level security transparently filters SQL result sets, preventing regional branch personnel from querying high-net-worth accounts outside their territory.