Skip to content

E5: engagement authorization artifact in the target gate, hash-chained audit schema - #16

Open
cybersicilian wants to merge 10 commits into
mainfrom
ej/20261124-092436-5933f8
Open

cybersicilian wants to merge 10 commits into
mainfrom
ej/20261124-092436-5933f8

Conversation

@cybersicilian

@cybersicilian cybersicilian commented Nov 24, 2026 •

Copy link
Copy Markdown

Why

E5 follow-up: audit-chain head lock serializes all intercept writes

What: audit_append (db/migrations/0016_engagement_governance.sql) takes audit_chain_head FOR UPDATE and holds it until commit. Every intercept_pending write (trigger), login audit and rbac.denied therefore queues behind any open transaction that already wrote an intercept row. A task archive (db/task_archives_restore.go ~L67, which deletes intercept rows early in a long transaction) stalls gate decisions, dials and logins until it commits. There is also a plausible deadlock risk for multi-statement transactions that write an intercept row and then need another lock (task delete settleTaskTargetRequests, decide-plus-pin in db/target_pins.go).

What changed

  • E5: engagement authorization artifact in the target gate, hash-chained audit schema (7417d80)

    Migration 0016: audit_chain (append-only, SHA-256 linked, row triggers on
    intercept_pending/artex_users/engagement_authorizations), artex_users,
    engagement_authorizations (versioned, immutable rows).

    The artifact (scope, time window, technique classes) is consulted inside the
    existing target gate: run() and ungated() check it first, and target-less calls
    go through authorizeCall from CheckTargets/CheckUngated. Refusals are decided
    intercept rows. Card c-669406.

  • E5: authorization and audit-chain endpoints, chain verification with tamper tests (b5c74e9)

    GET/POST /api/tasks/{id}/authorization, POST .../revoke;
    GET /api/intercept/history/chain and /chain/verify. Verification recomputes
    every hash, checks seq continuity and the head row, and compares each
    intercept history row with its newest chain entry. Card c-669406.

  • E5: governance endpoints read the task id from the path, HTTP test (aa90ed4)

  • E5: RBAC (admin/operator/reviewer/client_read) over the existing JWT, users API, docs (50384f0)

    Console users in artex_users; tokens carry uid/uv and are checked against the
    row on every request (fails closed). The legacy ARTEX login stays admin.
    requireAuth enforces a declarative route policy (server/rbac_policy.go) matched
    on the mux pattern; refusals answer 403 and are appended to the audit chain.
    Logins are audited. Fix: the authorization check no longer claims the call's
    trace entry unless it refuses (kept exact intercept correlation).
    docs/GOVERNANCE.md documents roles, the artifact and the chain. Card c-669406.

  • E5: review fixes — spawn_task inherits the artifact, snapshot/UTC verify, tighter reads (7bd8478)

    • spawn_task: the child inherits the caller's current artifact (read from the
      call's scope); a revoked/expired artifact refuses the spawn, and the gate
      keeps window/revocation on spawn_task.
    • Local tools return before the artifact lookup (never refused, no query).
    • Verify runs in one repeatable-read UTC snapshot; the row trigger pins UTC.
    • Reviewers lose raw traffic exchange/blob/HAR/stream and conversation messages.
    • change-password is limited to the ARTEX session; actor names reserved;
      control characters stripped from audited usernames.
    • Docs and CHANGELOG. Card c-669406.
  • HANDOFF: E5 state, triage, decisions, follow-up cards (934ba39)

  • HANDOFF: renumber triage (12a9480)

  • HANDOFF: deltas stamp (b59577d)

  • db: chain audit row entries at commit (migration 0018) so the head lock no longer stalls gate writes (c-ba9f64) (730ddb1)

    The intercept_pending, artex_users and engagement_authorizations audit
    triggers become DEFERRABLE INITIALLY DEFERRED constraint triggers. The
    audit_chain_head lock is now taken only during COMMIT, after every other
    lock, so a task archive no longer stalls gate decisions, logins and
    rbac.denied entries, and write-then-lock transactions cannot deadlock on
    the head. Concurrency tests reproduce both failures without 0018.

  • HANDOFF: deltas stamp (c-ba9f64) (6d78d3a)

Files changed

Tests touched: db/audit_chain_concurrency_test.go, db/governance_test.go, db/migrate_test.go, db/users_test.go, intercept/authorization_test.go, intercept/target_gate_test.go, server/auth_cookie_test.go, server/governance_api_test.go …

31 files, +3798 −31
File + −
db/authorization.go 321 0
server/rbac_pg_test.go 290 0
server/rbac_policy_test.go 290 0
db/audit_chain.go 258 0
server/governance_api.go 234 0
server/rbac.go 226 0
db/governance_test.go 212 0
db/users.go 202 0
server/users_api.go 198 0
server/rbac_policy.go 192 0
intercept/authorization_test.go 191 0
db/migrations/0016_engagement_governance.sql 188 0
db/audit_chain_concurrency_test.go 184 0
intercept/authorization.go 138 0
docs/GOVERNANCE.md 122 0
server/governance_api_test.go 120 0
intercept/technique.go 104 0
db/users_test.go 98 0
HANDOFF.md 75 10
db/migrations/0018_audit_chain_deferred.sql 49 0
server/auth.go 32 15
intercept/target_gate.go 17 1
server/orchestration.go 13 0
server/auth_cookie.go 10 1
guard/guard.go 8 0
intercept/target_gate_test.go 7 0
CHANGELOG.md 6 0
intercept/target_egress.go 5 1
db/migrate_test.go 3 2
server/auth_cookie_test.go 3 1
server/server.go 2 0

Opened by Composite · ej/20261124-092436-5933f8 → main · card c-ba9f64 · run 20261124-092436-5933f8

🤖 Generated with Claude Code


Summary by cubic

Adds engagement governance: role-based console users, per-task authorization artifacts the target gate enforces, and a hash-chained audit log over intercept history, users, and authorizations.

New Features

  • Roles admin, operator, reviewer, and client_read are enforced through a declarative route policy over the existing JWT; the legacy ARTEX login stays the break-glass admin.
  • Per-task authorization artifacts set scope, a time window, and allowed technique classes; the gate refuses out-of-window, revoked, out-of-scope, and unauthorized-technique calls and logs them as decided intercept rows.
  • The audit chain is append-only and SHA-256 linked, written by row triggers plus logins and role refusals; /chain/verify recomputes every hash and flags tampering.
  • Agents that spawn a task inherit the caller's current artifact; a revoked or expired artifact refuses the spawn.
  • Admin-only endpoints manage users, the per-task artifact, and the chain views.

Migration

  • Migration 0018 makes the audit triggers DEFERRABLE INITIALLY DEFERRED so the chain head lock is taken only at commit, removing write stalls and deadlock risk during long transactions such as task archives.

Written for commit 6d78d3a. Summary will update on new commits.

View guided diff Turn on auto-fix

cybersicilian and others added 10 commits November 24, 2026 06:10
…d audit schema

Migration 0016: audit_chain (append-only, SHA-256 linked, row triggers on
intercept_pending/artex_users/engagement_authorizations), artex_users,
engagement_authorizations (versioned, immutable rows).

The artifact (scope, time window, technique classes) is consulted inside the
existing target gate: run() and ungated() check it first, and target-less calls
go through authorizeCall from CheckTargets/CheckUngated. Refusals are decided
intercept rows. Card c-669406.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tamper tests

GET/POST /api/tasks/{id}/authorization, POST .../revoke;
GET /api/intercept/history/chain and /chain/verify. Verification recomputes
every hash, checks seq continuity and the head row, and compares each
intercept history row with its newest chain entry. Card c-669406.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… users API, docs

Console users in artex_users; tokens carry uid/uv and are checked against the
row on every request (fails closed). The legacy ARTEX login stays admin.
requireAuth enforces a declarative route policy (server/rbac_policy.go) matched
on the mux pattern; refusals answer 403 and are appended to the audit chain.
Logins are audited. Fix: the authorization check no longer claims the call's
trace entry unless it refuses (kept exact intercept correlation).
docs/GOVERNANCE.md documents roles, the artifact and the chain. Card c-669406.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ify, tighter reads

- spawn_task: the child inherits the caller's current artifact (read from the
  call's scope); a revoked/expired artifact refuses the spawn, and the gate
  keeps window/revocation on spawn_task.
- Local tools return before the artifact lookup (never refused, no query).
- Verify runs in one repeatable-read UTC snapshot; the row trigger pins UTC.
- Reviewers lose raw traffic exchange/blob/HAR/stream and conversation messages.
- change-password is limited to the ARTEX session; actor names reserved;
  control characters stripped from audited usernames.
- Docs and CHANGELOG. Card c-669406.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck no longer stalls gate writes (c-ba9f64)

The intercept_pending, artex_users and engagement_authorizations audit
triggers become DEFERRABLE INITIALLY DEFERRED constraint triggers. The
audit_chain_head lock is now taken only during COMMIT, after every other
lock, so a task archive no longer stalls gate decisions, logins and
rbac.denied entries, and write-then-lock transactions cannot deadlock on
the head. Concurrency tests reproduce both failures without 0018.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T16:53:58.481089Z
We couldn’t complete this review. Comment @codex review to try again.
6d78d3a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

25 issues found across 31 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="HANDOFF.md">

<violation number="1" location="HANDOFF.md:62">
P3: This current-state entry points a cold handoff to the old E5 source branch, although this revision already contains E5 through the 0018 branch. State that E5 is included in the current revision instead, so the next operator does not inspect the wrong branch.</violation>
</file>

<file name="CHANGELOG.md">

<violation number="1" location="CHANGELOG.md:12">
P2: The verifier path is incomplete here: `/chain/verify` is not a registered endpoint and returns 404. Publish the full `GET /api/intercept/history/chain/verify` path so operators can actually run chain verification.</violation>
</file>

<file name="db/migrations/0018_audit_chain_deferred.sql">

<violation number="1" location="db/migrations/0018_audit_chain_deferred.sql:33">
P1: Applying migration 0018 before the pending 0017 migration makes future upgrades fail closed: the migration loader rejects 0017 as older than the already-applied 0018. Renumber this migration or ensure 0017 is shipped and applied before 0018 can reach deployed databases.</violation>
</file>

<file name="db/authorization.go">

<violation number="1" location="db/authorization.go:112">
P2: Unicode domain authorizations are stored in a different representation from gated targets. Normalize domain and host scope values with the same IDNA-to-ASCII canonicalization used by `intercept.NormalizeTarget`, or reject non-ASCII names, so an authorization for an IDN does not refuse every request to that authorized host.</violation>
</file>

<file name="server/rbac_policy_test.go">

<violation number="1" location="server/rbac_policy_test.go:48">
P2: This route-inventory test does not cover all registered endpoints despite its name, so a missing or incorrect RBAC rule for finding-traffic edits or side questions can pass unnoticed. Include every constructed pattern, or replace source scanning with a shared route inventory used by registration and tests.</violation>

<violation number="2" location="server/rbac_policy_test.go:87">
P1: This allowlist makes the RBAC test bless client_read/reviewer access to raw finding traffic and bodies instead of catching it. Exclude the traffic subtree and add explicit denial cases, then tighten the corresponding policy rule so those endpoints require the sensitive-data permission.</violation>
</file>

<file name="server/rbac_policy.go">

<violation number="1" location="server/rbac_policy.go:120">
P1: This prefix allowlist lets `client_read` and reviewers download raw finding traffic bodies, which can contain captured secrets. Require `permOperate` for the traffic-body route before the broad findings rule.</violation>
</file>

<file name="db/audit_chain_concurrency_test.go">

<violation number="1" location="db/audit_chain_concurrency_test.go:30">
P2: `withinBound` can hang forever instead of failing after its three-second timeout. Run the operation with cancellation or bound the post-release wait so an unresponsive operation cannot wedge the test suite.</violation>

<violation number="2" location="db/audit_chain_concurrency_test.go:163">
P2: This test does not reliably establish that tx1 is waiting on tx2 before committing tx2, so it can pass without exercising the claimed lock-order interaction. Synchronize on observable PostgreSQL lock-wait state before calling `tx2.Commit`.</violation>
</file>

<file name="db/audit_chain.go">

<violation number="1" location="db/audit_chain.go:172">
P2: `verifyAudit` starts scanning at sequence 1 and ignores lower sequence numbers. Validate the full sequence range or enforce `seq >= 1`, otherwise an extra `seq=0` entry can survive verification while the head remains valid.</violation>

<violation number="2" location="db/audit_chain.go:228">
P2: `VerifyAudit` misses source-row tampering: an intercept row deleted behind its trigger is never checked, and `artex_users` and `engagement_authorizations` are never checked at all. Compare the latest non-DELETE entry for every audited table with live rows, treating a latest DELETE as the expected absence.</violation>
</file>

<file name="server/governance_api.go">

<violation number="1" location="server/governance_api.go:61">
P2: `GET /api/tasks/{id}/authorization` returns 200 with an empty or exposed artifact list for nonexistent or soft-deleted tasks. Check task existence and deletion status before listing so clients do not confuse a missing task with an unconfigured one.</violation>

<violation number="2" location="server/governance_api.go:104">
P2: The optional revoke body rejects an empty chunked request because `ContentLength` is `-1` and decoding returns EOF. Treat EOF as no body while continuing to reject malformed JSON.</violation>

<violation number="3" location="server/governance_api.go:212">
P2: `callerAuthorization` reports revoked artifacts as `AUTHORIZATION_OUT_OF_WINDOW`, unlike the target gate’s distinct `AUTHORIZATION_REVOKED` result. Check `Revoked` first and return `AuthorizationRevoked` so callers and audit handling can distinguish revocation from expiry.</violation>
</file>

<file name="docs/GOVERNANCE.md">

<violation number="1" location="docs/GOVERNANCE.md:5">
P3: The opening schema pointer omits migration 0018, which contains the deferred-trigger definition required for the documented audit behavior. Point readers to both migrations or call 0016 the base schema.</violation>

<violation number="2" location="docs/GOVERNANCE.md:13">
P3: The reviewer row says reviewers can read everything except three categories, but reviewers also cannot read raw traffic or conversation messages. Align the table with the route policy so operators do not grant reviewers access they do not have.</violation>

<violation number="3" location="docs/GOVERNANCE.md:26">
P3: The reserved-name list omits `artex`, so an administrator may expect that username to be available and receive a validation failure. Include the lowercase bootstrap name in the list and explain its reservation.</violation>

<violation number="4" location="docs/GOVERNANCE.md:47">
P3: This endpoint returns the newest version as `current` plus an `in_force` boolean, not a separate version in force. Document that distinction so API consumers do not treat an expired or revoked `current` artifact as active.</violation>

<violation number="5" location="docs/GOVERNANCE.md:51">
P3: The artifact is also enforced outside the target gate for `spawn_task`: `callerAuthorization` rejects revoked or expired callers before child creation. Scope the claim to target calls and document this separate spawn check.</violation>

<violation number="6" location="docs/GOVERNANCE.md:114">
P2: Row-entry actors are not unconditionally `artex.actor` at commit: target-gate intercepts and other writes can use the trigger fallbacks. Document those fallbacks so audit consumers do not misinterpret the actor as the transaction caller.</violation>
</file>

<file name="server/rbac.go">

<violation number="1" location="server/rbac.go:56">
P2: `parseSession` accepts every HMAC algorithm even though this service issues HS256 sessions. Pin the accepted algorithm to HS256 so tokens from another HMAC variant cannot enter the session-validation contract.</violation>

<violation number="2" location="server/rbac.go:152">
P2: This helper silently drops login and role-denial events when `AppendAudit` fails, so the required audit trail is incomplete during a chain or database outage. Propagate the append failure or durably queue the event and fail closed instead of treating security auditing as best effort.</violation>
</file>

<file name="intercept/technique.go">

<violation number="1" location="intercept/technique.go:37">
P2: `toolWords` treats the dots in script names as regexp wildcards, causing unrelated command names and paths to be classified as restricted techniques and refused under narrower artifacts. Escape each signal with `regexp.QuoteMeta` before joining the alternatives.</violation>

<violation number="2" location="intercept/technique.go:86">
P2: The default extractor drops every command field when any optional field has the wrong JSON type, allowing a tool whose command is carried in `args` to evade technique classification. Decode these fields independently, such as by first using `json.RawMessage` fields, so one malformed field cannot suppress a valid technique signal.</violation>
</file>

<file name="server/orchestration.go">

<violation number="1" location="server/orchestration.go:334">
P1: The spawn path snapshots the parent authorization before creating the child, then copies it without rechecking the parent. An admin can publish or revoke a newer version in between, allowing the child to start under superseded terms; revalidate or lock the parent version during inheritance.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

-- * SET CONSTRAINTS ... IMMEDIATE would bring back the old behaviour for that
-- transaction; the application never issues it.

DROP TRIGGER IF EXISTS trg_intercept_pending_audit ON intercept_pending;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Applying migration 0018 before the pending 0017 migration makes future upgrades fail closed: the migration loader rejects 0017 as older than the already-applied 0018. Renumber this migration or ensure 0017 is shipped and applied before 0018 can reach deployed databases.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At db/migrations/0018_audit_chain_deferred.sql, line 33:

<comment>Applying migration 0018 before the pending 0017 migration makes future upgrades fail closed: the migration loader rejects 0017 as older than the already-applied 0018. Renumber this migration or ensure 0017 is shipped and applied before 0018 can reach deployed databases.</comment>

<file context>
@@ -0,0 +1,49 @@
+--   * SET CONSTRAINTS ... IMMEDIATE would bring back the old behaviour for that
+--     transaction; the application never issues it.
+
+DROP TRIGGER IF EXISTS trg_intercept_pending_audit ON intercept_pending;
+CREATE CONSTRAINT TRIGGER trg_intercept_pending_audit
+    AFTER INSERT OR UPDATE OR DELETE ON intercept_pending
</file context>

return true
}
return strings.HasPrefix(path, "/api/report/") || path == "/api/exploration/findings" ||
strings.HasPrefix(path, "/api/exploration/findings/")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This allowlist makes the RBAC test bless client_read/reviewer access to raw finding traffic and bodies instead of catching it. Exclude the traffic subtree and add explicit denial cases, then tighten the corresponding policy rule so those endpoints require the sensitive-data permission.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At server/rbac_policy_test.go, line 87:

<comment>This allowlist makes the RBAC test bless client_read/reviewer access to raw finding traffic and bodies instead of catching it. Exclude the traffic subtree and add explicit denial cases, then tighten the corresponding policy rule so those endpoints require the sensitive-data permission.</comment>

<file context>
@@ -0,0 +1,290 @@
+		return true
+	}
+	return strings.HasPrefix(path, "/api/report/") || path == "/api/exploration/findings" ||
+		strings.HasPrefix(path, "/api/exploration/findings/")
+}
+
</file context>

Comment thread server/rbac_policy.go

// --- client_read: the allowlist for the client-facing role ---
{http.MethodGet, "/api/report", true, permClientRead},
{http.MethodGet, "/api/exploration/findings", true, permClientRead},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This prefix allowlist lets client_read and reviewers download raw finding traffic bodies, which can contain captured secrets. Require permOperate for the traffic-body route before the broad findings rule.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At server/rbac_policy.go, line 120:

<comment>This prefix allowlist lets `client_read` and reviewers download raw finding traffic bodies, which can contain captured secrets. Require `permOperate` for the traffic-body route before the broad findings rule.</comment>

<file context>
@@ -0,0 +1,192 @@
+
+	// --- client_read: the allowlist for the client-facing role ---
+	{http.MethodGet, "/api/report", true, permClientRead},
+	{http.MethodGet, "/api/exploration/findings", true, permClientRead},
+	{http.MethodGet, "/api/stats", false, permClientRead},
+	{http.MethodGet, "/api/tasks/{id}/outcome", false, permClientRead},
</file context>

Comment thread server/orchestration.go
// its current version, so spawning cannot shed the scope, window or
// techniques. A revoked or out-of-window artifact refuses the spawn
// (the gate refuses it first; this is the second line).
inherited, err := s.callerAuthorization(ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The spawn path snapshots the parent authorization before creating the child, then copies it without rechecking the parent. An admin can publish or revoke a newer version in between, allowing the child to start under superseded terms; revalidate or lock the parent version during inheritance.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At server/orchestration.go, line 334:

<comment>The spawn path snapshots the parent authorization before creating the child, then copies it without rechecking the parent. An admin can publish or revoke a newer version in between, allowing the child to start under superseded terms; revalidate or lock the parent version during inheritance.</comment>

<file context>
@@ -327,6 +327,14 @@ func (s *Server) toolSpawnTask() actool.CoreTool {
+			// its current version, so spawning cannot shed the scope, window or
+			// techniques. A revoked or out-of-window artifact refuses the spawn
+			// (the gate refuses it first; this is the second line).
+			inherited, err := s.callerAuthorization(ctx)
+			if err != nil {
+				return actool.Errorf(err.Error()), nil
</file context>

Comment thread CHANGELOG.md
- **Engagement governance** (`docs/GOVERNANCE.md`):
- **Console users and roles.** The roles are `admin`, `operator`, `reviewer` and `client_read`. A declarative route policy is enforced in `requireAuth`. Admins manage users through `/api/users`, and the `ARTEX` login stays the break-glass admin.
- **Per-task authorization artifact.** It sets the scope, the time window and the allowed technique classes. It is versioned and immutable (`/api/tasks/{id}/authorization`), and the existing target gate enforces it: out-of-window, revoked, out-of-scope and unauthorized-technique calls are refused and recorded as decided intercept rows. A child task spawned by an agent inherits its caller's artifact.
- **Hash-chained audit log.** It covers the intercept history, the users and the artifacts, written by row triggers in the same transaction, plus logins and refusals by role. `GET /api/intercept/history/chain` lists the entries and `/chain/verify` checks them. The schema is migration 0016.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The verifier path is incomplete here: /chain/verify is not a registered endpoint and returns 404. Publish the full GET /api/intercept/history/chain/verify path so operators can actually run chain verification.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At CHANGELOG.md, line 12:

<comment>The verifier path is incomplete here: `/chain/verify` is not a registered endpoint and returns 404. Publish the full `GET /api/intercept/history/chain/verify` path so operators can actually run chain verification.</comment>

<file context>
@@ -6,6 +6,12 @@ All notable changes to this project are documented in this file. The format is b
+- **Engagement governance** (`docs/GOVERNANCE.md`):
+  - **Console users and roles.** The roles are `admin`, `operator`, `reviewer` and `client_read`. A declarative route policy is enforced in `requireAuth`. Admins manage users through `/api/users`, and the `ARTEX` login stays the break-glass admin.
+  - **Per-task authorization artifact.** It sets the scope, the time window and the allowed technique classes. It is versioned and immutable (`/api/tasks/{id}/authorization`), and the existing target gate enforces it: out-of-window, revoked, out-of-scope and unauthorized-technique calls are refused and recorded as decided intercept rows. A child task spawned by an agent inherits its caller's artifact.
+  - **Hash-chained audit log.** It covers the intercept history, the users and the artifacts, written by row triggers in the same transaction, plus logins and refusals by role. `GET /api/intercept/history/chain` lists the entries and `/chain/verify` checks them. The schema is migration 0016.
+  - **Audit appends at commit** (migration 0018). The row triggers are deferred constraint triggers, so the chain head is locked only while a transaction commits. A long transaction such as a task archive no longer stalls gate decisions and logins, and a transaction that writes an intercept row and then waits on another lock no longer risks a deadlock on the head.
+
</file context>
Suggested change
- **Hash-chained audit log.** It covers the intercept history, the users and the artifacts, written by row triggers in the same transaction, plus logins and refusals by role. `GET /api/intercept/history/chain` lists the entries and `/chain/verify` checks them. The schema is migration 0016.
- **Hash-chained audit log.** It covers the intercept history, the users and the artifacts, written by row triggers in the same transaction, plus logins and refusals by role. `GET /api/intercept/history/chain` lists the entries and `GET /api/intercept/history/chain/verify` checks them. The schema is migration 0016.

Comment thread docs/GOVERNANCE.md
conversation messages: those carry the credentials the agents used.
- `POST /api/auth/change-password` changes only the `ARTEX` password, and only an `ARTEX` session can
call it. An admin changes a console user's password with `PATCH /api/users/{id}`.
- The names `system`, `anonymous`, `human`, `rule`, `model`, `target`, `db` and `admin` are reserved,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The reserved-name list omits artex, so an administrator may expect that username to be available and receive a validation failure. Include the lowercase bootstrap name in the list and explain its reservation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/GOVERNANCE.md, line 26:

<comment>The reserved-name list omits `artex`, so an administrator may expect that username to be available and receive a validation failure. Include the lowercase bootstrap name in the list and explain its reservation.</comment>

<file context>
@@ -0,0 +1,122 @@
+  conversation messages: those carry the credentials the agents used.
+- `POST /api/auth/change-password` changes only the `ARTEX` password, and only an `ARTEX` session can
+  call it. An admin changes a console user's password with `PATCH /api/users/{id}`.
+- The names `system`, `anonymous`, `human`, `rule`, `model`, `target`, `db` and `admin` are reserved,
+  because the audit trail uses them for automatic actors.
+- A user's session token carries the user's version, and any password, role or disabled change bumps
</file context>
Suggested change
- The names `system`, `anonymous`, `human`, `rule`, `model`, `target`, `db` and `admin` are reserved,
The names `artex` (the bootstrap login), `system`, `anonymous`, `human`, `rule`, `model`, `target`, `db` and `admin` are reserved,

Comment thread docs/GOVERNANCE.md

Three mechanisms keep each engagement within what the client signed: console **roles**, a per-task
**authorization artifact** that the target gate enforces, and a **hash-chained audit log** over the
intercept history. All of the schema is in `db/migrations/0016_engagement_governance.sql`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The opening schema pointer omits migration 0018, which contains the deferred-trigger definition required for the documented audit behavior. Point readers to both migrations or call 0016 the base schema.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/GOVERNANCE.md, line 5:

<comment>The opening schema pointer omits migration 0018, which contains the deferred-trigger definition required for the documented audit behavior. Point readers to both migrations or call 0016 the base schema.</comment>

<file context>
@@ -0,0 +1,122 @@
+
+Three mechanisms keep each engagement within what the client signed: console **roles**, a per-task
+**authorization artifact** that the target gate enforces, and a **hash-chained audit log** over the
+intercept history. All of the schema is in `db/migrations/0016_engagement_governance.sql`.
+
+## Roles (RBAC)
</file context>
Suggested change
intercept history. All of the schema is in `db/migrations/0016_engagement_governance.sql`.
intercept history. The base schema is in `db/migrations/0016_engagement_governance.sql`; migration `0018_audit_chain_deferred.sql` changes the audit triggers to deferred constraint triggers.

Comment thread docs/GOVERNANCE.md
}
```

`GET /api/tasks/{id}/authorization` returns every version, the one in force, and the list of technique

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This endpoint returns the newest version as current plus an in_force boolean, not a separate version in force. Document that distinction so API consumers do not treat an expired or revoked current artifact as active.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/GOVERNANCE.md, line 47:

<comment>This endpoint returns the newest version as `current` plus an `in_force` boolean, not a separate version in force. Document that distinction so API consumers do not treat an expired or revoked `current` artifact as active.</comment>

<file context>
@@ -0,0 +1,122 @@
+}
+```
+
+`GET /api/tasks/{id}/authorization` returns every version, the one in force, and the list of technique
+classes. `POST /api/tasks/{id}/authorization/revoke` adds a version that authorizes nothing. Versions
+can't be edited; the database rejects an `UPDATE`.
</file context>
Suggested change
`GET /api/tasks/{id}/authorization` returns every version, the one in force, and the list of technique
`GET /api/tasks/{id}/authorization` returns every version, the newest version as `current`, whether it is in force, and the list of technique

Comment thread docs/GOVERNANCE.md
|---|---|
| `admin` | everything, including users, authorization artifacts and guardrail configuration (intercept rules, asset rules, target-gate exemptions, judge, tool config, settings) |
| `operator` | run engagements: create, start and steer tasks, chat, tools, traffic; decide approvals |
| `reviewer` | read everything except secrets, raw LLM records and logs; decide approvals; triage findings |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The reviewer row says reviewers can read everything except three categories, but reviewers also cannot read raw traffic or conversation messages. Align the table with the route policy so operators do not grant reviewers access they do not have.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/GOVERNANCE.md, line 13:

<comment>The reviewer row says reviewers can read everything except three categories, but reviewers also cannot read raw traffic or conversation messages. Align the table with the route policy so operators do not grant reviewers access they do not have.</comment>

<file context>
@@ -0,0 +1,122 @@
+|---|---|
+| `admin` | everything, including users, authorization artifacts and guardrail configuration (intercept rules, asset rules, target-gate exemptions, judge, tool config, settings) |
+| `operator` | run engagements: create, start and steer tasks, chat, tools, traffic; decide approvals |
+| `reviewer` | read everything except secrets, raw LLM records and logs; decide approvals; triage findings |
+| `client_read` | read the report, the findings, the stats and a task's outcome and coverage. Nothing else. **The role is global for now:** a `client_read` user sees every client's findings, so give it only to someone entitled to all of them (per-client binding is a follow-up) |
+
</file context>
Suggested change
| `reviewer` | read everything except secrets, raw LLM records and logs; decide approvals; triage findings |
| `reviewer` | read non-sensitive data except secrets, raw LLM records, logs, raw traffic exchanges/blobs/HAR/stream and conversation messages; decide approvals; triage findings |

Comment thread docs/GOVERNANCE.md
classes. `POST /api/tasks/{id}/authorization/revoke` adds a version that authorizes nothing. Versions
can't be edited; the database rejects an `UPDATE`.

The **existing target gate** enforces the newest version, and nothing else does. The check is in

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The artifact is also enforced outside the target gate for spawn_task: callerAuthorization rejects revoked or expired callers before child creation. Scope the claim to target calls and document this separate spawn check.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/GOVERNANCE.md, line 51:

<comment>The artifact is also enforced outside the target gate for `spawn_task`: `callerAuthorization` rejects revoked or expired callers before child creation. Scope the claim to target calls and document this separate spawn check.</comment>

<file context>
@@ -0,0 +1,122 @@
+classes. `POST /api/tasks/{id}/authorization/revoke` adds a version that authorizes nothing. Versions
+can't be edited; the database rejects an `UPDATE`.
+
+The **existing target gate** enforces the newest version, and nothing else does. The check is in
+`intercept/authorization.go`, and every gate entry point calls it before its own rules: `CheckTargets`
+when the gate is on, `CheckUngated` when it is off, and the connection-level dial checks and redirect
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant