MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Security
Row-Level Security

Row-Level Security

Row-Level Security (RLS) restricts which rows a user can see based on their roles, attributes, and organizational context. The RLS engine automatically injects WHERE clauses into queries before they reach the execution engine, ensuring that users only access data they are authorized to see.


How RLS Works

User Query                    RLS Engine                    Execution Engine
    |                            |                               |
    |--- SELECT * FROM orders -->|                               |
    |                            |--- Resolve user policies ---->|
    |                            |--- Build WHERE predicates --->|
    |                            |--- Inject into query -------->|
    |                            |                               |
    |                            |--- SELECT * FROM orders   --->|
    |                            |    WHERE tenant_id = ?        |
    |                            |    AND region IN (...)        |
    |                            |                               |
    |<-- Filtered results -------|<-- Results -------------------|

Policy Types

TypeDescriptionExample
Tenant isolationAll queries filtered by tenant IDtenant_id = :tenantId
Role-basedData filtered by user roleManagers see all regions; analysts see assigned regions
Attribute-basedData filtered by user attributesUsers see data for their department only
Column-valueSpecific column values restrictedFinancial data restricted to finance role

Policy Resolution

Policies are resolved in the following order:

  1. Tenant policy: Always applied, non-negotiable
  2. Table-level policies: Applied if the queried table has registered policies
  3. Column-level policies: Applied for specific sensitive columns
  4. User attribute policies: Applied based on the user's profile attributes

Multiple policies on the same table are combined with AND logic.


Policy Configuration

RLS policies are configured through the governance service and stored in the data catalog. The Query Engine fetches applicable policies at query time via the GovernanceServiceClient.

FieldDescription
tableNameTable the policy applies to
predicateExpressionSQL predicate to inject
applicableRolesRoles this policy applies to
excludedRolesRoles exempt from this policy
priorityEvaluation order for conflicting policies

Performance Considerations

  • RLS predicates are injected before query optimization, allowing the engine to push them down to storage
  • Policies are cached per-tenant with short TTL to balance security freshness and performance
  • Complex policies with subqueries may impact query planning time