Skip to content

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

Merged
cybersicilian merged 21 commits into
mainfrom
ej/20261124-132958-94f4bf
Nov 24, 2026
Merged

cybersicilian merged 21 commits into
mainfrom
ej/20261124-132958-94f4bf

Conversation

@cybersicilian

@cybersicilian cybersicilian commented Nov 24, 2026 •

Copy link
Copy Markdown

Refs BaaRai#425

Why

E5 follow-up: web UI for users, task authorization and audit chain

What: the E5 backend has no UI.

  • Users: a table page (admin) on GET/POST/PATCH/DELETE /api/users.
  • Task authorization: a panel on the task page: the current version, an in-force badge, the version history table, and an edit form on GET/POST /api/tasks/{id}/authorization plus /revoke, with technique classes from technique_classes.
  • Intercept history: a "Chain" tab listing GET /api/intercept/history/chain and a Verify button on /chain/verify that shows head_seq/head_hash and the mismatched rows.
  • Role awareness: hide actions the role lacks, using the role and permissions that GET /api/auth/session now returns, and handle 403 without logging out.
  • …

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)

  • E5: bind client_read users to their companies (c-5b5421) (ed9dfc4)

    client_read was global: a client account for company A could read every
    client's findings, reports and exports. Bindings now live in
    artex_user_companies (migration 0019, audited at commit like the other
    governance tables) and are managed at GET/PUT /api/users/{id}/companies.

    Every route rbacPolicy opens to client_read has a binder (client_scope.go)
    that runs after the role check: findings routes are narrowed to the bound
    company through the feat(web): global company switcher in the sidebar BaaRai/ARTEX#425 company filter, ids and tasks outside the binding
    answer 404, an unbound client gets 403, and a route without a binder is
    refused. Task ownership and the unanchored-finding fallback count only
    operator-made company scope rows, so an agent cannot widen what a client
    sees. The client report and stats no longer carry global asset/traffic
    counts. Live retests across all clients moved to the read permission.

  • docs: client binding (c-5b5421) in GOVERNANCE, CHANGELOG, HANDOFF (b6682a1)

  • HANDOFF: deltas stamp (c-5b5421) (f2b2f6f)

  • web(E5): session role/permissions context, governance API client, role-filtered sidebar, username login (c-869050) (59e85fe)

  • web(E5): Users page, task Authorization tab, audit Chain tab with Verify; client_read-safe sidebar (c-869050) (60e20d8)

    • /system/users (admin): table with inline role/enabled, set password, delete,
      client_read company bindings, add-user dialog.
    • Task detail Authorization tab: current version + status badge, version
      history table, admin-only new-version form and revoke.
    • Approval Records: Approvals | Chain tabs; chain table with filters, paging,
      entry sheet, Verify (head_seq/head_hash, broken_at, rows_mismatched).
    • client_read sessions skip the company switcher and the global retest poll.
    • verify.sh runs the governance unit tests and the i18n check; tr/zh-CN strings.
  • HANDOFF: E5 web UI state, triage, decisions, follow-up cards (c-869050) (6bb0a97)

  • HANDOFF: shorten c-869050 current-state entry (7f9af4f)

  • HANDOFF: deltas stamp (c-869050) (f0debbf)

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/client_scope_pg_test.go …

72 files, +7182 −123
File + −
web/src/components/audit-chain.tsx 327 0
db/authorization.go 321 0
server/client_scope.go 294 0
server/rbac_policy_test.go 293 0
server/rbac_pg_test.go 292 0
web/src/app/(main)/function/tasks/detail/_tabs/authorization-form.tsx 280 0
server/users_api.go 261 0
db/audit_chain.go 260 0
server/governance_api.go 234 0
server/rbac.go 226 0
server/client_scope_pg_test.go 224 0
db/governance_test.go 212 0
db/users.go 202 0
server/rbac_policy.go 197 0
intercept/authorization_test.go 191 0
db/migrations/0016_engagement_governance.sql 188 0
db/audit_chain_concurrency_test.go 184 0
web/src/app/(main)/system/users/page.tsx 171 0
web/src/app/(main)/system/users/_components/user-row.tsx 156 0
docs/GOVERNANCE.md 150 0
intercept/authorization.go 138 0
web/src/app/(main)/system/users/_components/add-user-dialog.tsx 133 0
db/user_companies.go 129 0
web/src/app/(main)/function/tasks/detail/_tabs/authorization-tab.tsx 125 0
web/src/lib/governance-types.ts 124 0
HANDOFF.md 105 17
server/governance_api_test.go 120 0
web/src/app/(main)/function/tasks/detail/_tabs/authorization-parts.tsx 113 0
web/src/app/(main)/system/users/_components/companies-dialog.tsx 110 0
intercept/technique.go 104 0
web/src/app/(main)/system/users/_components/password-dialog.tsx 100 0
db/users_test.go 98 0
web/src/i18n/locales/tr.json 96 1
web/src/i18n/locales/zh-CN.json 96 1
web/src/components/audit-chain-verify.tsx 90 0
web/src/lib/governance.ts 87 0
web/src/app/(main)/function/tasks/detail/_tabs/authorization-history.tsx 77 0
web/src/lib/governance-api.ts 61 0
web/src/lib/governance.test.mjs 61 0
web/src/app/(main)/layout.tsx 30 26
server/auth.go 39 15
db/migrations/0018_audit_chain_deferred.sql 49 0
web/src/lib/auth.ts 36 13
web/src/components/audit-chain-detail.tsx 44 0
server/client_scope_test.go 39 0
server/server.go 23 11
web/src/navigation/sidebar/sidebar-items.ts 24 5
db/migrations/0019_user_company_bindings.sql 26 0
web/src/app/(auth)/login/page.tsx 18 8
web/src/hooks/use-session.tsx 24 0
db/findings.go 18 4
web/src/components/audit-chain-format.ts 20 0
intercept/target_gate.go 17 1
web/src/app/(main)/_components/sidebar/nav-user.tsx 13 5
web/src/app/(main)/system/intercept/approvals/page.tsx 17 1
web/src/app/(main)/system/users/_components/role-label.ts 16 0
web/src/app/(main)/_components/sidebar/app-sidebar.tsx 11 4
server/orchestration.go 13 0
web/src/lib/api-errors.ts 12 0
server/auth_cookie.go 10 1
… 12 more

Opened by Composite · ej/20261124-132958-94f4bf → main · card c-869050 · run 20261124-132958-94f4bf

🤖 Generated with Claude Code


Summary by cubic

Adds engagement governance: console user roles (admin/operator/reviewer/client_read), per-task authorization artifacts enforced inside the target gate, and a hash-chained audit log over the intercept history, with the web UI to manage and verify them.

New Features

  • Console users replace the single account model; every request re-checks the user against the database, sessions carry role and permissions, and a declarative route policy (server/rbac_policy.go) fails closed on refusals (403, never logout).
  • A task's authorization artifact (scope, time window, technique classes) blocks calls with the gate on or off; refusals land as decided intercept rows, and spawned tasks inherit the caller's artifact.
  • The audit chain is SHA-256 linked and written by row triggers in the same transaction, so it cannot be skipped or rolled back; Verify recomputes every hash and reports the first broken entry.
  • client_read users are bound to companies: findings, tasks, reports, stats, and exports narrow to the binding, out-of-binding ids answer 404, and unbound clients get 403 everywhere.
  • Web UI adds the admin Users page, the task Authorization tab (version history, admin-only edits, revoke), and the Approval Records Chain tab with Verify, all filtered by the session role.

Bug Fixes

  • Audit chain writes moved to commit-time constraint triggers (migration 0018); a task archive no longer stalls gate decisions, logins, or rbac.denied entries behind the chain head lock, and write-then-lock transactions can no longer deadlock on it.

Written for commit f0debbf. Summary will update on new commits.

View guided diff

cybersicilian and others added 21 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]>
client_read was global: a client account for company A could read every
client's findings, reports and exports. Bindings now live in
artex_user_companies (migration 0019, audited at commit like the other
governance tables) and are managed at GET/PUT /api/users/{id}/companies.

Every route rbacPolicy opens to client_read has a binder (client_scope.go)
that runs after the role check: findings routes are narrowed to the bound
company through the BaaRai#425 company filter, ids and tasks outside the binding
answer 404, an unbound client gets 403, and a route without a binder is
refused. Task ownership and the unanchored-finding fallback count only
operator-made company scope rows, so an agent cannot widen what a client
sees. The client report and stats no longer carry global asset/traffic
counts. Live retests across all clients moved to the read permission.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… for c-869050 web UI

# Conflicts:
#	HANDOFF.md
…e-filtered sidebar, username login (c-869050)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ify; client_read-safe sidebar (c-869050)

- /system/users (admin): table with inline role/enabled, set password, delete,
  client_read company bindings, add-user dialog.
- Task detail Authorization tab: current version + status badge, version
  history table, admin-only new-version form and revoke.
- Approval Records: Approvals | Chain tabs; chain table with filters, paging,
  entry sheet, Verify (head_seq/head_hash, broken_at, rows_mismatched).
- client_read sessions skip the company switcher and the global retest poll.
- verify.sh runs the governance unit tests and the i18n check; tr/zh-CN strings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	HANDOFF.md
#	db/migrate_test.go
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cybersicilian
cybersicilian merged commit 3af5069 into main Nov 24, 2026
@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.

cybersicilian added a commit that referenced this pull request Nov 24, 2026
…(c-13e86c) (#41)

* web: open SSE streams same-origin so the session cookie reaches them (c-13e86c)

Since the session moved to an HttpOnly cookie, getToken() returns null, but
sseUrl still sent non-production builds (next dev) straight to <host>:8787.
That cross-origin EventSource carries no cookie and no token, so every
connect answered 401 and the Sessions tab showed Reconnecting. Other calls
went through the same-origin /api rewrite and worked. Predates E5.

- web/src/lib/sse.ts: sseUrl is always a same-origin /api/ path (throws
  otherwise); NEXT_PUBLIC_SSE_BASE is removed (a cross-origin stream cannot
  present the cookie, and CORS '*' forbids credentials).
- next.config.mjs: compress:false in dev, measured: with a browser's
  Accept-Encoding the rewrite gzips and buffers the stream; without
  compression frames arrive as sent.
- server: PG test signs in through the login handler as the bootstrap
  ARTEX admin and as a console user, then opens the activity stream with
  only the cookie and reads a frame; no session -> 401.

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

* server: SSE streams send a first comment when they open (c-13e86c)

streamActivity and streamLogs flushed only headers until the first event or
the 20 s ping. The Next.js dev rewrite passes headers on only with a first
body byte, so the EventSource stayed unopened and the Sessions tab showed
Reconnecting for 20 s on an idle task (measured: TTFB 20.0 s through next
dev, immediate direct). openSSE sets the SSE headers and writes ': open'.
The PG test now asserts the comment is the first line.

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

* HANDOFF: c-13e86c state, gotchas, decision

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

* HANDOFF: condense the E5 entry to its on-main state (#31) so Current state fits

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

* HANDOFF: move the 2026-11-23 audit's operator-facing list to docs/handoff/

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

* HANDOFF: deltas stamp (c-13e86c)

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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