fixup! feat: let a service account name who can deploy as it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-10-30 07:24:51 -07:00
co-authored by Claude Opus 5.5
parent 9ad95a2b09
commit dcbf751c21
33 changed files with 142 additions and 1052 deletions
+19 -6
View File
@@ -2851,6 +2851,7 @@ async fn create_app_internal<'a>(
// leaves with a concurrent rename or removal, including a freed username later
// rebinding the stored principal, is known and accepted: see `resolve_on_behalf_of`.
let should_preserve = app.preserve_on_behalf_of.unwrap_or(false)
&& windmill_common::can_preserve_on_behalf_of(&authed)
&& (app.policy.on_behalf_of.is_some() || app.policy.on_behalf_of_email.is_some());
let mut preserved_on_behalf_of: Option<String> = None;
@@ -2865,9 +2866,12 @@ async fn create_app_internal<'a>(
)
.await?;
} else {
let folder_default =
windmill_common::folders::folder_default_for_deploy(&authed, &db, w_id, &app.path)
.await?;
let folder_default = if windmill_common::can_preserve_on_behalf_of(&authed) {
windmill_common::folders::resolve_folder_default_permissioned_as(&db, w_id, &app.path)
.await?
} else {
None
};
app.policy.on_behalf_of =
Some(folder_default.unwrap_or_else(|| username_to_permissioned_as(&authed.username)));
}
@@ -3843,6 +3847,7 @@ async fn update_app_internal<'a>(
let mut preserved_on_behalf_of: Option<String> = None;
if let Some(npolicy) = ns.policy.as_mut() {
let should_preserve = ns.preserve_on_behalf_of.unwrap_or(false)
&& windmill_common::can_preserve_on_behalf_of(&authed)
&& (npolicy.on_behalf_of.is_some() || npolicy.on_behalf_of_email.is_some());
if should_preserve {
@@ -4049,9 +4054,17 @@ async fn update_app_internal<'a>(
.as_deref()
.or(npolicy.on_behalf_of.as_deref())
.unwrap_or("another user");
return Err(Error::PermissionDenied(format!(
"app {path} runs as {runs_as}: change who can open it by deploying it"
)));
return Err(Error::PermissionDenied(if composes_only {
format!(
"app {path} runs as {runs_as}: change who can open it by deploying it"
)
} else {
format!(
"app {path} runs as {runs_as}: only admins and members of \
wm_deployers can change who can open it without deploying it, and a \
deploy from you makes it run as you"
)
}));
}
npolicy.set_execution_mode(mode);
if composes_only {
+9 -16
View File
@@ -9033,8 +9033,8 @@ fn operator_preview_refusal(job_id: Option<Uuid>) -> error::Error {
/// The identity a preview asks to run as, or `None` when it runs as the caller.
///
/// A preview is request-supplied code, so running it as someone else is impersonation, not
/// "running their runnable": only those who may set a runnable's `on_behalf_of` to that identity
/// on deploy (`can_deploy_as`) may ask for it. Naming oneself is always allowed. Operators are
/// "running their runnable": only those who may set a runnable's `on_behalf_of` on deploy
/// (admins and `wm_deployers`) may ask for it. Naming oneself is always allowed. Operators are
/// refused even in `wm_deployers`: the datatable-query exemption lets them reach this route
/// without being able to deploy anything.
pub(crate) async fn preview_on_behalf_of(
@@ -9050,27 +9050,20 @@ pub(crate) async fn preview_on_behalf_of(
if requested == own || requested == authed.email {
return Ok(None);
}
let refused = || {
Error::PermissionDenied(
"Only admins, members of wm_deployers and those a service account's deployers list \
names can run a preview on behalf of another user"
if !role_can_code(db, w_id, authed).await?
|| !windmill_common::can_preserve_on_behalf_of(authed)
{
return Err(Error::PermissionDenied(
"Only admins and members of wm_deployers can run a preview on behalf of another user"
.to_string(),
)
};
if !role_can_code(db, w_id, authed).await? {
return Err(refused());
));
}
let permissioned_as =
windmill_common::resolve_on_behalf_of(None, Some(requested), true, authed, w_id, db)
.await?
.unwrap_or(own.clone());
if permissioned_as == own {
// `resolve_on_behalf_of` falls back to the caller when the target's list refuses them.
return if windmill_common::can_preserve_on_behalf_of(authed) {
Ok(None)
} else {
Err(refused())
};
return Ok(None);
}
let email =
windmill_common::users::get_email_from_permissioned_as_uncached(&permissioned_as, w_id, db)