Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
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.

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;
}

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).

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",
})

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, status
FROM tickets
WHERE ($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[];
  • A @public operation cannot reference auth.id or auth.role because no session exists.
  • The verification harness confirms that public endpoints do not expose protected data (PUBLIC check).

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.