Specification Language
Access Control & CEL Policies
Aegil enforces zero-trust row-level security (RLS) by compiling Common Expression Language (CEL) policy expressions directly into PostgreSQL SQL query filters. Because access checks are compiled into SQL clauses rather than evaluated in application memory, unauthorized records are never leaked across tenant boundaries.
Defining CEL access policies
Section titled “Defining CEL access policies”namespace Helpdesk;
@policy({ read: "auth.role == 'admin' || auth.id == self.reporterId", write: "auth.role == 'admin' || (auth.id == self.reporterId && self.status == 'Open')", delete: "auth.role == 'admin'",})@entity({ table: "tickets" })model Ticket { @pk id: uuid;
@owner reporterId: uuid;
title: string; status: TicketStatus;}CEL variables available in policies
Section titled “CEL variables available in policies”| Variable | Type | Source | Meaning |
|---|---|---|---|
auth.id |
uuid / int |
Authenticated session | The unique user ID of the signed-in caller. |
auth.role |
string |
Authenticated session | The role assigned to the caller ("admin", "customer", etc.). |
self.<field> |
Depends on field | Database row | The specific column value of the row being read, updated, or deleted. |
self.<relation>.<field> |
Depends on parent | Related database row | Single-hop parent relation traversal (e.g. self.ticket.reporterId). |
Common policy patterns
Section titled “Common policy patterns”1. Multi-tenant ownership (Users see only their own data)
Section titled “1. Multi-tenant ownership (Users see only their own data)”@policy({ read: "auth.id == self.ownerId", write: "auth.id == self.ownerId", delete: "auth.id == self.ownerId",})2. Admin override (Admins see everything, users see own rows)
Section titled “2. Admin override (Admins see everything, users see own rows)”@policy({ read: "auth.role == 'admin' || auth.id == self.ownerId", write: "auth.role == 'admin' || auth.id == self.ownerId", delete: "auth.role == 'admin'",})3. State-guarded edits (Users can only edit while status is Open)
Section titled “3. State-guarded edits (Users can only edit while status is Open)”@policy({ read: "auth.id == self.ownerId", write: "auth.id == self.ownerId && self.status == 'Open'",})4. Parent relation inheritance (Child comments check ticket owner)
Section titled “4. Parent relation inheritance (Child comments check ticket owner)”@policy({ read: "auth.role == 'admin' || auth.id == self.ticket.reporterId", write: "auth.id == self.authorId", delete: "auth.role == 'admin' || auth.id == self.authorId",})Server-side SQL pushdown
Section titled “Server-side SQL pushdown”Aegil does not evaluate CEL by fetching rows into application memory. Instead, Aegil compiles CEL expressions directly into PostgreSQL parameterized SQL queries:
SELECT id, reporter_id, title, statusFROM ticketsWHERE ($1 = 'admin' OR reporter_id = $2);Because the policy is enforced directly inside the database query engine:
- Unauthorized rows are filtered out at the SQL level and cannot leak across tenant boundaries.
- Database indexes are utilized efficiently.
- Protection is guaranteed before any hook or application code runs.
Exposing unauthenticated endpoints with @public
Section titled “Exposing unauthenticated endpoints with @public”By default, every operation requires a valid signed-in user session. To create an endpoint that does not require login, annotate it with @public:
@public@autoQuery({ entity: "CatalogItem" })op listCatalog(): CatalogItem[];Important constraints on @public
Section titled “Important constraints on @public”- A
@publicoperation cannot referenceauth.idorauth.rolebecause no session exists. - The verification harness confirms that public endpoints do not expose protected data (
PUBLICcheck).
What could go wrong?
Section titled “What could go wrong?”| What you see | Why | What to do |
|---|---|---|
ERR_POLICY_SYNTAX |
A CEL expression contains invalid syntax or an unknown operator. | Use standard CEL operators (==, !=, &&, ||, <, <=). |
ERR_POLICY_FIELD_UNKNOWN |
A CEL policy references a field that is not declared on the model. | Check the spelling of self.<field> (use self, not resource). |
ERR_PUBLIC_AUTH_CONFLICT |
An operation is annotated @public but tries to evaluate auth.id or auth.role. |
Remove @public if login is required, or remove the auth reference from the policy. |
Next steps
Section titled “Next steps”- Learn State Machines & Workflows.
- Learn Platforms & Device Permissions.
- Learn Full-Stack Runtime Architecture.