Skip to content

feat(auth): AgentCredential substrate — ADR-026 Phase 0 - #1312

Merged
lilyshen0722 merged 4 commits into
mainfrom
feat/agent-credential-substrate
Aug 28, 2026
Merged

lilyshen0722 merged 4 commits into
mainfrom
feat/agent-credential-substrate

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

The token substrate the #1310 review made a hard prerequisite, additive by design:

  • AgentCredential collection: per-token records — kind (runtime|daemon), owner, agent identity, machineId, parentId lineage, scopes, status
  • Auth: consults the collection FIRST — active status, expiry, and parent-revocation rejection (a runtime token minted by a revoked daemon credential is dead even though the bearer string is intact) — then falls back to legacy embedded tokens unchanged
  • revokeCascade: breadth-first descendant walk, so revoking a daemon credential kills everything it minted
  • Dual-write at mint (provision path wired; other call sites keep legacy-only until touched)
  • GET/DELETE /api/credentials: list own, revoke with cascade (owner or admin)

4 invariant tests on mongodb-memory-server: legacy fallback, revoked-credential rejection, lineage rejection, cascade completeness.

Phase 1 (machine rows, CAS adoption, daemon mint) builds on this. @vera's D4 threat model is the reference: this PR is the 'nothing to build on' blocker cleared.

🤖 Generated with Claude Code

https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

Per-token records with issuer lineage and cascade revocation, additive:
auth consults the collection first (status + expiry + parent-revocation
rejection) and falls back to embedded User.agentRuntimeTokens, so every
existing token keeps working. New mints dual-write when the caller
identity is known. GET/DELETE /api/credentials for listing + cascade
revoke (owner or admin).

Fixes the #1310 review findings: revocation is no longer a false
promise, and a removed machine's minted children die with its daemon
credential.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK
Comment thread backend/routes/credentials.ts Fixed
Comment thread backend/routes/credentials.ts Fixed
Comment thread backend/routes/credentials.ts Fixed
Comment thread backend/routes/credentials.ts Fixed
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

CodeQL status, for the record: the two alerts in backend/routes/credentials.ts are fixed (rate limiters added at the new head). The remaining open alerts are pre-existing unlimited routes in agentsRuntime.ts/agentEnsemble.ts that the agentRuntimeAuth middleware edit pulled into changed-code scope — they are the fleet's CAP polling endpoints, and rate-limiting them safely needs poller-cadence-sized caps, tracked in the issue just filed. CodeQL is advisory here (only Test & Coverage is required); merge waits on Test & Coverage green + @vera's security sign-off, not on the pre-existing alerts.

lilyshen0722 and others added 2 commits August 27, 2026 18:06
The new credential lookup hung on the unmocked model (10s timeouts).
Legacy tests exercise the fallback; credential paths have their own
memory-server suite.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK
(b) WS bypass: validateAgentToken now gates on the credential ledger
with the same semantics as the HTTP middleware — revoked credentials
and children of revoked issuers cannot connect over WS.
(c) mint ordering: credential row is written BEFORE the embedded record;
a ledger failure fails the mint — no token exists without a row when an
issuer is known.
Early-return gap: reusing an existing pre-substrate token backfills a
credential row (no lineage claimed), so the existing fleet becomes
listable and cascade-revocable instead of the collection staying empty.

Two WS-suite tests pin the gate. (WS suite is CI-verified — it fails
locally even unmodified, environment artifact.)

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

@vera all three findings closed at the new head:

  • (b) WS bypass: validateAgentToken now consults the ledger first — revoked credential → null, child of revoked issuer → null, same semantics as the HTTP middleware. Two tests pin it in the WS suite.
  • (c) mint ordering inverted: credential row is created BEFORE the embedded record and a ledger failure fails the whole mint — the working-token-with-no-row state is unreachable when an issuer is known.
  • Early-return backfill: reusing an existing pre-substrate token upserts a credential row (kind runtime, owner, agent — no lineage claimed for unknown provenance), so the fleet's existing tokens become listable and revocable instead of the collection staying decoratively empty.

Re-verify when you can — merge still waits on you.

@lilyshen0722
lilyshen0722 merged commit 1e4d1ca into main Aug 28, 2026
10 of 11 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/agent-credential-substrate branch August 28, 2026 01:19
samxu01 pushed a commit that referenced this pull request Aug 29, 2026
…claim

Two corrections from sprint-review's gate, both verified here rather than
accepted:

- /pulls/:n/comments (inline review comments) is a third collection and does
  carry commit_id. The rule stands — every inline comment's
  pull_request_review_id resolves to an event /pulls/:n/reviews returns
  (#1312, #1302, #1260) — but the entry's surface count was wrong, in an
  entry about getting a surface count wrong. Also: they are not rare here;
  a repo-wide sweep finds them on #1312/#1302/#1297/#1274/#1260/#1176/#1094/#1022.
  The 0-across-five-PRs sample was all docs rows.

- The entry claimed the comments collection is "what gh pr view N prints
  without flags". False. Bare gh pr view prints neither. --comments prints
  BOTH interleaved, split only by a status: line and with no sha on either;
  --json comments returns half. On #1338: 2 vs 1.

Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Aug 30, 2026
… a commit (#1338)

* docs(ax): entry 51 — a PR's two comment surfaces, and the one without a commit_id

`gh pr view --json comments` and `/pulls/:n/reviews` are disjoint sets, not a
set and a subset: `gh pr review --comment` files a review event that never
appears in the comments collection. The comments surface is the default
projection and the obvious one to reach for, so an agent asking "has anyone
gated the tree that would press?" reads it, sees nothing, and concludes nobody
has — which is what produced a false published warning against pressing a
ready PR.

The sharper half is that an issue comment carries no `commit_id` at all, so
that surface cannot answer the question even when it does show a gate.
Measured across eight open PRs: one with a live gate a comments read omits,
one with a gate at a dead sha, and one correctly gated with zero review
events, where the only thing binding the approval to a tree is that the
reviewer typed the sha into the prose.

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

* docs(ax): entry 51 — third collection, and correct the gh-projection claim

Two corrections from sprint-review's gate, both verified here rather than
accepted:

- /pulls/:n/comments (inline review comments) is a third collection and does
  carry commit_id. The rule stands — every inline comment's
  pull_request_review_id resolves to an event /pulls/:n/reviews returns
  (#1312, #1302, #1260) — but the entry's surface count was wrong, in an
  entry about getting a surface count wrong. Also: they are not rare here;
  a repo-wide sweep finds them on #1312/#1302/#1297/#1274/#1260/#1176/#1094/#1022.
  The 0-across-five-PRs sample was all docs rows.

- The entry claimed the comments collection is "what gh pr view N prints
  without flags". False. Bare gh pr view prints neither. --comments prints
  BOTH interleaved, split only by a status: line and with no sha on either;
  --json comments returns half. On #1338: 2 vs 1.

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

* docs(ax): entry 51 — the gate check built from it is prefix-width-sensitive

The #1330 case forces a prose-sha query; that query has a free width
parameter. This repo writes 8-char shas, so a 9-char prefix returns zero
across all 12 open PRs measured — indistinguishable from an arm that never
ran. At 8 it finds a gate at head on 9 of 12. Prescribe 7 (git's minimum
abbreviation) plus a positive control for any arm that returns an
all-population zero.

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

* docs(ax): entry 51 — delete the prefix width, don't retune it

sprint-review's review of 4ce6e8a is right twice. "This repo writes 8"
is a majority habit, not a rule — #1322 and a #1325 comment write 9
(re-derived, not borrowed). And "cut to 7 so it catches any convention
shorter than 8" is self-refuting: grep 'a1607e8' does not match a1607e,
so 7 relocates the threshold and tells the next reader the check is safe.

Replace the width with a width-free comparison: extract hex tokens from
the body and test whether the head STARTS WITH the token. Verified on the
same population (a1607e8 on #1330, 35e4a1a on #1327). The residual
minimum-token-length knob fails by over-reporting, which is visible,
rather than to zero, which reads as an answer. Promote the positive
control above the width advice — it is what catches the class.

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

---------

Co-authored-by: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Sep 1, 2026
…s select is benign, and main is red without saying so (#1431)

The contract test (#1210, CI from Aug 25) and the credential substrate
(#1312, merged Aug 28) were each green alone and broke only on main:
selectCallCount went 1 -> 2 via AgentCredential.findById().select('status'),
a CREDENTIAL projection that leaves req.agentUser's fullness untouched.
Exactly the two-green-PRs-broken-contract shape AX entry 53 names, landed
by the same press that had just merged entry 53. Count re-certified to 2
with BOTH projections enumerated, so the next .select( still trips
consciously. Verified against the live middleware: 2 selects, both
matches, neither User.findOne projected.


Claude-Session: https://claude.ai/code/session_01TdEJoXUmbHmW5TFk7hfkbK

Co-authored-by: Claude Fable 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.

2 participants