Firewall docsPolicy & detection

Policies as code · OPA

The guided builder is a friendly surface over a precise engine: every policy compiles to Open Policy Agent (OPA). Switch any policy to Code view to see the split that makes this safe to operate at scale.

The Code view showing editable policy data beside the fixed Rego authorization logic.
Code view. Your policy data (left, editable JSON) beside the authorization logic (right, fixed Rego). You change the data; the logic is audited and never edited by admin input.

Two inputs, one decision

Every authorization decision is a pure function of two documents. Nothing else — no clock, no network, no hidden state — feeds the verdict, which is exactly what makes a decision reproducible months later during an audit.

DocumentWhat it is
inputThe request being judged: the caller's resolved policy (role), and the model, tool, scopes, and topics it wants.
data.rolesYour policies, compiled. One entry per policy, keyed by name, holding its grants, denies, guardrails, and budgets.

What a policy compiles to

The builder's fields become a flat data document under data.roles["your_policy"]. This is the entire vocabulary the engine reads:

"default_model_tier": {
  "mode":          "block",        // block = enforce · monitor = observe
  "pii_policy":    "log",          // log · redact · block
  "models_allow":  ["claude-sonnet-4-5", "claude-haiku-4-5"],
  "tools_allow":   ["kb.search", "report.generate", "data.query"],
  "tools_deny":    ["loan.review", "loan.approve", "wire.process"],
  "scopes_allow":  ["kb:*", "data:*", "reports:*"],
  "scopes_deny":   [],
  "topics_deny":   ["compensation", "mnpi"],
  "budgets":       { "tokens_per_day": 100000, "requests_per_minute": 60 }
}

The decision surface

The fixed module — package aifw.authz — exposes one rule per dimension of the request. Each is a small, total function with a safe default, so an unmapped or malformed input can only ever produce a denial.

Models — allow-list

A model is permitted only if it appears in the policy's models_allow. The default is false: a policy that grants no models denies every request.

default allow_model := false
allow_model if {
  rd := data.roles[input.role]
  input.model in rd.models_allow
}

Tools — three verdicts

Tools distinguish an explicit denial from a mere absence of a grant, so an audit can tell "we refused this" apart from "this was never offered." Explicit denies always win over allows.

default tool_verdict := "not_allowed"
tool_verdict := "denied_explicit" if input.tool in data.roles[input.role].tools_deny
tool_verdict := "allowed" if {
  not input.tool in data.roles[input.role].tools_deny
  input.tool in data.roles[input.role].tools_allow
}
VerdictMeaning
allowedIn tools_allow and not in tools_deny.
denied_explicitNamed in tools_deny — refused even if also allowed elsewhere.
not_allowedNamed in neither list — no grant exists, so it is denied by default.

Data scopes — every scope must pass

A request often touches several data scopes at once. All of them must be allowed for the request to proceed — one denied scope fails the whole request. Scope matching honors the wildcard families you author (kb:* covers kb:article:123).

allow_scopes if every s in input.scopes {
  scope_allowed(s, data.roles[input.role])
}

Topics — deny-list guardrail

Topics run the other way: anything in the policy's topics_deny stops the request, independent of which model or tool was requested. This is how a baseline blocks compensation or mnpi for everyone it covers.

Derived tool-denies

Compilation closes one gap the raw data does not spell out. If a tool would touch a data scope your policy denies, the compiler adds that tool to tools_deny automatically — even when you never named it. So a policy that denies the customers:pii scope also denies a "look up full customer record" tool that reads it, and you reason about data boundaries without enumerating every tool that might cross one.

# You wrote only this:
"scopes_deny": ["customers:pii"]

# Compilation derives this, because account.lookup_full touches customers:pii:
"tools_deny": ["…", "account.lookup_full"]  // ← added for you

Fail-closed by construction

Every rule has a deny-shaped default, so the failure modes are safe without any special-casing:

  • An unknown policy name resolves to no entry in data.roles — models fail closed and every tool verdict is not_allowed.
  • Empty or malformed input matches no allow rule, so it is denied.
  • A policy that grants nothing denies everything. Least privilege is the resting state, not a setting you remember to enable.

Worked example

The same request, judged against two policies from the sample tenant — identical input, different data, fully determined outcome:

Requestdefault_model_tierfrontier_model_access
model claude-opus-4-8model_denied not grantedallow granted
tool data.queryallowedallowed
tool wire.processdenied_explicitnot_allowed
topic compensationtopic_deniedallow

The Rego is read-only for a reason: a policy engine you can edit is a policy engine an attacker can edit. The logic stays fixed and audited; all of your intent lives in the data — which is versioned, immutable once published, and replayable for any past decision.

Type to search the documentation.