Unlike table-level permissions, RLS allows for granular control based on user-specific attributes.
Basic Mechanism
The basic mechanism of RLS involves defining a per-table SQLWHERE
clause that Wisdom automatically injects into every query that uses that table. This filter can leverage Wisdom-specific custom functions to access information about the user running the query. For example, a policy can be set to only return rows where the user_email
column matches the logged-in user’s email address.
How the SQL Executor Works
All SQL queries in Wisdom pass through a central SQL Executor module. When a query is initiated, the SQL Executor:- Identifies the tables referenced in the query.
- Looks up any RLS policies defined for those tables.
- Resolves Wisdom custom functions (such as
USER_EMAIL()
) into their current values. - Rewrites the query to include the appropriate row filters safely.
Key Concepts
Understanding the core building blocks of RLS helps in configuring and managing it effectively.Dynamic Filters with Custom Functions
Dynamic filters adapt to the identity of the logged-in user. Policies often rely on Wisdom’s built-in functions to inject the right conditions at query time. Commonly used functions include:USER_EMAIL()
– returns the email address of the current user.USER_ATTRIBUTE('attribute_name')
– retrieves a custom attribute value for the user, typically synced from a SAML SSO provider during setup.
USER_ATTRIBUTE_INT('attribute_name')
– resolves to an integer.USER_ATTRIBUTE_STR('attribute_name')
– equivalent toUSER_ATTRIBUTE()
for strings.USER_ATTRIBUTE_STR_LIST('attribute_name')
– maps to a list of strings, for example:
USER_ATTRIBUTE_INT_LIST('attribute_name')
– maps to a list of integers.
Entitlements Tables
For more advanced setups, RLS can leverage an entitlements table stored in your data warehouse. This table centralizes user permissions and typically includes columns like:user_email
resource_type
resource_value
user_email | resource_type | resource_value |
---|---|---|
john@askwisdom.ai | Territory | USA |
john@askwisdom.ai | Department | * |
*
wildcard in resource_value
grants a user access to all resources of that type.
User Attributes
User attributes, mapped from SAML attributes during SSO configuration, allow policies to reflect organizational properties such as department, region, or tenant.Validation and Administration
Proper validation and administration ensure your RLS policies work as intended.Preview and Impersonation
For testing purposes, you can preview filtered data:- Impersonate a user to see the data as they would.
- Set temporary custom attributes at preview time for troubleshooting.