Row-level security
Row filters restrict which rows a user sees in a table. They live in a
YAML file passed with --row-filters, which reloads on SIGHUP, and can
also come from the policy.
tables: lake.analytics.customers: # catalog.schema.table rules: - roles: [analyst_north] where: "region = 'north'" - users: ["ana@example.com", "*@corp.example.com"] where: "region IN (SELECT region FROM ctl.main.acl WHERE usr = getvariable('curral_user'))"curral serve ... --row-filters rls.yamlHow rules match
Section titled “How rules match”- A rule applies to whoever matches it, by role or by user (exact name or
*@domain). - A user who matches several rules sees the union: the
whereclauses are combined withOR. - A user who matches no rule is not filtered. Whether they may read the table at all is the policy’s decision.
Filters driven by data
Section titled “Filters driven by data”getvariable('curral_user') and getvariable('curral_roles') expose the
caller inside a where. With an ACL table, access changes by editing data
instead of configuration:
where: "region IN (SELECT region FROM ctl.main.acl WHERE usr = getvariable('curral_user'))"For a request a service makes on someone’s behalf,
getvariable('curral_identity') holds the identity it sent, as JSON (empty
otherwise):
where: "slug = json_extract_string(getvariable('curral_identity'), '$.page.slug')"Session variables never outlive the request.
Filters from the policy
Section titled “Filters from the policy”The policy can return row filters too, as a map of fully qualified tables to
SQL predicates. The rule is data.curral.row_filters by default
(--policy-row-filters-query):
row_filters := {"lake.analytics.customers": "region = 'north'"} if { "analyst_north" in input.roles}- Undefined means no extra filter; a malformed result or an evaluation error denies the request.
- A policy predicate is ANDed with the file’s filter for the same table, and both apply before the caller’s own filters, joins and aggregations.
- It works for every caller, and is the natural place for filters that
depend on
input.identityorinput.actor.
Validation
Section titled “Validation”Each where is validated against the real table at startup, in
curral check and on reload. An error aborts startup; on reload, the
previous file is kept.
Every filter, from the file or the policy, must be a single SQL
expression: balanced parentheses outside quotes, and no ;, comments or
dollar quotes. Anything else fails the load (file) or denies the request
(policy), so a value such as x') OR ('1'='1 cannot widen a filter. Even
so, do not build predicates by interpolating input.identity into strings
in Rego: compare against curral_identity inside the SQL instead.
How it is enforced
Section titled “How it is enforced”Each reference to the table in the user’s query becomes, in DuckDB’s own
syntax tree, a subquery that filters first. The user’s query runs on top
of it, so WHERE, joins and aggregations never see hidden rows.
Queries that cannot be protected safely are denied with
decided_by: protection. The rules are shared with column masking; see
What gets denied.
/v1/schema flags filtered tables with "row_filtered": true, and the dry
run and audit log list the filters applied (row_filters).
Tables created after startup
Section titled “Tables created after startup”--row-filters-missing strict (the default) aborts boot or reload when a
configured table does not exist. Use --row-filters-missing warn to log the
missing table and retain its rule for when the table becomes available.
Other validation errors still fail. Local views over protected local tables
are also rewritten; see Protected local views.