Skip to content

Commit 3487ccc

Browse 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>
1 parent 785d432 commit 3487ccc

15 files changed

Lines changed: 1057 additions & 78 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/core': patch
3+
'@objectstack/plugin-security': patch
4+
---
5+
6+
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.

‎packages/core/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
"test:watch": "vitest"
4040
},
4141
"devDependencies": {
42-
"@objectstack/metadata-core": "workspace:*",
4342
"@objectstack/refd-timer-testkit": "workspace:*",
4443
"@types/node": "^26.6.5",
4544
"esbuild": "^0.28.2",
4645
"typescript": "^6.0.3",
4746
"vitest": "^4.1.11"
4847
},
4948
"dependencies": {
49+
"@objectstack/metadata-core": "workspace:*",
5050
"@objectstack/spec": "workspace:*",
5151
"@objectstack/types": "workspace:*",
5252
"zod": "^4.6.6"

‎packages/core/src/security/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ export {
433433
type SecurityCatalogSources,
434434
type SecurityCatalogEntry,
435435
type SecurityCatalogReader,
436+
// ADR-0150 D3/D4/D7 — permission sets by (package, name), the resolver handed in.
437+
resolveCatalogReference,
438+
type SecurityCatalogPackageScopedRegistry,
439+
type SecurityCatalogReferenceScope,
440+
type SecurityCatalogResolution,
436441
} from './security-catalog.js';
437442

438443
// ADR-0131 D3/D4/D10 — the junction rows turned into the `permissionSets` each

‎packages/core/src/security/resolve-authz-context.ts‎

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import {
8484
type OrganizationReach,
8585
} from './organization-reach.js';
8686
import { derivePosture } from './posture-ladder.js';
87-
import { securityCatalogReaderOf, type SecurityCatalogReader } from './security-catalog.js';
87+
import { securityCatalogReaderOf, type SecurityCatalogEntry, type SecurityCatalogReader } from './security-catalog.js';
8888
import { resolveSystemWriteOrganization, type SystemWriteOrganizationDecision } from './system-write-organization.js';
8989
import { METADATA_ACTIVATION_TABLE } from '../utils/metadata-activation-store.js';
9090

@@ -1410,13 +1410,19 @@ interface CatalogSetBody {
14101410
* [ADR-0131 D3/D4] The body of the permission set `name` names, read from its
14111411
* catalog definition — or `undefined` when the catalog holds no set of that
14121412
* name (or no catalog is bound), which confers nothing.
1413+
*
1414+
* [ADR-0150 D7] `position` is the position whose `permissionSets` names it:
1415+
* the set then resolves from the package that declared the position (D3), and
1416+
* a name that rule refuses confers nothing. Omitted, the name is a stored
1417+
* grant's, resolved as a caller with no package.
14131418
*/
14141419
async function catalogSetBody(
14151420
catalog: SecurityCatalogReader | undefined,
14161421
name: string,
1422+
position?: SecurityCatalogEntry,
14171423
): Promise<CatalogSetBody | undefined> {
14181424
if (!catalog) return undefined;
1419-
const entry = await catalog.resolve('permission', name);
1425+
const entry = await catalog.resolve('permission', name, position ? { position } : undefined);
14201426
if (!entry) return undefined;
14211427
return {
14221428
name: entry.name,
@@ -1425,6 +1431,17 @@ async function catalogSetBody(
14251431
};
14261432
}
14271433

1434+
/** What {@link positionBoundSetNames} reads: each position's set names, and the position each was read from. */
1435+
interface PositionBindings {
1436+
/** The sets each position's definition names, in declared order. */
1437+
named: Map<string, string[]>;
1438+
/**
1439+
* [ADR-0150 D7] The catalog entry of each position read — what each of its
1440+
* sets resolves from ({@link catalogSetBody}'s `position`).
1441+
*/
1442+
entries: Map<string, SecurityCatalogEntry>;
1443+
}
1444+
14281445
/**
14291446
* [ADR-0131 D3/D4] The sets each of `positions` names in its catalog
14301447
* definition, in declared order — THE position-bound read: every position's
@@ -1436,13 +1453,16 @@ async function catalogSetBody(
14361453
async function positionBoundSetNames(
14371454
catalog: SecurityCatalogReader | undefined,
14381455
positions: readonly string[],
1439-
): Promise<Map<string, string[]>> {
1456+
): Promise<PositionBindings> {
14401457
const named = new Map<string, string[]>();
1441-
if (!catalog) return named;
1458+
const entries = new Map<string, SecurityCatalogEntry>();
1459+
if (!catalog) return { named, entries };
14421460
for (const positionName of positions) {
1443-
named.set(positionName, positionSetNamesOf((await catalog.resolve('position', positionName))?.definition));
1461+
const entry = await catalog.resolve('position', positionName);
1462+
if (entry) entries.set(positionName, entry);
1463+
named.set(positionName, positionSetNamesOf(entry?.definition));
14441464
}
1445-
return named;
1465+
return { named, entries };
14461466
}
14471467

14481468
/**
@@ -1555,14 +1575,14 @@ export async function readPositionGrantsInForce(
15551575
): Promise<{ inForce: Map<string, string[]>; disabledPositions: Set<string> }> {
15561576
const names = [...new Set(positions.filter((n) => typeof n === 'string' && n !== ''))];
15571577
const catalog = securityCatalogReaderOf(ql);
1558-
const namedByPosition = await positionBoundSetNames(catalog, names);
1578+
const { named: namedByPosition, entries: positionEntries } = await positionBoundSetNames(catalog, names);
15591579
const disabled = await readDisabledCatalogNames(ql, names, [...namedByPosition.values()].flat());
15601580
const inForce = setsInForceByPosition(names, namedByPosition, disabled);
15611581
for (const [positionName, setNames] of inForce) {
15621582
const held: string[] = [];
15631583
for (const setName of setNames) {
15641584
if (held.includes(setName)) continue;
1565-
if (await catalogSetBody(catalog, setName)) held.push(setName);
1585+
if (await catalogSetBody(catalog, setName, positionEntries.get(positionName))) held.push(setName);
15661586
}
15671587
inForce.set(positionName, held);
15681588
}
@@ -1790,7 +1810,8 @@ async function resolveGuestAnchorGrants(
17901810
): Promise<GuestAnchorGrants | undefined> {
17911811
if (!ql || typeof ql.find !== 'function') return undefined;
17921812
const catalog = securityCatalogReaderOf(ql);
1793-
const bound = (await positionBoundSetNames(catalog, [GUEST_POSITION])).get(GUEST_POSITION) ?? [];
1813+
const guestBindings = await positionBoundSetNames(catalog, [GUEST_POSITION]);
1814+
const bound = guestBindings.named.get(GUEST_POSITION) ?? [];
17941815
if (bound.length === 0) return undefined;
17951816

17961817
const organization = await resolveGuestOrganization(ql, tenancyPosture);
@@ -1806,7 +1827,7 @@ async function resolveGuestAnchorGrants(
18061827
const bodies: CatalogSetBody[] = [];
18071828
for (const name of bound) {
18081829
if (disabled.permissions.has(name)) continue;
1809-
const body = await catalogSetBody(catalog, name);
1830+
const body = await catalogSetBody(catalog, name, guestBindings.entries.get(GUEST_POSITION));
18101831
if (body && !bodies.some((b) => b.name === body.name)) bodies.push(body);
18111832
}
18121833
foldCatalogSetBodies(grants, bodies);
@@ -2148,22 +2169,27 @@ export async function resolveUserAuthzGrants(
21482169
// effect, a membership-derived role (`org_owner`) included.
21492170
const readPositionLedger = async (): Promise<{
21502171
namedByPosition: Map<string, string[]>;
2172+
positionEntries: Map<string, SecurityCatalogEntry>;
21512173
disabled: { positions: Set<string>; permissions: Set<string> };
21522174
}> => {
21532175
if (grants.positions.length === 0) {
2154-
return { namedByPosition: new Map(), disabled: { positions: new Set(), permissions: new Set() } };
2176+
return {
2177+
namedByPosition: new Map(),
2178+
positionEntries: new Map(),
2179+
disabled: { positions: new Set(), permissions: new Set() },
2180+
};
21552181
}
21562182
// The definitions first (in-process), so the ONE ledger read can ask about
21572183
// every position and every set this resolution may grant.
2158-
const namedByPosition = await positionBoundSetNames(catalog, grants.positions);
2184+
const { named: namedByPosition, entries: positionEntries } = await positionBoundSetNames(catalog, grants.positions);
21592185
const disabled = await readDisabledCatalogNames(
21602186
ql,
21612187
grants.positions,
21622188
[...ledgerSetNames, ...[...namedByPosition.values()].flat()],
21632189
);
2164-
return { namedByPosition, disabled };
2190+
return { namedByPosition, positionEntries, disabled };
21652191
};
2166-
const [defaultOrganizationId, { namedByPosition, disabled }] = await Promise.all([
2192+
const [defaultOrganizationId, { namedByPosition, positionEntries, disabled }] = await Promise.all([
21672193
anchorReadsDefaultOrganization ? memoisedDefaultOrganizationId(ql) : Promise.resolve(undefined),
21682194
readPositionLedger(),
21692195
]);
@@ -2175,15 +2201,19 @@ export async function resolveUserAuthzGrants(
21752201
const applyingGrants = upsRows.filter(
21762202
(r) => grantAppliesInTenant(grantOrganizationOf(r), tenantId) || anchorsPlatformStanding(r),
21772203
);
2178-
// Position-bound sets (§6a), by name, in the order the held positions name them.
2179-
const boundSetNames: string[] = [];
2204+
// Position-bound sets (§6a), in the order the held positions name them —
2205+
// each with the position that names it, since [ADR-0150 D7] a set resolves
2206+
// from the package that declared its position.
2207+
const boundSets: Array<{ setName: string; positionName: string }> = [];
21802208
let hasPlatformAdminGrant = false;
21812209
if (disabled.positions.size > 0) {
21822210
grants.positions = grants.positions.filter((n) => !disabled.positions.has(n));
21832211
}
21842212
for (const [positionName, setNames] of setsInForceByPosition(grants.positions, namedByPosition, disabled)) {
21852213
for (const setName of setNames) {
2186-
if (!boundSetNames.includes(setName)) boundSetNames.push(setName);
2214+
if (!boundSets.some((b) => b.setName === setName && b.positionName === positionName)) {
2215+
boundSets.push({ setName, positionName });
2216+
}
21872217
// [ADR-0090 D5] The `everyone` anchor's bindings are the default ones.
21882218
recordOrigin(setName, positionName === 'everyone'
21892219
? { kind: 'default' }
@@ -2234,8 +2264,12 @@ export async function resolveUserAuthzGrants(
22342264
hasPlatformAdminGrant = true;
22352265
}
22362266
}
2237-
for (const name of boundSetNames) {
2238-
const body = await catalogSetBody(catalog, name);
2267+
for (const { setName: name, positionName } of boundSets) {
2268+
// Asked per naming position, never once per name: a reference one
2269+
// position's package cannot resolve (ADR-0150 D3) must not withhold the
2270+
// set another position names in a scope that resolves it.
2271+
if (takenNames.has(name)) continue;
2272+
const body = await catalogSetBody(catalog, name, positionEntries.get(positionName));
22392273
if (!body) continue;
22402274
take(body, !disabled.permissions.has(name));
22412275
}

0 commit comments

Comments
 (0)