Skip to content

Commit e7396e1

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-pasvxm
2 parents 243250a + 8c9260f commit e7396e1

31 files changed

Lines changed: 1793 additions & 159 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/metadata': patch
3+
---
4+
5+
feat(metadata): a read-only count of the history snapshots the drained-key scrub would rewrite
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`@objectstack/metadata/migrations` gains `scrubHistoryDrainedKeys(driver, { mode: 'count' })`, the count mode of a one-time scrub of `sys_metadata_history` snapshots written before history started withholding what a connector save drains (undeclared `auth` keys).
11+
12+
- **One predicate.** A stored snapshot is counted exactly when `historySnapshotBody` — the helper both history writers already store through — would store a different body for it today. Nothing in the count names a key or a type, so the count and the write-time withholding cannot disagree, and a snapshot written since that withholding landed is never counted.
13+
- **Read-only.** It takes a driver's `find` and nothing else, pages the table by primary key, and reports the number of affected rows, the number of distinct items they belong to, and the affected rows' ids as opaque handles. A body that is not JSON, or one the snapshot helper cannot reduce, is listed beside the count, never folded into it. The result never carries a key name, a value or a body.
14+
- **Count only.** Any other mode is refused before anything is read. The rewrite of stored history runs only after the maintainer confirms the count; run the count on a copy of the database and hand its numbers over privately.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@objectstack/platform-objects': patch
4+
---
5+
6+
feat(plugin-auth): an SSO sign-in grants the ordinary permission set its IdP group is mapped to
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
An enterprise SSO provider (OIDC or SAML, through `@better-auth/sso`) can now drive what its users may do from the groups the identity provider sends at sign-in, through the same `sys_idp_group_mapping` mappings a SCIM connection uses. There is no second mapping model.
12+
13+
- **Where the groups come from.** Set the provider's own claim mapping to fill `groups`: `mapping.extraFields: { groups: 'groups' }` for an OIDC claim named `groups`, or the attribute name an IdP uses for SAML (for example Entra ID's groups claim URI). The value may be one string or a list of strings. A provider whose mapping fills no `groups` behaves as before.
14+
- **Saving a mapping.** `POST /api/v1/auth/admin/scim/set-group-mapping` now also takes `providerId` in place of `connectionId` (exactly one of the two; both is `400 VALIDATION_FAILED` on `providerId`). The grant's organization is the provider's own `organization_id`; a provider that names none, or an unknown provider, is refused `400 VALIDATION_FAILED` on `providerId`. With SSO off the save is refused `503`. The same platform-admin gate and the same organization-boundary judgement apply: administrator sets and every set outside the organization boundary are refused, and without a security service the save is refused `503`. The row is stored with `source_kind: 'sso'` (a new option on `sys_idp_group_mapping.source_kind`) and `source_id` = the provider id.
15+
- **At each sign-in.** Every sign-in through the provider matches each group value against the provider's mappings (by `groupExternalId` when the mapping names one, which suits Entra ID's group object ids, else by exact `groupDisplayName`) and makes the user's grants follow them: a mapped group grants its set in the provider's organization, and a group the user has left loses the set at their next sign-in. A sign-in with no groups removes the grants that provider made earlier. The boundary is asked again before every grant, so a set that becomes an administrator set after its mapping was saved grants nothing, and with no security service nothing is granted. Only grants the provider made (their `reason` names the provider) are ever removed: a grant made by hand, or by SCIM, is never touched. Every write goes through the engine, so the break-glass last-administrator guard still refuses what it refuses elsewhere. If applying the mappings fails, the sign-in still succeeds and the failure is logged at `error`.
16+
- **Deleting a mapping.** `POST /api/v1/auth/admin/scim/delete-group-mapping` removes an SSO mapping and, at once, the grants its provider made of that set in that organization, unless another of the provider's mappings still names that set (then each user's next sign-in decides).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): a tenant's edit follows its item across the packages of one App
6+
7+
Clause-②: no — no accept set changes; the lookup scope widens only within one suite (triage 6724363147)
8+
Metadata-protocol: none
9+
10+
When a later version of an App moves an item from one of its packages to another (an ADR-0130 D4 suite split such as a flat App becoming an App plus modules, or the rollback of one), the item's reads no longer drop the tenant's edit of it. Before, the edit was still stored and every read served the vendor's item: the reads looked for the edit under the package that ships the item now, and the edit names the package that shipped it at the time of the edit.
11+
12+
- **What follows.** The App pair's (`<app>.custom`) declared override whose `overrides.package` names a former owner of the item, and a row bound to the former owner itself (a Regime O save stored before ADR-0146 D11 closed saves naming the read-only base). Each is served at the package that ships the item now, by name (with and without `?package=`), in the list and as the layered read's `effective`.
13+
- **Same App, read from the install record.** Two installed packages are of one App when `appOf` answers the same App for both over the registry's installed manifests. When the former owner is no longer installed (a rollback), the record is the row's binding to the App's pair, which the save door admits only for a package of that App. Never an id or name prefix.
14+
- **What never follows.** A row bound to, or declaring, a package of another App; a row of another App's pair; a row whose former owner still ships the item (it stays that package's edit); an `object` (it takes no tenant overlay, `ITEM_LOCKED`); and, between two former owners' rows, neither.
15+
- **Nothing is written.** The row keeps its binding and body, so a rollback needs no reverse step; the next save of the item writes the current owner's address, as every save does.

‎content/docs/permissions/tenant-audit-census.mdx‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ are reported as `undecidable` rather than assumed either way.
132132

133133
The same holds twice over for the context. An options argument spelled as a
134134
literal can be read; one spelled `options`, `{ ...opts }`, or handed through a
135-
forwarding shim cannot, and **57 of the 275 sites are spelled that way**. A
135+
forwarding shim cannot, and **57 of the 276 sites are spelled that way**. A
136136
context resolved from an inline literal or a local `const` can be tested for
137137
`isSystem`; one arriving from a helper call cannot.
138138

@@ -197,10 +197,10 @@ reproduce them. Where it disagrees, it disagrees on the page:
197197

198198
| carried figure | where it survives | this census |
199199
| :--- | :--- | ---: |
200-
| 175 write call sites | quoted in the merged changeset | **275** |
200+
| 175 write call sites | quoted in the merged changeset | **276** |
201201
| 24 carrying no tenant context | quoted in the merged changeset | **3** provable and tenancy-enabled; **30** more whose options argument is unreadable |
202-
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **195 of 275** decidable, **80** undecidable |
203-
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 152 decidably elevated, 0 decidably not, 113 undecidable |
202+
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **196 of 276** decidable, **80** undecidable |
203+
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 153 decidably elevated, 0 decidably not, 113 undecidable |
204204
| 141 and 132, two independent re-derivations | the card that filed this work | — |
205205

206206
**The differences are not reconciled, and deliberately so.** The old census's
@@ -211,17 +211,17 @@ at any commit.
211211

212212
Two structural facts do plausibly widen this reading against any hand or regex
213213
one, and both are counted in the generated tables below: the 62 sites reached
214-
through an erased (`any`) receiver, and the 71 that name their object through a
214+
through an erased (`any`) receiver, and the 72 that name their object through a
215215
`const` rather than inline. An instrument that read either the way a person does
216216
would report a smaller number and would not say so.
217217

218218
The fourth row is the one worth flagging to anyone citing it. **The 135 / 77%
219219
figure has no surviving corroboration anywhere in the tree.** This census reads
220-
152 of 275 (55%) as decidably elevated, with 113 more whose elevation is a
220+
153 of 276 (55%) as decidably elevated, with 113 more whose elevation is a
221221
run-time fact — so the claim is neither confirmed nor refuted, and the honest
222222
answer is that a static reading cannot settle it.
223223

224-
⇒ **Cite `3 / 275`, and say what it is**: the sites whose options argument was
224+
⇒ **Cite `3 / 276`, and say what it is**: the sites whose options argument was
225225
READ and holds no tenant context, against a decidably tenancy-enabled object.
226226
That is the control's provable yield surface. ⛔ Do not cite it as "the sites
227227
without tenant context" — **30 further sites** have an options argument this
@@ -233,29 +233,29 @@ cannot read, and they are neither in nor out.
233233

234234
| what | count |
235235
| :--- | ---: |
236-
| write call sites on the application surface | **275** |
237-
| …whose object name is statically decidable | 195 |
236+
| write call sites on the application surface | **276** |
237+
| …whose object name is statically decidable | 196 |
238238
| …whose object name is chosen at run time | 80 |
239-
| …against an object with tenancy ENABLED | 189 |
239+
| …against an object with tenancy ENABLED | 190 |
240240
| …against an object that declares tenancy off | 6 |
241-
| threading a tenant context | 208 |
241+
| threading a tenant context | 209 |
242242
| PROVABLY carrying none (options read, no context key) | **10** |
243243
| …of those, against a decidably tenancy-enabled object | **3** |
244244
| options argument UNREADABLE — may or may not carry one | 57 |
245245
| …of those, against a decidably tenancy-enabled object | 30 |
246-
| threading a decidably ELEVATED (`isSystem`) context | 152 |
246+
| threading a decidably ELEVATED (`isSystem`) context | 153 |
247247
| threading a context that is decidably NOT elevated | 0 |
248248
| threading a context whose elevation is a run-time fact | 113 |
249249

250250
| how the instrument reached the site | count |
251251
| :--- | ---: |
252-
| receiver carried a readable engine type | 213 |
252+
| receiver carried a readable engine type | 214 |
253253
| receiver erased, placed by the object NAME | 52 |
254254
| receiver erased, placed by an `object: string` PARAMETER | 5 |
255255
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 5 |
256256

257257
| object name spelled inline | 124 |
258-
| object name spelled through a `const` | 71 |
258+
| object name spelled through a `const` | 72 |
259259
| object name is an `object: string` parameter | 7 |
260260
| object name is some other run-time expression | 73 |
261261

@@ -307,12 +307,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
307307
their values are not compared. The reasoning, and the measurement behind it,
308308
are in `scripts/check-tenant-audit-census.mjs`.
309309

310-
Measured on 2026-11-08 at `fe3aea79c`.
310+
Measured on 2026-11-08 at `da13e5987`.
311311

312312
| corpus scale (not enforced) | count |
313313
| :--- | ---: |
314-
| tracked non-test sources scanned | 1063 |
315-
| engine-shaped types recognised | 114 |
314+
| tracked non-test sources scanned | 1068 |
315+
| engine-shaped types recognised | 115 |
316316
| declared objects in the registry | 132 |
317317
| same-named calls subtracted as non-engine | 243 |
318318

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts.md‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ silent, and `node scripts/tenant-audit-census.mjs --write` is the resolution.
3333

3434
| Measure | Value |
3535
|---|---:|
36-
| Write call sites | 275 |
37-
| Object name statically decidable | 195 |
36+
| Write call sites | 276 |
37+
| Object name statically decidable | 196 |
3838
| Object name chosen at run time | 80 |
39-
| Against a tenancy-enabled object | 189 |
39+
| Against a tenancy-enabled object | 190 |
4040
| Against an object declaring tenancy off | 6 |
41-
| Threading a tenant context | 208 |
41+
| Threading a tenant context | 209 |
4242
| Provably carrying none | 10 |
4343
| …and decidably tenancy-enabled | 3 |
4444
| Options argument unreadable | 57 |
4545
| …and decidably tenancy-enabled | 30 |
46-
| Threading a decidably elevated context | 152 |
46+
| Threading a decidably elevated context | 153 |
4747
| Threading a decidably non-elevated context | 0 |
4848
| Threading a context of undecidable elevation | 113 |
4949

@@ -90,12 +90,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
9090
their values are not compared. The reasoning, and the measurement behind it,
9191
are in `scripts/check-tenant-audit-census.mjs`.
9292

93-
Measured on 2026-11-08 at `fe3aea79c`.
93+
Measured on 2026-11-08 at `da13e5987`.
9494

9595
| corpus scale (not enforced) | count |
9696
| :--- | ---: |
97-
| tracked non-test sources scanned | 1063 |
98-
| engine-shaped types recognised | 114 |
97+
| tracked non-test sources scanned | 1068 |
98+
| engine-shaped types recognised | 115 |
9999
| declared objects in the registry | 132 |
100100
| same-named calls subtracted as non-engine | 243 |
101101

@@ -158,6 +158,7 @@ Measured on 2026-11-08 at `fe3aea79c`.
158158
| `packages/plugins/plugin-auth/src/idp-group-mapping-admin.ts` | `delete` | `IDP_GROUP_MAPPING_OBJECT` | undecidable | PROVABLY NONE | 1 |
159159
| `packages/plugins/plugin-auth/src/idp-group-mapping-admin.ts` | `insert` | `IDP_GROUP_MAPPING_OBJECT` | undecidable | options unreadable | 1 |
160160
| `packages/plugins/plugin-auth/src/idp-group-mapping-admin.ts` | `insert` | `sys_audit_log` | enabled | elevated | 1 |
161+
| `packages/plugins/plugin-auth/src/idp-group-mapping-admin.ts` | `delete` | `sys_user_permission_set` | enabled | elevated | 1 |
161162
| `packages/plugins/plugin-auth/src/idp-locale-claim.ts` | `update` | `sys_user` | enabled | elevated | 1 |
162163
| `packages/plugins/plugin-auth/src/mcp-client-last-use.ts` | `update` | `sys_oauth_consent` | enabled | elevated | 1 |
163164
| `packages/plugins/plugin-auth/src/member-role-canonical.ts` | `update` | `MEMBER_OBJECT` | undecidable | elevated | 1 |

‎packages/metadata-protocol/src/protocol-environment-rows.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import type { StoredOverlayRow } from './item-lock.js';
5050
import { overlayMemberWhere } from './migrations/overlay-index.js';
5151
import type { ObjectStackProtocolImplementation } from './protocol.js';
5252
import { rowMatchesOverlayWhere, servedOverlayRowCandidates } from './protocol.js';
53-
import { isServedOverrideRowOf } from './served-override.js';
53+
import { holdsServedOverlayCandidate } from './protocol-overlay-merge.js';
5454
import { installedManifestsOfEngine } from './installed-manifests.js';
5555

5656
/**
@@ -64,6 +64,7 @@ export interface EnvironmentRowsHost {
6464
readonly engine: ObjectStackProtocolImplementation['engine'];
6565
readonly findEnvironmentRow: ObjectStackProtocolImplementation['findEnvironmentRow'];
6666
readonly findEnvironmentRows: ObjectStackProtocolImplementation['findEnvironmentRows'];
67+
readonly shippedArtifactsOf: ObjectStackProtocolImplementation['shippedArtifactsOf'];
6768
readonly legacyOrganizationRowsOf: ObjectStackProtocolImplementation['legacyOrganizationRowsOf'];
6869
readonly rethrowUnlessMetadataStoreUnprovisioned: ObjectStackProtocolImplementation['rethrowUnlessMetadataStoreUnprovisioned'];
6970
readonly withoutLegacyOrganizationRows: ObjectStackProtocolImplementation['withoutLegacyOrganizationRows'];
@@ -97,7 +98,7 @@ export async function findEnvironmentRow(this: Pick<EnvironmentRowsHost, 'engine
9798

9899
/** The body of `ObjectStackProtocolImplementation#findServedOverlayRow`; the method's docblock there is its contract. */
99100
export async function findServedOverlayRow(
100-
this: Pick<EnvironmentRowsHost, 'engine' | 'findEnvironmentRow'>,
101+
this: Pick<EnvironmentRowsHost, 'engine' | 'findEnvironmentRow' | 'findEnvironmentRows' | 'shippedArtifactsOf'>,
101102
args: {
102103
type: string;
103104
name: string;
@@ -119,7 +120,14 @@ export async function findServedOverlayRow(
119120
// read); with no package context (legacy/runtime reader), any row.
120121
const other = PLURAL_TO_SINGULAR[args.type] ?? SINGULAR_TO_PLURAL[args.type];
121122
const installed = installedManifestsOfEngine(this.engine);
122-
for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId, servedOverride: args.servedOverride, installed })) {
123+
// [#31593] The code packages that ship the item, read once, when a
124+
// moved edit of it can be a candidate (`suite-moved-overlay.ts`).
125+
let shippers: ReadonlySet<string> | undefined;
126+
const ships = (packageId: string): boolean => {
127+
shippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name, undefined, args.member));
128+
return shippers.has(packageId);
129+
};
130+
for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId, servedOverride: args.servedOverride, installed, ships })) {
123131
const type = candidate.spelling === 'canonical' ? args.type : other;
124132
if (type === undefined) continue;
125133
const where: Record<string, unknown> = {
@@ -130,6 +138,17 @@ export async function findServedOverlayRow(
130138
...overlayMemberWhere(type, args.member),
131139
};
132140
if (candidate.packageId !== undefined) where.package_id = candidate.packageId;
141+
if (candidate.moved === 'base') {
142+
// [#31593] A row bound to a former owner of the item, at any
143+
// binding: every row of the item is read and the predicate
144+
// picks; two former owners' rows are never guessed between.
145+
const rows = activeRows !== undefined && args.state === 'active'
146+
? activeRows.filter((stored) => rowMatchesOverlayWhere(stored, where))
147+
: await this.findEnvironmentRows('sys_metadata', { where, context: { isSystem: true } });
148+
const moved = (rows ?? []).filter((row) => holdsServedOverlayCandidate(candidate, row, installed, ships));
149+
if (moved.length === 1) return { row: moved[0], overrideOf: candidate.overrideOf };
150+
continue;
151+
}
133152
// [#21911, ADR-0096] The explicit system opt-in: a platform store
134153
// read, which no caller's grants scope — the door that asked
135154
// already authorized the caller, and the protocol scopes the row
@@ -143,8 +162,10 @@ export async function findServedOverlayRow(
143162
// candidate only when it declares the override of the address's
144163
// package ({@link isServedOverrideRowOf}, on the row's own binding and
145164
// body): an undeclared row of the pair is the pair's own item.
165+
// [#31593] …and the moved-override candidate only when its body
166+
// declares a former owner of the item ({@link isMovedOverrideRowOf}).
146167
if (candidate.overrideOf !== undefined) {
147-
if (isServedOverrideRowOf(row, candidate.overrideOf, installed)) return { row, overrideOf: candidate.overrideOf };
168+
if (holdsServedOverlayCandidate(candidate, row, installed, ships)) return { row, overrideOf: candidate.overrideOf };
148169
continue;
149170
}
150171
return { row };

0 commit comments

Comments
 (0)