Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f3782ae
test(service-datasource): measure the package-less Setup datasource c…
claude Dec 4, 2026
9989137
Merge remote-tracking branch 'origin/main' into claude/issue-39398-wip
claude Dec 4, 2026
93d8254
feat(metadata-protocol): the own-reference judge passes the datasourc…
claude Dec 4, 2026
5a86271
fix(service-datasource): the Setup datasource create saves through th…
claude Dec 4, 2026
d2a614a
test(service-datasource): the door's writes go through the kernel sav…
claude Dec 4, 2026
145e2ac
test(metadata-protocol): no wire states the minted reference, and a b…
claude Dec 4, 2026
09cfb0b
docs(spec): register the Setup datasource create's package requiremen…
claude Dec 4, 2026
ef0082b
test(dogfood): the Setup datasource creates name the package they are…
claude Dec 4, 2026
5e5f94b
feat(app-shell): the Setup datasource editor offers the writable pack…
claude Dec 4, 2026
8535319
refactor(service-datasource): drop the door-write tracking the projec…
claude Dec 4, 2026
bd4fb89
docs(audits): regenerate the service-datasource write census (the doo…
claude Dec 4, 2026
6488e4d
fix(service-datasource): relay the kernel's package-less create refus…
claude Dec 4, 2026
ab00da2
test: pin the wire premise on the published save request; guard the c…
claude Dec 4, 2026
7b7c720
test(service-datasource): pay the driver load at collection; the stor…
claude Dec 4, 2026
86b65fa
docs: Metadata-protocol narrowed at minor, and the Setup datasource c…
claude Dec 4, 2026
03546fb
fix(metadata-protocol): the save hands the server-stated minted refer…
claude Dec 4, 2026
30a601c
Merge remote-tracking branch 'origin/main' into claude/issue-39398-wip
claude Dec 4, 2026
a0cb208
chore(metadata-protocol): record the Setup datasource door's save as …
claude Dec 4, 2026
b5ea483
fix(service-datasource): the save's projector leaves the door's own w…
claude Dec 4, 2026
d0dfe00
fix(service-datasource): an edit sends the body a read serves; a refu…
claude Dec 4, 2026
bcda593
fix(metadata-protocol): a body binding a credentials reference retire…
claude Dec 4, 2026
9f9887c
docs(changeset): Clause-② yes (narrowing), naming both arms and the t…
claude Dec 4, 2026
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
33 changes: 33 additions & 0 deletions .changeset/39398-setup-datasource-create-names-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
'@objectstack/service-datasource': minor
'@objectstack/metadata-protocol': minor
'@objectstack/spec': minor
'@object-ui/app-shell': minor
---

fix(service-datasource): a datasource created in Setup is saved through the kernel save, into a named package, and a create naming none is refused `422 WRITABLE_PACKAGE_REQUIRED`

Clause-②: yes (narrowing) — narrowed: a Setup datasource create naming no package is refused, and an edit of a datasource whose stored config or pool the schema refuses is refused until it sends the block corrected; widened in the same change: the `@objectstack/spec/kernel` exports `getMetadataTypeCarryForwardRetirement` and `MetadataCarryForwardRetirement`
Metadata-protocol: narrowed
Skills-docs: updated here — content/docs/data-modeling/external-datasources.mdx (a datasource created in Setup is saved into the writable package the request names; skills/** teach no Setup datasource create)

<!-- adr-0087: registered setup-datasource-create-names-package -->

**BREAKING** accept-set narrowing (ADR-0070 D1; ruling record 7408558495).

- **Before:** `POST /api/v1/datasources` (the Setup "Datasources" create) inserted its row straight into the metadata table, bound to no package, so it was the one create door the kernel's package-less create judgment never saw.
- **Now:** the door's create, edit (`PATCH /api/v1/datasources/{name}`) and credential migration (`POST /api/v1/datasources/{name}/migrate-credential`) are saved through the kernel save, and every judge of that save answers them. A create names its package with `package` in the request body; naming none answers `422 WRITABLE_PACKAGE_REQUIRED` in this door's words, the writable packages on `error.details.writablePackages`, nothing stored and the secret sealed for the request removed again. An empty or non-string `package` answers `400 VALIDATION_ERROR`. An edit and a migration are saved in the package the row is stored in. No new exemption: the reference to the secret the door has just sealed is stated to the save by server code only (never by any HTTP or MCP door), and passes the own-reference rule only when it is the body's reference and no other stored datasource row holds it. A host with no metadata save answers `503 SERVICE_UNAVAILABLE` instead of writing the row itself.
- **Imports land with their datasource.** An object imported from a datasource added in Setup is saved in the package that datasource is stored in; from a package-less one it still lands loose.
- **Console:** the Setup datasource editor shows the refusal in the server's words with one button per writable package, and picking one sends the create again into that package.
- **Not touched:** the door's delete (`DELETE /api/v1/datasources/{name}`) still removes the row directly.

## FROM → TO

| FROM | TO |
|:---|:---|
| `POST /api/v1/datasources` `{ "name": "wh", "driver": "postgres", … }` | `POST /api/v1/datasources` `{ "name": "wh", "driver": "postgres", …, "package": "my_pkg" }` |
| `PATCH /api/v1/datasources/{name}` `{ "active": false }` on a datasource whose stored `config` or `pool` the schema refuses for anything but an inline credential (answered `400 DATASOURCE_ADMIN_ERROR`, naming the key) | `PATCH /api/v1/datasources/{name}` `{ "active": false, "config": { …the stored config without the key the refusal names } }` |

One-line fix: name the writable package the new datasource belongs to; on the second arm, send the corrected `config` (or `pool`) with the edit. An edit of an existing datasource is saved in place on the body a read serves: the credentials a row stored before inline credentials were refused still holds in `config` are carried forward by the save, so its `label` and `active: false` edits keep saving, and a row whose stored config or pool the schema now refuses for any other reason is refused until the edit sends it corrected.

- **A bound reference retires the inline credential, on every door.** A datasource save whose body binds `external.credentialsRef` no longer carries the driver's inline credential slot (`config.password`; turso's `config.authToken`) forward from the stored row: the row is written without it, and the save names each dropped position on its answer (`advisories`, rule `withheld-key-dropped`; the admin door's update answer as `droppedWithheldKeys`). With a reference bound the connect path never reads that slot. The credential migration (`POST /api/v1/datasources/{name}/migrate-credential`) therefore leaves the reference and no inline password at rest, after a restart too. Former alias spellings and a URL-embedded password are still carried forward, and the migration still reports them as `remaining`.
4 changes: 3 additions & 1 deletion content/docs/data-modeling/external-datasources.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ Datasources** (stamped `origin: code`, read-only in the UI) and via
run the "Sync objects" wizard.

A datasource created in Setup (`POST /api/v1/datasources`) is a `datasource`
item of the environment's metadata. Under the `group` and `isolated` tenancy
item saved into the writable package the request names (`package` in the body);
a create naming none is refused `422 WRITABLE_PACKAGE_REQUIRED`, listing the
writable packages. Under the `group` and `isolated` tenancy
postures only the platform operator creates, changes or removes one, or migrates
its credential; any other caller is refused `403`, naming the posture, whatever
it holds, as at the `/meta` doors ([tenancy modes](/docs/deployment/tenancy-modes)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.

| Measure | Value |
|---|---:|
| Write call sites | 6 |
| Object name statically decidable | 6 |
| Write call sites | 4 |
| Object name statically decidable | 4 |
| Object name chosen at run time | 0 |
| Object name spelled inline | 2 |
| Object name spelled through a `const` | 4 |
| Object name spelled through a `const` | 2 |
| Object name is an `object: string` parameter | 0 |
| Object name is some other run-time expression | 0 |
| Against a tenancy-enabled object | 6 |
| Against a tenancy-enabled object | 4 |
| Against an object declaring tenancy off | 0 |
| Threading a tenant context | 6 |
| Threading a tenant context | 4 |
| Provably carrying none (options read, no context key) | 0 |
| …and decidably tenancy-enabled | 0 |
| Options argument unreadable | 0 |
| …and decidably tenancy-enabled | 0 |
| Threading a decidably elevated (`isSystem`) context | 6 |
| Threading a decidably elevated (`isSystem`) context | 4 |
| Threading a decidably non-elevated context | 0 |
| Threading a context of undecidable elevation | 0 |
| Receiver carried a readable engine type | 6 |
| Receiver carried a readable engine type | 4 |
| Receiver erased, placed by the object NAME | 0 |
| Receiver erased, placed by an `object: string` PARAMETER | 0 |
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 0 |
Expand All @@ -48,7 +48,6 @@ a row or a number here — fix the code, or the census, and regenerate.
| file | verb | object | tenancy | tenant context | n |
|---|---|---|---|---|---:|
| `packages/services/service-datasource/src/datasource-admin-plugin.ts` | `delete` | `sys_metadata` | enabled | elevated | 1 |
| `packages/services/service-datasource/src/datasource-admin-plugin.ts` | `insert` | `sys_metadata` | enabled | elevated | 1 |
| `packages/services/service-datasource/src/datasource-admin-plugin.ts` | `update` | `sys_metadata` | enabled | elevated | 2 |
| `packages/services/service-datasource/src/datasource-admin-plugin.ts` | `update` | `sys_metadata` | enabled | elevated | 1 |
| `packages/services/service-datasource/src/datasource-secret-binder.ts` | `delete` | `sys_secret` | enabled | elevated | 1 |
| `packages/services/service-datasource/src/datasource-secret-binder.ts` | `insert` | `sys_secret` | enabled | elevated | 1 |
27 changes: 20 additions & 7 deletions packages/metadata-protocol/src/metadata-redaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@
* ⛔ It does NOT create cleartext, and does not migrate it out either: it
* preserves what is already at rest. Getting stored cleartext OUT of the store
* is #8081 item 3's migration and is deliberately not attempted here — with
* ONE exception the redactor itself declares. A position it names in
* `notCarriedForwardKeys` (#28640 ②B, ruling 6566912252: a connector's
* undeclared `auth` keys, which no door accepts and nothing reads) is never
* re-grafted, so a save of the served form drops it from the row, and the
* save names each dropped position on its answer
* TWO exceptions, both declared in `@objectstack/spec/kernel`, never named
* here. A position the redactor names in `notCarriedForwardKeys` (#28640 ②B,
* ruling 6566912252: a connector's undeclared `auth` keys, which no door
* accepts and nothing reads), and a position the type's carry-forward
* retirement names for the INCOMING body (`getMetadataTypeCarryForwardRetirement`,
* ruling record 7416154891: a datasource's inline credential slot once the
* body binds `external.credentialsRef`, which the connect path then never
* reads), are never re-grafted, so a save of the served form drops them from
* the row, and the save names each dropped position on its answer
* ({@link carryForwardRedactedValuesReportingDrops}).
*
* ## Why nothing is stamped on the wire
Expand All @@ -73,7 +77,7 @@
*/

import { createHmac, randomBytes } from 'node:crypto';
import { getMetadataTypeRedactor } from '@objectstack/spec/kernel';
import { getMetadataTypeCarryForwardRetirement, getMetadataTypeRedactor } from '@objectstack/spec/kernel';
import type { MetadataTypeRedactor } from '@objectstack/spec/kernel';
// [#21120] The family-wide stored-metadata-body primitives — the object set,
// the object predicate, the column names and the body redactor — live in
Expand Down Expand Up @@ -105,6 +109,11 @@ function redactorFor(type: string): MetadataTypeRedactor | undefined {
return getMetadataTypeRedactor(PLURAL_TO_SINGULAR[type] ?? type);
}

/** The type's carry-forward retirement, resolved through the same spelling as {@link redactorFor}. */
function carryForwardRetirementFor(type: string) {
return getMetadataTypeCarryForwardRetirement(PLURAL_TO_SINGULAR[type] ?? type);
}

/**
* Whether any redactor is registered for `type`.
*
Expand Down Expand Up @@ -617,7 +626,11 @@ function planCarryForward<T>(type: string, incoming: T, stored: unknown): { out:
// [#28640 ②B] The withheld positions the redactor marks NOT carried
// forward: never re-grafted, so the save drops each one the stored row
// holds and the incoming body does not — and reports it (`dropped`).
const notCarriedForward = new Set(served.notCarriedForwardKeys ?? []);
// [ruling record 7416154891] …and the ones the type's retirement names for
// what the INCOMING body declares (a bound credentials reference), which
// the stored body alone cannot say on a first bind.
const retiredByIncoming = carryForwardRetirementFor(type)?.(incoming as Record<string, unknown>) ?? [];
const notCarriedForward = new Set([...(served.notCarriedForwardKeys ?? []), ...retiredByIncoming]);
const dropped: string[] = [];
const unchanged = { out: incoming, landed: [] as string[], dropped };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
* seal a new value or keep its own record's stored reference.** A credentials
* reference is minted by the platform when a secret is bound (the datasource
* admin door's `secret`), and the readers of a stored datasource act on
* whatever reference its row holds. This door seals nothing, so the one
* reference a save through it may name is the one its own stored row already
* holds:
* whatever reference its row holds. A save through this door seals nothing
* of its own, so the one reference it may name is the one its own stored row
* already holds, or the one reference the admin door has just sealed for this
* very write (below):
*
* - a create (no stored row) naming any reference is refused;
* - a create (no stored row) naming any reference is refused, unless it is
* the server-stated minted reference;
* - an edit naming a reference other than its row's, or naming one where its
* row holds none, is refused;
* row holds none, is refused, unless it is the server-stated minted
* reference;
* - an edit sending back its row's own reference — the GET → edit → PUT
* round trip, since the read serves the reference — keeps it, and so does a
* first draft sending back the reference of the active row it overlays;
Expand All @@ -41,6 +44,20 @@
* already holds (`source` set: the stored-metadata migration) keep their
* pass-through, as the system principal does under the #27582 rule.
*
* [ADR-0070 D1, ruling record 7408558495 (A2)] The datasource admin door, the
* one sealer of datasource credentials, writes through this save too: it seals
* the secret, then saves the record naming the new reference, and states that
* reference as `mintedCredentialsRef`, a request member server code alone sets
* (no HTTP or MCP door forwards it). That is the parent rule's "seal a new
* value" arm, at the place the sealer now saves. The body's reference passes
* only when it EQUALS the stated one and NO stored `datasource` row other than
* the one this save writes holds it (a newly minted reference is held by none),
* so the statement can never point a datasource at a reference another one
* holds. A stated reference the body does not name changes nothing: the body
* is judged as it would be without it. Only this judge reads the member; every
* other judge, the package-less create judgment included, runs as before, and
* `source` stays unset.
*
* [#27818] The doors that make a STORED body the active row ask the same
* judge, as `door: 'restore'` and `door: 'publish'`: the restore doors
* (`rollbackMetaItem` and `revertCommit`'s restore limb, through the restore
Expand All @@ -65,6 +82,44 @@ function namedCredentialsRef(body: unknown): unknown {
return (external as { credentialsRef?: unknown }).credentialsRef;
}

/**
* [ruling record 7408558495 (A2)] Whether a stored `datasource` row other than
* the one this save writes (`name` in `packageId`'s layer) names `credentialsRef`.
* Every state is read, drafts included: a reference a draft names is held. A
* host with no store to read answers "held", and a read that fails throws: the
* pass is never granted on a read that did not happen.
*
* The reference is compared here, not pushed into the query: it lives inside
* the serialized `metadata` body, which has no column of its own and no
* predicate that is portable across the drivers. The rows read are this
* environment's datasource rows only, and the read runs only on the
* server-stated path, when the body names the stated reference.
*/
async function heldByAnotherDatasourceRow(
engine: { find(object: string, query: Record<string, unknown>): Promise<unknown> } | undefined,
credentialsRef: string,
name: string,
packageId: string | null,
): Promise<boolean> {
if (typeof engine?.find !== 'function') return true;
// A read that fails throws to the save, which answers it: never a pass.
const rows = await engine.find('sys_metadata', { where: { type: 'datasource' }, context: { isSystem: true } });
if (!Array.isArray(rows)) return true;
for (const row of rows as Array<Record<string, unknown>>) {
if (row?.name === name && ((row.package_id as string | null | undefined) ?? null) === packageId) continue;
let body: unknown = row?.metadata;
if (typeof body === 'string') {
try {
body = JSON.parse(body);
} catch {
return true;
}
}
if (namedCredentialsRef(body) === credentialsRef) return true;
}
return false;
}

/**
* The refusal a `datasource` save owes when its body names an
* `external.credentialsRef` its own stored row does not hold, else `undefined`.
Expand All @@ -87,6 +142,17 @@ export async function datasourceCredentialsRefSaveRefusal(args: {
* refusal's words, never what is judged.
*/
door?: 'restore' | 'publish';
/**
* [ruling record 7408558495 (A2)] The reference the datasource admin door
* has just minted for this write (`mintedCredentialsRef` on the save
* request), stated by server code only. See the module header.
*/
mintedCredentialsRef?: string;
/**
* The store, read only when a minted reference is stated and the body
* names it: the "no other row holds it" half of the pass.
*/
engine?: { find(object: string, query: Record<string, unknown>): Promise<unknown> };
}): Promise<(Error & { code: 'VALIDATION_ERROR'; status: 400 }) | undefined> {
if (args.type !== 'datasource' || args.source !== undefined) return undefined;
const named = namedCredentialsRef(args.item);
Expand All @@ -101,6 +167,14 @@ export async function datasourceCredentialsRefSaveRefusal(args: {
}
const own = namedCredentialsRef(head?.body);
if (typeof own === 'string' && own === named) return undefined;
if (
typeof args.mintedCredentialsRef === 'string'
&& args.mintedCredentialsRef !== ''
&& named === args.mintedCredentialsRef
&& !(await heldByAnotherDatasourceRow(args.engine, named, args.name, target.packageId ?? null))
) {
return undefined;
}
const adminDoor = `To bind a credential, send the secret to the datasource admin door instead (Setup → Datasources, `
+ `\`POST /api/v1/datasources\` or \`PATCH /api/v1/datasources/${args.name}\`).`;
const why = 'because a reference is minted by the platform when a secret is bound.';
Expand Down
12 changes: 12 additions & 0 deletions packages/metadata-protocol/src/protocol-door-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ type SaveMetaItemRequest = {
* already holds. Set by server code only; no HTTP door forwards it.
*/
inheritedGrantObjects?: readonly string[],
/**
* [ADR-0070 D1, ruling record 7408558495 (A2)] The `external.credentialsRef`
* the datasource admin door has just minted for this write by sealing a
* secret (`POST /api/v1/datasources`, its `PATCH` with a secret, and the
* credential migration). Read by the own-reference judge alone
* ({@link datasourceCredentialsRefSaveRefusal}): a `datasource` body naming
* exactly this reference passes when no other stored datasource row holds
* it. Every other judge still runs, the package-less create judgment
* included, and `source` stays unset. Set by server code only; no HTTP or
* MCP door forwards it.
*/
mintedCredentialsRef?: string,
/**
* [#38174, ruling 7380917604 (A)] The fifth named exemption from the
* package-less create refusal: a create the organization-ownership
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata-protocol/src/protocol-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ export class ProtocolSaveFacet {
const repo = host.getOverlayRepo();
const credentialsRefRefusal = await datasourceCredentialsRefSaveRefusal({
headAt: (...a) => repo.headAt(...a), type: singularType, name: request.name, item: request.item,
mode, packageId: request.packageId, source: request.source,
mode, packageId: request.packageId, source: request.source, mintedCredentialsRef: request.mintedCredentialsRef, engine: host.engine,
});
if (credentialsRefRefusal) throw credentialsRefRefusal;
}
Expand Down
Loading
Loading