Skip to content

feat(secrets): record every secret read in the audit chain, governance on or off - #1126

Merged
sandstream merged 6 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-secret-read-events
Nov 27, 2026
Merged

sandstream merged 6 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-secret-read-events

Conversation

@sandstream

@sandstream sandstream commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #1115 (base branch claude/web-kit-status-sync-p6fg9a-protected-audit-secrets-keys). Protected — owner merges (src/secrets*, src/check-secrets.ts, src/audit-secrets.ts, src/exec-broker/).

Found by kit-research note kms-decrypt-evidence-vs-kit (Plan item 4, owner-approved): a read through kit should be a request someone can see later, per key, names only.

What governance gates today, and why reads were invisible

DEFAULT_GOVERNANCE in src/governance.ts ships enabled: false, and withGovernance (src/governance-middleware.ts) returns before any audit:

  // Skip governance if disabled
  if (!governanceConfig.enabled) {
    return await operation();
  }

What governance adds when it is on, per docs/COMMANDS.md: "Enabled governance checks permissions, revocation, budget, and configured secret expiration before execution." plus "Governance and resource rules record their own audit events when enabled." Its events go through logAuditEvent, which also stamps [governance.agent] and does the opt-in remote push ([governance.audit].remote).

The only record of a kit secrets read was that governed secrets.generate, so the default config recorded nothing. Writes were already recorded without governance through appendAuditEventDirect (src/secrets-write-record.ts). The hash chain and the HMAC anchor are not governance-only: appendSerialized anchors both paths.

Change

New src/secrets-read-record.ts: one secrets.read event per store, appended through appendAuditEventDirect (same chain, same anchor as writes), before the value is fetched or handed on. Metadata: name/names (key names), store, via (the kit surface), harness (Claude Code or Codex, from detectAgentSession), and agent_id/agent_name from [governance.agent] where the caller has the config. Never a value, never a digest of one. Time is the event timestamp.

Read path Where it is recorded
kit secrets, secrets sync, secrets onecli register, MCP kit_secrets generateSecrets (src/secrets.ts)
kit secrets validate, kit fix deploy step, branch-protection audit resolveRecorded (one key)
kit run, MCP kit_run (and kit setup commands) executeCommand (src/run.ts): the .env.local names given to the child
exec-broker (enforce mode) brokerExec: the requested env names handed to run()
kit check vault probes (op read, get-secret-value, …) checkSecrets: names of non-env/config keys it probes
kit secrets incident unchanged: already records secrets.incident with names
gate-env nothing to record: it is a write gate (src/commands/gate.ts cmdGateEnv blocks plaintext writes to .env*) and never resolves or injects a secret

A source-scan test fails if resolveViaBackend( is called from any file other than the five that record the read first.

Fail closed. If the record cannot be appended (damaged chain, unwritable log, missing sealed log), kit refuses the read: kit secrets writes no .env.local, kit run does not start the child, the broker does not call run(). The append failure also turns the exit code non-zero (src/audit-loss.ts). Owner decision point: this means a broken .kit-audit.jsonl now blocks kit secrets / kit run with governance off, where before it did not. The record is written before the fetch, so it can over-report (a read that then fails), never under-report.

Unchanged and still governance-only: permission/revocation/budget/approval checks, the agent stamp on governed events, the remote push. With governance on, kit secrets now writes both the governed secrets.generate and the new secrets.read.

kit audit secrets now includes secrets.read and prints via=/harness=.

Before / after

Scratch project, governance off (default), fixture values fixture-not-a-secret-0001 and 4821, kit secrets then kit run -- node -e "":

=== base (#1115 head)
.kit-audit.jsonl not created (0 events)
kit audit secrets --json: {"summary":{"totalEvents":0,"keyCount":0,...},"reports":[],"unattributed":[]}

=== this branch
secrets.read {"names":["DEMO_DB_PASSWORD","DEMO_PIN"],"store":"config","via":"kit secrets"}
secrets.read {"names":["DEMO_DB_PASSWORD","DEMO_PIN"],"store":".env.local","via":"kit run"}
kit audit secrets --json: totalEvents 4, keyCount 2
fixture values in .kit-audit.jsonl: 0

New tests (src/secrets-read-record.test.ts) run against the base:

not ok 1 - `kit secrets` records the key names, the store and the surface   (ENOENT .kit-audit.jsonl)
not ok 2 - the MCP kit_secrets tool records its surface                    (ENOENT)
not ok 3 - `kit run` records the .env.local names it hands the child        (ENOENT)
not ok 4 - `kit check` records the vault-backed names it probes            (ENOENT)
not ok 5 - refuses the read, and writes no .env.local, when the chain cannot take the record
# tests 5  # pass 0  # fail 5

On this branch: # tests 9 # pass 9 # fail 0 (adds harness attribution for Claude Code and Codex, per-store grouping, and the resolveViaBackend source scan). Existing tests that counted audit lines (run-policy-contract, broker) now account for the read event. kit secrets sync --dry-run still resolves every value, so it now leaves one secrets.read record (names only); command-validation.test.ts allows exactly that and checks the value is absent. Full Linux suite locally: 13344 pass, 2 fail (audit-external-process-interruption SIGTERM/SIGINT, which fail identically on the base in this container).

Harnesses

The record is written by kit itself, so it happens under any harness or a plain terminal. harness is named for Claude Code (CLAUDECODE=1) and Codex (CODEX_THREAD_ID), the two kit has measured. Cursor, Cline, Copilot, Gemini CLI and Augment (the other harnesses in AGENT_TARGETS) are recorded with via and the declared agent, but no harness name: kit has no measured env marker for them.

Coverage limit

Reads through kit only. A process that opens .env.local itself is not visible; that is PR 4's subject (inject at exec time).

Platforms

Tested on Linux. Paths use node:path (dirname/resolve; devNull from node:os for sync). No shell or POSIX-only call added. Windows runs in CI. macOS is unverified.

node scripts/prepush.mjs --allow "enforcement gate liveness": all steps pass locally except the known local-only kit review --enforce tool gaps and Semgrep (not installed). adr check: no new violations.


Generated by Claude Code

…e on or off

kit secrets with the default config wrote no audit event: the only record of a
read was the governed secrets.generate, and withGovernance returns before any
audit when governance is off. Reads now append a secrets.read event (key names,
store, kit surface, detected harness, declared agent; never a value) through the
same hash-chained append writes use, before the value is fetched. A read that
cannot be recorded is refused.

Covers kit secrets (sync, validate, onecli), MCP kit_secrets, kit run and
kit_run, the exec-broker, kit check's vault probes, kit fix and the
branch-protection audit. A source scan keeps every resolveViaBackend call behind
a recorded read.

Found by kit-research note kms-decrypt-evidence-vs-kit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sandstream-kit-reviewer sandstream-kit-reviewer 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.

kit review gate at 074c93c12c1a: not approved.

  • checks did not pass: windows shard 4/4, windows-native
  • touches protected paths (permissions, secrets), which the owner approves: src/audit-secrets.ts, src/check-secrets.test.ts, src/check-secrets.ts, src/commands/secrets.ts, src/exec-broker/broker.test.ts, src/exec-broker/broker.ts, src/secrets-read-record.test.ts, src/secrets-read-record.ts, src/secrets-sync.ts, src/secrets.ts

kit secrets sync --dry-run still resolves every value, so it now appends a
secrets.read record (names only). The preview test keeps asserting that no
value is written and nothing else changes, and that the record names the key
without its value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sandstream-kit-reviewer sandstream-kit-reviewer 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.

kit review gate at 4ef7091992d8: not approved.

  • touches protected paths (permissions, secrets), which the owner approves: src/audit-secrets.ts, src/check-secrets.test.ts, src/check-secrets.ts, src/commands/secrets.ts, src/exec-broker/broker.test.ts, src/exec-broker/broker.ts, src/secrets-read-record.test.ts, src/secrets-read-record.ts, src/secrets-sync.ts, src/secrets.ts

Base automatically changed from claude/web-kit-status-sync-p6fg9a-protected-audit-secrets-keys to main November 27, 2026 11:27
…-sync-p6fg9a-protected-secret-read-events

# Conflicts:
#	src/run.ts
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer 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.

kit review gate at ac2f1d592b71: not approved.

  • checks did not pass: build-and-test, checks (format, lint, build, gates), linux shard 4/4
  • touches protected paths (permissions, secrets), which the owner approves: src/audit-secrets.ts, src/check-secrets.test.ts, src/check-secrets.ts, src/commands/secrets.ts, src/exec-broker/broker.test.ts, src/exec-broker/broker.ts, src/secrets-read-record.test.ts, src/secrets-read-record.ts, src/secrets-sync.ts, src/secrets.ts

…cret-read-events

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/COMMANDS.md sits exactly at the 600-line file-size gate on main, so
the 11 lines this branch added there failed `kit standards --enforce`.
The paragraph describes what a read writes to the audit log, which is what
DATA_FLOW.md (linked from the top of COMMANDS.md) documents per operation.
COMMANDS.md keeps a single, folded sentence in the `kit run` section with
a link to it. No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer 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.

kit review gate at 867bced4761b: not approved.

  • touches protected paths (permissions, secrets), which the owner approves: src/audit-secrets.ts, src/check-secrets.test.ts, src/check-secrets.ts, src/commands/secrets.ts, src/exec-broker/broker.test.ts, src/exec-broker/broker.ts, src/secrets-read-record.test.ts, src/secrets-read-record.ts, src/secrets-sync.ts, src/secrets.ts

@sandstream
sandstream merged commit f4a0966 into main Nov 27, 2026
36 of 38 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a-protected-secret-read-events branch November 27, 2026 13:38
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.

2 participants