Skip to content

Policy Engine

Phase 1 implements role-based field filtering via middleware. The system uses three hardcoded roles with progressive data visibility.

RoleBudgetStrategyMetricsLogs
ceoFull accessFull accessAll metricsFull access
dept_headAllocated visible, spent redacted (-1)Proposed strategies redactedAll metricsFull access
team_memberHidden entirelyDescriptions redacted, IDs strippedtarget direction metrics hiddenHidden entirely

The policyMiddleware reads the X-Lattice-Role header, defaults to team_member, and attaches a filterEntity function to the Hono context. This function deep-clones the entity and strips fields based on role before the response is sent. The filter is applied on GET single entity and PATCH responses.

Beyond the middleware filtering, a dedicated endpoint allows explicit policy evaluation against the policies table in D1. This table stores {subject, action, object, condition, effect} rules. Evaluation is deny-first: deny rules are sorted before allow rules, and if no policy matches, the default is deny.