Lua RLS Plugin
Row-Level Security implementation using Lua scripts.
Type
- Interceptor
Description
Allows defining custom row-level security logic using Lua scripts, which are executed for each row in the result set.
Configuration
lua_rls: script: | function filter_rows(row, context) if context.user_role == "admin" then return true end return row.tenant_id == context.tenant_id end variables: # Global variables available to Lua script max_rows: 1000 debug: true cache_size: 100 # Size of the Lua VM cache
Context Object Properties
The context
parameter of the filter_rows
function contains the following properties:
- Authentication Claims: All JWT claims from the authenticated user are available directly as properties (e.g.,
context.user_role
,context.tenant_id
,context.email
, etc.). - Request Headers: All HTTP request headers are available as properties (with the same case as they appear in the request).
- Custom Variables: Any custom variables defined in the
variables
configuration section are available as global variables.
Example Context Properties
-- Authentication claims from JWT or OAuth providerscontext.user_id -- User's unique identifiercontext.user_role -- User's role (e.g., "admin", "user")context.tenant_id -- Tenant/organization identifiercontext.email -- User's email addresscontext.groups -- User's groups or permissionscontext.org_id -- Organization identifier
-- Request headers (same case as in HTTP request)context.Authorization -- Authorization headercontext.X-Tenant-ID -- Custom tenant headercontext.User-Agent -- User agent header