Skip to content

v0.19.10

@edgrosvenor edgrosvenor tagged this 12 Oct 14:17
* feat: rotate accepts an exact locked purpose/subject predicate

A consumer that pre-selects a credential by purpose and subject holds that
answer only until its own query returns. Rotation takes an id, so the row's
purpose, subject, kind or ownership could change in between and an id-only
rotation had no way to notice. Consumers were left pre-selecting and hoping.

RotateOptions now carries an optional ExactCredentialTarget: the purpose and
subject the caller believes the row has, plus optionally kind and ownership.
Every rotation path that locks the source row re-proves the predicate against
the LOCKED row before consuming a submission nonce or minting anything, so a
retarget cannot land between the caller's selection and the write, and a
refusal leaves no trace.

Additive and backward compatible. Callers that pass no target behave exactly
as before, nothing about the replacement changes either way, and the two-phase
semantics (committed phase one, separately fallible phase two) are untouched.
It is a PHP-level option rather than a transport field: a predicate an HTTP or
CLI client supplies about itself buys no safety, and the row boundary those
transports need is CredentialManagementScope.

Closes the "BfC rotate locked-boundary predicate remains package debt" finding
from Wake PR5 security review round 2.

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

* test: state what the refused-nonce test actually proves

Mutation 2 (moving the predicate check after the submission consume) left
this test green: the consume is a conditional DELETE inside phase one, so
the rollback restores the nonce whatever the check order. The claim is the
outcome, and the note now says so rather than claiming an ordering the test
cannot see.

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

* docs: do not credit the check order for what the rollback delivers

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

* fix: phase two locks and re-proves the exact target before it retires

Security review finding 1 (BLOCKER). The exact target was proved against the
source under phase one's lock, but phase one commits and releases that lock
before the cutover retirement runs, and the retirement updated expires_at by
id alone. A retarget queued behind phase one's lock commits in that window,
and phase two then shortens the expiry of a row that now belongs to another
subject. The reviewer reproduced it on Postgres: outcome rotated,
old_subject_ref app-b, old_expires_in_seconds 3599.686443.

The retirement is a mutation of the source row, so it owes the predicate the
same locked proof phase one gave it. When a target is pinned, phase two now
takes its own transaction, locks the source, re-proves the target against the
LOCKED row, and writes the expiry before committing. A mismatch retires
nothing and raises RotationCutoverIncomplete::targetMovedBeforeRetirement,
which says phase one stands and the superseded row is still live: a bare
RotationRefused would let a caller conclude nothing happened.

The two-phase contract is unchanged. Phase two is still a separate,
separately fallible transaction, and no caller has to wrap rotation in an
outer transaction. A caller that pins nothing keeps exactly the retirement it
had: the guarded expiry-set by id, no phase-two lock, no new failure mode.

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

* fix: assert the exact target inside the signing-root lifecycle lock

Security review finding 2 (BLOCKER). The signing-root branch asserted the
caller's target against the unlocked pre-read and then entered
SigningRootLifecycle::rotate(), which proves the CANONICAL root identity
under its installation lock but never the identity the caller pinned. The
deleted comment claimed those were equivalent. They are not: a reserved row
carrying a noncanonical subject can become canonical between the two checks,
and the lifecycle then accepts it. The reviewer reproduced it on Postgres:
outcome rotated, two signing-root rows, old_rotated true.

The target now travels into the lifecycle and is asserted against the source
read under the installation lock, before any replacement is created and
before any audit write.

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

* test: pgsql regressions for both security-review interleaves

Finding 1: the retarget has to land between phase one's commit and phase
two's write, which means starting it while phase one holds the source lock.
The hook is the package's own verb matrix — authorizeVerb() is consulted
inside mintReplacement after lockForUpdate() returns — and from there the
test starts a retargeting process and waits until Postgres reports it
blocked on a lock over credentials. Lock grants are FIFO, so the retarget is
served before phase two's own request with no sleeps.

Finding 2: the test holds the installation authority row the signing-root
lifecycle locks, lets the rotating worker queue behind it, retargets the
reserved row from a noncanonical subject to the canonical one, and commits.
The worker then reads the source under the lifecycle's lock.

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

* docs: README covers the phase-two and signing-root locked rechecks

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

* fix: authorize the locked row on the signing-root path, and ask authority first

Security review round 2 (BLOCKER). The rework moved the exact target into
the lifecycle lock but left the verb-matrix decision in front of it, so
verbAllowed() was consulted with the subject of the UNLOCKED pre-read. A
reserved row is reserved by its purpose, so it can carry a noncanonical
subject and become canonical before the installation lock is granted: the
declaration is asked about app-a, allows it, and the lifecycle then rotates
the canonical subject the declaration denies. That contradicts the
AuthorizesCredentialVerbs contract, whose subject is the target row's own.
The reviewer reproduced it on Postgres: outcome rotated, root count 2, old
root rotated_at present, locked subject bfc:signing-root.

SigningRootLifecycle now consults the matrix itself, with the subject of the
source it selected under the installation lock, before any replacement or
audit write. RotateCredential decides neither the authority answer nor the
target on the reserved path; both travel into the lifecycle.

The mint and reissue paths already authorized the locked row — mintReplacement
and reissuePendingDelivery both pass ->subject() from a lockForUpdate()
read inside their own transaction — so this is the one path that did not, and
the class is now uniform: the subject the matrix authorizes is the subject of
the row that gets mutated.

Also, per the judge advisory, the exact target is asserted BEHIND the matrix
decision on every locked path. A caller who may not rotate this subject
learns nothing about the row from a predicate answer. One consequence is
stated rather than hidden: a row whose purpose has been cleared is now
refused by the stored-purpose guard before the predicate is consulted. It
still refuses and still writes nothing.

And the round-2 wording advisory: "Nothing partial was written" becomes
"Nothing was written in phase two", which is what is true.

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

* test: regression for the stale signing-root authorization, and the new ordering

The round-2 interleave: an ordinary subject-aware declaration allows rotation
for app-a and denies it for the canonical signing-root subject. The reserved
row sits at app-a when the pre-read happens and is canonical by the time the
installation lock is granted, so whichever subject the matrix is asked about
decides the outcome, and the outcome reveals which row the package asked
about.

Two sqlite tests follow the reordering: one pins that a cleared stored
purpose is now refused by the stored-purpose guard ahead of the predicate,
and one pins that the authority question is answered before the predicate
question.

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

* docs: README states that authority is answered before the predicate

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

---------

Co-authored-by: Ed Grosvenor <ed@artisan.build>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Assets 2
Loading