fix: readable caller and grants in variable/resource perm errors (#12200)

* fix: show caller identity, not the raw authed struct, in resource perm errors

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

* fix: spell out read/write access in perm error grant lists

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-04 18:13:43 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 26f671fe92
commit 647452b181
2 changed files with 32 additions and 7 deletions
+8 -4
View File
@@ -25,6 +25,7 @@ use windmill_common::workspaces::{check_deploy_rules, operator_can_draft, RuleCh
use crate::secret_backend_ext::rename_vault_secret;
use crate::var_resource_cache::{auth_identity, cache_resource, get_cached_resource};
use crate::variables::{describe_authed, describe_extra_perms};
use windmill_common::utils::{
check_proper_path, check_proper_type_name, escape_ilike_pattern, sanitize_db_error,
BulkDeleteRequest,
@@ -727,13 +728,16 @@ pub async fn explain_resource_perm_error(
.fetch_optional(db)
.await?;
return Err(Error::NotAuthorized(format!(
"Resource exists but you don't have access to it:\nresource perms: {}\nfolder perms: {}\nauthed as: {authed:?}",
serde_json::to_string_pretty(&extra_perms).unwrap_or_default(), serde_json::to_string_pretty(&folder_extra_perms).unwrap_or_default()
"Resource exists but you don't have access to it:\nresource perms: {}\nfolder perms: {}\nauthed as: {}",
describe_extra_perms(Some(&extra_perms)),
describe_extra_perms(folder_extra_perms.as_ref()),
describe_authed(Some(authed))
)));
} else {
return Err(Error::NotAuthorized(format!(
"Resource exists but you don't have access to it:\nresource perms: {}\nauthed as: {authed:?}",
serde_json::to_string_pretty(&extra_perms).unwrap_or_default()
"Resource exists but you don't have access to it:\nresource perms: {}\nauthed as: {}",
describe_extra_perms(Some(&extra_perms)),
describe_authed(Some(authed))
)));
}
}
+24 -3
View File
@@ -480,7 +480,7 @@ async fn get_value(
/// The grants alone can't explain a denial: a job started on behalf of another
/// user is authorized as that user, so the error has to name who was actually
/// asking or it reads as a grant bug.
fn describe_authed(authed: Option<&(impl Authable + Sync)>) -> String {
pub(crate) fn describe_authed(authed: Option<&(impl Authable + Sync)>) -> String {
match authed {
Some(authed) => format!(
"username: {}, email: {}, groups: {:?}, folders: {:?}",
@@ -493,6 +493,25 @@ fn describe_authed(authed: Option<&(impl Authable + Sync)>) -> String {
}
}
/// `extra_perms` maps a `u/<user>` or `g/<group>` to whether it may write; the raw `true` /
/// `false` reads as allowed / denied, so name the access level instead.
pub(crate) fn describe_extra_perms(perms: Option<&Value>) -> String {
let Some(perms) = perms else {
return "folder not found".to_string();
};
let Some(map) = perms.as_object().filter(|m| !m.is_empty()) else {
return "none".to_string();
};
map.iter()
.map(|(grantee, can_write)| match can_write.as_bool() {
Some(true) => format!("{grantee} (read & write)"),
Some(false) => format!("{grantee} (read only)"),
None => format!("{grantee} ({can_write})"),
})
.collect::<Vec<_>>()
.join(", ")
}
/// Including the variable's and its folder's `extra_perms` in the error is intended, not a
/// leak: who holds access to an item is not secret within a workspace, and it tells the
/// denied caller whom to ask. Keep the maps in the message.
@@ -526,12 +545,14 @@ async fn explain_variable_perm_error(
.await?;
return Err(Error::NotAuthorized(format!(
"Variable exists but you don't have access to it:\nvariable perms: {}\nfolder perms: {}\nauthed as: {}",
serde_json::to_string_pretty(&extra_perms).unwrap_or_default(), serde_json::to_string_pretty(&folder_extra_perms).unwrap_or_default(), describe_authed(authed)
describe_extra_perms(Some(&extra_perms)),
describe_extra_perms(folder_extra_perms.as_ref()),
describe_authed(authed)
)));
} else {
return Err(Error::NotAuthorized(format!(
"Variable exists but you don't have access to it:\nvariable perms: {}\nauthed as: {}",
serde_json::to_string_pretty(&extra_perms).unwrap_or_default(),
describe_extra_perms(Some(&extra_perms)),
describe_authed(authed)
)));
}