Skip to content

Commit c43de8c

Browse files
committed
test(dogfood): re-point the runAs and anonymous-guest flow pins to flow start admission's record rule
A start input the definition reads as a record id is judged as the caller, for every runAs, before the run exists (#29365). The runAs proofs now hand the flows rows that rule admits (a note the member may read but not write; a row the definition fixes by a literal), and the refusal is pinned as 404 RECORD_NOT_FOUND with no run recorded and nothing disclosed. Claude-Session: https://claude.ai/code/session_01ADHkmSoKQWHgd1oZe8j7Pu Co-authored-by: Claude <noreply@anthropic.com>
1 parent d93acbb commit c43de8c

3 files changed

Lines changed: 207 additions & 27 deletions

File tree

‎packages/qa/dogfood/test/declarative-endpoint-anonymous-guest.dogfood.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
// registered after boot runs last, right before the driver), and what the
2222
// caller is told (status, envelope, and that no byte of the row comes back).
2323
//
24+
// Flow start admission's third question (#29365) runs before the executor: a
25+
// start input the definition reads as a record id is judged as the caller, for
26+
// every runAs, before the run exists. The guest is a caller like any other
27+
// (`isSystem: false`), so a guest start naming a row it cannot read is refused
28+
// `404 RECORD_NOT_FOUND` and the executor is never asked; the executor pin
29+
// below uses a start that names no row.
30+
//
2431
// The fixture is inline and throwaway on purpose, like the policy fixture: it
2532
// exists only to be probed. Every anonymous endpoint carries the armed rate
2633
// limit ADR-0121 D6 makes its publish obligation, so booting at all is a
@@ -282,10 +289,12 @@ describe('[#22147] object_operation at authRequired:false — the anonymous requ
282289
describe('[#22147] flow at authRequired:false — the flow executor is handed the guest', () => {
283290
it('carries the guest position with no user and no elevation, and the run\'s data call never reaches the engine principal-less', async () => {
284291
resetProbes();
292+
// A start that names no row: flow start admission has nothing to load, so
293+
// the executor is reached and its own identity rule is what answers.
285294
const res = await stack.api('/apps/anonguest/read', {
286295
method: 'POST',
287296
headers: { 'content-type': 'application/json' },
288-
body: JSON.stringify({ params: { noteId: seededId } }),
297+
body: JSON.stringify({ params: {} }),
289298
});
290299
const text = await res.text();
291300

@@ -305,4 +314,27 @@ describe('[#22147] flow at authRequired:false — the flow executor is handed th
305314
expect(engineCalls).toEqual([]);
306315
expect(driverReached).toEqual([]);
307316
});
317+
318+
it('a guest start naming a row the guest cannot read is refused at the door as the guest — 404, no run, nothing disclosed', async () => {
319+
resetProbes();
320+
const res = await stack.api('/apps/anonguest/read', {
321+
method: 'POST',
322+
headers: { 'content-type': 'application/json' },
323+
body: JSON.stringify({ params: { noteId: seededId } }),
324+
});
325+
const text = await res.text();
326+
expect(res.status, text).toBe(404);
327+
const body = JSON.parse(text) as { success?: boolean; data?: unknown; error?: { code?: string } };
328+
expect(body.success).toBe(false);
329+
expect(body.error?.code).toBe('RECORD_NOT_FOUND');
330+
expect(body).not.toHaveProperty('data');
331+
expect(text).not.toContain(SEEDED_NAME);
332+
// Refused before the run exists: the executor was never asked.
333+
expect(flowContexts).toEqual([]);
334+
// The door's load of the row ran in the GUEST's scope — never principal-less,
335+
// never the system principal — and no security layer let it reach the driver.
336+
expect(engineCalls.length).toBeGreaterThan(0);
337+
for (const call of engineCalls) expectGuest(call.context);
338+
expect(driverReached).toEqual([]);
339+
});
308340
});

‎packages/qa/dogfood/test/fixtures/flow-runas-fixture.ts‎

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
// through a `runAs: 'user'` PARENT whose `subflow` node calls the elevated child
3535
// (`runas_system_touch_via_parent` / `runas_system_read_via_parent`). The
3636
// elevation the proof is about still belongs to the child; the parent adds none.
37+
//
38+
// Flow start admission's third question (#29365) judges every start input a
39+
// flow's definition reads as a record id (a CRUD node's `filter.id`, handed on
40+
// through `subflow`) in the CALLER's own scope, for every `runAs`, before the
41+
// run exists: an input the caller cannot read is refused 404 RECORD_NOT_FOUND.
42+
// So the proofs pick rows the rule admits:
43+
// • WRITE — an admin note marked `status: 'shared'`, which the member may
44+
// READ (a select-only policy) but still not WRITE (the owner policy): the
45+
// id passes the door, and the write is where the two `runAs` part ways.
46+
// • READ — `runas_<mode>_read_sealed`, whose definition fixes the row by a
47+
// literal (`SEALED_NOTE_NAME`), with no start input at all: the elevated
48+
// read sees an admin note the member cannot, the user-mode read does not.
3749

3850
import { defineStack } from '@objectstack/spec';
3951
import { ObjectSchema, Field } from '@objectstack/spec/data';
@@ -117,10 +129,48 @@ function readFlow(name: string, runAs: 'system' | 'user'): Flow {
117129
};
118130
}
119131

132+
/** The `name` of the admin note the sealed read flows fix by a literal. */
133+
export const SEALED_NOTE_NAME = 'runas-sealed-note';
134+
135+
/** The `status` that makes an admin note readable (never writable) to a member. */
136+
export const SHARED_STATUS = 'shared';
137+
138+
/**
139+
* `runas_<mode>_read_sealed` — start → get_record → end, where the DEFINITION
140+
* names the row (a literal `name` filter) and the start hands it nothing. The
141+
* read is the run's own choice of row, so it shows what the run's identity can
142+
* see, with no caller input for flow start admission to judge.
143+
*/
144+
function sealedReadFlow(name: string, runAs: 'system' | 'user'): Flow {
145+
return {
146+
name,
147+
label: `RunAs ${runAs} sealed read`,
148+
type: 'autolaunched',
149+
runAs,
150+
variables: [{ name: 'found', type: 'text', isOutput: true }],
151+
nodes: [
152+
{ id: 'start', type: 'start', label: 'Start' },
153+
{
154+
id: 'get',
155+
type: 'get_record',
156+
label: 'Get the sealed note',
157+
config: { objectName: 'runas_note', filter: { name: SEALED_NOTE_NAME }, outputVariable: 'found' },
158+
},
159+
{ id: 'end', type: 'end', label: 'End' },
160+
],
161+
edges: [
162+
{ id: 'e1', source: 'start', target: 'get' },
163+
{ id: 'e2', source: 'get', target: 'end' },
164+
],
165+
};
166+
}
167+
120168
export const runasSystemTouch = touchFlow('runas_system_touch', 'system', 'touched-system');
121169
export const runasUserTouch = touchFlow('runas_user_touch', 'user', 'touched-user');
122170
export const runasSystemRead = readFlow('runas_system_read', 'system');
123171
export const runasUserRead = readFlow('runas_user_read', 'user');
172+
export const runasSystemReadSealed = sealedReadFlow('runas_system_read_sealed', 'system');
173+
export const runasUserReadSealed = sealedReadFlow('runas_user_read_sealed', 'user');
124174

125175
/**
126176
* `<child>_via_parent` — start → subflow(child) → end, under `runAs: 'user'`:
@@ -129,14 +179,14 @@ export const runasUserRead = readFlow('runas_user_read', 'user');
129179
* land on the parent's `found` output (so a read child's own `found` arrives as
130180
* `output.found.found` on the trigger response).
131181
*/
132-
function viaParent(child: Flow, withOutput: boolean): Flow {
182+
function viaParent(child: Flow, withOutput: boolean, handsNoteId = true): Flow {
133183
return {
134184
name: `${child.name}_via_parent`,
135185
label: `${child.label} (via a user-mode parent)`,
136186
type: 'autolaunched',
137187
runAs: 'user',
138188
variables: [
139-
{ name: 'noteId', type: 'text', isInput: true },
189+
...(handsNoteId ? [{ name: 'noteId', type: 'text', isInput: true }] : []),
140190
...(withOutput ? [{ name: 'found', type: 'object', isOutput: true }] : []),
141191
],
142192
nodes: [
@@ -148,7 +198,7 @@ function viaParent(child: Flow, withOutput: boolean): Flow {
148198
config: {
149199
flowName: child.name,
150200
// `input.*` is a value slot (#19939): the parent's own input, as a CEL envelope.
151-
input: { noteId: { dialect: 'cel', source: 'noteId' } },
201+
input: handsNoteId ? { noteId: { dialect: 'cel', source: 'noteId' } } : {},
152202
...(withOutput ? { outputVariable: 'found' } : {}),
153203
},
154204
},
@@ -163,6 +213,7 @@ function viaParent(child: Flow, withOutput: boolean): Flow {
163213

164214
export const runasSystemTouchViaParent = viaParent(runasSystemTouch, false);
165215
export const runasSystemReadViaParent = viaParent(runasSystemRead, true);
216+
export const runasSystemReadSealedViaParent = viaParent(runasSystemReadSealed, true, false);
166217

167218
/** A minimal, self-contained app config the dogfood harness can boot. */
168219
export const runasFixtureStack = defineStack({
@@ -182,6 +233,9 @@ export const runasFixtureStack = defineStack({
182233
runasUserRead,
183234
runasSystemTouchViaParent,
184235
runasSystemReadViaParent,
236+
runasSystemReadSealed,
237+
runasUserReadSealed,
238+
runasSystemReadSealedViaParent,
185239
],
186240
});
187241

@@ -191,6 +245,11 @@ export const runasFixtureStack = defineStack({
191245
* owner RLS policy on ALL operations keyed on `created_by`. A member can read
192246
* and write their OWN notes, but neither read nor write the admin's — the exact
193247
* cross-owner isolation the runAs proof needs on both directions.
248+
*
249+
* One select-only policy widens READS alone: an admin note whose `status` is
250+
* `SHARED_STATUS` is readable to the member (read policies OR-combine), and
251+
* stays unwritable (no write policy admits it). That is the row the write
252+
* proof hands a flow: one the caller can show it reads, and cannot touch.
194253
*/
195254
const FIXTURE_MEMBER_SET = 'runas_fixture_member';
196255

@@ -200,7 +259,10 @@ export const runasMemberSet: PermissionSet = PermissionSetSchema.parse({
200259
objects: {
201260
runas_note: { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true },
202261
},
203-
rowLevelSecurity: [RLS.ownerPolicy('runas_note', 'created_by')],
262+
rowLevelSecurity: [
263+
RLS.ownerPolicy('runas_note', 'created_by'),
264+
{ name: 'runas_note_shared_read', object: 'runas_note', operation: 'select', using: `status == '${SHARED_STATUS}'` },
265+
],
204266
});
205267

206268
/**

0 commit comments

Comments
 (0)