From 0fcc349e97ac23afb8ba1c930e4b84659ccf58d0 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Wed, 4 Nov 2026 06:35:07 -0800 Subject: [PATCH] docs: describe who performs each read an item makes Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 +++ CONTEXT.md | 7 ++++++ docs/access-reads.md | 56 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 docs/access-reads.md diff --git a/AGENTS.md b/AGENTS.md index 406a9bffd8..e6630fe26e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -47,6 +47,9 @@ Open-source platform for internal tools, workflows, API integrations, background - **Workspace roles**: `docs/workspace-roles.md` — instance-defined roles with per-workspace overrides, the capabilities a role holds, why `ApiAuthed::is_operator` must be derived from the role, and the `role_seat` table billing reads +- **Access reads**: `docs/access-reads.md` — what `/access/reads` says an item reads and who + performs each read (its caller, its account, a step's own account, an app's viewer). The scan + mirrors who the runtime runs each piece as, so changing that changes `tag` in `access_reads.rs`. - **Operator write rights**: `docs/operator-write-rights.md` — which `operator_settings` flags are enforced rather than cosmetic, and why a right that is granted-unless-withdrawn needs `Option` fields and a jsonb merge rather than a serde default diff --git a/CONTEXT.md b/CONTEXT.md index 054960607c..f015fff0a4 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -92,3 +92,10 @@ _Avoid_: permission level, access level, rank Reserved for the path prefix that says where an item lives — `u/alice` or `f/team`. A folder's `owners` column in the database is its admin members; call those admins, never owners, in the UI. _Avoid_: using "owner" for a folder admin + +**Reference**: +A workspace item that a script, flow or app names by path: a resource or variable it reads or +writes, or a script or flow its code starts. The access views turn references into grants. An +**asset** is the data the code touches, such as a data table or an object storage file, recorded +in `asset` rows; a resource can be both, but only a reference says what access the code needs. +_Avoid_: dependency (the packages in a lockfile), asset (for an item the code names) diff --git a/docs/access-reads.md b/docs/access-reads.md new file mode 100644 index 0000000000..b185a26427 --- /dev/null +++ b/docs/access-reads.md @@ -0,0 +1,56 @@ +# What an item reads, and who reads it + +`POST /w/{workspace}/access/reads` (`backend/windmill-api-groups/src/access_reads.rs`) returns +what a script, flow or app reads when it runs, with each read credited to the identity the +runtime performs it as. Two features take a slice of that answer +(`frontend/src/lib/components/access/detectNeeds.ts`): + +- The access view's "What it reads" (`neededByGrantee`) lists what a member needs to run the + item: what whoever opens it reads, the item's own reads when it runs as its caller or as that + member, and the reads of a nested runnable that runs as that member. +- The run-as settings (`neededByRunAs`) list what an account needs when the item runs as it: the + item's own reads and the reads of a nested runnable that runs as that account. + +## Who performs each read + +The scan mirrors the runtime. A change to who a step, a runnable or a task runs as must change +`tag` in `access_reads.rs` too. + +| Code that reads | Reads as | +|---|---| +| A script or flow with no `on_behalf_of` | whoever starts it | +| A script or flow with `on_behalf_of` | that account | +| A flow's inline step, and the JavaScript of its input transforms (`variable('…')`) | the flow's runner | +| A static `$res:`/`$var:` argument | the job that receives it: the flow's runner for an inline step, the step's own runner for a path step | +| A flow step calling a script or flow by path | the target's `on_behalf_of` if set, else the flow's runner; the step needs no read on its target | +| A workflow-as-code `taskScript`/`taskFlow`, an AI agent's tool | like a flow step | +| An AI agent's MCP server and its linked `agent` resource | the agent step's job | +| An SDK `runScriptByPath`/`runFlow` call | the calling job, which needs read on the target; the target then runs as its own `on_behalf_of` if set | +| An app runnable in `publisher`, `guest` or `anonymous` mode, inline or by path | the policy's `on_behalf_of`; a called script's own `on_behalf_of` is dropped | +| An app runnable in `viewer` mode | whoever opens the app | +| A full-code app's frontend files (`value.files`) | whoever opens the app, in every mode | +| A `$res:`/`$var:` link inside a resource's value | whoever reads the resource | + +An app in `publisher`, `guest` or `anonymous` mode whose policy has no `on_behalf_of` fails every +run until it is redeployed. The response's `runs_as` then has no principal, and `errors` says so. + +## How it reads + +- Every item is fetched under the caller's RLS and token scopes, in `user_db` transactions, so + the answer never shows more than the caller can open. The handler takes no `DB`, which keeps a + plain-pool read from being added by accident. An item that is missing and one the caller cannot + read give the same error line. +- A script called by path is read at the version a run starts: its newest version with a lock, + else its newest. A step pinned to a hash reads that hash. +- Code is parsed by the parsers the deploy-time asset inference uses + (`windmill-api-scripts/src/body_parse.rs`), which return the item references beside the assets. + A language with no parser, and code that fails to parse, is scanned lexically for literal SDK + calls. +- A resource asset's access type describes the data behind the resource, and reaching that data + takes read on the resource either way. A write comes only from `setResource`/`setVariable`. +- Assets that are not workspace items, such as data tables and object storage files, are listed + under `others`: item grants do not cover them. +- Not found: a path built while the item runs, passed through a helper, or read in a module the + item imports. +- Limits: 4 levels of steps, SDK runs and agents (resource links add none), 500 items, and 1 MiB + of code parsed per file; past that, code is scanned lexically.