From ea806b4ab5f93a899544ac80758868ca078f95ec Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:18:56 +0000 Subject: [PATCH 1/3] feat(plugin-security): a host can keep a platform baseline contribution at read, or decline it SecurityPlugin takes platformBaselineOverrides, keyed by contributed set name and object: 'read' keeps the object's read and withholds its create, 'decline' withholds the object. It is applied inside the platform baseline seam where a contribution is admitted, so every reader of the set reads the narrowed body. It only takes bits away; a set left granting nothing joins no baseline; an override that matched nothing by kernel:bootstrapped is warned. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM --- .../33132-platform-baseline-host-overrides.md | 10 ++ .../docs/permissions/attachments-access.mdx | 18 +++ packages/plugins/plugin-security/src/index.ts | 2 + ...platform-baseline-sets.integration.test.ts | 78 +++++++++- .../src/platform-baseline-sets.test.ts | 97 +++++++++++- .../src/platform-baseline-sets.ts | 138 ++++++++++++++++-- .../src/security-plugin-security-service.ts | 18 ++- .../plugin-security/src/security-plugin.ts | 40 ++++- 8 files changed, 382 insertions(+), 19 deletions(-) create mode 100644 .changeset/33132-platform-baseline-host-overrides.md diff --git a/.changeset/33132-platform-baseline-host-overrides.md b/.changeset/33132-platform-baseline-host-overrides.md new file mode 100644 index 00000000000..925fc4ad3ad --- /dev/null +++ b/.changeset/33132-platform-baseline-host-overrides.md @@ -0,0 +1,10 @@ +--- +'@objectstack/plugin-security': patch +--- + +feat(plugin-security): a host can keep a platform baseline contribution at read, or decline it, through `platformBaselineOverrides` + +Clause-②: no — a new, opt-in `SecurityPlugin` option. Omitted, every platform baseline contribution is admitted as contributed, as before. +Metadata-protocol: none + +`SecurityPlugin` takes `platformBaselineOverrides`, keyed by contributed permission set name and object: `'read'` keeps the object's read and withholds its create, `'decline'` withholds the object. For example, a host on which members must not create attachments declares `{ storage_attachment_member: { sys_attachment: 'read' } }`. The override is applied inside the platform baseline seam, where the contribution is admitted, so the data plane, `security/explain`, the effective-access read and the `everyone` anchor all read the narrowed set. It only takes bits away. A set left granting nothing joins no baseline. An override that no contribution matched by the end of boot is logged at `warn`, naming it. A malformed declaration is refused when the plugin is constructed. Before, a host could only get this by wrapping the security service's `contributePlatformBaselineSet`. (#33132) diff --git a/content/docs/permissions/attachments-access.mdx b/content/docs/permissions/attachments-access.mdx index 3b806461b37..65318df58a3 100644 --- a/content/docs/permissions/attachments-access.mdx +++ b/content/docs/permissions/attachments-access.mdx @@ -53,6 +53,24 @@ The set reaches no one else: auth service is composed for the download check; then it contributes no set either, and the boot log names the missing gate and what to add. +A host can also narrow the set for its own deployment, through the +`SecurityPlugin` option `platformBaselineOverrides`. It names a contributed set +and one of its objects, and either keeps that object at read (`'read'`) or +withholds it (`'decline'`). A host on which members must see attachments but +never create them declares: + +```ts +new SecurityPlugin({ + platformBaselineOverrides: { storage_attachment_member: { sys_attachment: 'read' } }, +}); +``` + +Members then keep the read, and a create is refused `PERMISSION_DENIED` (403); +`security/explain` and the effective-access read show the narrowed set. An +override only takes bits away. A set left granting nothing joins no baseline, +and an override that matched no contributed set by the end of boot is logged +at `warn` naming it, so a renamed set or object does not pass unnoticed. + The set carries **no edit and no delete** (ADR-0090 D5: a set every member holds carries no delete bit). Editing or deleting attachments still needs an explicit grant on `sys_attachment` (see Delete below). An app can also grant read and diff --git a/packages/plugins/plugin-security/src/index.ts b/packages/plugins/plugin-security/src/index.ts index 50459dc5a4e..9765d8d3a26 100644 --- a/packages/plugins/plugin-security/src/index.ts +++ b/packages/plugins/plugin-security/src/index.ts @@ -8,6 +8,8 @@ */ export { SecurityPlugin } from './security-plugin.js'; +// [#33132] The shape of `SecurityPluginOptions.platformBaselineOverrides`, for a host that declares one. +export type { PlatformBaselineOverride, PlatformBaselineOverrides } from './platform-baseline-sets.js'; export { PermissionEvaluator } from './permission-evaluator.js'; export { RLSCompiler, RLS_DENY_FILTER } from './rls-compiler.js'; export { FieldMasker, maskFieldValue, MASK_CHAR } from './field-masker.js'; diff --git a/packages/plugins/plugin-security/src/platform-baseline-sets.integration.test.ts b/packages/plugins/plugin-security/src/platform-baseline-sets.integration.test.ts index dec651af512..02feba4a785 100644 --- a/packages/plugins/plugin-security/src/platform-baseline-sets.integration.test.ts +++ b/packages/plugins/plugin-security/src/platform-baseline-sets.integration.test.ts @@ -20,7 +20,9 @@ * `everyone` definition names it; an external member and an agent principal * gain nothing; a contribution naming another package's object is refused on * the real registry; the window is closed once the kernel has bootstrapped; - * and a deployment declaring no member baseline hands the set to no one. + * a deployment declaring no member baseline hands the set to no one; and a + * host's `platformBaselineOverrides` (#33132) keeps the set at read, so a + * member's create is refused while the read still serves. * Each refusal rule on its own: `platform-baseline-sets.test.ts`. */ @@ -34,6 +36,7 @@ import type { ISecurityService, PlatformBaselineSetContribution } from '@objects import { mapDataError } from '@objectstack/types'; import { SecurityPlugin } from './security-plugin.js'; import { defaultPermissionSets } from './objects/default-permission-sets.js'; +import type { PlatformBaselineOverrides } from './platform-baseline-sets.js'; /** The platform service's package id, and the object it registers. */ /** The members this suite drives, each one the plugin serves. */ @@ -137,7 +140,12 @@ function servicePlugin(outcomes: Record): Plugin { }; } -async function boot(fallbackPermissionSet: string | null, outcomes: Record, logs?: BootLogs): Promise { +async function boot( + fallbackPermissionSet: string | null, + outcomes: Record, + logs?: BootLogs, + platformBaselineOverrides?: PlatformBaselineOverrides, +): Promise { const kernel = new ObjectKernel({ logger: { level: 'silent' } }); // Every plugin context logs through the kernel's one logger: the calls are // the record, whatever level the logger then prints at. @@ -149,7 +157,9 @@ async function boot(fallbackPermissionSet: string | null, outcomes: Record { + let kernel: ObjectKernel; + let ql: ObjectQL; + let security: SecurityService; + const outcomes: Record = {}; + const logs: BootLogs = { info: [], warn: [] }; + let alice: Ctx; + + beforeAll(async () => { + kernel = await boot(APP_SET.name, outcomes, logs, { + [SERVICE_SET.name]: { [NOTE]: 'read' }, + // Names a set no service contributes: it withholds nothing and is said. + pbs_renamed_member: { [NOTE]: 'decline' }, + }); + ql = kernel.getService('objectql'); + security = kernel.getService('security'); + await seedPeople(ql); + alice = await contextOf(ql, ALICE); + }, 120_000); + + afterAll(async () => { + if (kernel) await Promise.race([kernel.shutdown(), new Promise((r) => setTimeout(r, 10_000))]); + }, 30_000); + + it('the set still joins the baseline, and a member still reads the object', async () => { + expect(outcomes.own).toEqual({ joined: true }); + const rows = (await ql.find(NOTE, { context: alice } as never)) as Array>; + expect(rows.map((r) => r.name)).toContain('seeded note'); + }); + + it('a member\'s create is refused 403, and the explainer says the create is not allowed', async () => { + expect(await refusal(() => ql.insert(NOTE, { name: 'alice wrote this' }, { context: alice } as never), NOTE)) + .toMatchObject({ status: 403 }); + const decision = await security.explain({ object: NOTE, operation: 'create' }, alice); + expect(decision.allowed).toBe(false); + }); + + it('the catalog holds the narrowed body: read on, create off', () => { + const item = (ql as any).registry.getItem('permission', SERVICE_SET.name); + expect(item?.objects?.[NOTE]).toMatchObject({ allowRead: true, allowCreate: false }); + }); + + it('the admission line says what the host narrowed', () => { + const admitted = logs.info.filter(([m]) => String(m).startsWith(`[security] platform baseline set '${SERVICE_SET.name}'`)); + expect(admitted).toHaveLength(1); + expect(admitted[0][0]).toBe( + `[security] platform baseline set '${SERVICE_SET.name}' from '${SERVICE}': ${NOTE} (read) — ` + + 'joined the member baseline every signed-in member holds through the everyone anchor.' + + ` The host's platformBaselineOverrides narrowed it: ${NOTE}: kept at read.`, + ); + expect(admitted[0][1]).toEqual({ contributor: SERVICE, set: SERVICE_SET.name, joined: true, overridden: [`${NOTE}: kept at read`] }); + }); + + it('an override no contribution matched is warned once the kernel has bootstrapped', () => { + const unmatched = logs.warn.filter(([m]) => String(m).includes('[security] platformBaselineOverrides names')); + expect(unmatched).toHaveLength(1); + expect(unmatched[0][0]).toContain(`'pbs_renamed_member.${NOTE}'`); + expect(unmatched[0][0]).toContain('withheld nothing'); + expect(unmatched[0][1]).toEqual({ override: `pbs_renamed_member.${NOTE}` }); + }); +}); diff --git a/packages/plugins/plugin-security/src/platform-baseline-sets.test.ts b/packages/plugins/plugin-security/src/platform-baseline-sets.test.ts index 38d4c41940b..6d61fa0c13f 100644 --- a/packages/plugins/plugin-security/src/platform-baseline-sets.test.ts +++ b/packages/plugins/plugin-security/src/platform-baseline-sets.test.ts @@ -15,7 +15,12 @@ import { describe, it, expect } from 'vitest'; import { PermissionSetSchema } from '@objectstack/spec/security'; -import { PlatformBaselineSets, type PlatformBaselineHost, type PlatformBaselineRegistry } from './platform-baseline-sets.js'; +import { + PlatformBaselineSets, + readPlatformBaselineOverridesOption, + type PlatformBaselineHost, + type PlatformBaselineRegistry, +} from './platform-baseline-sets.js'; const CONTRIBUTOR = 'com.example.service.notes'; const OWN = 'pbs_note'; @@ -232,3 +237,93 @@ describe('a refused contribution changes nothing', () => { expect(message).toMatch(/the registry refused the set: permission 'pbs_notes_member' is held/); }); }); + +describe('#33132 — the host\'s overrides narrow an admitted contribution, and never widen one', () => { + const TWO = Object.freeze({ + name: SET.name, + objects: { [OWN]: { allowRead: true, allowCreate: true }, pbs_draft: { allowRead: true, allowCreate: true } }, + }); + + it("'read' keeps the object's read and withholds its create; the narrowed body is what is registered", () => { + const r = rig(); + const seams = new PlatformBaselineSets(readPlatformBaselineOverridesOption({ [SET.name]: { [OWN]: 'read' } })); + const admitted = seams.contribute(CONTRIBUTOR, SET, r.host); + expect(admitted).toMatchObject({ joined: true, overridden: [`${OWN}: kept at read`] }); + expect(admitted.set.objects?.[OWN]).toMatchObject({ allowRead: true, allowCreate: false }); + expect(r.registered).toHaveLength(1); + expect((r.registered[0].item.objects as any)[OWN]).toMatchObject({ allowRead: true, allowCreate: false }); + expect(r.host.baseline).toContain(SET.name); + expect(seams.body(SET.name)?.objects?.[OWN]).toMatchObject({ allowCreate: false }); + }); + + it("'decline' on one of two objects withholds that object and keeps the other as contributed", () => { + const r = rig(); + const seams = new PlatformBaselineSets(readPlatformBaselineOverridesOption({ [SET.name]: { pbs_draft: 'decline' } })); + const admitted = seams.contribute(CONTRIBUTOR, TWO, r.host); + expect(admitted).toMatchObject({ joined: true, overridden: ['pbs_draft: declined'] }); + expect(Object.keys(admitted.set.objects ?? {})).toEqual([OWN]); + expect(admitted.set.objects?.[OWN]).toMatchObject({ allowRead: true, allowCreate: true }); + }); + + it('a set the overrides leave granting nothing is not registered and joins no baseline', () => { + const r = rig(); + const before = [...r.host.baseline]; + const seams = new PlatformBaselineSets(readPlatformBaselineOverridesOption({ [SET.name]: { [OWN]: 'decline' } })); + const admitted = seams.contribute(CONTRIBUTOR, SET, r.host); + expect(admitted).toMatchObject({ joined: false, overridden: [`${OWN}: declined`] }); + expect(r.registered).toEqual([]); + expect(r.host.baseline).toEqual(before); + expect(seams.unmatchedOverrides()).toEqual([]); + }); + + it("'read' on an object the set grants create only withholds it: an override never adds read", () => { + const r = rig(); + const createOnly = { name: SET.name, objects: { [OWN]: { allowCreate: true } } }; + const seams = new PlatformBaselineSets(readPlatformBaselineOverridesOption({ [SET.name]: { [OWN]: 'read' } })); + const admitted = seams.contribute(CONTRIBUTOR, createOnly, r.host); + expect(admitted).toMatchObject({ joined: false, overridden: [`${OWN}: declined (the set grants it no read to keep)`] }); + expect(r.registered).toEqual([]); + }); + + it('a contribution the seam refuses is refused with an override too, and the override stays unmatched', () => { + const seams = new PlatformBaselineSets(readPlatformBaselineOverridesOption({ [SET.name]: { [OWN]: 'read' } })); + const message = refusalOf({ ...SET, objects: { [OWN]: { allowRead: true, allowEdit: true } } }, { seams }); + expect(message).toContain("carries 'allowEdit'"); + expect(seams.unmatchedOverrides()).toEqual([`${SET.name}.${OWN}`]); + }); + + it('another set is admitted as contributed, and an override naming nothing admitted is reported unmatched', () => { + const r = rig(); + const seams = new PlatformBaselineSets( + readPlatformBaselineOverridesOption({ pbs_other_member: { [OWN]: 'decline' }, [SET.name]: { pbs_gone: 'decline' } }), + ); + const admitted = seams.contribute(CONTRIBUTOR, SET, r.host); + expect(admitted).toMatchObject({ joined: true, overridden: [] }); + expect(admitted.set.objects?.[OWN]).toMatchObject({ allowRead: true, allowCreate: true }); + expect(seams.unmatchedOverrides()).toEqual([`pbs_other_member.${OWN}`, `${SET.name}.pbs_gone`]); + }); + + it('no override declared: the admitted set is the contribution, with nothing overridden', () => { + const r = rig(); + const admitted = new PlatformBaselineSets().contribute(CONTRIBUTOR, SET, r.host); + expect(admitted.overridden).toEqual([]); + expect(admitted.set.objects?.[OWN]).toMatchObject({ allowRead: true, allowCreate: true }); + }); +}); + +describe('#33132 — readPlatformBaselineOverridesOption refuses a malformed declaration', () => { + it('reads undefined as no override', () => { + expect(readPlatformBaselineOverridesOption(undefined)).toEqual({}); + }); + + it.each([ + ['a non-object', ['x'], 'not an object keyed by contributed permission set name'], + ['an empty set name', { '': { [OWN]: 'read' } }, 'a set name is empty'], + ['a set entry naming no object', { [SET.name]: {} }, `the entry for '${SET.name}' names no object`], + ["object '*'", { [SET.name]: { '*': 'decline' } }, "names object '*'"], + ['an unknown verdict', { [SET.name]: { [OWN]: 'none' } }, `'${SET.name}.${OWN}' is "none"`], + ])('refuses %s', (_label, raw, fragment) => { + expect(() => readPlatformBaselineOverridesOption(raw)).toThrow(fragment); + expect(() => readPlatformBaselineOverridesOption(raw)).toThrow('[security] SecurityPlugin option platformBaselineOverrides refused'); + }); +}); diff --git a/packages/plugins/plugin-security/src/platform-baseline-sets.ts b/packages/plugins/plugin-security/src/platform-baseline-sets.ts index f2ea54b3a2f..babfc1dbd08 100644 --- a/packages/plugins/plugin-security/src/platform-baseline-sets.ts +++ b/packages/plugins/plugin-security/src/platform-baseline-sets.ts @@ -60,6 +60,27 @@ * contribution, and every refusal, is logged by the seam that calls * {@link PlatformBaselineSets.contribute}. * + * ## What a host may change (`platformBaselineOverrides`) + * + * A host that composes a platform service may still not want every member to + * hold what that service contributes (#33132: a cross-tenant control plane + * that must not let an organization administrator create `sys_attachment` + * rows). It declares that on `SecurityPlugin` + * (`SecurityPluginOptions.platformBaselineOverrides`), by contributed set name + * and object, and the declaration is applied HERE, where the contribution is + * admitted, so every reader of the set reads the narrowed body: + * + * - `'read'` keeps the object's read and withholds its create; + * - `'decline'` withholds the object's grant entirely. + * + * An override only ever narrows: the contribution is first held to every rule + * above as the contributor wrote it, and the host can then take bits away, + * never add one. A set left granting nothing is not registered and joins no + * baseline (`joined: false`, as for a deployment with no baseline). An + * override that matched no admitted contribution by the time the boot window + * closes is reported at `warn` ({@link PlatformBaselineSets.unmatchedOverrides}), + * so a renamed set or object is said rather than silently left in force. + * * This seam is for always-on platform services. A tenant-installed package * suggests a default set and a `manage_metadata` holder accepts it * (`suggested-audience-bindings.ts`, ADR-0090 D5); it does not contribute here. @@ -74,6 +95,49 @@ const SET_KEYS: ReadonlySet = new Set(['name', 'label', 'description', ' /** The object-permission bits a contributed set may carry. */ const OBJECT_BITS: ReadonlySet = new Set(['allowRead', 'allowCreate']); +/** + * What a host does to one object of a contributed set: keep it at read + * (`'read'`), or withhold it (`'decline'`). See the module doc. + */ +export type PlatformBaselineOverride = 'read' | 'decline'; + +/** The host's overrides: contributed set name → object → {@link PlatformBaselineOverride}. */ +export type PlatformBaselineOverrides = Readonly>>>; + +const OVERRIDES: ReadonlySet = new Set(['read', 'decline']); + +function refuseOption(detail: string): never { + throw new Error(`[security] SecurityPlugin option platformBaselineOverrides refused: ${detail}`); +} + +/** + * Read `SecurityPluginOptions.platformBaselineOverrides`, frozen, or throw the + * refusal naming the malformed entry. `undefined` reads as no override. + */ +export function readPlatformBaselineOverridesOption(raw: unknown): PlatformBaselineOverrides { + if (raw === undefined) return Object.freeze({}); + if (!isPlainRecord(raw)) refuseOption('it is not an object keyed by contributed permission set name.'); + const out: Record>> = {}; + for (const [setName, objects] of Object.entries(raw)) { + if (setName.length === 0) refuseOption('a set name is empty.'); + if (!isPlainRecord(objects) || Object.keys(objects).length === 0) { + refuseOption(`the entry for '${setName}' names no object.`); + } + const perObject: Record = {}; + for (const [object, verdict] of Object.entries(objects)) { + if (object.length === 0 || object === '*') { + refuseOption(`the entry for '${setName}' names object '${object}'; an override names one object of the set.`); + } + if (typeof verdict !== 'string' || !OVERRIDES.has(verdict)) { + refuseOption(`'${setName}.${object}' is ${JSON.stringify(verdict)}; it is 'read' (keep read, withhold create) or 'decline' (withhold the object).`); + } + perObject[object] = verdict as PlatformBaselineOverride; + } + out[setName] = Object.freeze(perObject); + } + return Object.freeze(out); +} + /** The registry members the seam uses: the object's owner, and the set's registration. */ export interface PlatformBaselineRegistry { getObjectOwner(name: string): { packageId?: string } | undefined; @@ -100,6 +164,11 @@ export interface PlatformBaselineContribution { readonly set: PermissionSet; /** Whether the name joined the composed baseline. */ readonly joined: boolean; + /** + * What the host's overrides changed, one line per object (`'sys_attachment: kept at read'`); + * empty when none applied. + */ + readonly overridden: readonly string[]; } function refuse(contributor: string, detail: string): never { @@ -119,6 +188,11 @@ export class PlatformBaselineSets { private anchorDerived = false; private joinedAfterDerivation = false; private readonly byContributor = new Map(); + /** `set.object` keys of the host's overrides that an admitted contribution matched. */ + private readonly matched = new Set(); + + /** @param overrides the host's declaration, as {@link readPlatformBaselineOverridesOption} reads it. */ + constructor(private readonly overrides: PlatformBaselineOverrides = Object.freeze({})) {} /** * Admit one contribution, or throw the refusal. See the module doc for the @@ -202,25 +276,71 @@ export class PlatformBaselineSets { if (!parsed.success) { refuse(contributor, `it is not a well-formed permission set (${parsed.error.issues.map((i) => i.message).join('; ')}).`); } - const set = parsed.data as PermissionSet; - const offending = describeHighPrivilegeBits(set); + const offending = describeHighPrivilegeBits(parsed.data as PermissionSet); if (offending) refuse(contributor, `it carries ${offending}, which the everyone anchor forbids.`); + // The host's overrides narrow the admitted set; they never add a bit. + const { set, overridden, matched } = this.applyOverrides(parsed.data as PermissionSet); + const grantsSomething = Object.keys(set.objects ?? {}).length > 0; + // The registry's own one-holder rule answers a name another package holds. - try { - registry.registerItem('permission', { ...set }, 'name', contributor); - } catch (e) { - refuse(contributor, `the registry refused the set: ${(e as Error)?.message ?? e}`); + if (grantsSomething) { + try { + registry.registerItem('permission', { ...set }, 'name', contributor); + } catch (e) { + refuse(contributor, `the registry refused the set: ${(e as Error)?.message ?? e}`); + } } this.byContributor.set(contributor, set); + for (const key of matched) this.matched.add(key); - // A deployment that declares no baseline hands out none. - const joined = host.baseline.length > 0; + // A deployment that declares no baseline hands out none, and a set the + // host's overrides left granting nothing joins none. + const joined = grantsSomething && host.baseline.length > 0; if (joined && !host.baseline.includes(set.name)) { host.baseline.push(set.name); if (this.anchorDerived) this.joinedAfterDerivation = true; } - return { contributor, set, joined }; + return { contributor, set, joined, overridden }; + } + + /** Apply the host's overrides for `set.name` to its objects; see the module doc. */ + private applyOverrides(set: PermissionSet): { set: PermissionSet; overridden: string[]; matched: string[] } { + const forSet = this.overrides[set.name]; + if (!forSet) return { set, overridden: [], matched: [] }; + const overridden: string[] = []; + const matched: string[] = []; + const objects: Record[string]> = {}; + for (const [object, entry] of Object.entries(set.objects ?? {})) { + const verdict = forSet[object]; + if (verdict === undefined) { + objects[object] = entry; + continue; + } + matched.push(`${set.name}.${object}`); + if (verdict === 'read' && entry.allowRead === true) { + objects[object] = { ...entry, allowCreate: false }; + overridden.push(`${object}: kept at read`); + } else { + overridden.push(verdict === 'read' ? `${object}: declined (the set grants it no read to keep)` : `${object}: declined`); + } + } + return { set: { ...set, objects }, overridden, matched }; + } + + /** + * The host's overrides no admitted contribution matched, as `set.object`. + * Read when the boot window closes: each one is a declaration that withheld + * nothing, a set or object name that is wrong or was renamed. + */ + unmatchedOverrides(): string[] { + const out: string[] = []; + for (const [setName, objects] of Object.entries(this.overrides)) { + for (const object of Object.keys(objects)) { + if (!this.matched.has(`${setName}.${object}`)) out.push(`${setName}.${object}`); + } + } + return out; } /** The body of the contributed set `name`, if one was admitted. */ diff --git a/packages/plugins/plugin-security/src/security-plugin-security-service.ts b/packages/plugins/plugin-security/src/security-plugin-security-service.ts index 0081b0ce37e..6a1efe8d394 100644 --- a/packages/plugins/plugin-security/src/security-plugin-security-service.ts +++ b/packages/plugins/plugin-security/src/security-plugin-security-service.ts @@ -449,12 +449,24 @@ export function registerSecurityService( const grants = Object.entries(admitted.set.objects ?? {}) .map(([object, p]) => `${object} (${[p.allowRead ? 'read' : '', p.allowCreate ? 'create' : ''].filter(Boolean).join(', ')})`) .join(', '); + // [#33132] What the host's platformBaselineOverrides changed, said on the same line. + const overridden = admitted.overridden.length > 0 + ? ` The host's platformBaselineOverrides narrowed it: ${admitted.overridden.join('; ')}.` + : ''; ctx.logger.info( - `[security] platform baseline set '${admitted.set.name}' from '${admitted.contributor}': ${grants} — ` + + `[security] platform baseline set '${admitted.set.name}' from '${admitted.contributor}': ${grants || 'nothing'} — ` + (admitted.joined ? 'joined the member baseline every signed-in member holds through the everyone anchor.' - : 'registered, and handed to no one: this deployment declares no member baseline (fallbackPermissionSet: null).'), - { contributor: admitted.contributor, set: admitted.set.name, joined: admitted.joined }, + : grants === '' + ? 'declined by the host, handed to no one.' + : 'registered, and handed to no one: this deployment declares no member baseline (fallbackPermissionSet: null).') + + overridden, + { + contributor: admitted.contributor, + set: admitted.set.name, + joined: admitted.joined, + ...(admitted.overridden.length > 0 ? { overridden: admitted.overridden } : {}), + }, ); if (admitted.joined) this.epoch.bump('metadata'); return { name: admitted.set.name, joined: admitted.joined }; diff --git a/packages/plugins/plugin-security/src/security-plugin.ts b/packages/plugins/plugin-security/src/security-plugin.ts index 857f0f29c22..ee13615f8f4 100644 --- a/packages/plugins/plugin-security/src/security-plugin.ts +++ b/packages/plugins/plugin-security/src/security-plugin.ts @@ -280,7 +280,7 @@ import { owdOpenWritesCoversOperation, } from './platform-ownership-policies.js'; import { OwnershipFloorAlternates } from './ownership-floor-alternates.js'; -import { PlatformBaselineSets } from './platform-baseline-sets.js'; +import { PlatformBaselineSets, readPlatformBaselineOverridesOption, type PlatformBaselineOverrides } from './platform-baseline-sets.js'; import { refuseUndeclaredExternalObjectScope, registeredObjectsOf, @@ -1143,6 +1143,29 @@ export interface SecurityPluginOptions { * look enforced. */ acceptedDefaultPermissionSets?: readonly string[]; + /** + * [#33132] Narrow what an always-on platform service contributes to the + * member baseline (`ISecurityService.contributePlatformBaselineSet`), by + * contributed set name and object: + * + * - `'read'`: members keep the object's read, and its create is withheld; + * - `'decline'`: the object's grant is withheld entirely. + * + * For example, a host on which an organization administrator must not + * create attachments declares + * `{ storage_attachment_member: { sys_attachment: 'read' } }`. + * + * Applied where the contribution is admitted, so the data plane, the + * explainer, the effective-access read and the `everyone` anchor all read + * the narrowed set. It only narrows: a contribution is first held to the + * seam's own rules, and an override never adds a bit. A set left granting + * nothing joins no baseline. An entry that no contribution matched by the + * end of boot is logged at `warn`, so a renamed set or object is said, not + * silently left in force. A malformed entry is refused at construction. + * + * Omitted (the default), every contribution is admitted as contributed. + */ + platformBaselineOverrides?: PlatformBaselineOverrides; } /** @@ -1632,7 +1655,7 @@ export class SecurityPlugin implements Plugin { * reads them, and closed to contributions at `kernel:bootstrapped`. The * seam and its rules: `platform-baseline-sets.ts`. */ - private readonly platformBaselineSets = new PlatformBaselineSets(); + private readonly platformBaselineSets: PlatformBaselineSets; constructor(options: SecurityPluginOptions = {}) { this.bootstrapPermissionSets = @@ -1648,6 +1671,7 @@ export class SecurityPlugin implements Plugin { // with the platform's own, never one displacing the other (ADR-0090 D5). this.baselinePermissionSets = composeHumanBaselinePermissionSets(this.fallbackPermissionSet); this.acceptedDefaultPermissionSets = readAcceptedDefaultPermissionSetsOption(options.acceptedDefaultPermissionSets); + this.platformBaselineSets = new PlatformBaselineSets(readPlatformBaselineOverridesOption(options.platformBaselineOverrides)); // [ADR-0090 D10] The baseline is held by every signed-in person, so an // agent ceiling set is never part of it, however it was named. refuseAgentCeilingInBaselineOptions(this.fallbackPermissionSet, this.acceptedDefaultPermissionSets); @@ -1934,7 +1958,17 @@ export class SecurityPlugin implements Plugin { // after the derivation above began is not yet named by the anchor's // definition, so the anchor is derived again before anything serves. (ctx as any).hook('kernel:bootstrapped', async () => { - if (this.platformBaselineSets.close()) await this.declareEveryone(ctx.logger); + const owed = this.platformBaselineSets.close(); + // [#33132] An override nothing matched withheld nothing: say so. + for (const entry of this.platformBaselineSets.unmatchedOverrides()) { + ctx.logger.warn( + `[security] platformBaselineOverrides names '${entry}', which no platform service contributed during boot, ` + + 'so it withheld nothing. A renamed set or object leaves its grant in force: check the name against the ' + + "'[security] platform baseline set' lines of this boot.", + { override: entry }, + ); + } + if (owed) await this.declareEveryone(ctx.logger); }); } From 9fec20a7b528120d95a77c7c94bb93faf013ac29 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:25:18 +0000 Subject: [PATCH 2/3] docs(plugin-security): declare the platformBaselineOverrides option as a widening, and say a declined set holds no name Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM --- .changeset/33132-platform-baseline-host-overrides.md | 2 +- .../plugins/plugin-security/src/platform-baseline-sets.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.changeset/33132-platform-baseline-host-overrides.md b/.changeset/33132-platform-baseline-host-overrides.md index 925fc4ad3ad..d92d300b5c7 100644 --- a/.changeset/33132-platform-baseline-host-overrides.md +++ b/.changeset/33132-platform-baseline-host-overrides.md @@ -4,7 +4,7 @@ feat(plugin-security): a host can keep a platform baseline contribution at read, or decline it, through `platformBaselineOverrides` -Clause-②: no — a new, opt-in `SecurityPlugin` option. Omitted, every platform baseline contribution is admitted as contributed, as before. +Clause-②: yes (widening) — `SecurityPlugin` accepts a new, opt-in option, `platformBaselineOverrides`, and the package exports two new types, `PlatformBaselineOverride` and `PlatformBaselineOverrides`. Omitted, every platform baseline contribution is admitted as contributed, as before. Metadata-protocol: none `SecurityPlugin` takes `platformBaselineOverrides`, keyed by contributed permission set name and object: `'read'` keeps the object's read and withholds its create, `'decline'` withholds the object. For example, a host on which members must not create attachments declares `{ storage_attachment_member: { sys_attachment: 'read' } }`. The override is applied inside the platform baseline seam, where the contribution is admitted, so the data plane, `security/explain`, the effective-access read and the `everyone` anchor all read the narrowed set. It only takes bits away. A set left granting nothing joins no baseline. An override that no contribution matched by the end of boot is logged at `warn`, naming it. A malformed declaration is refused when the plugin is constructed. Before, a host could only get this by wrapping the security service's `contributePlatformBaselineSet`. (#33132) diff --git a/packages/plugins/plugin-security/src/platform-baseline-sets.ts b/packages/plugins/plugin-security/src/platform-baseline-sets.ts index babfc1dbd08..dbcfe726a50 100644 --- a/packages/plugins/plugin-security/src/platform-baseline-sets.ts +++ b/packages/plugins/plugin-security/src/platform-baseline-sets.ts @@ -75,8 +75,9 @@ * * An override only ever narrows: the contribution is first held to every rule * above as the contributor wrote it, and the host can then take bits away, - * never add one. A set left granting nothing is not registered and joins no - * baseline (`joined: false`, as for a deployment with no baseline). An + * never add one. A set left granting nothing is not registered, so it holds + * no registry name (another package may then register that name), and it + * joins no baseline (`joined: false`, as for a deployment with no baseline). An * override that matched no admitted contribution by the time the boot window * closes is reported at `warn` ({@link PlatformBaselineSets.unmatchedOverrides}), * so a renamed set or object is said rather than silently left in force. From 4ebb712e4a4f8d3709f6c7b8a8f9ce5eb6ce47c0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:25:39 +0000 Subject: [PATCH 3/3] docs(plugin-security): state only what a declined set's registration leaves Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM --- packages/plugins/plugin-security/src/platform-baseline-sets.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/plugins/plugin-security/src/platform-baseline-sets.ts b/packages/plugins/plugin-security/src/platform-baseline-sets.ts index dbcfe726a50..91b2714ec52 100644 --- a/packages/plugins/plugin-security/src/platform-baseline-sets.ts +++ b/packages/plugins/plugin-security/src/platform-baseline-sets.ts @@ -76,8 +76,7 @@ * An override only ever narrows: the contribution is first held to every rule * above as the contributor wrote it, and the host can then take bits away, * never add one. A set left granting nothing is not registered, so it holds - * no registry name (another package may then register that name), and it - * joins no baseline (`joined: false`, as for a deployment with no baseline). An + * no name in the engine registry, and it joins no baseline (`joined: false`, as for a deployment with no baseline). An * override that matched no admitted contribution by the time the boot window * closes is reported at `warn` ({@link PlatformBaselineSets.unmatchedOverrides}), * so a renamed set or object is said rather than silently left in force.