Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/32780-stored-permission-set-package-slot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/objectql': patch
---

fix(metadata-protocol): two namespaces' stored permission sets of one name are each kept and served at their own package

Clause-②: yes (widening) — widened: a save, publish or restore of a permission set whose name a package of another namespace stores moves from `422 NAMESPACE_CONFLICT` to saved; and a restart over a stored set of one package beside a set of the name another namespace's package ships or declares moves from a boot refused with `422 NAMESPACE_CONFLICT` to a boot that serves each package's set at its package.
Metadata-protocol: none

A permission set is `(package, name)` (ADR-0150 D2). The host kernel now keeps a stored permission set bound to a package in that package's own registry slot, at the save's write-through and at the boot hydration alike. It used to put every stored set of a name into the name's one bare registry entry, so a second package's set of the name took the first one's place. The save door therefore refused it, even when the two packages had two namespaces, and a restart over a stored set beside another namespace's shipped or declared set of the name was refused.

What moves, for packages `crm` and `hr` of two namespaces:

- FROM `422 NAMESPACE_CONFLICT` naming `crm` TO saved, for `hr`'s save, publish or restore of a set whose name `crm` stores. `crm`'s own save of a set of the name beside the one `hr` stores, and a third namespace's, are admitted too. A grant bound to each package confers that package's set, in every order the boot reads the stored rows.
- FROM a boot refused with `422 NAMESPACE_CONFLICT` TO a boot that serves each set at its package, for a restart over a set `hr` stores beside a set of the name `crm` ships or declares. `crm` keeps serving the set it ships, `hr` serves the set it stores, and the stored set is tenant-authored and bound to `hr`. The packaged-permission-set lock reads only the shipped set as packaged.
- A delete of one package's stored set retires that package's slot alone, and the other package's set stays served, before and after a restart.
- The refusal that stays (two packages of one namespace, a platform namespace, a package with no namespace, the environment, a name the platform requests by spelling) now names steps the writer can take: rename its own set, or delete a set the environment or another package stores. It no longer tells the writer to rename the set inside another package. Envelope unchanged: `422 NAMESPACE_CONFLICT`.

Unchanged: a package's stored set counts as its holding of the name at every name check. A package of the same namespace declaring or registering the name beside it is refused with `422 NAMESPACE_CONFLICT`, and so is a cold boot where it is held against a package that declares or ships the name (ADR-0048 N.3), including a stored set bound to the declaring package itself. A grant naming no package of a name two packages hold confers nothing (ADR-0150 D3). A package-less stored permission row keeps the name's bare registry entry, as before.
50 changes: 42 additions & 8 deletions packages/metadata-protocol/src/protocol-registry-hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ function soleHolderOf(registry: { packageScopedHoldersOf?(type: string, name: st
* - a `permission`: a stored fork of a shipped permission set keeps the
* disposition of its own maintainer ruling (detection, never a silent
* change of the grants the deployment enforces; see
* `isUnservedSealedOverlay`).
* `isUnservedSealedOverlay`). A row of a package that holds no set of the
* name is that package's own set (ADR-0150 D2): it wears no other
* package's envelope ({@link ownPermissionEnvelope}) and takes its own
* package's slot ({@link takesPackageOverlaySlot}), so it is never a
* holder's item to decline.
*/
function judgesRowHolder(canonicalType: string): boolean {
return canonicalType !== 'flow' && canonicalType !== 'permission' && !BORROWED_ENVELOPE_DECLINED_TYPES.has(canonicalType);
Expand Down Expand Up @@ -267,12 +271,39 @@ function namesNoHolderAmongMany(
*
* ⛔ Not a `flow`: the name's one bare slot keeps the shipping package's
* declared override over any other row ({@link incomingTakesStoredFlowSlot},
* #28717), which the boot pull reads. ⛔ Not a `permission`: a stored fork of
* a shipped permission set keeps the disposition of its own maintainer ruling
* (see {@link judgesRowHolder}). A package-less row keeps the bare slot.
* #28717), which the boot pull reads. A package-less row keeps the bare slot.
*
* A `permission` takes its package's slot too (ADR-0150 D2/D3 "security
* catalog: permission sets by (package, name)"): a set is `(package, name)`, so
* two namespaces' stored sets of one name are two sets, each served at its own
* package and each retired by its own delete, in every boot read order. With
* the one bare slot the set stored last took the other package's place, so the
* save door had to refuse a second namespace's stored set. Its envelope is its
* own package's ({@link ownPermissionEnvelope}).
*/
function takesPackageOverlaySlot(canonicalType: string): boolean {
return PACKAGE_SLOTTED_STORE_TYPES.has(canonicalType) && canonicalType !== 'flow' && canonicalType !== 'permission';
return PACKAGE_SLOTTED_STORE_TYPES.has(canonicalType) && canonicalType !== 'flow';
}

/**
* [ADR-0150 D2/D4] The artifact whose envelope a stored `permission` row bound
* to `bound` wears: `artifact` only when it is the row's own package's set, or
* the set of the base whose customization pair `bound` is (ADR-0146). The
* artifact lookup scoped to a package that ships no set of the name falls back
* to a package that does; that package's envelope is never this row's. With
* none of its own, the row registers as the tenant-authored set it is, bound
* to its own package. Any other type, or a package-less row, keeps `artifact`.
*/
function ownPermissionEnvelope(
registry: InstalledPackageSource,
canonicalType: string,
bound: string | undefined,
artifact: unknown,
): unknown {
if (canonicalType !== 'permission' || bound === undefined || artifact === undefined || artifact === null) return artifact;
const shipper = (artifact as { _packageId?: unknown })._packageId;
if (shipper === bound) return artifact;
return typeof shipper === 'string' && isPairOf(bound, shipper, installedManifestsOf(registry)) ? artifact : undefined;
}

/** {@link pairRowEnvelopeHolder}'s answer for a row that is not a customization pair's row of a two-holder name. */
Expand Down Expand Up @@ -889,9 +920,12 @@ export class ProtocolRegistryHydrationFacet {
const envelopePackage = pairHolder !== NOT_A_PAIR_ROW
? pairHolder
: options.packageId ?? (scoped ? soleHolderOf(registry, canonicalType, rowName) : undefined);
const artifact = envelopePackage === null ? undefined : host.lookupArtifactItem(
// [ADR-0150 D2] A stored permission row wears its own package's
// envelope only ({@link ownPermissionEnvelope}), never the envelope of
// another namespace's set the lookup falls back to.
const artifact = envelopePackage === null ? undefined : ownPermissionEnvelope(registry, canonicalType, boundPackageOf(options.packageId), host.lookupArtifactItem(
type, (data as any).name, envelopePackage ?? undefined, bundleMemberOf(type, data),
);
));
// [#29600] See the header: a dashboard, report or email-template row
// bound to a package that ships no artifact of its name, under a name
// another package ships, is not registered under the bare name, where
Expand Down Expand Up @@ -1958,7 +1992,7 @@ export class ProtocolRegistryHydrationFacet {
// where the pair relation names zero or several bases: the only
// refusal {@link readHealBaseline} lets through for a bound row.
// Its entry sits in the bare slot for a type with no package
// overlay slot (`flow`, `permission`), where it kept serving the
// overlay slot (`flow`; a `permission` until it took its own), where it kept serving the
// deleted body to the non-holder's read and stood as a refused
// holder read's candidate. Retiring it picks nobody and restores
// each holder's exact address (entry kept → retired).
Expand Down
41 changes: 24 additions & 17 deletions packages/metadata-protocol/src/protocol-save-door-refusals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ function registryPackageHoldersOf(registry: unknown, name: string): readonly str
* set of a name ACTIVE under an owner other than a holder it meets is refused
* here, with nothing written — a package never writes into a record another
* owns (ADR-0086 D4). The environment meets every holder, as before. A set
* another package STORES meets every writer too: the registry keeps one entry
* per stored set of a name, so two stored sets of one name are not yet kept
* apart there (#31698), and a second one stays refused.
* another package STORES is judged by the same predicate as a shipped one: the
* registry keeps each package's stored set of a name in that package's own
* slot (the hydrator's package overlay slot, ADR-0150 D2/D4), so a second
* namespace's stored set lands beside the first, each served at its package.
*
* ## The owner
*
Expand All @@ -376,8 +377,8 @@ function registryPackageHoldersOf(registry: unknown, name: string): readonly str
*
* - **The stored active rows** of the environment (ADR-0131 D6), by
* `package_id`. A set published through the metadata door is stored, and
* the registry holds it in the bare slot with no package (hydration and the
* write-through register a stored row without one), so only the row says
* the registry holds it in its package's overlay slot, which the
* registry's package-held reading does not count, so only the row says
* which package it belongs to — the half the registry's reading cannot see,
* and why this door's reading is wider than the cold boot's.
* - **The registry's package half** ({@link registryPackageHoldersOf}): a set
Expand Down Expand Up @@ -444,18 +445,17 @@ export async function permissionSetNameCollisionRefusal(
// holder the writing package does not meet under the ONE predicate the
// install gate asks ({@link permissionSetHoldersMeet}) holds its own set of
// the name, not this one. The environment, on either side, still meets
// every holder. ⛔ A STORED row of another package still holds the name
// whatever its namespace: the registry keeps one entry per stored set of a
// name, so a second stored set would take the first one's place there. Two
// namespaces' sets of one name are admitted where the first is shipped (an
// installed package's own), never beside another package's stored set.
// every holder. A STORED set of another package is judged the same way:
// the registry keeps each package's stored set in that package's own slot,
// so a second namespace's set lands beside it and neither takes the
// other's place.
const namespaceOf = (packageId: string): string | undefined => {
const namespace = (this.engine?.registry as { getPackage?: (id: string) => { manifest?: { namespace?: unknown } } | undefined } | undefined)
?.getPackage?.(packageId)?.manifest?.namespace;
return typeof namespace === 'string' && namespace !== '' ? namespace : undefined;
};
const meets = (holder: string | null): boolean =>
holder === null || written === null || storedPackages.has(holder)
holder === null || written === null
|| permissionSetHoldersMeet(namespaceOf(written), namespaceOf(holder), name);
const foreign = [...holders]
.filter((holder) => holder !== written && meets(holder))
Expand All @@ -465,19 +465,26 @@ export async function permissionSetNameCollisionRefusal(

const holderPhrase = (holder: string | null) => (holder === null ? 'the environment catalog' : `package "${holder}"`);
const writer = written === null ? 'this environment' : `package "${written}"`;
const releases = foreign
.map((holder) => (holder === null ? 'rename or delete the environment catalog\'s set' : `rename it in package "${holder}"`))
// The steps the WRITER can take: a name of its own, or deleting a set the
// environment or another package STORES (a stored set is deleted through
// the metadata door); never an edit inside another package. A set a
// package ships leaves the writer only the rename.
const deletable = foreign.filter((holder) => holder === null || storedPackages.has(holder));
const releases = deletable
.map((holder) => (holder === null ? 'delete the environment catalog\'s set' : `delete the set package "${holder}" stores`))
.join(', or ');
const remedy = verb === 'restore'
? `Restore it once the name is free (${releases} first), or save this version's body as a set of a name no other `
+ 'holder holds.'
: `Rename this set to a name no other holder holds (prefix it with your own module prefix), or ${releases} first.`;
? (releases === ''
? 'Save this version\'s body as a set of a name no other holder holds.'
: `Restore it once the name is free (${releases} first), or save this version's body as a set of a name no other `
+ 'holder holds.')
: `Rename this set to a name no other holder holds (prefix it with your own module prefix)${releases === '' ? '' : `, or ${releases} first`}.`;
const err = new Error(
`Security catalog name conflict: ${writer} cannot ${verb} the permission set "${name}" — it is already held by `
+ `${foreign.map(holderPhrase).join(' and ')}. Nothing was ${verb === 'publish' ? 'published' : 'written'}. ${remedy} `
+ 'A permission set holds one name per namespace: two packages of one namespace, a platform package '
+ '(`base`, `system`, `sys`), a package with no namespace, the environment, or a name the platform requests '
+ 'by spelling share one set of it, and a set another package stores holds its name. See ADR-0150 D2.',
+ 'by spelling share one set of it. See ADR-0150 D2.',
) as Error & { code: 'NAMESPACE_CONFLICT'; status: 422 };
err.code = 'NAMESPACE_CONFLICT';
err.status = 422;
Expand Down
Loading
Loading