fix: accept instance groups as access view principals

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-11-03 02:48:29 -08:00
co-authored by Claude Opus 5.5
parent 02452aa8ab
commit 5221f09ffc
3 changed files with 33 additions and 3 deletions
@@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS(SELECT 1 FROM group_ WHERE workspace_id = $1 AND name = $2)\n OR EXISTS(SELECT 1 FROM instance_group WHERE name = $2)",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "?column?",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
null
]
},
"hash": "fa97f5dfbe9772472b16e3987e58343102bb0a0195038d7fdac1e80dd45bf604"
}
+6 -2
View File
@@ -17,17 +17,21 @@ async fn test_member_cannot_read_another_members_access(db: Pool<Postgres>) -> a
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 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', nobody else's.
// 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)
+4 -1
View File
@@ -224,8 +224,11 @@ async fn get_access(
usr.email
}
"g" => {
// Instance groups are granted through the same `g/<name>` keys, and the check above
// lets their members ask, so a name from either table is a group here.
let exists = sqlx::query_scalar!(
"SELECT EXISTS(SELECT 1 FROM group_ WHERE workspace_id = $1 AND name = $2)",
"SELECT EXISTS(SELECT 1 FROM group_ WHERE workspace_id = $1 AND name = $2)
OR EXISTS(SELECT 1 FROM instance_group WHERE name = $2)",
&w_id,
name
)