Skip to content

store: rekey authors to the signed principal at sign-in (no issuer required) - #13

Merged
reoring merged 1 commit into
mainfrom
feat/rekey-authors-on-sign-in
Nov 23, 2026
Merged

reoring merged 1 commit into
mainfrom
feat/rekey-authors-on-sign-in

Conversation

@reoring

@reoring reoring commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rekey legacy authors on authenticated requests using the SDK's signed
    Identity.Access.Principal together with its verified Identity.Principal.Subject.
    Do not derive caller principals from an unproven historical issuer.
  • Resolve by principal first. Only a legacy row with principal IS NULL can be
    selected by subject and rekeyed, under a row lock in one write transaction.
    Retain author ULIDs, articles, likes, follows, and Directory links.
  • Already-keyed authors use one identity SELECT and no identity write. Mutations
    still refresh changed OIDC profile fields; Directory names stay authoritative.
    Ownership and social actions keep using the resolved author ULID, and platform
    role checks are unchanged.
  • Fail closed on conflicting retained subjects or a principal uniqueness
    violation: HTTP 409, author_principal_conflict,
    The signed principal is already linked to another author.
  • Make MEMO_LEGACY_OIDC_ISSUER optional. Unset/empty skips startup backfill and
    leaves legacy principals NULL; the existing explicit-issuer backfill remains
    available only when the historical issuer can be proven.
  • Extend store and real-SDK API integration coverage and update README operator
    instructions. No module version change or new migration is needed.

Deployment

  1. Confirm the destination Platform API includes appthrust/platform#7087 (the
    signed-principal prerequisite remains). Record the old Memo image and take a
    PostgreSQL backup; retain both through the rollback window.
  2. Stop every old Memo writer, then roll out the new version. No migration
    environment variable is required. Mixed-version rollout is still disallowed:

    old binaries continue writing subject-keyed rows.
  3. Verify a known author's sign-in and draft read/edit, stable author ULID,
    Directory link, existing likes/follows, and owner/admin restrictions. Authors
    who do not sign in remain inert with NULL principals; their published content
    and relationships are preserved, and they do not block startup.

Optional: if an operator can prove the exact issuer of every historical
subject, set MEMO_LEGACY_OIDC_ISSUER for the existing transactional startup
backfill and remove it after verification. The old schema never recorded issuer;
do not guess from the current URL or email. Unknown/mixed histories should use
lazy rekeying without this setting.

Rollback (unchanged)

  • Before reopening writes: stop the new binary; confirm every author has its
    historical subject. In one transaction drop authors.principal, restore
    authors.subject NOT NULL, and remove only 002_author_principal.sql from
    memo_schema_migrations. Restart the recorded old image. IDs and relationships
    remain intact.
  • After new authors exist: do not switch binaries blindly or overwrite new
    writes with a backup
    . New rows contain only a principal; SHA-256 is not
    reversible. Obtain a verified issuer/subject crosswalk, match it using the
    exact platform hash, stop writers, populate only missing legacy subjects, and
    verify complete/unique subjects before the same rollback. If a mapping is
    unknown or two issuers share a subject, retain all data and use a forward fix.
    Do not invent subjects or discard rows.
  • No Platform API rollback is required; the old SDK tolerates the signed facts.
    This app binary still requires a #7087-capable platform.

Full operator instructions: README, “Signed author keys: upgrade and rollback”.

Verification

Using ~/.codex/skills/serialize-vm-tests/scripts/serialize-vm-tests -- with
SERIALIZE_VM_TESTS_TARGET=local:

  • go build ./... — PASS (exit 0), via the wrapper's --class short admission.
  • go vet ./cmd/server/... — PASS (exit 0).
  • go test ./cmd/server/... -count=1 — PASS (exit 0), including real PostgreSQL
    store tests and the SDK OIDC/exchange/signature API path.
  • The initial run of the same command was RED: the changed empty-issuer test
    failed with the previous mandatory MEMO_LEGACY_OIDC_ISSUER startup error.
  • The first build attempt exited 124 while queued behind another VM-test holder;
    neither build nor vet executed in that attempt. The successful build used the
    documented short-job class for this small Go module, without bypassing the
    wrapper's pressure admission or locks.

BUILTIN_APPSERVER_TEST_DATABASE_URL pointed only to the task-local PostgreSQL
server through .tmp/rekey-pg-socket (port 55439); the integration tests did not
skip for lack of a database. Per-test schemas were isolated and cleaned. The
server was stopped and its task-owned data, socket directory, and logs removed.

Coverage includes stable ULIDs and relationships, no repeat author write
(xmin unchanged), principal-first lookup, rejection of subject fallback for
rekeyed authors, sequential/concurrent conflicting claims, the real principal
unique constraint, concurrent same-subject sign-in, optional issuer startup,
explicit backfill, and unchanged owner/admin/social restrictions.

No commit, push, tag, publication, or live cluster access was performed.

The startup backfill needs the historical issuer of every legacy subject, which
ink cannot prove (the old schema never stored it). A wrong issuer would compute
wrong principals and silently detach every user from their author.

Sign-in delivers the signed principal next to the verified bearer subject, so
RekeyAuthorOnSignIn binds the legacy row to that principal in one write
transaction; already-keyed authors cost one SELECT. A principal already linked
to a different subject is a 409 author_principal_conflict. MEMO_LEGACY_OIDC_ISSUER
is now optional: unset skips the backfill; set keeps it for operators who can
prove the issuer. Un-rekeyed rows are inert.
@reoring
reoring merged commit 85074c6 into main Nov 23, 2026
3 checks passed
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.

1 participant