You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3487ccc
Browse filesBrowse the repository at this point in the historyBrowse files
feat(core, plugin-security)!: permission sets resolve by (package, name), and a package position's sets resolve from its package (ADR-0150 E3) (#31815)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99Aqw5TrjgthJiwHzU17N9R)_Fixes#31674
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: follow-up #31819
Narrowing: (1) a package position's bare reference to a permission set
whose only holder is an environment-authored item, or whose only body is
the metadata service's, D3 (a) (not measurable first-party: no
first-party package tree holds an environment item; the dogfood boot
refused 0); (2) a package position's bare reference to a permission set
whose only holder is a package outside the position package's declared
closure, per the epic seat's reading 6728487836 (first-party: 0).
Sibling in the same release artifact: 0. Measured statically over every
first-party position declaration: the showcase's positions name only
showcase sets, app-crm's positions name only its own set, and the
built-in positions name only the security plugin's own sets (the
audience anchors are the environment's reference, below). HotCRM is
outside this session's repository access: NOT MEASURED.
## 维护者速读
- 改了什么:安全目录里的权限集改按(软件包, 名称)解析,走 core 里同一条包寻址规则和 metadata-core
里同一个依赖闭包。职位引用权限集时,从声明这个职位的软件包去解析:本包的、它声明依赖的包的、或 `sys`
的;够不着就拒绝并列出每个候选。职位本身不变(仍是环境级一个名字一个持有者)。
- 为什么改:专题 #31527 的子卡 E3(ADR-0150
D3/D4/D7)。以前按名字取第一个注册的权限集,一个包的职位可能拿到别的包或环境里同名的权限集,取哪个看注册顺序,也没有任何提示。
-
风险与回滚:只有「包里的职位引用了本包够不着的权限集」的部署会看到变化:那个职位不再通过这个名字授权,启动时的目录引用报告逐个列出职位和每个候选。存储的授权、环境自建的职位、管理员对包职位的覆盖、everyone/guest
锚点仍按整个环境解析,行为不变。第一方实测 0 个。回滚即 revert 本 PR。
- 先看:`packages/core/src/security/security-catalog.ts` 的
`referenceCaller` 与
`resolvePermissionScoped`(谁算调用方、拒绝时不回退);`packages/core/src/security/resolve-authz-context.ts`
的
`catalogSetBody`(授权路径把职位传进去);`packages/plugins/plugin-security/src/catalog-reference-report.ts`(拒绝写进报告)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run
src/security-catalog-permission-sets-by-package.test.ts`,预期 14 个用例全绿。
- 需要你做的:无,席位落地。
## What changes
Permission sets are behavioural metadata (ADR-0150 D1 bucket 2), so the
security catalog now reads them by `(package, name)`. Positions and
capabilities are unchanged.
- **`@objectstack/core` `security/security-catalog.ts`.** A registry
that carries the package-scoped reads (`packageScopedHoldersOf`,
`getPackageScopedItem`, `getEnvironmentScopedItem`, `getArtifactItem`)
is read by `(package, name)` for permission sets. ObjectQL's
`SchemaRegistry` carries all of them. The catalog calls the one rule,
`resolvePackageScopedHolders` (R/R2), over the registry's holders, with
the one closure walk, `packageResolutionClosure`
(`@objectstack/metadata-core`). That is the same holder set objectql's
`resolvePackageScopedName` hands the rule. ⛔ No second rule, no second
closure, no first-registered fallback, no injected resolver.
- **Who asks.** A position's `permissionSets` resolve as a caller in the
package that shipped the position (`resolve(type, name, { position })`).
Four kinds of reference are the environment's, resolved as a caller with
no package: a stored grant (it carries only the name until ADR-0150 D8),
an environment-authored position, an administrator's overlay or
`.custom` override of a package's position (told apart from the shipped
item by `getArtifactItem`), and the audience anchors `everyone` and
`guest`.
- **A refusal confers nothing.** `resolve` answers `undefined`. The new
`resolveReference` returns the refusal with every candidate, in the
rule's words.
- **The registry's answer is final.** A holder the rule resolved that
may not be served (a disabled package's set) is not-found, never a
second by-name read. The metadata service is read only for a name the
registry holds nowhere. It reads by name only, so its body is the
environment's: a caller with no package is served it, and for a
package's reference it is the D3 (a) refusal (`outside-closure`, naming
the environment, in the rule's message), so the boot report and the
delegated-admin boundary still name it.
- **The list** has one entry per `(package, name)` holder plus the
environment's own item.
- A registry carrying only some of the package-scoped reads is refused
at construction. A by-name stand-in (a test double without the holder
reads) is read by name, as before.
- **`@objectstack/core` `security/resolve-authz-context.ts`.** Every
position-bound set read passes its position: the position grants in
force, the guest anchor, and §6a/6b. A set one position cannot resolve
is still granted through another position that can.
- **`@objectstack/plugin-security`.**
- `delegated-admin-gate.ts`: the organization boundary and the
delegate's scope resolve a position's sets from that position. A refusal
is the boundary failure, and its reason carries the refusal.
- `catalog-reference-report.ts`: a position's unresolved sets now carry
`refusals` (each set with its reason and every candidate), in the log
line and its meta.
- `access-upgrade-check.ts`: the projected catalog passes the reference
scope through.
- **Package edge.** `@objectstack/core` moves
`@objectstack/metadata-core` from devDependencies to dependencies (seat
amendment). No cycle: metadata-core depends on spec and zod, and spec
depends on no workspace package. `check:lean-entry-closure` holds its
admitted set (15 packages), and `core-boundary.ratchet` is green.
- **`scripts/platform-object-tenancy-census.mjs`** (outside the card's
file surface, forced by the edge above). The census evaluates each
source as CommonJS. Through core's barrel, it now reaches
metadata-core's `createRequire(import.meta.url)`, which has no CommonJS
spelling. The loader hands such a module its own file URL. It is the
only loader of its kind in `scripts/`.
## Tests
- `packages/core/src/security/security-catalog.test.ts` (+12, two of
them extended in review round 1). These pin the catalog's plumbing
around the rule, over a stand-in registry with the package-scoped reads:
- a refusal confers nothing and names every candidate, with no fallback;
- two holders in the closure, and two environment-wide, are refused,
naming both;
- who asks: package positions, the environment's positions, anchors,
stack positions;
- a name the registry holds nowhere: the metadata service's body serves
a caller with no package, and is the D3 (a) refusal naming the
environment for a package's reference;
- a resolved holder that may not be served (a disabled package's set,
with a metadata-service body of that name) is final: not-found for every
caller;
- the list is keyed per holder;
- positions and capabilities are read by name;
- partial registries are refused, and by-name stand-ins stay by-name;
- a throwing read is `AuthzStoreUnavailable`.
-
`packages/plugins/plugin-security/src/security-catalog-permission-sets-by-package.test.ts`
(new, 14), over the real `SchemaRegistry` and core's grant path:
- the own set, a `sys` set and a dependency's set resolve;
- an environment-only set is refused (D3 (a)), and so is an
outside-closure package set, each naming its holder and each granting
nothing; the by-name read is asserted to have served both on base;
- a set refused for one position is still granted through another
position;
- stored grants, environment positions and administrator overlays
resolve environment-wide;
- the `everyone` anchor binds an accepted package `isDefault` set, and a
second package holding that name is refused at registration, naming
both, while the anchor keeps the first;
- the list is keyed per holder;
- every package-less read and the list equal the by-name read under
phase 1;
- a same-name position from a second package is still refused (D7).
- `delegated-admin-gate-catalog.test.ts` (+1): the scoped organization
boundary refuses an out-of-closure set, naming its holder.
- `catalog-reference-report.test.ts` (+1): the report lists an
out-of-closure set with the refusal naming every candidate.
**Forced test changes** (rigs that served sets a booted kernel's
registry holds, and so read as the narrowing):
- `catalog-reference-report.test.ts` and
`delegable-scope-no-identity-positions.posture.test.ts`: the stubbed
manifest service now registers the plugin's own permission sets into the
engine registry under the plugin, as a booted kernel does. Before, they
were served only from a stand-in metadata service, which in a booted
kernel does not carry them (the catalog doc's measurement table).
Without this, the built-in `org_external` position could not reach
`external_default`.
- `catalog-reference-report.test.ts`, the "listed per position" block:
the binding position's package now declares the set package, and the set
package also ships the auditor set. The outside-closure case uses a
second package that declares nothing.
## Acceptance notes
- **The epic's red lines.** (1) Never loosens: no first-registered
fallback, no second lookup once the registry has answered, no
environment-wide guess. Each pin was ablated (below). (2) Every refusal
names every candidate, in the rule's words, in `resolveReference`, the
boundary failure and the boot report. (3) Independently releasable:
ADR-0150's readings, below.
- **ADR-0150 readings.**
- (a) The phase-1 one-holder tests stay green.
`registry-security-catalog-namespace` is untouched, and the D7 pin here
shows a second same-name position is still refused.
- (b) Bare-name behaviour is unchanged for every name with one holder
and a package-less or in-closure caller. The parity pin over the real
registry checks every package-less read and the list against the by-name
read. The only change is the declared narrowing.
- (c) No migration.
- (d) `Clause-②: no (narrowing)`. The protocol is unchanged, and the
changeset carries `adr-0087: not-required (no-migration-prescription)`.
- **The audience anchors (the epic seat's reading).** `everyone` and
`guest` are registered by the security plugin, but `declareEveryone`
composes their sets from the deployment's baseline plus every package
`isDefault` set an administrator accepted (`readAcceptedEveryoneSets`,
ADR-0090 D5/D9). That is the environment's binding (ADR-0150 D7), so the
anchors resolve as a caller with no package. Read from the security
plugin's package, the rule would refuse an accepted app default, such as
the showcase's `showcase_member_default`, as outside the closure. Child
A records this reading in ADR-0150.
- **A set only the metadata service holds**, read by a package's
position, is the D3 (a) refusal naming the environment (ruled in review
round 1). In a booted kernel the engine registry holds every permission
set, so this refuses nothing there (the catalog's measurement table, and
the dogfood below); it is counted in the D3 (a) arm of the Narrowing
line.
- **Out of scope.**
`packages/cli/src/commands/migrate/organization-ownership.ts` builds a
catalog over a stand-in registry and stays by name: #31817.
- **New public names** (the seat's call):
`SecurityCatalogReader.resolveReference`, `resolveCatalogReference`,
`SecurityCatalogReferenceScope`, `SecurityCatalogResolution`,
`SecurityCatalogPackageScopedRegistry`, and
`PositionNamingUnresolvedSets.refusals`.
<details><summary>Ablation readings (each through
scripts/ablation-replace.mjs, core rebuilt and checked by
ablation-dist-preflight; restored, blob == HEAD, git diff HEAD
empty)</summary>
1. A refusal falls back to the registry's first-registered read: core 1
failed / 25; plugin-security 5 failed / 39 (D3 (a), outside-closure, a
second position still grants, the boundary refusal, the report's
refusal).
2. A position's reference asks as no package: core 5 failed / 26;
plugin-security 5 failed / 39.
3. The audience anchors ask as the security plugin's package: core 1
failed / 26; plugin-security 2 failed / 39 (both anchor pins).
4. The list picks one entry per name: core 1 failed / 26.
Plugin-security stays green, as designed: under phase 1 every name has
one holder, so the real registry cannot tell the two lists apart.
5. The grant path drops the position: plugin-security 3 failed / 39 (D3
(a), outside-closure, a second position still grants). Core's catalog
suite stays green (the mutation is outside the catalog).
6. The census loader without the `import.meta.url` hand-off:
`check:platform-object-tenancy-census` exits 1 (SyntaxError: Cannot use
'import.meta' outside a module).
7. (Round 1, item 1) A resolved holder that may not be served falls
through to the metadata service: core 1 failed / 26 (the
disabled-package pin).
8. (Round 1, item 2) A package's reference to a metadata-only set
answers not-found: core 1 failed / 26 (the D3 (a) refusal pin).
After restoring, `ablation-dist-preflight @objectstack/core E3_ABLATION
--absent`: the marker is absent from all 14 built files, and the tree is
clean against HEAD.
</details>
## Review round 1 (epic seat 6732998040), answered
- Item 1: once the registry has answered, its answer is final. A
resolved holder that may not be served is not-found, and the metadata
service is read only for a name the registry holds nowhere. Pinned, red
without the fix (ablation 7).
- Item 2: a set only the metadata service holds, read by a package's
position, is the D3 (a) refusal naming the environment, never not-found
and never served. Pinned, red without the fix (ablation 8).
- Q2: the CLI catalog is #31817. Skills-docs: #31819.
## Verification
All readings are on head `f2f8b4ff`, which carries both round-1 fixes.
<details><summary>Readings</summary>
- CI on `f2f8b4ff`: 57 checks passed and 9 were skipped; none failed.
- Full dogfood, run under `os-verify-lock` (VERDICT command-exit 0 for
both steps): first `pnpm --filter '@objectstack/dogfood^...' build`,
then `pnpm --filter @objectstack/dogfood test`. Results: 440 files
passed and 3 skipped (443); 3654 tests passed and 41 skipped. The boot's
catalog reference report logged no refusal in the whole run: 0 lines for
`outside-closure`, `ambiguous-in-closure` or `ambiguous-in-environment`.
That is the first-party count, measured on a boot.
- `node scripts/pm/dispatch-gates.mjs --commands`: 107 gates derived,
and all 107 exit 0. `--ran` reconciles them as 107 run and 0
NOT-MEASURED, with an exit code recorded for each.
- On the first pass, before round 1, three gates were red and were
fixed: the changeset's ADR-0087 marker, the tenancy census loader, and
the teardown self-test (its pinned fixture commit was fetched into the
shallow clone).
- `check:dual-build-cjs-loads` ran after a full `turbo run build` under
the lock: exit 0.
- `pnpm --filter @objectstack/core typecheck` and `pnpm --filter
@objectstack/plugin-security typecheck`: exit 0.
- Core `src/security/`: 65 files, 1279 tests passed. Plugin-security
full suite under the lock: 251 files, 6050 passed, 45 skipped, 0 failed.
- Ablations 7 and 8, one per round-1 item, each turned its pin red in
core (1 failure each). After each, the code was restored and `git diff
HEAD` was empty.
- Lint: neither touched package has a `lint` script, so root `eslint
--no-inline-config packages/core packages/plugins/plugin-security` was
run instead: exit 0.
- Line budget: +1057 / −78 over 15 files, including `pnpm-lock.yaml` and
the census script.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmQVUJS5C8V1H8EC7wC
<!-- signed: domain:server#3 · os-steve ·
session_01ADHkmQVUJS5C8V1H8EC7wC -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(core, plugin-security)!: permission sets are read by (package, name), and a package position's sets resolve from its package
7
+
8
+
Clause-②: no (narrowing)
9
+
Metadata-protocol: none
10
+
11
+
<!-- adr-0087: not-required (no-migration-prescription) nothing an author writes is renamed, removed or re-shaped; the change is which permission set a position's bare name reads at runtime, so there is no stored or authored shape for objectstack migrate meta to rewrite -->
12
+
13
+
Permission sets are now resolved by (package, name) (ADR-0150 D3/D4/D7). The security catalog reads each permission set through the one package-scoped rule in `@objectstack/core` and the one declared-closure walk in `@objectstack/metadata-core`, and a position's `permissionSets` resolves from the package that declared the position: that package's own set, else the one holder in its declared dependency closure (plus `sys`), else a refusal that names every candidate. Stored grants, an environment-authored position, an administrator's overlay of a package position and the `everyone`/`guest` anchors still resolve across the whole environment, so they answer as before. Positions are unchanged: one environment-wide slot per name, and a second package holder is still refused. The permission-set list now has one entry per (package, name) holder.
14
+
15
+
Who is affected: a deployment where a package's position names a permission set that its package cannot reach. That happens when the set is held only by an environment-authored item, or only by a package outside the position package's declared dependencies. Before this change the bare name served that set. Now the position grants nothing through that name. The boot's catalog reference report lists each such position with every candidate holder. No first-party package or example does this.
16
+
17
+
Fix: declare a dependency on the package that holds the set, or bind the set through an administrator overlay of the position. An overlay resolves the set the way the environment does.
18
+
19
+
`@objectstack/core` now depends on `@objectstack/metadata-core` at runtime (it was a dev dependency), because the security catalog reads the declared-closure walk from there.
0 commit comments