Repository navigation
✨ feat: Log audit decisions - #563
Conversation
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Reviewed at b270c27. LGTM: the mirror is small and consistent, the stdout-before-XADD ordering in auditBestEffort is the right call for the Redis-down debugging story, and the whitelist test is a good guard. No blocking issues. Inline: one gap where run_finalized is skipped on error paths, missing test coverage for the RedisRefreshStore emits, ADR/spec registration in the README indexes, and three test/ordering nits.
Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, knative-server, harness), tests, docs (ADR + spec + observability), security/data-handling
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed-off: yes
CI status: passing (15/15)
| toResultRecord(result, body.sessionId, new Date().toISOString()), | ||
| RESULT_TTL_SECONDS, | ||
| ); | ||
| emitLifecycle('run_finalized', { |
There was a problem hiding this comment.
suggestion: run_finalized is only reached on the happy path. If writeResult throws (Redis down, which is exactly the case ADR-0044 wants stdout to cover) or runLeaf rejects, route().catch(internalError) answers 500 and the run_started line is left without a matching run_finalized. An operator grepping for unterminated runs then can't tell "crashed" from "still running". Consider wrapping everything after run_started in try { … } catch (err) { emitLifecycle('run_finalized', { status: 'failed', reason: 'error' }); throw err; } (or a finally-with-flag), plus a test where runLeaf rejects.
| await deps.refresh.revoke(r.refreshToken, Date.now()).catch(() => {}); | ||
|
|
||
| // Sanity floor: a regression that stops emission must not silently shrink the array. | ||
| // (Refresh mirror lives on RedisRefreshStore; tests use the in-memory store, so only the |
There was a problem hiding this comment.
suggestion: As this comment says, makeDeps uses the in-memory refresh store, so none of the five new RedisRefreshStore emits (refresh_issued/rotated/reuse_detected/refused/revoked) runs in any test. The refresh calls in these three policy tests only add noise. refresh-redis.test.ts already runs against a real Redis with new RedisRefreshStore(redis, policy, prefix), so passing a capturing log as the 4th arg there would cover the decision mapping (reuse → refresh_reuse_detected, revoke only on result 1) and the identifiers-only rule on that seam. That seam is the riskiest one, because displayName/label sit right next to it.
| expect( | ||
| FORBIDDEN_KEYS, | ||
| `forbidden key ${JSON.stringify(key)} in ${JSON.stringify(line)}`, | ||
| ).not.toContain(key.toLowerCase()); |
There was a problem hiding this comment.
nit: FORBIDDEN_KEYS mixes camelCase entries (apiKey, credentialValue, promptText, displayName) with a key.toLowerCase() lookup, so those four never match ('displayname' ≠ 'displayName'). The ALLOWED_KEYS check above still catches them, so nothing leaks today, but the second guard is partly dead. Lower-case the list (or compare case-insensitively on both sides).
| const deps = makeDeps(); | ||
| await seedCredential(deps, alice.sub); | ||
| await seedCredential(deps, bob.sub); | ||
| deps.identity = { |
There was a problem hiding this comment.
nit: deps.identity = { ...deps.identity } is a no-op, and bySubject.get(alice.sub)!.subject === alice.sub is true by construction of the map. As written, the test only proves that two session_created lines with two distinct subjects were emitted. To check attribution, assert each subject's sessionId matches the session id its own createSession response returned.
| 'credential_issued' | 'operator_fallback_used', | ||
| }; | ||
| // Inline fallback (not resolveAuditLog): avoids a handlers.ts <-> exchange.ts cycle. | ||
| (deps.log ?? defaultAuditLog)({ event: 'audit', ...exchangeEntry }); |
There was a problem hiding this comment.
nit: Unlike auditBestEffort, this index.audit is not best-effort. If the XADD fails, the exchange answers 503 and no credential is returned, but stdout already says credential_issued. The same applies to session_created/model_changed/session_deleted in handlers.ts, although there the state change itself has already happened. For the exchange, consider emitting after the await (Redis down already gets a loud redis_unavailable line), or document in ADR-0044 that the mirror records an attempted decision for these sites.
| @@ -0,0 +1,59 @@ | |||
| # ADR-0044: Mirror audit decisions to component stdout as structured JSON, carrying subject and sessionId | |||
There was a problem hiding this comment.
suggestion: ADR-0044 isn't added to the index table in docs/adrs/README.md (it stops at 0043), and 2026-10-20-audit-log-mirror-design.md isn't registered in docs/specs/README.md. The PR checklist marks this item as done, and docs/CONTRIBUTING-DOCS.md requires it. The docs check doesn't enforce it, which is why CI is green.
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Sixteen ADRs still said Proposed although their decisions are in code on main. Each status line now names the merged PRs that implemented it and the date the core landed (format of ADR-0042), and notes what is still owed where only part is built: - 0028 (rossoctl#170, rossoctl#201, rossoctl#340; its KEDA transport removed by ADR-0041) - 0029 (rossoctl#171), 0030 (rossoctl#214), 0031 (rossoctl#214, rossoctl#225) - 0032 (rossoctl#249, rossoctl#350, as amended by MI1) - 0035 (rossoctl#251; ADR-0048 adds lease mode beside it) - 0036 (rossoctl#347), 0038 (rossoctl#458), 0039 (rossoctl#467), 0040 (rossoctl#481) - 0043 (rossoctl#560, rossoctl#588, rossoctl#600, rossoctl#615), 0044 (rossoctl#563), 0045 (rossoctl#620) - 0046 (phase 1: rossoctl#630, rossoctl#641, rossoctl#646; phase 2 owed) - 0047 (M1 and M3: rossoctl#704, rossoctl#713, rossoctl#717, rossoctl#765; M2 owed) - 0048 (rossoctl#706, rossoctl#763, rossoctl#802, rossoctl#808, rossoctl#814; off by default until the security review's lease sections are signed off) The README index follows, and its 0033 row, which still said Proposed after rossoctl#249 accepted the ADR, is corrected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
The
sh:cp:auditRedis stream has the lifecycle, but kubectl logs is silent per request today — operators debugging a leaf have nothing to grep without cluster-admin Redis access. This mirrors every audit decision to component stdout as one JSON line, carrying subject + sessionId.Closes #359
Details
Control plane - Every audit decision — session create/update/delete, credential writes and exchanges, config-bundle promotes and deletes, sandbox creates and deletes, and the full refresh-token lifecycle — now writes a JSON line to component stdout as well as the Redis stream. The mirror fires before the Redis write, so operators still see the decision when Redis is unavailable.
Data plane - The run path adds two lifecycle events: one when a leaf begins execution, one when it terminates. The pair carries the caller's subject, the session and workload identifiers, the dispatch kind, and the terminal status. Internal saturation retries don't double-emit, and the deprecated Knative/KEDA drain stays untouched.
Shape - One flat JSON object per line, keyed by event and decision. The signature matches the supervisor's existing structured-log convention so a future consolidation is a rename, not a rewrite. Attribution is carried by explicit parameters at each emit site — no request-scoped context or async-storage plumbing was needed.
Policy - Only identifiers appear in the output: subjects, session IDs, workload IDs, content-addressed digests, enum status codes. User-authored content (prompts, agent responses, file names inside workloads, display names), credential values, and verbatim error messages are prohibited.
Docs
Assisted-By: Claude (Anthropic AI) [email protected]
Checklist
git commit -s).make lintand the tests for the touched packages pass.docs/page, with the right maturity label (seedocs/CONTRIBUTING-DOCS.md).make check-linkspasses if any Markdown changed.docs/specs/README.mdordocs/adrs/README.md.