Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 25 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,37 @@
# Covenant

An in-perimeter **AI inference governance and FinOps control plane** for organizations that must show who used which model, with what data, where it ran and what it cost. Every LLM request passes through one governed pipeline: identified, classified, policy-routed, budget-checked, cost-attributed and audited — including the requests that get refused.
An in-perimeter **AI inference governance and FinOps control plane** for organizations that must show who used which model, with what data, where it ran and what it cost. Every LLM request passes through one governed pipeline: identified, classified, policy-routed, budget-checked, cost-attributed and audited; including the requests that get refused.

Research artifact: can inference governance be an architecturally separable control layer — enforceably, evidentially, and at acceptable cost?
Research artifact: can inference governance be an architecturally separable control layer; enforceably, evidentially, and at acceptable cost?

**Start here:** [User guide](docs/user-guide.md) · [7-minute demo](docs/demo-7-minute.md) · [Console usage guide](docs/console-quickstart.md) · [Tavily setup](docs/web-search.md)

## Deployment and trust boundaries

```mermaid
flowchart LR
subgraph Org["Customer perimeter"]
direction LR
Apps["Calling applications<br/>(app key → team)"] --> C["Covenant appliance<br/>canonical proxy + policy middleware"]
Console["Admin console<br/>(admin token)"] --> C
C --> Ollama["Local models<br/>(Ollama, in perimeter)"]
C -.-> Audit[("Hash-chained audit<br/>+ budget ledger")]
Vault["Server-side secrets<br/>(env / vault)"] -.-> C
end
C == "approved egress allow-list only" ==> Providers["Approved model providers<br/>(Anthropic, OpenAI)"]
C == "Public only, opt-in" ==> Search["Tavily web search"]
Browser["Direct SaaS use in a browser"] -. "outside Covenant's scope" .-> Providers
```

Credentials stay on the server; the console never holds an application key or a provider key. Egress is limited to the
startup allow-list. Traffic that does not pass through Covenant (for example a browser talking to a SaaS chatbot) is not
governed by it; that needs network or endpoint controls.

## Request journey

```mermaid
flowchart LR
A["Identify caller<br/>application → team"] --> B["Classify<br/>workload baseline,<br/>detection may raise"]
B --> P["Policy<br/>one match → approved<br/>primary + fallback"]
P --> R["Sanitize<br/>only for an opted-in<br/>structured-record route"]
R --> K["Exact cache"] --> G["Rate · pause · budget<br/>reserve before spend"]
G --> W["Web search<br/>(Public, opt-in)"] --> M["Model call<br/>Local or External"]
M --> F["Finalize cost"] --> E[("Audit record<br/>every request, refused too")]
P -. "no match / not eligible" .-> X["Refuse (fail-closed)"] -.-> E
```

The patterns are a canonical proxy with policy middleware, approved model routing with bounded fallback,
retrieval-augmented answers from one governed web search, an exact-match cache, and per-request attribution and
tamper-evident audit. Covenant does **not** rewrite prompts, does not judge answer quality, and has no learned quality
router. The optional length-based strategy is a deterministic size threshold (characters / 4), not a quality signal.
Sanitization (ADR-0016) applies only to a bounded structured record on a dedicated route. It is not anonymisation.
## System overview

Applications send AI requests through Covenant. It checks the caller, data, policy and budget before selecting an approved model. Local processing stays inside the organization. Cloud inference and web search cross the boundary only when permitted. Every outcome has an audit record and cost attribution.

![Covenant system overview](docs/diagrams/covenant-overview.svg)

[Edit the overview in Draw.io](docs/diagrams/covenant-overview.drawio)

## Request flow

The numbered flow shows the checks in execution order. A matching cache entry avoids a model call. A refusal stops further work, but earlier calls can still have a cost. The final record identifies the application, team, route, outcome and charges.

![Covenant request processing flow](docs/diagrams/covenant-architecture.svg)

[Edit the detailed diagram in Draw.io](docs/diagrams/covenant-architecture.drawio)

**Architecture patterns:** canonical proxy, policy middleware, provider adapters, exact-match cache, governed retrieval and tamper-evident audit. Routing follows configured rules. Covenant does not evaluate answer quality or automatically rewrite prompts.

**Scope:** traffic must pass through Covenant to be governed. Direct chatbot access needs network or endpoint controls. Sensitive-data inspection is heuristic, not comprehensive DLP. The optional sanitized route accepts a narrow structured schema; it does not anonymize arbitrary prose or PHI.

Both diagrams use editable Draw.io shapes and connectors. The matching SVG images are generated from [the diagram source](docs/diagrams/gen_diagram.py).

## Working principles

1. **Fail-closed.** No policy match → deny. Unclassified defaults to the most restrictive class. Misconfiguration → the appliance refuses to start. Raw PII/PHI never reaches a public provider. The one opt-in exception (ADR-0016) sends only a Covenant-built, sanitized payload of a bounded structured record for a dedicated PII workload; PHI and free text never qualify.
2. **Governance is the pipeline, not a bolt-on.** Every capability — classification, policy, budgets, attribution, audit — is an ordered stage in one middleware chain. Nothing bypasses it.
1. **Fail-closed.** No policy match → deny. Unclassified defaults to the most restrictive class. Misconfiguration → the appliance refuses to start. Detected raw PII/PHI is excluded from public provider routes. The one opt-in exception (ADR-0016) sends only a Covenant-built, sanitized payload of a bounded structured record for a dedicated PII workload; PHI and free text never qualify.
2. **Governance is the pipeline, not a bolt-on.** Every capability; classification, policy, budgets, attribution, audit; is an ordered stage in one middleware chain. Nothing bypasses it.
3. **Everything is evidence.** Each request, allowed or denied, appends exactly one hash-chained audit entry. Altering any past entry breaks every hash after it.
4. **The perimeter is sacred.** Deployed inside the customer boundary; egress only to approved model endpoints and explicitly enabled Public web search (ADR-0015); no phone-home.

Expand Down
104 changes: 104 additions & 0 deletions docs/adr/ADR-0019-workload-sensitive-data-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# ADR-0019 — Per-workload action on detected sensitive data: route or reject

**Status:** Accepted
**Date:** 2026-11-02
**Relates to:** ADR-0012 (trusted baseline; detection may only escalate), ADR-0013 (PII/PHI never external; no match ⇒
refuse), ADR-0016 (sanitized structured-record exception), ADR-0018 (local inspection; incomplete ⇒ refuse).

## Context
Detection escalates a request's classification (ADR-0012): final = max(workload baseline, detected). The escalated
request is then routed by whatever policy covers PII/PHI. In the demo seed that is `sensitive` (PII & PHI → local
model), a policy with no profile scope. So a request sent under the **Public** workload that contains an SSN is
served by the local model.

That is safe: nothing leaves the perimeter. The evidence also records it: the audit record and the console show the
escalated classification and the detector signal. But the request still succeeds on a destination the caller did not
declare for: they said "this is public content", the content contradicts that, and the gateway serves it elsewhere
instead of refusing. Two things follow:

- a workload cannot say "never accept sensitive data" — the most it gets is an after-the-fact evidence entry;
- the demo cannot show the difference between "an Internal workload that is approved to process sensitive data
locally" and "a Public workload that must never receive it". Both end up on the same local model.

A UI-side fix (pinning a model, special-casing an example name) would not change what the gateway does for a raw API
caller, so it would be theatre. The decision has to be server-side, per workload, versioned and audited.

## Decision
1. **A workload profile states what happens when detection finds PII or PHI.** New field
`WorkloadProfileConfig.SensitiveDataAction`, wire name `sensitive_data_action`:
- `route` (default): today's behaviour. The classification is escalated and the policy for PII/PHI decides.
ADR-0013 still applies, so that policy can only use local targets — except the ADR-0016 sanitized policy.
- `reject`: when detection raises the classification to PII or PHI, the request is **refused at the classify
stage**, before policy, sanitization, cache, rate limit, budget, web search and provider. Nothing is sent
anywhere and nothing is reserved.

The name is `route`, not `route_local`: the profile does not choose the destination; the versioned policy does,
and the existing invariants keep PII/PHI local.

2. **Default `route`; existing configurations are unchanged.** A version without the field reads as `route`. No
stored version is rewritten. The dedicated sanitized-record workload (baseline PII, ADR-0016) keeps working.

3. **Validation.** `reject` is valid only on a Public- or Internal-baseline profile (code
`sensitive_action_requires_non_sensitive_baseline`). On a PII/PHI baseline every request is sensitive by
declaration, so rejecting "detected" sensitive data would reject everything. An undefined value is `invalid_enum`.

4. **One rule, three callers.** `SensitiveDataRules.Rejects(cfg, profileId, finalClassification)` decides;
`SensitiveDataRules.Explain(...)` builds the reason and `SensitiveDataRules.Suggestions(...)` the suggested
workloads. The rule is called by:
- the classify stage (runtime);
- `POST /admin/policies/simulate` (the preview shows the same refusal and reason);
- `PolicyEngineV2.Evaluate` (defence in depth). This also means the impact preview and route summaries show
"refused" for PII/PHI under a `reject` workload.

Incomplete inspection (ADR-0018) is still checked first and still refuses with `inspection_incomplete`.

5. **Evidence and feedback.** The refusal is a governance denial at stage `classify` with reason code
`sensitive_data_rejected`. The audit record keeps:
- the escalated classification (PII/PHI);
- the detector signal label (never the matched value);
- the application, team and workload.

The reason names the workload and the detected kind. When the same application is granted another workload under
which the engine would route that classification (action `route`, an eligible route), the reason also suggests it
by id. The simulate response returns the same suggestion as `suggested_profiles`. The suggestion is computed by
the policy engine, never hard-coded.

6. **Demo seed.** `public-demo` is seeded with `reject`; `internal-default` keeps `route`. Seeds only create a first
version; an existing runtime is not changed (see Migration).

## Migration (existing saved configurations)
Nothing changes until an operator saves a new version. To get the new demo behaviour on a runtime created before
this ADR, set `sensitive_data_action` to `reject` on the Public workload. This creates version N+1, audited as
`config.activated`. Either:

- **Console:** Policies → Workloads → *Public demo* → Edit → "When sensitive data is detected" → **Reject the
request** → Save.
- **API:**
1. `GET /admin/config`; note `etag` (`"vN"`).
2. In `config.profiles`, on the entry with `"id": "public-demo"`, add `"sensitive_data_action": "reject"`.
3. `POST /admin/config/validate` with `{"base_version": N, "config": …}`. Expect `valid: true`. The impact lists
PII and PHI under `public-demo` changing to `refused: …`.
4. `PUT /admin/config` with `If-Match: "vN"` and `{"config": …, "change_summary": "public-demo rejects detected
sensitive data (ADR-0019)"}`.

Rollback is the normal configuration rollback to vN.

## Consequences
- A Public workload can now say "never accept sensitive data". The caller gets an explicit refusal with the reason
and a suggested workload, instead of a local answer to a request it declared public.
- The console offers the Internal-local / Public-rejected example pair only to an application whose workloads show both
halves, so applications without that set-up are not shown sensitive-data examples.
- The audit still shows what was detected, so Usage still counts "sensitive detected".
- One more profile field in the configuration contract, the UI DTO and the workload editor.
- Detection quality limits still apply (ADR-0018): `reject` acts on what the local inspector detects. It does not
guarantee that a Public request is free of sensitive data.

## Alternatives considered
- **Policy-level flag** ("this PII policy refuses for Public"). Rejected: the policy is chosen by the escalated
classification, so it no longer knows which workload the caller declared, unless every sensitive policy is
profile-scoped. It is also the wrong owner: the declaration belongs to the workload.
- **Always reject sensitive data under Public.** Rejected: a breaking change for existing deployments, and some
operators want "serve locally" as the safe default.
- **UI pin / example special-casing.** Rejected: it does not govern raw API callers.
- **`route_local` as a second action.** Rejected: the profile would then pick a destination, bypassing the
versioned policy that owns routing.
9 changes: 5 additions & 4 deletions docs/demo-7-minute.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ pricing.

## 3. Sensitive record: denied, then an explicit sanitized route (≈2.5 min)

1. **Local, then denied:** example **Sensitive data detected: served locally** (same prompt, policy chooses → local), then
**Sensitive data: explicit external attempt is blocked**. The synthetic SSN `000-12-3456` raises the request
to PII, and the pinned external model is refused at Policy. The red **Sensitive · PII (detected …)** chip shows it;
nothing is sent.
1. **Local, then denied:** choose **Demo application**, then **Internal workload: sensitive data served locally**.
Use example selects Internal. Run it, switch to Public, and run the identical prompt. The synthetic SSN raises
classification to PII; the Public workload rejects it at Classify, before cache, search or any model call.
The paired **Public workload: the same sensitive data is rejected** example is recommended too.
Configure the Public workload to **Reject the request** on detection before the session.
2. **Explicit policy:** Policies → Routes → the `support-records` route. Show the **Sanitized external route** section:
- only the dedicated PII workload uses it;
- only the listed identifier fields and tasks are accepted;
Expand Down
2 changes: 1 addition & 1 deletion docs/demo-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ From **Overview**, click **Open Playground**. Choose **Send a request as → Exa

1. **Research assistant → Public research: local model + governed web search.** Show local inference, Tavily sources and the separate search charge.
2. **Engineering assistant → Compare local coding with <configured external model>** (for example Claude Opus 5.5; the title comes from the approved route). Before Run, the steps say: local first, then an explicit comparison. Run locally, then press **Compare with Claude Opus 5.5**. It is a separate paid request using the same original prompt and caller; which answer is better is your judgement.
3. **Communications assistant → More examples → Sensitive data detected: served locally**, then **Sensitive data: explicit external attempt is blocked**. Same synthetic prompt: with policy choosing it is *Served locally · sensitive data detected*; with the example's explicit external pin it is *Blocked · sensitive data cannot go external* (a governance block, not a provider outage). Switching workload resets the example's pin to “Let policy choose”.
3. **Demo application → Internal workload: sensitive data served locally.** Use example selects **Internal**. Run and show the local answer. Switch only the workload to **Public** and run the same prompt: the gateway rejects it before cache, search or model calls. The paired Public rejection example is also in the recommended list. This requires the Public workload's **When sensitive data is detected** setting to be **Reject the request**.
4. **Support assistant → Sensitive record: sanitized external call (opt-in).** Use example, review the placeholder-only payload, tick the confirmation and Run. Only the supported structured record qualifies; arbitrary prose and PHI do not.
5. **Engineering assistant → More examples → Repeat a request: exact cache hit.** Run twice within five minutes. The second is audited but makes no provider call.
6. Open **Usage** to show who pays; **Requests** (25 per page, Previous/Next) → **View** explains an individual decision; **Budgets** shows Global plus the additional application ceiling over the same charges. **Audit & evidence → Check audit integrity** checks record consistency, not answer correctness.
Expand Down
Loading
Loading