Repository navigation
feat(store,core): per-record ownership via an opaque extension principal (#331) - #734
Merged
Merged
Conversation
…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
…ip (#331) 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
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and change
Closes #331. Unblocks #529.
Core: request principal (RIM-EXT-PRINCIPAL-001)
providesPrincipal: truemay callExtensionRequest.setPrincipal({id}). Other extensions on the route read the frozenExtensionRequest.principal({id, provider}ornull).ExtensionActivation.principalMountslists an extension's mounts that are guarded by a principal-providing policy.authorize()on a route whose policies name it. It counts only ifauthorize()allows the request; a denial or throw discards it.middleware()/handle(), afterauthorize()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.test/extension-principal.test.tsuses a synthetic non-auth provider.Auth
apikey:<key id>and records a key creates belong to that key. Transfer when a key is revoked is filed as [Request]: transfer store records owned by an API key when the key is rotated or revoked #732.Store
extensions.store.config.collections.<name>.ownership: owner | shared. The defaultsharedis unchanged.On an owned collection:
_owner. It is stored only, never returned; a body naming_ownergets 400; PUT/PATCH keep the stored owner.If-Matchand body validation.Idempotency-Keyreuse is scoped per principal.401 principal_required.key(and therefore short links) on an owned collection;shared;_ownerin the data file.urlcode-store ownerless | ownerless-assign --owner <id> | ownerless-deletecommand runs with the server stopped, because it takes the directory lock.--examplewith auth: the todos collection is nowownership: owner, a decision by the owner. Without auth it stays shared and still needs--ack store:public-write.docs/STORE.mdcalls it multi-user-safe only for owned collections.Owner decisions (2026-09-25)
maxRecordsstays collection-wide, so one user can fill it.Package budgets
Verification
Run on Node v26.10.0:
npm run verifyon the ownership and budget commits, on the latestmain: exit 0. Root 845 tests; workspaces 34, 97, 233, 29, 53 and 66;test:addons4. All 0 failures, includingbuild-addon-manifest --checkandaudit:packages.--examplecommit:npm run check,build-addon-manifest --check,audit:packagesandtest:addons(4/4) pass.test/addons.test.tsplustest/extension-principal.test.ts: 24/24.npm run test:package: exit 0 on this branch (674649 packed, 2765868 unpacked bytes, 452 files).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.--exampletodos 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