From 6b0b7b3ee9555448fddc2799b2b813c51204e749 Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Sun, 20 Sep 2026 09:55:27 +0300 Subject: [PATCH] docs: sync CHANGELOG, roadmap.yaml and spec 107 tasks.md with merged main CHANGELOG.md's Unreleased section was missing entries for 9 recent behavior-changing commits, most notably the Spec 105 scope-hardening security fixes (#1283/#1284/#1285) and Spec 107 SSO features (#1293/#1296). roadmap.yaml had drifted stale in both directions for two in-flight specs: - Spec 105 (agent-scope-hardening): 4 merged PRs (A #1279, B #1282, D #1283, E #1284) still showed status: todo, and PR H0 (#1285) had no roadmap task entry at all. Flipped to done; genuinely outstanding work (PR C/F/G/H1) is untouched. - Spec 107 (sso): PR-D (#1296) is merged but the epic and its task still read in_review. Verified all 87 files PR-D touched exist on disk (internal/audit/*, docs/features/audit-log.md, config, docs, frontend) and that verification.md records a completed multi-round cross-model review and a passing SC-009 benchmark, then ticked the 20 checkbox-lag tasks (T096-T115, T118-T119) in tasks.md and flipped both the task and epic status to done. Regenerated ROADMAP.md via scripts/gen-roadmap.py. --- CHANGELOG.md | 39 ++++++++- ROADMAP.md | 84 +++++++++---------- roadmap.yaml | 22 +++-- .../107-server-edition-sso-hardening/tasks.md | 48 +++++------ 4 files changed, 119 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1374dbf1..fb8b2fc44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,8 +46,43 @@ Releases follow [Semantic Versioning](https://semver.org/). agent can gate a multi-step plan without leaving the MCP session. Optional `filters` (`read_only_only`, `exclude_destructive`, `exclude_open_world`); every run is on the activity record, and the returned `request_id` finds it. (spec 099, [#969](https://github.com/smart-mcp-proxy/mcpproxy-go/issues/969)) - -### Bug Fixes +- **oauth:** the OAuth callback path is now configurable via `redirect_uri` instead of being + hardcoded, for deployments that front the callback behind a reverse proxy or a fixed path + requirement. ([#1316](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1316)) +- **server edition / sso:** generic OIDC front door — IdP-group-to-server allowlist grants, one + entitlement predicate shared by REST and the Web UI, and a tenant session principal on the + core REST API. (spec 107 PR-C, [#1293](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1293)) +- **server edition / sso:** an attributable JSONL audit line is now emitted at every + authorization decision and tool-call funnel, so a tenant admin can trace who did what. + (spec 107 PR-D, [#1296](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1296)) + +### Bug Fixes + +- **security/scope:** `set_profile` and `/mcp/p` now report the intersection of an agent + token's grant and the requested profile through a single selectable-profile predicate; a + non-selectable profile is refused identically to a nonexistent one, closing a scope-disclosure + gap. (spec 105 PR D, FR-003/004, [#1283](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1283)) +- **security/scope:** log lines now attribute to the record's actual subject, the OAuth callback + log is bound to the authenticated subject rather than the request, and container ownership + labels use the canonical identity — previously a narrowly-scoped token's actions could be + logged under the wrong identity. (spec 105 PR E, FR-007, [#1284](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1284)) +- **security/scope:** stored-script enumeration is now administrator-only; a non-admin agent + token could previously list stored scripts outside its grant. (spec 105 PR H0, FR-012, + [#1285](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1285)) +- **isolation:** scanner (security-scan) isolation mode is now resolved separately from process + (spawn) isolation — a remote HTTP/HTTPS upstream server was previously skipping Docker + security scanners entirely because both modes resolved to the same "none" decision. + ([GH #1303](https://github.com/smart-mcp-proxy/mcpproxy-go/issues/1303), + [#1315](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1315)) +- **upstream/stdio:** an ambiguous health-check failure on a stdio server no longer kills an + in-flight tool call — only a confirmed-dead process does. Also fixes `call_tool_write` + silently dropping its arguments on the affected path. + ([#1317](https://github.com/smart-mcp-proxy/mcpproxy-go/issues/1317), + [#1320](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1320)) +- **config:** persisted vs. effective configuration are now split — `serve` flags, `MCPPROXY_*` + env vars and an API key sourced from the environment are honored for the running process but + are never written back into `mcp_config.json`, so they can't leak into the persisted file or + survive a restart unintentionally. ([#1302](https://github.com/smart-mcp-proxy/mcpproxy-go/pull/1302)) - **mcp/describe_tool:** on the direct surface, the returned definition named the tool `:` and recommended a `call_with` intent variant — neither of which that surface diff --git a/ROADMAP.md b/ROADMAP.md index 0616d7cfd..dfb143187 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -81,7 +81,6 @@ graph LR - 🔵 **MCP protocol upgrade to 2026-07-28 revision** — In progress · P1 - 🔵 **Planning/docs truth automation** — In progress · P2 - 🔵 **Discovery-quality eval harness (Spec 065 second half)** — In progress · P3 -- 🟡 **Spec 107 server edition SSO front door hardened for real IdPs** — In review · P2 - ⚪ **Windows native tray app** — Todo · P2 - ⚫ **Server marketplace** — Todo · P3 · parked - ⚫ **Audit SIEM integration** — Todo · P3 · parked @@ -92,6 +91,7 @@ graph LR - 🟢 **Connect step trust: preview, visible backup, one-click undo** — Done · P0 - 🟢 **Registries — easier search + add-server** — Done · P1 - 🟢 **Tray↔core decoupling: socket/REST API only, no config-file reads** — Done · P2 +- 🟢 **Spec 107 server edition SSO front door hardened for real IdPs** — Done · P2 ## Epic details @@ -227,6 +227,7 @@ graph LR scope_cache_legacy_invalidation["FR-002 + FR-001 remainder: legacy/unstamped a…"] scope_log_attribution["FR-007 remainder: per-record canonical log ow…"] scope_target_identity_producers["FR-009 remainder: producer-side exact-name id…"] + scope_fix_stored_script_admin["FR-012: stored-script enumeration is administ…"] scope_regression_suite["FR-011/FR-013/FR-014: two-fixture differentia…"] scope_retrieve_tools --> scope_refusal_shapes @@ -241,8 +242,8 @@ graph LR classDef done fill:#1f7a1f,stroke:#0d3d0d,color:#ffffff; classDef todo fill:#6e7781,stroke:#3d4248,color:#ffffff; - class scope_fix_target_tier,scope_fix_tail_log,scope_fix_set_profile,scope_fix_read_cache,scope_fix_prompts_profile_url done; - class scope_retrieve_tools,scope_direct_publication,scope_refusal_shapes,scope_selectable_profile_predicate,scope_cache_legacy_invalidation,scope_log_attribution,scope_target_identity_producers,scope_regression_suite todo; + class scope_fix_target_tier,scope_fix_tail_log,scope_fix_set_profile,scope_fix_read_cache,scope_fix_prompts_profile_url,scope_selectable_profile_predicate,scope_cache_legacy_invalidation,scope_log_attribution,scope_target_identity_producers,scope_fix_stored_script_admin done; + class scope_retrieve_tools,scope_direct_publication,scope_refusal_shapes,scope_regression_suite todo; ``` | Task | Status | Refs | @@ -255,10 +256,11 @@ graph LR | FR-005: retrieve_tools filters by scope BEFORE limiting; indexed counts, usage ranking, debug output and session risk computed over the authorized population only | ⚪ Todo | — | | FR-008: direct-surface definitions take owner and tier from their own registration identity at every publication seam, both skew directions, full and deferred | ⚪ Todo | — | | FR-010: scope-first refusal precedence; dispatch denials and 'available servers' never name hidden servers; describe_tool not-found and alias resolution computed over the authorized corpus | ⚪ Todo | — | -| FR-003/FR-004 remainder: selectable-profile predicate for UNPINNED tokens on /mcp/p/, /mcp/p, /mcp/p/ and set_profile; identical status+body across missing / deleted / not-selectable / pin-mismatch / no-profiles (#1225 + #1227 follow-up lists) | ⚪ Todo | — | -| FR-002 + FR-001 remainder: legacy/unstamped and internal (registry, guesser) cache entries refused for every caller and durably invalidated; monotone recursive provenance; existence-non-disclosing refusal on MCP and REST (#1226 follow-up list) | ⚪ Todo | — | -| FR-007 remainder: per-record canonical log ownership (a/b vs a_b share one file), filter-before-limit + authorized lines_returned, subject-bound OAuth-callback logging, canonical container ownership in Docker cleanup (#1224 follow-up list) | ⚪ Todo | — | -| FR-009 remainder: producer-side exact-name identity (checkToolApprovals / differential index collapse ns:erase to erase), direct-name dispatch + preflight share lookupToolApproval, unresolved/stale identity refuses scoped callers, full 54-cell acceptance tables (#1223 follow-up list) | ⚪ Todo | — | +| FR-003/FR-004 remainder: selectable-profile predicate for UNPINNED tokens on /mcp/p/, /mcp/p, /mcp/p/ and set_profile; identical status+body across missing / deleted / not-selectable / pin-mismatch / no-profiles (#1225 + #1227 follow-up lists) | 🟢 Done | #1283 | +| FR-002 + FR-001 remainder: legacy/unstamped and internal (registry, guesser) cache entries refused for every caller and durably invalidated; monotone recursive provenance; existence-non-disclosing refusal on MCP and REST (#1226 follow-up list) | 🟢 Done | #1282 | +| FR-007 remainder: per-record canonical log ownership (a/b vs a_b share one file), filter-before-limit + authorized lines_returned, subject-bound OAuth-callback logging, canonical container ownership in Docker cleanup (#1224 follow-up list) | 🟢 Done | #1284 | +| FR-009 remainder: producer-side exact-name identity (checkToolApprovals / differential index collapse ns:erase to erase), direct-name dispatch + preflight share lookupToolApproval, unresolved/stale identity refuses scoped callers, full 54-cell acceptance tables (#1223 follow-up list) | 🟢 Done | #1279 | +| FR-012: stored-script enumeration is administrator-only (PR H0) | 🟢 Done | #1285 | | FR-011/FR-013/FR-014: two-fixture differential oracle with sentinels across the applicability matrix, credential-authenticated HTTP matrix over every /mcp surface, admin p95 perf gate on the frozen 527-tool snapshot | ⚪ Todo | — | @@ -427,39 +429,6 @@ graph LR -
-🟡 Spec 107 server edition SSO front door hardened for real IdPs — In review · P2 - -> Generic OIDC, IdP-group -> server allowlist, attributable JSONL audit line; freeze the latent multiuser/credential-injection code. Research: docs/research/server-edition-2026-09-14 (#1281). - -Spec: [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) - -```mermaid -graph LR - sso_pr_a_freeze_cut["PR-A freeze/cut latent code + config normalis…"] - sso_pr_b_oidc_front_door["PR-B generic OIDC provider + front door behin…"] - sso_pr_c_group_allowlist["PR-C one entitlement predicate, group grants,…"] - sso_pr_d_audit_line["PR-D attributable JSONL audit line + auth_eve…"] - - sso_pr_a_freeze_cut --> sso_pr_b_oidc_front_door - sso_pr_b_oidc_front_door --> sso_pr_c_group_allowlist - sso_pr_c_group_allowlist --> sso_pr_d_audit_line - - classDef done fill:#1f7a1f,stroke:#0d3d0d,color:#ffffff; - classDef in_review fill:#9a6700,stroke:#5c3d00,color:#ffffff; - class sso_pr_a_freeze_cut,sso_pr_b_oidc_front_door,sso_pr_c_group_allowlist done; - class sso_pr_d_audit_line in_review; -``` - -| Task | Status | Refs | -| --- | --- | --- | -| PR-A freeze/cut latent code + config normaliser + per-owner token cap (US5, US6) | 🟢 Done | #1287 | -| PR-B generic OIDC provider + front door behind ingress + telemetry v13 (US2, US7) | 🟢 Done | #1292 | -| PR-C one entitlement predicate, group grants, tenant Web UI session principal (US1, US4) | 🟢 Done | #1293 | -| PR-D attributable JSONL audit line + auth_event + config/doctor/metrics (US3) | 🟡 In review | #1296 | - -
-
⚪ tpa-db: versioned TPA signature database for the offline scanner — Todo · P1 @@ -881,6 +850,37 @@ graph LR
+
+🟢 Spec 107 server edition SSO front door hardened for real IdPs — Done · P2 + +> Generic OIDC, IdP-group -> server allowlist, attributable JSONL audit line; freeze the latent multiuser/credential-injection code. Research: docs/research/server-edition-2026-09-14 (#1281). + +Spec: [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) + +```mermaid +graph LR + sso_pr_a_freeze_cut["PR-A freeze/cut latent code + config normalis…"] + sso_pr_b_oidc_front_door["PR-B generic OIDC provider + front door behin…"] + sso_pr_c_group_allowlist["PR-C one entitlement predicate, group grants,…"] + sso_pr_d_audit_line["PR-D attributable JSONL audit line + auth_eve…"] + + sso_pr_a_freeze_cut --> sso_pr_b_oidc_front_door + sso_pr_b_oidc_front_door --> sso_pr_c_group_allowlist + sso_pr_c_group_allowlist --> sso_pr_d_audit_line + + classDef done fill:#1f7a1f,stroke:#0d3d0d,color:#ffffff; + class sso_pr_a_freeze_cut,sso_pr_b_oidc_front_door,sso_pr_c_group_allowlist,sso_pr_d_audit_line done; +``` + +| Task | Status | Refs | +| --- | --- | --- | +| PR-A freeze/cut latent code + config normaliser + per-owner token cap (US5, US6) | 🟢 Done | #1287 | +| PR-B generic OIDC provider + front door behind ingress + telemetry v13 (US2, US7) | 🟢 Done | #1292 | +| PR-C one entitlement predicate, group grants, tenant Web UI session principal (US1, US4) | 🟢 Done | #1293 | +| PR-D attributable JSONL audit line + auth_event + config/doctor/metrics (US3) | 🟢 Done | #1296 | + +
+ ## Epics | Epic | Status | Priority | Progress | Spec | PR | @@ -895,7 +895,6 @@ graph LR | MCP protocol upgrade to 2026-07-28 revision | In progress | P1 | 19/81 (23%) | [058-mcp-2026-upgrade](./specs/058-mcp-2026-upgrade/) | | | Planning/docs truth automation | In progress | P2 | — | | | | Discovery-quality eval harness (Spec 065 second half) | In progress | P3 | — | [065-evaluation-foundation](./specs/065-evaluation-foundation/) | | -| Spec 107 server edition SSO front door hardened for real IdPs | In review | P2 | 102/126 (81%) | [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) | | | tpa-db: versioned TPA signature database for the offline scanner | Todo | P1 | — | [101-tpa-db](./specs/101-tpa-db/) | | | Auto routing mode: budget-fitted tool surface per session (spec 104) | Todo | P1 | — | [104-auto-routing-mode](./specs/104-auto-routing-mode/) | | | Windows native tray app `MCP-43` | Todo | P2 | — | | | @@ -915,6 +914,7 @@ graph LR | Scanner simplification (deterministic default, opt-in deep scan) | Done | P1 | 38/42 (90%) | [077-scanner-simplification](./specs/077-scanner-simplification/) | | | Deferred-schema serialization for the direct tools/list surface (spec 102) | Done | P1 | 89/89 (100%) | [102-schema-deferred](./specs/102-schema-deferred/) | #1063 | | Tray↔core decoupling: socket/REST API only, no config-file reads | Done | P2 | — | | | +| Spec 107 server edition SSO front door hardened for real IdPs | Done | P2 | 126/126 (100%) | [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) | | ## Shipped (archived) @@ -1036,4 +1036,4 @@ Legend: `shipped` ≥95% checked · `in-flight` 1–94% · `drafted` 0% · `—` | [104-auto-routing-mode](./specs/104-auto-routing-mode/) | — | — | | [105-agent-scope-hardening](./specs/105-agent-scope-hardening/) | `in-flight` | 42/109 (39%) | | [106-security-residual-fixes](./specs/106-security-residual-fixes/) | `shipped` | 18/19 (95%) | -| [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) | `in-flight` | 102/126 (81%) | +| [107-server-edition-sso-hardening](./specs/107-server-edition-sso-hardening/) | `shipped` | 126/126 (100%) | diff --git a/roadmap.yaml b/roadmap.yaml index e05731bd2..0c0175aae 100644 --- a/roadmap.yaml +++ b/roadmap.yaml @@ -444,24 +444,34 @@ epics: depends_on: [scope-retrieve-tools] - id: scope-selectable-profile-predicate title: "FR-003/FR-004 remainder: selectable-profile predicate for UNPINNED tokens on /mcp/p/, /mcp/p, /mcp/p/ and set_profile; identical status+body across missing / deleted / not-selectable / pin-mismatch / no-profiles (#1225 + #1227 follow-up lists)" - status: todo + status: done priority: P1 + pr: "#1283" depends_on: [scope-fix-set-profile, scope-fix-prompts-profile-url] - id: scope-cache-legacy-invalidation title: "FR-002 + FR-001 remainder: legacy/unstamped and internal (registry, guesser) cache entries refused for every caller and durably invalidated; monotone recursive provenance; existence-non-disclosing refusal on MCP and REST (#1226 follow-up list)" - status: todo + status: done priority: P2 + pr: "#1282" depends_on: [scope-fix-read-cache] - id: scope-log-attribution title: "FR-007 remainder: per-record canonical log ownership (a/b vs a_b share one file), filter-before-limit + authorized lines_returned, subject-bound OAuth-callback logging, canonical container ownership in Docker cleanup (#1224 follow-up list)" - status: todo + status: done priority: P2 + pr: "#1284" depends_on: [scope-fix-tail-log] - id: scope-target-identity-producers title: "FR-009 remainder: producer-side exact-name identity (checkToolApprovals / differential index collapse ns:erase to erase), direct-name dispatch + preflight share lookupToolApproval, unresolved/stale identity refuses scoped callers, full 54-cell acceptance tables (#1223 follow-up list)" - status: todo + status: done priority: P2 + pr: "#1279" depends_on: [scope-fix-target-tier] + - id: scope-fix-stored-script-admin + title: "FR-012: stored-script enumeration is administrator-only (PR H0)" + status: done + priority: P2 + pr: "#1285" + depends_on: [] - id: scope-regression-suite title: "FR-011/FR-013/FR-014: two-fixture differential oracle with sentinels across the applicability matrix, credential-authenticated HTTP matrix over every /mcp surface, admin p95 perf gate on the frozen 527-tool snapshot" status: todo @@ -802,7 +812,7 @@ epics: - id: sso title: Spec 107 server edition SSO front door hardened for real IdPs - status: in_review + status: done priority: P2 spec: specs/107-server-edition-sso-hardening depends_on: [] @@ -825,7 +835,7 @@ epics: pr: "#1293" - id: sso-pr-d-audit-line title: PR-D attributable JSONL audit line + auth_event + config/doctor/metrics (US3) - status: in_review + status: done depends_on: [sso-pr-c-group-allowlist] pr: "#1296" diff --git a/specs/107-server-edition-sso-hardening/tasks.md b/specs/107-server-edition-sso-hardening/tasks.md index 5c628674d..aa09d2b86 100644 --- a/specs/107-server-edition-sso-hardening/tasks.md +++ b/specs/107-server-edition-sso-hardening/tasks.md @@ -216,52 +216,52 @@ Gate set for every PR = plan.md §Gates. Never claim a skipped gate passed; writ ### Tests first -- [ ] T096 [US3] **[compile-red until T099]** Write failing `internal/audit/canonical_test.go`: published JCS vectors in `internal/audit/testdata/canonical/*.json` (RFC 8785 appendix samples, nested maps/arrays, non-ASCII/escaped strings, `1`/`1.0`/`1e0` equal, `-0`→`0`, `9007199254740993`, UTF-16 key ordering); an **independent** test-package implementation computes the expected hashes; `_auth_*` keys excluded via `security.StripInternalArgs` — `internal/audit/canonical_test.go`, `internal/audit/testdata/canonical/` -- [ ] T097 [P] [US3] **[compile-red until T099]** Write failing `internal/audit/line_test.go` + `schema_test.go`: every line the builder can produce validates against `contracts/audit-line.schema.json` (copied to `docs/schemas/audit-line-v1.schema.json`) — the published file is **consumer-tolerant** (`additionalProperties: true` at every object level so a strict consumer survives a minor additive change under the same `$id`), and `schema_test.go` derives the **producer-strict** variant at test time (flips every `additionalProperties` to `false` in the loaded document) so the exact key set is proven by the test, not the published file; `schema_test.go` also accepts an external JSONL path (`MCPPROXY_AUDIT_JSONL= go test ./internal/audit -run TestExternalJSONLValidates`) so the quickstart/T116 gate validates a real sink file with the `santhosh-tekuri/jsonschema/v6` dependency already in `go.mod` — no `npx ajv-cli`; **negative fixtures** for the identity rules the schema now encodes: `session_user`/`session_admin` without `user_id` or with the wrong `role`, `anonymous` with `user_id`, `anonymous` with `provider`, `agent_token` without `token_name`/`token_prefix`, an **owned** `agent_token` (`user_id` present) missing any of `user_email`/`role`/`provider`, an ownerless `agent_token` carrying `role` or `provider`, `email_hash` beside `user_id`, `auth_event` with `user_email`, `surface: login` with `reason: logout`, `surface: logout` with `reason: ok`, and the **reason-conditioned identity rules** of the `auth_event` branch: `reason: ok` (and `logout`, `subject_mismatch`, `user_disabled`) with `caller.kind: anonymous` or without `user_id`, `domain_not_allowed`/`userinfo_subject_mismatch` without `email_hash` or with a `session_*` caller, `provider_error` with `user_id`, a pre-identity reason (`nonce_mismatch`) with `email_hash` — each must be rejected; a **schema-identity sync test** asserts that `schema_version` const, `$id`, `title` and the published filename `docs/schemas/audit-line-v.schema.json` carry the same `N` and that the contract copy and the published copy are byte-identical; per-event forbidden keys are **unrepresentable**, not checked at runtime: three event-specific constructors (`NewAuthz`, `NewToolCall`, `NewAuthEvent`) take typed structs that have no field for a forbidden key, so an `authz` line with `outcome` does not compile and the count invariant (SC-003) cannot be broken by a dropped line; the schema test validates every constructor's output; the structural redaction rule (builder has no parameter for argument/response/error text); sentinel byte-absence test with **nine** distinct high-entropy sentinels — args, response, error text, caller-supplied `_auth_user_email`, and the caller/operator-controlled strings the line *does* carry: `client.name`/`client.version` (MCP `clientInfo` / `X-MCPProxy-Client`), `token_name`, `profile`, and a caller-supplied `server` and `tool` on a **refused** dispatch (the caller may name any `server:tool` pair; the `authz deny` line records it per FR-016) — each untrusted string field is sanitised **per field** at build time (the fixed-prefix secret patterns masked, length-capped; never the high-entropy rule, which would mask legitimate long identifiers and break FR-016's attribution) and the schema is validated *after* sanitisation; the whole-line defence-in-depth pass of FR-015 uses **only the fixed-prefix credential patterns** (`sk-ant-`, `AKIA`, `ghp_`/`gho_`, `Bearer …`, …) and **never the generic `high_entropy` rule** (`sanitizer.go:104` masks any quoted 32+ char `[A-Za-z0-9+/]` run — it would rewrite every `args_sha256` and `email_hash`, breaking the schema after validation); fixture: a line whose `args_sha256`/`email_hash` and a 40-char alphanumeric `server` name survive the pass byte-identical, while a planted `AKIA…` in `client.name` and a caller-supplied `AKIA…:ghp_…` target on a refused dispatch are masked **at build time by the per-field pass** so the writer's whole-line pass finds nothing; **the whole-line pass is asserted to be the identity on every constructor output** (every fixture line: `sanitised == line`, byte-compared) — because every caller- or operator-controlled field is already sanitised per field, the pass can only fire on a builder bug, and that is reported: a hit increments `Sink.SanitizerHits()` (always-on atomic, beside `WriteFailures()`, mirrored to `mcpproxy_audit_sanitizer_hits_total` and read by `doctor`) and logs one WARN per minute naming the field-less fact that a line was rewritten; the masked line is still written (defence in depth wins over FR-016's real-name rule — the exception FR-016 itself now states, documented in `docs/features/audit-log.md`) — `internal/audit/{line_test.go,schema_test.go,sink_test.go}` -- [ ] T098 [P] [US3] **[compile-red until T099]** Write failing `internal/audit/sink_test.go`: the sink owns an **always-on** atomic write-failure counter (`Sink.WriteFailures() uint64`, independent of the metrics flag — doctor and the Prometheus mirror both read it); file sink append-only, write-through, a line never split across rotation (lumberjack via the exported `logs.NewRotatingWriter`), stdout sink writes raw JSON to an injected `io.Writer` (never through zap), unwritable path at construction → error mapped to exit code 4 by the caller (lumberjack opens lazily on first `Write`, so the constructor must probe the path itself — `OpenFile(O_APPEND|O_CREATE|O_WRONLY)` then close — before installing the rotating writer), runtime write failure → counter increments, call proceeds, error logged at most once per minute (fake clock), 2,000 concurrent writes under a saturated fake event bus → 2,000 lines — `internal/audit/sink_test.go` +- [x] T096 [US3] **[compile-red until T099]** Write failing `internal/audit/canonical_test.go`: published JCS vectors in `internal/audit/testdata/canonical/*.json` (RFC 8785 appendix samples, nested maps/arrays, non-ASCII/escaped strings, `1`/`1.0`/`1e0` equal, `-0`→`0`, `9007199254740993`, UTF-16 key ordering); an **independent** test-package implementation computes the expected hashes; `_auth_*` keys excluded via `security.StripInternalArgs` — `internal/audit/canonical_test.go`, `internal/audit/testdata/canonical/` +- [x] T097 [P] [US3] **[compile-red until T099]** Write failing `internal/audit/line_test.go` + `schema_test.go`: every line the builder can produce validates against `contracts/audit-line.schema.json` (copied to `docs/schemas/audit-line-v1.schema.json`) — the published file is **consumer-tolerant** (`additionalProperties: true` at every object level so a strict consumer survives a minor additive change under the same `$id`), and `schema_test.go` derives the **producer-strict** variant at test time (flips every `additionalProperties` to `false` in the loaded document) so the exact key set is proven by the test, not the published file; `schema_test.go` also accepts an external JSONL path (`MCPPROXY_AUDIT_JSONL= go test ./internal/audit -run TestExternalJSONLValidates`) so the quickstart/T116 gate validates a real sink file with the `santhosh-tekuri/jsonschema/v6` dependency already in `go.mod` — no `npx ajv-cli`; **negative fixtures** for the identity rules the schema now encodes: `session_user`/`session_admin` without `user_id` or with the wrong `role`, `anonymous` with `user_id`, `anonymous` with `provider`, `agent_token` without `token_name`/`token_prefix`, an **owned** `agent_token` (`user_id` present) missing any of `user_email`/`role`/`provider`, an ownerless `agent_token` carrying `role` or `provider`, `email_hash` beside `user_id`, `auth_event` with `user_email`, `surface: login` with `reason: logout`, `surface: logout` with `reason: ok`, and the **reason-conditioned identity rules** of the `auth_event` branch: `reason: ok` (and `logout`, `subject_mismatch`, `user_disabled`) with `caller.kind: anonymous` or without `user_id`, `domain_not_allowed`/`userinfo_subject_mismatch` without `email_hash` or with a `session_*` caller, `provider_error` with `user_id`, a pre-identity reason (`nonce_mismatch`) with `email_hash` — each must be rejected; a **schema-identity sync test** asserts that `schema_version` const, `$id`, `title` and the published filename `docs/schemas/audit-line-v.schema.json` carry the same `N` and that the contract copy and the published copy are byte-identical; per-event forbidden keys are **unrepresentable**, not checked at runtime: three event-specific constructors (`NewAuthz`, `NewToolCall`, `NewAuthEvent`) take typed structs that have no field for a forbidden key, so an `authz` line with `outcome` does not compile and the count invariant (SC-003) cannot be broken by a dropped line; the schema test validates every constructor's output; the structural redaction rule (builder has no parameter for argument/response/error text); sentinel byte-absence test with **nine** distinct high-entropy sentinels — args, response, error text, caller-supplied `_auth_user_email`, and the caller/operator-controlled strings the line *does* carry: `client.name`/`client.version` (MCP `clientInfo` / `X-MCPProxy-Client`), `token_name`, `profile`, and a caller-supplied `server` and `tool` on a **refused** dispatch (the caller may name any `server:tool` pair; the `authz deny` line records it per FR-016) — each untrusted string field is sanitised **per field** at build time (the fixed-prefix secret patterns masked, length-capped; never the high-entropy rule, which would mask legitimate long identifiers and break FR-016's attribution) and the schema is validated *after* sanitisation; the whole-line defence-in-depth pass of FR-015 uses **only the fixed-prefix credential patterns** (`sk-ant-`, `AKIA`, `ghp_`/`gho_`, `Bearer …`, …) and **never the generic `high_entropy` rule** (`sanitizer.go:104` masks any quoted 32+ char `[A-Za-z0-9+/]` run — it would rewrite every `args_sha256` and `email_hash`, breaking the schema after validation); fixture: a line whose `args_sha256`/`email_hash` and a 40-char alphanumeric `server` name survive the pass byte-identical, while a planted `AKIA…` in `client.name` and a caller-supplied `AKIA…:ghp_…` target on a refused dispatch are masked **at build time by the per-field pass** so the writer's whole-line pass finds nothing; **the whole-line pass is asserted to be the identity on every constructor output** (every fixture line: `sanitised == line`, byte-compared) — because every caller- or operator-controlled field is already sanitised per field, the pass can only fire on a builder bug, and that is reported: a hit increments `Sink.SanitizerHits()` (always-on atomic, beside `WriteFailures()`, mirrored to `mcpproxy_audit_sanitizer_hits_total` and read by `doctor`) and logs one WARN per minute naming the field-less fact that a line was rewritten; the masked line is still written (defence in depth wins over FR-016's real-name rule — the exception FR-016 itself now states, documented in `docs/features/audit-log.md`) — `internal/audit/{line_test.go,schema_test.go,sink_test.go}` +- [x] T098 [P] [US3] **[compile-red until T099]** Write failing `internal/audit/sink_test.go`: the sink owns an **always-on** atomic write-failure counter (`Sink.WriteFailures() uint64`, independent of the metrics flag — doctor and the Prometheus mirror both read it); file sink append-only, write-through, a line never split across rotation (lumberjack via the exported `logs.NewRotatingWriter`), stdout sink writes raw JSON to an injected `io.Writer` (never through zap), unwritable path at construction → error mapped to exit code 4 by the caller (lumberjack opens lazily on first `Write`, so the constructor must probe the path itself — `OpenFile(O_APPEND|O_CREATE|O_WRONLY)` then close — before installing the rotating writer), runtime write failure → counter increments, call proceeds, error logged at most once per minute (fake clock), 2,000 concurrent writes under a saturated fake event bus → 2,000 lines — `internal/audit/sink_test.go` ### Implementation -- [ ] T099 [US3] Implement `internal/audit/{attempt.go,canonical.go,line.go,sink.go}` per data-model §5 and contracts; the dependency runs one way only (`audit` → `logs`, never `logs` → `audit`): `internal/logs` exports `NewRotatingWriter(path string, maxSizeMB, maxBackups, maxAgeDays int, compress bool) (io.WriteCloser, error)` built on the same lumberjack construction as `newRotatingSink` (`logger.go:183-197`; primitive arguments, no `audit` type) and `NewStringSanitizer(opts ...SanitizerOption) *StringSanitizer` exposing the pattern set of `SecretSanitizer.sanitizeString` (`sanitizer.go:160`) without a zap core (`NewSecretSanitizer` takes and returns a `zapcore.Core`, `sanitizer.go:26`, and is not an `io.Writer`) with a `WithoutHighEntropy()` option; `audit.Sink` wraps the writer with `NewStringSanitizer(WithoutHighEntropy())` (T097 explains why the generic rule cannot run over a line that carries hashes) — `internal/audit/*.go`, `internal/logs/{logger.go,sanitizer.go}` +- [x] T099 [US3] Implement `internal/audit/{attempt.go,canonical.go,line.go,sink.go}` per data-model §5 and contracts; the dependency runs one way only (`audit` → `logs`, never `logs` → `audit`): `internal/logs` exports `NewRotatingWriter(path string, maxSizeMB, maxBackups, maxAgeDays int, compress bool) (io.WriteCloser, error)` built on the same lumberjack construction as `newRotatingSink` (`logger.go:183-197`; primitive arguments, no `audit` type) and `NewStringSanitizer(opts ...SanitizerOption) *StringSanitizer` exposing the pattern set of `SecretSanitizer.sanitizeString` (`sanitizer.go:160`) without a zap core (`NewSecretSanitizer` takes and returns a `zapcore.Core`, `sanitizer.go:26`, and is not an `io.Writer`) with a `WithoutHighEntropy()` option; `audit.Sink` wraps the writer with `NewStringSanitizer(WithoutHighEntropy())` (T097 explains why the generic rule cannot run over a line that carries hashes) — `internal/audit/*.go`, `internal/logs/{logger.go,sanitizer.go}` ## Phase D.2 — US3: lines at the funnels (P1) ### Tests first -- [ ] T100 [US3] **[behaviour-red]** Write failing `internal/server/activity_funnel_ctx_first_test.go`: an AST test asserting the first parameter of `emitActivityPolicyDecision` and `emitActivityToolCallCompleted` is `context.Context` (red on HEAD: `mcp.go:766,787` take strings first) — the existing `statusArgIndex` pin (`activity_result_status_test.go:133`, `status` at index 5) is **not** touched here: moving it to 6 before the signature changes would make the guard inspect `errorMsg` and pass for the wrong reason; the pin and the `mcp.go:762-765` comment move to 6 atomically inside T103; extend `mcp_activity_args_test.go:460-527` so a caller-supplied `_auth_*` never reaches the activity metadata (behaviour-red: the strip is asserted on the existing seam) — the audit-line half of that assertion and every `caller.kind` case live in T101 (`TestGetAuthMetadata_*` in `mcp_activity_agent_test.go` exercises the activity-log `_auth_*` metadata, `mcp.go:647-668`, not audit caller identity, so it is the wrong host for `caller.kind`) — files above -- [ ] T101 [P] [US3] **[compile-red until T099/T103]** Write failing `internal/server/audit_caller_test.go` (the `caller.kind`/`origin` derivation helper `auditCallerFromContext(ctx) audit.Caller` T103 adds, one case per kind: API key, socket/tray, **stdio** (stdio installs `auth.AdminContext()` with no connection source, `server.go:1039`, and `GetConnectionSource` defaults to TCP, `transport/context.go:25`, so without a stdio tag the line would say `api_key` — `stdioAuthContext` must tag `transport.ConnectionSourceStdio` and the derivation maps it to `caller.kind: stdio`, `origin: local`), anonymous, owned/ownerless agent token, `session_admin` (`CredentialKind` cookie/bearer), internal) and `internal/server/audit_dispatch_matrix_test.go` (both tags; server tag adds tenant tokens and `session_admin` on `/api/v1/tools/call`): the US3 matrix — surfaces (`call_tool_read|write|destructive`, direct, nested script, REST `/tools/call`, **native stdio** through the in-process stdio server) × caller kinds (`api_key`, `socket`, `anonymous`, `agent_token` tenant/admin by `caller.role`, `session_admin`, `internal`, `stdio`) × situations (allowed, upstream error, tier denial, scope denial of a hidden server with `disclosed:false` and the real name recorded, quarantine block, limiter shed → `tool_call rejected`, output-sanitisation block → `tool_call blocked`, bare `retrieve_tools`/`read_cache` → no line, 100 KB payload, synthetic secret) asserting: schema validity, count invariants under bus saturation (2,000 calls, 1,500 allow), `args_sha256` equality with the independent hash, `caller.kind` correctness, `source: api` despite `X-MCPProxy-Client: cli/x`, nested children keep the script's caller + `surface: code_execution` + `parent_id`, the wrapper writes no line, no `session_user` on `authz`/`tool_call`, no `outcome` on `authz` (FR-043(j)) — `internal/server/audit_dispatch_matrix_test.go` -- [ ] T102 [P] [US3] **[compile-red until T104]** Write failing `internal/jsruntime/runtime_authz_observer_test.go`: `checkDispatchGates` (`runtime.go:384-418`) reports scope/permission refusals through the observer on both the single and the batch path with the request context, `parent_id`, canonical target, tier and stripped arguments, exactly once — `internal/jsruntime/runtime_authz_observer_test.go` +- [x] T100 [US3] **[behaviour-red]** Write failing `internal/server/activity_funnel_ctx_first_test.go`: an AST test asserting the first parameter of `emitActivityPolicyDecision` and `emitActivityToolCallCompleted` is `context.Context` (red on HEAD: `mcp.go:766,787` take strings first) — the existing `statusArgIndex` pin (`activity_result_status_test.go:133`, `status` at index 5) is **not** touched here: moving it to 6 before the signature changes would make the guard inspect `errorMsg` and pass for the wrong reason; the pin and the `mcp.go:762-765` comment move to 6 atomically inside T103; extend `mcp_activity_args_test.go:460-527` so a caller-supplied `_auth_*` never reaches the activity metadata (behaviour-red: the strip is asserted on the existing seam) — the audit-line half of that assertion and every `caller.kind` case live in T101 (`TestGetAuthMetadata_*` in `mcp_activity_agent_test.go` exercises the activity-log `_auth_*` metadata, `mcp.go:647-668`, not audit caller identity, so it is the wrong host for `caller.kind`) — files above +- [x] T101 [P] [US3] **[compile-red until T099/T103]** Write failing `internal/server/audit_caller_test.go` (the `caller.kind`/`origin` derivation helper `auditCallerFromContext(ctx) audit.Caller` T103 adds, one case per kind: API key, socket/tray, **stdio** (stdio installs `auth.AdminContext()` with no connection source, `server.go:1039`, and `GetConnectionSource` defaults to TCP, `transport/context.go:25`, so without a stdio tag the line would say `api_key` — `stdioAuthContext` must tag `transport.ConnectionSourceStdio` and the derivation maps it to `caller.kind: stdio`, `origin: local`), anonymous, owned/ownerless agent token, `session_admin` (`CredentialKind` cookie/bearer), internal) and `internal/server/audit_dispatch_matrix_test.go` (both tags; server tag adds tenant tokens and `session_admin` on `/api/v1/tools/call`): the US3 matrix — surfaces (`call_tool_read|write|destructive`, direct, nested script, REST `/tools/call`, **native stdio** through the in-process stdio server) × caller kinds (`api_key`, `socket`, `anonymous`, `agent_token` tenant/admin by `caller.role`, `session_admin`, `internal`, `stdio`) × situations (allowed, upstream error, tier denial, scope denial of a hidden server with `disclosed:false` and the real name recorded, quarantine block, limiter shed → `tool_call rejected`, output-sanitisation block → `tool_call blocked`, bare `retrieve_tools`/`read_cache` → no line, 100 KB payload, synthetic secret) asserting: schema validity, count invariants under bus saturation (2,000 calls, 1,500 allow), `args_sha256` equality with the independent hash, `caller.kind` correctness, `source: api` despite `X-MCPProxy-Client: cli/x`, nested children keep the script's caller + `surface: code_execution` + `parent_id`, the wrapper writes no line, no `session_user` on `authz`/`tool_call`, no `outcome` on `authz` (FR-043(j)) — `internal/server/audit_dispatch_matrix_test.go` +- [x] T102 [P] [US3] **[compile-red until T104]** Write failing `internal/jsruntime/runtime_authz_observer_test.go`: `checkDispatchGates` (`runtime.go:384-418`) reports scope/permission refusals through the observer on both the single and the batch path with the request context, `parent_id`, canonical target, tier and stripped arguments, exactly once — `internal/jsruntime/runtime_authz_observer_test.go` ### Implementation -- [ ] T103 [US3] `ctx` as the first parameter of `emitActivityPolicyDecision` (`mcp.go:787`) and `emitActivityToolCallCompleted` (`:766`) and every call site (`mcp.go:2211-2425,2912-2934,6872`, `mcp_routing.go:425-468`, `output_sanitisation.go:113,138,287,328`, `mcp_code_execution.go:869,927`, test fixtures); install `audit.Attempt` before the first gate in `handleCallToolVariant` (`:2190-2197`), direct dispatch (`mcp_routing.go:412-414`), the REST direct path and the nested wrapper (`mcp_code_execution.go:691-704`); update the `statusArgIndex` pin to 6 and the `mcp.go:762-765` comment in the same commit (T100); funnels build and write `authz`/`tool_call` lines from the attempt + `AuthContext` + `reqcontext.RequestMeta` (client IP, mount; T050) + connection source; **sink wiring path** (no field exists today, `serveredition_wire.go:28-42`; the constructors take no options, `server.go:173,211`, and production calls `NewServerWithConfigPath`, `main.go:629ff`): add `type ServerOption func(*Server)` (package `server`; distinct from the existing `MCPProxyOption`, `mcp.go:271`) and a variadic `opts ...ServerOption` to **both** `NewServer` and `NewServerWithConfigPath` (`NewServer` forwards `opts` unchanged; backward-compatible — every existing caller passes none), `func WithAuditSink(sink audit.Sink) ServerOption`; `cmd/mcpproxy/main.go` constructs the sink and calls `NewServerWithConfigPath(cfg, path, logger, server.WithAuditSink(sink))` → `Server.auditSink` → `MCPProxyServer.auditSink` (nil = no-op in the personal default) and a **new typed field** `serveredition.Dependencies.AuditSink audit.Sink` (added at `internal/serveredition/registry.go:19-37`) set by `wireServerEditionOAuth` for T107; `caller.kind` derivation (incl. `stdio` via the new `transport.ConnectionSourceStdio` tag set in `stdioAuthContext`, `server.go:1039`); limiter shed from the returned `*limiter.LimitError`; post-dispatch blocks as `tool_call blocked` — `internal/server/{mcp.go,mcp_routing.go,mcp_code_execution.go,output_sanitisation.go,server.go}`, `internal/transport/context.go`, `internal/serveredition/registry.go`, `cmd/mcpproxy/main.go` -- [ ] T104 [US3] `jsruntime.ExecutionContext` authorization-decision observer invoked from `checkDispatchGates`; the wrapper installs it with the parent attempt; a refusal it reports is not re-reported by the completion emitters — `internal/jsruntime/runtime.go`, `internal/server/mcp_code_execution.go` -- [ ] T105a [P] [US3] **[compile-red until T105 (`audit.ErrorClassOf`)]** Write failing `internal/audit/error_class_test.go`: a table over the typed upstream errors (`context.Canceled`/`DeadlineExceeded`, `*limiter.LimitError`, the upstream transport/timeout/unavailable error types, validation and sanitisation errors, an unknown error → `internal`) → `upstream_error|upstream_timeout|upstream_unavailable|validation|sanitisation|internal|cancelled` — `internal/audit/error_class_test.go` -- [ ] T105 [P] [US3] (after T105a) `audit.ErrorClassOf(err error) ErrorClass` — the one helper — `internal/audit/error_class.go` +- [x] T103 [US3] `ctx` as the first parameter of `emitActivityPolicyDecision` (`mcp.go:787`) and `emitActivityToolCallCompleted` (`:766`) and every call site (`mcp.go:2211-2425,2912-2934,6872`, `mcp_routing.go:425-468`, `output_sanitisation.go:113,138,287,328`, `mcp_code_execution.go:869,927`, test fixtures); install `audit.Attempt` before the first gate in `handleCallToolVariant` (`:2190-2197`), direct dispatch (`mcp_routing.go:412-414`), the REST direct path and the nested wrapper (`mcp_code_execution.go:691-704`); update the `statusArgIndex` pin to 6 and the `mcp.go:762-765` comment in the same commit (T100); funnels build and write `authz`/`tool_call` lines from the attempt + `AuthContext` + `reqcontext.RequestMeta` (client IP, mount; T050) + connection source; **sink wiring path** (no field exists today, `serveredition_wire.go:28-42`; the constructors take no options, `server.go:173,211`, and production calls `NewServerWithConfigPath`, `main.go:629ff`): add `type ServerOption func(*Server)` (package `server`; distinct from the existing `MCPProxyOption`, `mcp.go:271`) and a variadic `opts ...ServerOption` to **both** `NewServer` and `NewServerWithConfigPath` (`NewServer` forwards `opts` unchanged; backward-compatible — every existing caller passes none), `func WithAuditSink(sink audit.Sink) ServerOption`; `cmd/mcpproxy/main.go` constructs the sink and calls `NewServerWithConfigPath(cfg, path, logger, server.WithAuditSink(sink))` → `Server.auditSink` → `MCPProxyServer.auditSink` (nil = no-op in the personal default) and a **new typed field** `serveredition.Dependencies.AuditSink audit.Sink` (added at `internal/serveredition/registry.go:19-37`) set by `wireServerEditionOAuth` for T107; `caller.kind` derivation (incl. `stdio` via the new `transport.ConnectionSourceStdio` tag set in `stdioAuthContext`, `server.go:1039`); limiter shed from the returned `*limiter.LimitError`; post-dispatch blocks as `tool_call blocked` — `internal/server/{mcp.go,mcp_routing.go,mcp_code_execution.go,output_sanitisation.go,server.go}`, `internal/transport/context.go`, `internal/serveredition/registry.go`, `cmd/mcpproxy/main.go` +- [x] T104 [US3] `jsruntime.ExecutionContext` authorization-decision observer invoked from `checkDispatchGates`; the wrapper installs it with the parent attempt; a refusal it reports is not re-reported by the completion emitters — `internal/jsruntime/runtime.go`, `internal/server/mcp_code_execution.go` +- [x] T105a [P] [US3] **[compile-red until T105 (`audit.ErrorClassOf`)]** Write failing `internal/audit/error_class_test.go`: a table over the typed upstream errors (`context.Canceled`/`DeadlineExceeded`, `*limiter.LimitError`, the upstream transport/timeout/unavailable error types, validation and sanitisation errors, an unknown error → `internal`) → `upstream_error|upstream_timeout|upstream_unavailable|validation|sanitisation|internal|cancelled` — `internal/audit/error_class_test.go` +- [x] T105 [P] [US3] (after T105a) `audit.ErrorClassOf(err error) ErrorClass` — the one helper — `internal/audit/error_class.go` ## Phase D.3 — `auth_event` lines (FR-017) -- [ ] T106 [US3] **[compile-red until T107]** Write failing `internal/serveredition/auth/auth_event_test.go`: exactly one line per terminal login attempt (every FR-013 reason incl. `authorization_denied` via the PR-B refusal fixtures + fault injection → `internal_error`), one per logout, none for an abandoned redirect; identity rule is **stage-dependent** (`user_id` when the store was reached and a record exists / `email_hash` when a verified email is known and the store was not yet consulted — `domain_not_allowed`, `userinfo_subject_mismatch`, and `provider_error` raised by the userinfo fetch after a verified ID token / neither before identity): `provider_error` is driven at **both** stages — the `UserinfoUnavailable`/`UserinfoRedirect`/`UserinfoNonJSON` knobs after a verified token (line carries `email_hash`, never `user_id`, even for a returning user) and a discovery/token-endpoint failure (line carries neither) — and every line validates against the schema; `flags` (`provider_rebound`, `redirect_rejected`, `groups_claim_missing`); token mint/rotate/revoke write no line; `session_user` appears only here — `internal/serveredition/auth/auth_event_test.go` -- [ ] T107 [US3] Emit `auth_event` lines by installing the emitter on the handler's `LoginResultObserver` hook (T044 — one terminal `LoginResult` per attempt, so the count invariant is the hook's, not re-derived from branches) and from `HandleLogout`, through the `audit.Sink` carried in `serveredition.Dependencies.AuditSink` (the typed `Dependencies.AuditSink` field T103 adds to `registry.go`, set by `serveredition_wire.go` from the server's sink; nil = no-op) and handed to the OAuth handler by `setup.go` (edition-neutral sink, server-only emitter) — `internal/serveredition/auth/oauth_handler.go`, `internal/serveredition/setup.go`, `internal/server/serveredition_wire.go` +- [x] T106 [US3] **[compile-red until T107]** Write failing `internal/serveredition/auth/auth_event_test.go`: exactly one line per terminal login attempt (every FR-013 reason incl. `authorization_denied` via the PR-B refusal fixtures + fault injection → `internal_error`), one per logout, none for an abandoned redirect; identity rule is **stage-dependent** (`user_id` when the store was reached and a record exists / `email_hash` when a verified email is known and the store was not yet consulted — `domain_not_allowed`, `userinfo_subject_mismatch`, and `provider_error` raised by the userinfo fetch after a verified ID token / neither before identity): `provider_error` is driven at **both** stages — the `UserinfoUnavailable`/`UserinfoRedirect`/`UserinfoNonJSON` knobs after a verified token (line carries `email_hash`, never `user_id`, even for a returning user) and a discovery/token-endpoint failure (line carries neither) — and every line validates against the schema; `flags` (`provider_rebound`, `redirect_rejected`, `groups_claim_missing`); token mint/rotate/revoke write no line; `session_user` appears only here — `internal/serveredition/auth/auth_event_test.go` +- [x] T107 [US3] Emit `auth_event` lines by installing the emitter on the handler's `LoginResultObserver` hook (T044 — one terminal `LoginResult` per attempt, so the count invariant is the hook's, not re-derived from branches) and from `HandleLogout`, through the `audit.Sink` carried in `serveredition.Dependencies.AuditSink` (the typed `Dependencies.AuditSink` field T103 adds to `registry.go`, set by `serveredition_wire.go` from the server's sink; nil = no-op) and handed to the OAuth handler by `setup.go` (edition-neutral sink, server-only emitter) — `internal/serveredition/auth/oauth_handler.go`, `internal/serveredition/setup.go`, `internal/server/serveredition_wire.go` ## Phase D.4 — Config, doctor, metrics (FR-014, FR-018, FR-039 part 4) -- [ ] T108 [US3] **[compile-red until T109]** Write failing `internal/config/audit_log_config_test.go`: defaults per edition (`EffectiveAuditLog`; **the server-edition stdout default applies to the HTTP transport only** — in native stdio mode standard output *is* the MCP transport, `server.go:968-989`: with the block **absent** the server-edition default resolves to `{enabled:false}` under stdio with one WARN line naming `audit_log.path` as the stdio-compatible sink (only the *default* is suppressed — FR-014 "an explicit value always wins" holds); an **explicit** `enabled: true, stdout: true` with no `path` under stdio is a sink-construction failure — typed `config.StartupError{ExitCode: 4}` `audit_log.stdout cannot be used under the stdio transport (stdout carries JSON-RPC); set audit_log.path` — never a silent disable; an explicit `path` is honoured and `stdout: true` beside it is dropped with the WARN), **omitted vs explicit** for every field (`compress` omitted → `true`, explicit `false` → `false`; `max_size_mb` omitted → 50, explicit `0` → validation error — the wire struct uses pointer fields so presence is observable, data-model §9), env overrides, validation messages (`no sink`, non-positive rotation values), `DetectConfigChanges` restart-pinned clause; `cmd/mcpproxy/audit_boot_test.go`: unwritable path → exit code 4 with the message — via a typed `config.StartupError{ExitCode: ExitCodeConfigError}` that `classifyError` (`main.go:846ff`) checks with `errors.As` **before** its string heuristics (today a `permission denied` message classifies as exit 5, `:869-873`); stdio + absent block → the WARN line and a disabled sink; stdio + explicit `{enabled:true, stdout:true}` and no `path` → exit code 4 with the message; stdio + explicit `path` → file sink, stdout dropped with the WARN; `enabled: false` under the server edition → startup warning; absent block under the server edition → one startup line — files above -- [ ] T109 [US3] Implement `AuditLogConfig` (`internal/config/audit_log.go`), accessor `EffectiveAuditLog(cfg, transport)` (stdio rule of T108), `validateAuditLog(cfg)` **called from both `Config.Validate()` and `ValidateDetailed()`** (`config.go`; the "no sink" and non-positive rotation messages of `contracts/config-keys.md`, so boot, PATCH and `/config/apply` agree — T108 drives all four doors), env in `applyTLSEnvOverrides`, `DetectConfigChanges` clause, sink construction in `cmd/mcpproxy/main.go` returning the typed `StartupError` (exit 4 through `classifyError`'s new `errors.As` branch, `exit_codes.go`), `mcpproxy_audit_write_failures_total` **counter** (monotonic `_total`, never a gauge) in `internal/observability` (metrics enabled only) **mirroring the sink's always-on atomic counter** (`Sink.WriteFailures()`, T098), `doctor` finding reading the sink's counter (works with metrics disabled) — registered from `internal/server` as a second `management.AddRuntimeWarningSource` (T052 seam) that reports `audit_log: N write failures since start (last: )` when `Sink.WriteFailures() > 0`; asserted through `management.(*service).Doctor` with a stub sink — `internal/config/{audit_log.go,config.go,loader.go,serveredition_accessors{,_stub}.go}`, `internal/runtime/config_hotreload.go`, `cmd/mcpproxy/main.go`, `internal/server/server.go`, `internal/observability/*.go`, `internal/management/diagnostics_audit_test.go` -- [ ] T110a [P] [US3] **[behaviour-red]** (no `AUDIT_LOG_FIELDS` export exists) Write failing `frontend/tests/unit/settings-audit-log.spec.ts`: the `audit_log.*` accordion rows of `contracts/config-keys.md` exist with `restart: true` and no secret control — `frontend/tests/unit/settings-audit-log.spec.ts` -- [ ] T110 [P] [US3] (after T110a) Wiring checklist: `make swagger` (`audit_log` on `Config`), `swagger-verify`; the `fields.ts` `AUDIT_LOG_FIELDS` accordion; Swift catalogue read-only rows and `python3 scripts/check-settings-parity.py` + `swift test` (`native-tests.yml:83,97`) green locally; `docs/configuration/config-file.md` + `environment-variables.md` + root `docs/configuration.md` rows; `TestContractsInSync` — `oas/*`, `frontend/src/views/settings/fields.ts`, `native/macos/MCPProxy/.../SettingsCatalog.swift`, docs +- [x] T108 [US3] **[compile-red until T109]** Write failing `internal/config/audit_log_config_test.go`: defaults per edition (`EffectiveAuditLog`; **the server-edition stdout default applies to the HTTP transport only** — in native stdio mode standard output *is* the MCP transport, `server.go:968-989`: with the block **absent** the server-edition default resolves to `{enabled:false}` under stdio with one WARN line naming `audit_log.path` as the stdio-compatible sink (only the *default* is suppressed — FR-014 "an explicit value always wins" holds); an **explicit** `enabled: true, stdout: true` with no `path` under stdio is a sink-construction failure — typed `config.StartupError{ExitCode: 4}` `audit_log.stdout cannot be used under the stdio transport (stdout carries JSON-RPC); set audit_log.path` — never a silent disable; an explicit `path` is honoured and `stdout: true` beside it is dropped with the WARN), **omitted vs explicit** for every field (`compress` omitted → `true`, explicit `false` → `false`; `max_size_mb` omitted → 50, explicit `0` → validation error — the wire struct uses pointer fields so presence is observable, data-model §9), env overrides, validation messages (`no sink`, non-positive rotation values), `DetectConfigChanges` restart-pinned clause; `cmd/mcpproxy/audit_boot_test.go`: unwritable path → exit code 4 with the message — via a typed `config.StartupError{ExitCode: ExitCodeConfigError}` that `classifyError` (`main.go:846ff`) checks with `errors.As` **before** its string heuristics (today a `permission denied` message classifies as exit 5, `:869-873`); stdio + absent block → the WARN line and a disabled sink; stdio + explicit `{enabled:true, stdout:true}` and no `path` → exit code 4 with the message; stdio + explicit `path` → file sink, stdout dropped with the WARN; `enabled: false` under the server edition → startup warning; absent block under the server edition → one startup line — files above +- [x] T109 [US3] Implement `AuditLogConfig` (`internal/config/audit_log.go`), accessor `EffectiveAuditLog(cfg, transport)` (stdio rule of T108), `validateAuditLog(cfg)` **called from both `Config.Validate()` and `ValidateDetailed()`** (`config.go`; the "no sink" and non-positive rotation messages of `contracts/config-keys.md`, so boot, PATCH and `/config/apply` agree — T108 drives all four doors), env in `applyTLSEnvOverrides`, `DetectConfigChanges` clause, sink construction in `cmd/mcpproxy/main.go` returning the typed `StartupError` (exit 4 through `classifyError`'s new `errors.As` branch, `exit_codes.go`), `mcpproxy_audit_write_failures_total` **counter** (monotonic `_total`, never a gauge) in `internal/observability` (metrics enabled only) **mirroring the sink's always-on atomic counter** (`Sink.WriteFailures()`, T098), `doctor` finding reading the sink's counter (works with metrics disabled) — registered from `internal/server` as a second `management.AddRuntimeWarningSource` (T052 seam) that reports `audit_log: N write failures since start (last: )` when `Sink.WriteFailures() > 0`; asserted through `management.(*service).Doctor` with a stub sink — `internal/config/{audit_log.go,config.go,loader.go,serveredition_accessors{,_stub}.go}`, `internal/runtime/config_hotreload.go`, `cmd/mcpproxy/main.go`, `internal/server/server.go`, `internal/observability/*.go`, `internal/management/diagnostics_audit_test.go` +- [x] T110a [P] [US3] **[behaviour-red]** (no `AUDIT_LOG_FIELDS` export exists) Write failing `frontend/tests/unit/settings-audit-log.spec.ts`: the `audit_log.*` accordion rows of `contracts/config-keys.md` exist with `restart: true` and no secret control — `frontend/tests/unit/settings-audit-log.spec.ts` +- [x] T110 [P] [US3] (after T110a) Wiring checklist: `make swagger` (`audit_log` on `Config`), `swagger-verify`; the `fields.ts` `AUDIT_LOG_FIELDS` accordion; Swift catalogue read-only rows and `python3 scripts/check-settings-parity.py` + `swift test` (`native-tests.yml:83,97`) green locally; `docs/configuration/config-file.md` + `environment-variables.md` + root `docs/configuration.md` rows; `TestContractsInSync` — `oas/*`, `frontend/src/views/settings/fields.ts`, `native/macos/MCPProxy/.../SettingsCatalog.swift`, docs ## Phase D.5 — Docs, E2E, benchmark, delivery -- [ ] T111 [P] [US3] `docs/features/audit-log.md` (schema table from `contracts/audit-line-events.md`, every vocabulary, versioning rule, crash window, Docker/stdout recipe, one vendor-neutral file/stdout scrape example) + `docs/schemas/audit-line-v1.schema.json` + `website/sidebars.js` entry; `docs/features/sensitive-data-detection.md:360` SIEM recipe points at it — files above -- [ ] T112 [P] [US3] `docs/operations/deploying-for-a-team.md` (Kubernetes + Keycloak walkthrough: Deployment `strategy: Recreate`, Secret via `${env:}`, Ingress, `public_url`, `trusted_proxies`, `access`, stdout audit, single-replica contract, `--config`+`--data-dir` volume rule, the open 105 items, the staleness bound and the upgrade-state table of T091) + sidebar entry; its config example stored at `docs/operations/examples/deploying-for-a-team.json` and loaded+validated by `internal/config/deploy_guide_example_test.go` (`-tags server`) — files above -- [ ] T113 [P] [US3] `scripts/test-api-e2e.sh`: after the activity tests (`:960-977`) assert that a personal instance with `audit_log.enabled=true, path=` wrote one `authz` + one `tool_call` line for the fixture call and none for `retrieve_tools`; keep the script's default run unchanged otherwise — `scripts/test-api-e2e.sh`, `test/e2e-config.json` (only if a second config is needed; restore afterwards) -- [ ] T114 [P] [US3] `.github/RELEASE_NOTICE.md` PR-D bullets: server-edition audit-to-stdout default, exit code 4 on an unwritable path — `.github/RELEASE_NOTICE.md` -- [ ] T115 [US3] SC-009 benchmark: Spec 105 FR-011 method (frozen 527-tool snapshot, 20 warm-ups, 200 calls, merge-base vs branch) for `call_tool_read`, `retrieve_tools`, `tools/list` with `audit_log` on, administrator and scoped tenant; record p95s in verification.md (quote USD beside tokens if any token figure is reported — `feedback_quote_usd_with_tokens`) — `bench/` (existing harness), `verification.md` +- [x] T111 [P] [US3] `docs/features/audit-log.md` (schema table from `contracts/audit-line-events.md`, every vocabulary, versioning rule, crash window, Docker/stdout recipe, one vendor-neutral file/stdout scrape example) + `docs/schemas/audit-line-v1.schema.json` + `website/sidebars.js` entry; `docs/features/sensitive-data-detection.md:360` SIEM recipe points at it — files above +- [x] T112 [P] [US3] `docs/operations/deploying-for-a-team.md` (Kubernetes + Keycloak walkthrough: Deployment `strategy: Recreate`, Secret via `${env:}`, Ingress, `public_url`, `trusted_proxies`, `access`, stdout audit, single-replica contract, `--config`+`--data-dir` volume rule, the open 105 items, the staleness bound and the upgrade-state table of T091) + sidebar entry; its config example stored at `docs/operations/examples/deploying-for-a-team.json` and loaded+validated by `internal/config/deploy_guide_example_test.go` (`-tags server`) — files above +- [x] T113 [P] [US3] `scripts/test-api-e2e.sh`: after the activity tests (`:960-977`) assert that a personal instance with `audit_log.enabled=true, path=` wrote one `authz` + one `tool_call` line for the fixture call and none for `retrieve_tools`; keep the script's default run unchanged otherwise — `scripts/test-api-e2e.sh`, `test/e2e-config.json` (only if a second config is needed; restore afterwards) +- [x] T114 [P] [US3] `.github/RELEASE_NOTICE.md` PR-D bullets: server-edition audit-to-stdout default, exit code 4 on an unwritable path — `.github/RELEASE_NOTICE.md` +- [x] T115 [US3] SC-009 benchmark: Spec 105 FR-011 method (frozen 527-tool snapshot, 20 warm-ups, 200 calls, merge-base vs branch) for `call_tool_read`, `retrieve_tools`, `tools/list` with `audit_log` on, administrator and scoped tenant; record p95s in verification.md (quote USD beside tokens if any token figure is reported — `feedback_quote_usd_with_tokens`) — `bench/` (existing harness), `verification.md` - [x] T116 [US3] Real-instance verification: quickstart §6 (`--phase d`: three lines for `a:echo` allow + `tool_call`, `b:echo` deny with `disclosed:false`; sentinel absent; `auth_event ok` for Alice; schema validation of the tail through `MCPPROXY_AUDIT_JSONL=$ROOT/audit.jsonl go test ./internal/audit -run TestExternalJSONLValidates` — no `npx ajv-cli`, T097), stdout mode in a `docker run` of the built image with `--entrypoint` checks, a stdio serve with the block absent → the WARN line and clean JSON-RPC on stdout, a stdio serve with an explicit stdout-only block → exit 4, unwritable path → exit 4, disk-full simulation (`/dev/full`) → call proceeds + counter; record — `verification.md` - [x] T117 [X] Full gate set + goldens unregenerated + `test-api-e2e.sh` with the new assertion — `verification.md` -- [ ] T118 [X] Cross-model review (briefs: audit package / funnels+attempt / nested observer+limiter / auth_event / config+docs), ≤ 10 rounds — `verification.md` -- [ ] T119 [X] Open PR-D; roadmap tick (`status: in_review` on the epic when all four are open); `gen-roadmap.py --check`; CI green; no merge without instruction — `roadmap.yaml`, `ROADMAP.md` +- [x] T118 [X] Cross-model review (briefs: audit package / funnels+attempt / nested observer+limiter / auth_event / config+docs), ≤ 10 rounds — `verification.md` +- [x] T119 [X] Open PR-D; roadmap tick (`status: in_review` on the epic when all four are open); `gen-roadmap.py --check`; CI green; no merge without instruction — `roadmap.yaml`, `ROADMAP.md` ---