mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
fix: read view-only folder grants in list_ws_specific_versions and agent test runs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c598383f27
commit
235087ae7f
@@ -1,5 +1,11 @@
|
||||
DROP FUNCTION acl_grants_run(JSONB, TEXT[]);
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
EXECUTE replace(pg_get_functiondef('list_ws_specific_versions'::regproc),
|
||||
$r$t.value IN ('true', 'write')$r$, 't.value::boolean IS true');
|
||||
END $$;
|
||||
|
||||
-- Back to booleans, so the casts below hold: a view-only grant becomes a read grant, which runs.
|
||||
DO $$
|
||||
DECLARE t TEXT;
|
||||
|
||||
@@ -35,6 +35,16 @@ BEGIN
|
||||
END LOOP;
|
||||
END $$;
|
||||
|
||||
-- Its folder write check is the same read of a grant: patched in place rather than restated whole.
|
||||
DO $$
|
||||
DECLARE def TEXT := pg_get_functiondef('list_ws_specific_versions'::regproc);
|
||||
BEGIN
|
||||
IF position('t.value::boolean IS true' IN def) = 0 THEN
|
||||
RAISE EXCEPTION 'list_ws_specific_versions no longer reads folder grants as expected';
|
||||
END IF;
|
||||
EXECUTE replace(def, 't.value::boolean IS true', $r$t.value IN ('true', 'write')$r$);
|
||||
END $$;
|
||||
|
||||
-- Whether any of `principals` holds a grant in `extra_perms` of a runnable that includes running.
|
||||
CREATE FUNCTION acl_grants_run(extra_perms JSONB, principals TEXT[])
|
||||
RETURNS BOOLEAN LANGUAGE sql IMMUTABLE AS $$
|
||||
|
||||
@@ -10742,8 +10742,32 @@ async fn run_preview_flow_job(
|
||||
// jobs:run scope so a narrowly-scoped token cannot escape its scope. See run_preview_script.
|
||||
check_scopes(&authed, || format!("jobs:run"))?;
|
||||
require_path_read_access_for_preview(&authed, &raw_flow.path)?;
|
||||
require_preview_label_runnable(&db, &authed, &w_id, RunnableAclKind::Flow, &raw_flow.path)
|
||||
.await?;
|
||||
// A saved agent's test run is this preview of its one-step flow, labelled `<agent>.chat`, as
|
||||
// `job_runnables` recognizes it.
|
||||
let agent_label = (raw_flow.value.modules.len() == 1
|
||||
&& raw_flow.value.modules[0].id == "__wm_agent_root")
|
||||
.then(|| {
|
||||
raw_flow
|
||||
.path
|
||||
.as_deref()
|
||||
.map(|p| p.strip_suffix(".chat").unwrap_or(p).to_string())
|
||||
});
|
||||
match agent_label {
|
||||
Some(label) => {
|
||||
require_preview_label_runnable(&db, &authed, &w_id, RunnableAclKind::Agent, &label)
|
||||
.await?
|
||||
}
|
||||
None => {
|
||||
require_preview_label_runnable(
|
||||
&db,
|
||||
&authed,
|
||||
&w_id,
|
||||
RunnableAclKind::Flow,
|
||||
&raw_flow.path,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
}
|
||||
// Step restrictions apply to a preview as they do to a deployed run, so they are checked
|
||||
// the same way: an invalid entry or an older worker would leave a step unrestricted.
|
||||
if windmill_common::scopes::validate_flow_step_job_token_scopes(&raw_flow.value)? {
|
||||
|
||||
@@ -64,3 +64,30 @@ async fn pairs_prod_and_dev_without_plain_forks(db: Pool<Postgres>) {
|
||||
assert_eq!(versions("lwd").await, vec!["lwd", "lwp"]);
|
||||
assert_eq!(versions("lwf").await, vec!["lwd", "lwf", "lwp"]);
|
||||
}
|
||||
|
||||
/// A member's folder grants are read for each workspace of the chain, a view-only one included.
|
||||
#[sqlx::test(migrations = "../migrations", fixtures("base"))]
|
||||
async fn reads_a_view_only_folder_grant(db: Pool<Postgres>) {
|
||||
insert_ws(&db, "lwp").await;
|
||||
sqlx::query(
|
||||
"INSERT INTO usr (workspace_id, email, username, is_admin, role) \
|
||||
VALUES ('lwp', 'test2@windmill.dev', 'test-user-2', false, 'User')",
|
||||
)
|
||||
.execute(&db)
|
||||
.await
|
||||
.expect("add member");
|
||||
sqlx::query(
|
||||
"INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms) \
|
||||
VALUES ('lwp', 'x', 'x', '{}', '{\"u/test-user-2\": \"read\"}')",
|
||||
)
|
||||
.execute(&db)
|
||||
.await
|
||||
.expect("add folder");
|
||||
|
||||
sqlx::query_scalar::<_, String>(
|
||||
"SELECT ws FROM list_ws_specific_versions('lwp', 'test2@windmill.dev', 'resource', 'u/admin/shared')",
|
||||
)
|
||||
.fetch_all(&db)
|
||||
.await
|
||||
.expect("call list_ws_specific_versions");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
getQueryStmtCountHeuristic,
|
||||
isJobResolvable,
|
||||
parseDbInputFromAssetSyntax,
|
||||
apiErrorMessage
|
||||
apiErrorMessage,
|
||||
canRun
|
||||
} from './utils'
|
||||
|
||||
// Mirrors the backend invariant that only failed or canceled rows can carry a resolution;
|
||||
@@ -600,3 +601,30 @@ describe('apiErrorMessage', () => {
|
||||
expect(apiErrorMessage(new Error('boom'))).toBe('boom')
|
||||
})
|
||||
})
|
||||
|
||||
// Mirrors `require_can_run`: run is the union of a caller's grants, and only `'read'` withholds it.
|
||||
describe('canRun', () => {
|
||||
const user = (o: object = {}) =>
|
||||
({
|
||||
username: 'bob',
|
||||
is_admin: false,
|
||||
is_super_admin: false,
|
||||
pgroups: ['g/ops'],
|
||||
folders_read: ['vo'],
|
||||
folders_view_only: ['vo'],
|
||||
...o
|
||||
}) as any
|
||||
it('withholds run when every grant is view-only', () => {
|
||||
expect(canRun('f/vo/s', { 'u/bob': 'read' }, user())).toBe(false)
|
||||
expect(canRun('f/vo/s', {}, user())).toBe(false)
|
||||
})
|
||||
it('runs on any grant that runs, whichever folder grant there is', () => {
|
||||
expect(canRun('f/vo/s', { 'g/ops': false }, user())).toBe(true)
|
||||
expect(canRun('f/vo/s', { 'u/bob': 'run' }, user())).toBe(true)
|
||||
expect(canRun('f/vo/s', {}, user({ folders_view_only: [] }))).toBe(true)
|
||||
})
|
||||
it('runs what the user or their group owns', () => {
|
||||
expect(canRun('u/bob/s', {}, user())).toBe(true)
|
||||
expect(canRun('g/ops/s', {}, user())).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user