mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-03 16:02:12 +00:00
* feat: let a workspace withdraw operator schedule and trigger writes Operators can create, edit and delete schedules and triggers today through the API, CLI and MCP, while the operator_settings flags beside them only hide those pages. An admin who wants operators to see what is scheduled without letting them change it cannot express that. Add manage_schedules and manage_triggers as enforced settings, gated at the schedule handlers and at the generic TriggerCrud routes so every trigger kind is covered by one check. They name capabilities operators already hold, so they are granted unless withdrawn, and absence has to mean "never configured" rather than a value. The read coalesces to true; the update endpoint merges into the stored jsonb with the two fields as Option<bool>, so an omitted key keeps what is stored. operator_settings is git-synced as a whole object, so a settings file written before these keys existed reaches the endpoint on every pull, and a serde or SQL default of either polarity would turn that pull into a silent withdrawal or restoration. The rights are read through a per-process cache, so withdrawing one publishes a notify_event that drops the entry on every replica. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dsf6VC4MVLisiEoeQkgbr4 * feat: let operators compose flows when the workspace grants the right Adds operator_settings.builder_flows: a workspace setting that lets every operator compose flows out of runnables that already exist. It does not make them authors. The boundary the operator role draws is authoring code and running arbitrary code, and this does not move it: check_flow_is_composition_only walks the value and refuses anything carrying code, including the shapes an obvious walk misses (code hoisted into a flow_node, an AI agent step's tools, and a linked ai_agent resource whose tool list is resolved at run time). What the walk cannot settle it returns for the caller to authorize under RLS: the worker tags the steps pin, every runnable they reference, and the (path, hash) of every version-pinned step. Composing a path is enough to run it and to run it as whoever it runs as, since the worker resolves a step's path with the root DB handle and adopts that runnable's on_behalf_of. A pinned hash needs its own check because dispatch ignores the path beside it. The gate runs on every write and on both request-supplied-value paths, flow preview and flow dependencies, or either becomes the way to run what the write path refuses. Operators of a builder workspace consume a full author seat; the EE companion carries the counting. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dsf6VC4MVLisiEoeQkgbr4 * feat: enforce operator write rights on the router and in the UI Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: close the capture gap and gate the trigger editors' write actions Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: gate acl writes and the native trigger drawer behind manage rights Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: refuse operator writes with 403 and gate sharing at the drawer Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * perf: resolve identity in the operator write gate only for writes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: gate the suspended-jobs actions and stop the route check refusing reads Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: explain the empty-state create button when operator writes are withdrawn Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: audit operator settings changes and fold path writes into native rows Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: open locked editors read-only and group the operator settings Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: skip email and azure lookups on editor open while triggers are locked Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs: state each operator-rights rationale once in comments Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: address CI review findings on operator write rights Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: keep capture move gated and skip it in the builders while locked Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: refuse builder-rights violations with 403 so operators stay logged in Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor: trim duplication in the operator builder gates Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: hide build app from builder operators on the flow page Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore: point at the companion EE PR merged with EE main Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: keep a builder's drafts list loading past drafts they cannot write Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: hide saved agents from builder operators in the step picker Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore: note the inlined seat rule and drop orphaned sqlx entries Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: stop a builder's step test from logging them out Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: refuse a builder's dependency job on a path it cannot write Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: keep builders from adding dynamic dropdown code to a flow A flow's dropdown code runs as whoever loads its form, so a builder may keep or drop the code stored on the flow it updates, never add or change it. The builder's editor hides the dropdown types and code, and previews options through the deployed flow; the inline dropdown refusal is a 403 so it no longer logs operators out. Also trims rationale comments repeated across sites. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: show why saving operator settings failed The seat-cap refusal on granting builder rights explains what to do; the toast now carries the server's message instead of a generic failure. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: check builder flow drafts like deploys and treat dropdown code as code A developer who loads a builder's flow draft in the editor runs its dynamic dropdown code as themselves, so a builder's draft now passes the same checks as a deploy. Dropdown code is refused like step code rather than kept or dropped, which also removes the exact-match comparison that refused builders over whitespace. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: bill a builder workspace's operators as developers on cloud The cloud seat count behind the Premium page, the sidebar usage and the fork cap still weighed every operator at half a seat, while the builder right makes them authors. The out-of-repo invoicing job must follow the same rule. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: check a builder's flow draft as it will be stored Draft storage strips NUL escapes after the builder check, so a key ending in one (value\u0000, x-windmill-dyn-select-code\u0000) passed the check as an unknown field and was stored under its plain name. The check now reads the sanitized text. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: list a builder's flow drafts and hide hub imports from builders A builder's undeployed flows now appear in the home list, the flow list and the folder counts. Hub project imports and templates bring scripts and apps along, so builders are no longer offered them. The docs record builders' JavaScript expressions as an accepted risk. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: keep the stored builder right when a settings payload omits it A git-synced settings file written before the key existed withdrew the right on every push. builder_flows now follows the manage_* rights: an omitted key leaves the stored value, and the CLI does not count it as a difference. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: word builder refusals by what the flow contains, test the tag refusal A builder refused on a developer's flow never changed its code, so the refusals now describe the flow ("has inline code, so only a developer can edit this flow") rather than an authoring attempt. The grant confirmation uses the neutral dialog: granting changes billing but destroys nothing. The integration test pins the refusal of a worker tag the workspace cannot use. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: read builder rights from the operating workspace, gate the flow page's audit logs entry Builder rights now come from useOperatorBuilderFlows(), next to the schedule and trigger locks, so an editor embedded for another workspace answers about that workspace; the legacy AI chat, one instance for the whole app, reads the navigation workspace. The flow page's Audit logs entry follows the operator audit_logs setting now that builders open that menu. Operator settings reset every value on load, null settings included, so nothing carries over from the previous workspace. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix: pick a dynamic dropdown's code source by the operating user's role The flow input editor, the flow test panel and the flow chat send the dropdown request to the operating workspace, so they now also choose inline versus deployed code by the role held there, through useOperatingUser(), instead of the navigation workspace's. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref to 40ac1c5f8cbce3843b582d9b392d3f3cc7eca3e6 This commit updates the EE repository reference after PR #815 was merged in windmill-ee-private. Previous ee-repo-ref: 31c9e66884b8ca805b20bbfad41fc428fbedbc0e New ee-repo-ref: 40ac1c5f8cbce3843b582d9b392d3f3cc7eca3e6 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
318 lines
10 KiB
Rust
318 lines
10 KiB
Rust
use serde_json::json;
|
|
use sqlx::{Pool, Postgres};
|
|
use windmill_common::workspaces::invalidate_operator_rights_cache;
|
|
use windmill_test_utils::*;
|
|
|
|
const WS: &str = "test-workspace";
|
|
|
|
fn operator_client() -> reqwest::Client {
|
|
let mut headers = reqwest::header::HeaderMap::new();
|
|
headers.insert(
|
|
reqwest::header::AUTHORIZATION,
|
|
reqwest::header::HeaderValue::from_str("Bearer OPERATOR_TOKEN_1").unwrap(),
|
|
);
|
|
reqwest::ClientBuilder::new()
|
|
.default_headers(headers)
|
|
.build()
|
|
.unwrap()
|
|
}
|
|
|
|
async fn set_builder(db: &Pool<Postgres>, flows: bool) -> anyhow::Result<()> {
|
|
sqlx::query(
|
|
"UPDATE workspace_settings SET operator_settings = $1::text::jsonb WHERE workspace_id = $2",
|
|
)
|
|
.bind(format!(r#"{{"builder_flows": {flows}}}"#))
|
|
.bind(WS)
|
|
.execute(db)
|
|
.await?;
|
|
// The right is read through a process-global 60s cache keyed by workspace id.
|
|
invalidate_operator_rights_cache(WS);
|
|
Ok(())
|
|
}
|
|
|
|
async fn add_script(db: &Pool<Postgres>, hash: i64, path: &str, owner: &str) -> anyhow::Result<()> {
|
|
sqlx::query(
|
|
"INSERT INTO script (workspace_id, hash, path, content, language, kind, created_by, schema,
|
|
summary, description, lock, extra_perms)
|
|
VALUES ($1, $2, $3, 'x', 'bun', 'script', $4, '{}', '', '', '', '{}')",
|
|
)
|
|
.bind(WS)
|
|
.bind(hash)
|
|
.bind(path)
|
|
.bind(owner)
|
|
.execute(db)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
|
|
fn composition_flow_at(path: &str, step_path: &str) -> serde_json::Value {
|
|
json!({
|
|
"path": path,
|
|
"summary": "",
|
|
"description": "",
|
|
"schema": {},
|
|
"value": {"modules": [{
|
|
"id": "a",
|
|
"value": {"type": "script", "path": step_path, "input_transforms": {}}
|
|
}]}
|
|
})
|
|
}
|
|
|
|
fn inline_code_flow(path: &str) -> serde_json::Value {
|
|
json!({
|
|
"path": path,
|
|
"summary": "",
|
|
"description": "",
|
|
"schema": {},
|
|
"value": {"modules": [{
|
|
"id": "a",
|
|
"value": {
|
|
"type": "rawscript",
|
|
"content": "export async function main() { return 1 }",
|
|
"language": "bun",
|
|
"input_transforms": {}
|
|
}
|
|
}]}
|
|
})
|
|
}
|
|
|
|
/// The whole boundary in one pass: the builder right lets an operator compose runnables that are
|
|
/// already deployed and nothing more, and the endpoints that author code stay shut whether or not
|
|
/// it is granted.
|
|
#[sqlx::test(migrations = "../migrations", fixtures("base", "permissions_test"))]
|
|
async fn test_operator_builder_flows_boundary(db: Pool<Postgres>) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
let server = ApiServer::start(db.clone()).await?;
|
|
let port = server.addr.port();
|
|
let api = format!("http://localhost:{port}/api/w/{WS}");
|
|
let c = operator_client();
|
|
|
|
// A composition-only flow references a runnable that exists and the builder can read, so the
|
|
// fixture needs one.
|
|
add_script(&db, 4241, "u/operator/some_script", "operator").await?;
|
|
|
|
set_builder(&db, false).await?;
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&composition_flow_at(
|
|
"u/operator/f1",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"an operator without the builder right must not create a flow"
|
|
);
|
|
|
|
set_builder(&db, true).await?;
|
|
// A payload that omits the key, like a git-sync file that predates it, keeps the right.
|
|
let resp = reqwest::Client::new()
|
|
.post(format!("{api}/workspaces/operator_settings"))
|
|
.header("Authorization", "Bearer SECRET_TOKEN")
|
|
.json(&json!({"runs": true}))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
|
|
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&composition_flow_at(
|
|
"u/operator/f1",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"a builder must be able to create a composition-only flow: {}",
|
|
resp.text().await?
|
|
);
|
|
|
|
let mut tagged = composition_flow_at("u/operator/f5", "u/operator/some_script");
|
|
tagged["tag"] = json!("privileged_group");
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&tagged)
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
400,
|
|
"a builder must not route a flow onto a worker tag the workspace cannot use"
|
|
);
|
|
|
|
let mut with_dyn_code = composition_flow_at("u/operator/f1", "u/operator/some_script");
|
|
with_dyn_code["schema"] =
|
|
json!({"x-windmill-dyn-select-code": "x", "x-windmill-dyn-select-lang": "bun"});
|
|
let resp = c
|
|
.post(format!("{api}/flows/update/u/operator/f1"))
|
|
.json(&with_dyn_code)
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not save a flow carrying dropdown code"
|
|
);
|
|
let resp = c
|
|
.post(format!("{api}/jobs/run/dynamic_select"))
|
|
.json(
|
|
&json!({"entrypoint_function": "f", "runnable_ref": {"source": "inline", "code": "x"}}),
|
|
)
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"an operator's inline dropdown refusal must not be a 401"
|
|
);
|
|
|
|
// A dependency job rewrites bookkeeping stored under the path it names, so a builder must not
|
|
// aim one at a path it cannot write.
|
|
let resp = c
|
|
.post(format!("{api}/jobs/run/flow_dependencies"))
|
|
.json(&json!({"path": "u/alice/private_flow", "flow_value": {"modules": []}}))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not run a dependency job on a path it cannot write"
|
|
);
|
|
|
|
// A legacy draft has no owner, so it lists as the builder's own, and a script draft is one
|
|
// the builder cannot write: that row must read as not writable, not fail the whole list.
|
|
sqlx::query(
|
|
"INSERT INTO draft (workspace_id, path, typ, value) VALUES ($1, 'u/operator/some_script', 'script', '{}')",
|
|
)
|
|
.bind(WS)
|
|
.execute(&db)
|
|
.await?;
|
|
let resp = c.get(format!("{api}/drafts/list")).send().await?;
|
|
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
|
|
let drafts: serde_json::Value = resp.json().await?;
|
|
assert_eq!(drafts[0]["can_write"], false, "{drafts}");
|
|
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&inline_code_flow("u/operator/f2"))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not deploy a flow carrying inline code"
|
|
);
|
|
|
|
// Draft storage strips a NUL, turning these keys into the plain ones the check reads.
|
|
let mut nul_value = inline_code_flow("u/operator/f1");
|
|
let v = nul_value.as_object_mut().unwrap().remove("value").unwrap();
|
|
nul_value["value\0"] = v;
|
|
let mut nul_dyn = composition_flow_at("u/operator/f1", "u/operator/some_script");
|
|
nul_dyn["schema"] = json!({"x-windmill-dyn-select-code\0": "x"});
|
|
for (draft, expected) in [
|
|
(
|
|
composition_flow_at("u/operator/f1", "u/operator/some_script"),
|
|
200,
|
|
),
|
|
(inline_code_flow("u/operator/f1"), 403),
|
|
(with_dyn_code.clone(), 403),
|
|
(nul_value, 403),
|
|
(nul_dyn, 403),
|
|
] {
|
|
let resp = c
|
|
.post(format!("{api}/drafts/update/flow/u/operator/f1"))
|
|
.json(&json!({ "value": draft, "force": true }))
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(
|
|
status,
|
|
expected,
|
|
"flow draft {draft}: {}",
|
|
resp.text().await?
|
|
);
|
|
}
|
|
|
|
// Same for the preview path, which runs a request-supplied flow value rather than a stored one.
|
|
let resp = c
|
|
.post(format!("{api}/jobs/run/preview_flow"))
|
|
.json(&json!({"value": inline_code_flow("u/operator/f2")["value"], "args": {}}))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not preview a flow carrying inline code"
|
|
);
|
|
|
|
// Authoring code directly stays shut with the right granted.
|
|
let resp = c
|
|
.post(format!("{api}/scripts/create"))
|
|
.json(&json!({
|
|
"path": "u/operator/s1",
|
|
"summary": "",
|
|
"description": "",
|
|
"content": "export async function main() { return 1 }",
|
|
"language": "bun",
|
|
"is_template": false
|
|
}))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a builder must not create a script"
|
|
);
|
|
|
|
// `permissions_test` gives the operator fixture no rights on `u/alice/**`.
|
|
add_script(&db, 4243, "u/alice/private", "alice").await?;
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&composition_flow_at("u/operator/f4", "u/alice/private"))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not compose a runnable it cannot read"
|
|
);
|
|
|
|
add_script(&db, 4242, "u/operator/pinned", "operator").await?;
|
|
let pinned = |hash: &str| {
|
|
json!({
|
|
"path": "u/operator/f3", "summary": "", "description": "", "schema": {},
|
|
"value": {"modules": [{
|
|
"id": "a",
|
|
"value": {
|
|
"type": "script", "path": "u/operator/pinned", "hash": hash,
|
|
"input_transforms": {}
|
|
}
|
|
}]}
|
|
})
|
|
};
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&pinned("0000000000000000"))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a builder must not pin a hash that is not a version of the step's path"
|
|
);
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&pinned("0000000000001092"))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"a builder must be able to pin the real version of a readable script: {}",
|
|
resp.text().await?
|
|
);
|
|
|
|
Ok(())
|
|
}
|