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
3850import { defineStack } from '@objectstack/spec' ;
3951import { 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+
120168export const runasSystemTouch = touchFlow ( 'runas_system_touch' , 'system' , 'touched-system' ) ;
121169export const runasUserTouch = touchFlow ( 'runas_user_touch' , 'user' , 'touched-user' ) ;
122170export const runasSystemRead = readFlow ( 'runas_system_read' , 'system' ) ;
123171export 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
164214export const runasSystemTouchViaParent = viaParent ( runasSystemTouch , false ) ;
165215export 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. */
168219export 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 */
195254const 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