Files
windmill/backend/tests/access_view.rs
9f7d00ef4e feat: grant and remove access from the access view (#12143)
* feat: show what a member, group or service account can access

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: grant and remove access from the access view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: point the EE ref at the access view usage counters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: show an error when what it reads cannot load the item itself

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: close only the grant navigator on escape, not the access view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: name groups in the access view's permission error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: map /access to the acls scope and list each group once

A token with scopes was refused before reaching the access endpoint, and a
member in a workspace group and an instance group of the same name got that
group twice, which broke the drawer's keyed list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: count every registered feature usage action

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: read pinned script versions and resource references in what it reads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: grant full-code apps under raw_app and show a branch from its first page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: type the navigator's reach map by plain string keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: read the operating workspace and user in the access view

GroupEditorDrawer is reachable from a session editor, where the navigation
workspace and user are the parent's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: grant in the operating workspace, not the navigation one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: read a full-code app's frontend source in what it reads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover a member reading their group's access

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: navigator sees folder ownership held through a group

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: what it reads finds resources in JSX, Svelte and Vue source

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: the navigator names the operating user's own grants

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: what it reads matches SDK calls in a component's template

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: what it reads says which paths it finds and which it can't

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: size the groups page loading rows like the loaded ones

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: open a group's access from the groups page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: show access as a folder tree with links to each item

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: show a group's access to superadmins who are not workspace admins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: escape closes only an open row menu in the access view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: rows with a grant menu stay as tall as the rest of the tree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: size the grant menu trigger to the tree row

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: accept instance groups as access view principals

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to c4e610999ca0d1abab06b1660cc48e486ab870b3

This commit updates the EE repository reference after PR #939 was merged in windmill-ee-private.

Previous ee-repo-ref: da6bb1965702eb57237882e5fda6179f72294a06

New ee-repo-ref: c4e610999ca0d1abab06b1660cc48e486ab870b3

Automated by sync-ee-ref workflow.

* chore: update ee-repo-ref to c4e610999ca0d1abab06b1660cc48e486ab870b3

This commit updates the EE repository reference after PR #939 was merged in windmill-ee-private.

Previous ee-repo-ref: da6bb1965702eb57237882e5fda6179f72294a06

New ee-repo-ref: c4e610999ca0d1abab06b1660cc48e486ab870b3

Automated by sync-ee-ref workflow.

* feat: parse item references beside assets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: report what an item reads and who reads it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: load what an item reads from the server

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: describe who performs each read an item makes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: read step paths with the runtime's path parser

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: grant only uncovered rows in the reads panel, show refusals in red

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: make disabled drill picker rows look disabled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: say in the grant navigator when the principal already reads a row

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: correct the operator lock, app source error and admin intro texts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: move what an item reads into its own pull request

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: grant and revoke from one row button in the grant navigator

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: check the static access queries with sqlx macros

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: widen the grant success pill to fit its text

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: let the folder dialog's buttons and the grant navigator answer their own keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: let enter confirm the folder dialog when the row button kept focus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: refuse an unknown principal when browsing items

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: lock a row's grant menu while it saves and show folder levels and empty folders

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: close a row's menu when its change starts so it does not reopen after the reload

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: settle the grant navigator on a failed folder load, search every page and return role lookup errors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-12-02 18:34:51 +01:00

135 lines
4.9 KiB
Rust

//! Another member's access lists paths the caller may not be able to read, so only a workspace
//! admin may ask for it.
//!
//! The auth cache is process-wide and keyed by workspace and token, so a test that gives
//! test-user-2 other groups or folders than another test does signs in with a token of its own.
use sqlx::{Pool, Postgres};
use windmill_test_utils::*;
#[sqlx::test(fixtures("base"))]
async fn test_member_cannot_read_another_members_access(db: Pool<Postgres>) -> anyhow::Result<()> {
initialize_tracing().await;
let server = ApiServer::start(db.clone()).await?;
let url = format!(
"http://localhost:{}/api/w/test-workspace/access/get",
server.addr.port()
);
let client = reqwest::Client::new();
sqlx::raw_sql(
"INSERT INTO group_ (workspace_id, name, summary, extra_perms) VALUES ('test-workspace', 'ops', '', '{}');
INSERT INTO usr_to_group (workspace_id, usr, group_) VALUES ('test-workspace', 'test-user-2', 'ops');
INSERT INTO instance_group (name) VALUES ('sre');
INSERT INTO email_to_igroup (email, igroup) VALUES ('test2@windmill.dev', 'sre')",
)
.execute(&db)
.await?;
// A member may read their own access and their groups', instance groups included, nobody
// else's.
for (principal, status) in [
("u/test-user", 403),
("g/all", 403),
("u/test-user-2", 200),
("g/ops", 200),
("g/sre", 200),
] {
let resp = client
.get(&url)
.query(&[("principal", principal)])
.header("Authorization", "Bearer SECRET_TOKEN_2")
.send()
.await?;
assert_eq!(resp.status(), status, "{principal}: {}", resp.text().await?);
}
// A scoped token reaches the route only if `/access` maps to a scope domain.
let scoped = client
.post(format!(
"http://localhost:{}/api/users/tokens/create",
server.addr.port()
))
.header("Authorization", "Bearer SECRET_TOKEN_2")
.json(&serde_json::json!({ "label": "scoped", "scopes": ["acls:read"], "workspace_id": "test-workspace" }))
.send()
.await?
.text()
.await?;
let resp = client
.get(&url)
.query(&[("principal", "u/test-user-2")])
.header("Authorization", format!("Bearer {scoped}"))
.send()
.await?;
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
Ok(())
}
/// The navigator writes grants with the kind it is given, and `acls/add` sends a full-code app's
/// change to git sync only under `raw_app`. `blocked` must refuse what `acls/add` would refuse.
#[sqlx::test(fixtures("base"))]
async fn test_browse_items_kind_and_blocked(db: Pool<Postgres>) -> anyhow::Result<()> {
initialize_tracing().await;
sqlx::raw_sql(
"INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, created_by)
VALUES ('test-workspace', 'fin', 'fin', '{u/test-user}', '{\"u/test-user-2\": false}', 'test-user');
INSERT INTO app (id, workspace_id, path, summary, policy, versions, extra_perms)
VALUES (1, 'test-workspace', 'f/fin/dash', '', '{}', '{1}', '{}');
INSERT INTO app_version (id, app_id, value, created_by, raw_app)
VALUES (1, 1, '{}', 'test-user', true);
INSERT INTO token (token_hash, token_prefix, token, email, label, super_admin)
VALUES (encode(sha256('BROWSE_TOKEN'::bytea), 'hex'), 'BROWSE_TOK', 'BROWSE_TOKEN',
'test2@windmill.dev', 'browse', false);",
)
.execute(&db)
.await?;
let server = ApiServer::start(db.clone()).await?;
let url = format!(
"http://localhost:{}/api/w/test-workspace/access/browse_items",
server.addr.port()
);
let browse = |token: &str| {
reqwest::Client::new()
.get(&url)
.query(&[("principal", "u/test-user-2"), ("prefix", "f/fin/")])
.header("Authorization", format!("Bearer {token}"))
.send()
};
let member: serde_json::Value = browse("BROWSE_TOKEN")
.await?
.error_for_status()?
.json()
.await?;
assert_eq!(
member["items"],
serde_json::json!([{
"kind": "raw_app",
"path": "f/fin/dash",
"grant": null,
"blocked": "Only admins of the workspace or of f/fin can share it"
}])
);
let admin: serde_json::Value = browse("SECRET_TOKEN")
.await?
.error_for_status()?
.json()
.await?;
assert_eq!(admin["items"][0]["blocked"], serde_json::Value::Null);
// A mistyped principal is refused rather than listed as holding nothing.
let resp = reqwest::Client::new()
.get(&url)
.query(&[("principal", "g/does_not_exist")])
.header("Authorization", "Bearer SECRET_TOKEN")
.send()
.await?;
assert_eq!(resp.status(), 404, "{}", resp.text().await?);
Ok(())
}