Skip to content

feat(store,core): per-record ownership via an opaque extension principal (#331) - #734

Merged
jimhoyd merged 3 commits into
mainfrom
claude/sleepy-shannon-xvazgl
Sep 25, 2026
Merged

jimhoyd merged 3 commits into
mainfrom
claude/sleepy-shannon-xvazgl

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Problem and change

Closes #331. Unblocks #529.

Core: request principal (RIM-EXT-PRINCIPAL-001)

  • API: an extension declaring providesPrincipal: true may call ExtensionRequest.setPrincipal({id}). Other extensions on the route read the frozen ExtensionRequest.principal ({id, provider} or null). ExtensionActivation.principalMounts lists an extension's mounts that are guarded by a principal-providing policy.
  • When it may be set: only while core awaits that provider's own authorize() on a route whose policies name it. It counts only if authorize() allows the request; a denial or throw discards it.
  • What is refused: a set from a non-provider, from middleware()/handle(), after authorize() returns, a second set, or a set by a second provider. The id must match ^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$, so an email address is refused.
  • Never from the client: core never reads the principal from headers, cookies, query, body or YAML, and guest function code never receives it.
  • Second-provider fixture: test/extension-principal.test.ts uses a synthetic non-auth provider.

Auth

Store

extensions.store.config.collections.<name>.ownership: owner | shared. The default shared is unchanged.

On an owned collection:

  • Create stamps _owner. It is stored only, never returned; a body naming _owner gets 400; PUT/PATCH keep the stored owner.
  • List, read, HEAD, PUT, PATCH, DELETE and increment are scoped to the caller. Cross-user access returns the same 404 body as a missing id, checked before If-Match and body validation.
  • Pagination and idempotency: list totals and cursors count only the caller's records, and Idempotency-Key reuse is scoped per principal.
  • No principal gets 401 principal_required.
  • Activation refuses:
    • an owned collection on a mount without a principal-providing policy;
    • key (and therefore short links) on an owned collection;
    • switching a collection that holds owned records back to shared;
    • a malformed _owner in the data file.
  • Legacy records: records with no owner are served to nobody and never assigned automatically. The new urlcode-store ownerless | ownerless-assign --owner <id> | ownerless-delete command runs with the server stopped, because it takes the directory lock.
  • --example with auth: the todos collection is now ownership: owner, a decision by the owner. Without auth it stays shared and still needs --ack store:public-write.
  • CRUD screen: it already calls the store API with the user's session, so it is per-user on owned collections. docs/STORE.md calls it multi-user-safe only for owned collections.

Owner decisions (2026-09-25)

Package budgets

  • Core unpacked: 2700 → 2720 KiB.
  • Core packed: 660 → 680 KiB, because the archive is about 659 KiB, within gzip variance of the old limit.
  • Store unpacked: 120 → 140 KiB.
  • Rationale is recorded next to each budget.

Verification

Run on Node v26.10.0:

  • npm run verify on the ownership and budget commits, on the latest main: exit 0. Root 845 tests; workspaces 34, 97, 233, 29, 53 and 66; test:addons 4. All 0 failures, including build-addon-manifest --check and audit:packages.
  • After the --example commit:
    • npm run check, build-addon-manifest --check, audit:packages and test:addons (4/4) pass.
    • Store suite: 53/53.
    • test/addons.test.ts plus test/extension-principal.test.ts: 24/24.
  • npm run test:package: exit 0 on this branch (674649 packed, 2765868 unpacked bytes, 452 files).
  • New tests:
    • test/extension-principal.test.ts (10): the principal contract, spoofing attempts and refusals.
    • packages/auth/test/principal.test.ts: which principals auth sets.
    • packages/store/test/ownership.test.ts (10): cross-user denial for every method, including across a restart; owner stamping and immutability; missing principal; activation refusals; legacy records and the CLI with its lock; downgrade refusal; per-principal idempotency; shared collections unchanged.
    • Scaffold and integration assertions that the --example todos are owned when auth is installed.

Compatibility and security

  • Additive. Existing collections stay shared, and the store refuses to start rather than guess on any ownership inconsistency.

  • Extension contract: it gains an optional providesPrincipal / setPrincipal / principal. The contract guards against mistakes, not hostile in-process code (extensions are trusted).

  • Not an independent security review.

  • Changes match the documented portable contract; docs/examples are updated where needed.

  • Relevant tests and package checks pass, or limitations are explained above.

  • No credentials, customer data or private project material are included.

  • Runtime/starter changes remain aligned where applicable.

🤖 Generated with Claude Code

https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP


Generated by Claude Code

…pal (#331)

Core carries one opaque, bounded, frozen principal per request
(RIM-EXT-PRINCIPAL-001). Only a registration declaring providesPrincipal
may set it, only via request.setPrincipal({id}) while core awaits that
extension's own authorize() on a route naming it, and it is committed only
when that authorize() allows the request. A second setter, a non-providing
extension, middleware()/handle(), a late or repeated call, or an id outside
^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$ is refused. It is never read from a
header, cookie, query, body or YAML. Activation receives principalMounts.

Auth declares providesPrincipal and sets the user id for a session (after
the CSRF check on writes) or apikey:<key id> for a bearer key.

Store collections may declare ownership: owner (default shared, unchanged):
create stamps the owner (_owner, never returned, not client-settable);
list/read/update/delete/increment are scoped to the principal, with another
principal's record answering the missing-record 404; no principal is 401;
activation refuses an owned collection whose mount has no principal-providing
policy, key on an owned collection, and owned records in a shared one.
Legacy ownerless records are served to nobody until the operator runs
urlcode-store ownerless / ownerless-assign / ownerless-delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
…r owned (#331)

When auth is installed (in the same command or already), the store
example's todos collection declares ownership: owner beside auth: true on
its mount, so each signed-in user sees and changes only their own todos
through the API and the /todos screen. Without auth the example stays
shared and still needs --ack store:public-write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
@jimhoyd
jimhoyd merged commit 5c757aa into main Sep 25, 2026
23 checks passed
@jimhoyd
jimhoyd deleted the claude/sleepy-shannon-xvazgl branch September 25, 2026 05:11
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.

[Request]: Per-record ownership for the store extension and CRUD screen

2 participants