mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-12 16:05:43 +00:00
* fix(security): a WM_TOKEN job token can never be a global superadmin (GHSA-hfh4-cx4h-3fcr)
Privilege escalation: an app/flow/schedule/trigger execution policy's `on_behalf_of`
(which a `wm_deployers` member can set) could point at a superadmin email. The
resulting job `WM_TOKEN` then passed the email-based superadmin checks, granting
instance superadmin. `forbid_superadmin_job_token` only guarded ~15 of ~75 routes.
Fix at the token layer: a WM_TOKEN must never satisfy a superadmin gate,
regardless of whose email it runs as (sentinel OR a real superadmin).
- `ApiAuthed` gains a `job_id` field, stamped once in `AuthCache::get_opt_job_authed`
from the resolved token's job_id (correct even on cache hits).
- `require_super_admin(db, email)` -> `require_super_admin(db, &ApiAuthed)`, rejects
`authed.job_id.is_some()`. `require_super_admin_email` kept for the few internal
callers without an ApiAuthed.
- `is_super_admin_authed(db, &ApiAuthed)` for the boolean `is_super_admin_email`
authorization branches on request handlers (workspace deletion, fork drops,
dev-workspace attach/archive, object-storage SSRF exemption, custom dbname, EE GHES
+ connected repositories, ...). Migrate ~75 sites (OSS + EE).
- CUSTOM_INSTANCE_DB reads the *authenticated* job_id, not the caller-supplied
`?job_id` query param. Worker-tag check takes a precomputed job-aware `is_super_admin`
on the request path.
Execution-time on-behalf checks (scheduled/flow worker-tag, Cloud enqueue quota,
is_devops_email) are hardened in a follow-up — see
docs/followup-onbehalf-execution-privilege-hardening.md.
Regression tests: a superadmin-email WM_TOKEN is rejected on `require_super_admin`
routes, on `DELETE /workspaces/delete/{w}` (403, workspace preserved), and on the
CUSTOM_INSTANCE_DB lookup with no `?job_id` (401); real superadmin tokens still succeed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: cap devops role at workspace admin and reject reserved on_behalf_of identities
Extends the job-token cap with three pieces:
- `require_devops_role` takes `&ApiAuthed` and rejects job tokens.
`is_devops_email` is true for superadmin emails, so every worker-management,
instance-config and service-log route was reachable by the same superadmin
`WM_TOKEN` that `require_super_admin` already rejects.
- A `job_id` claim that does not parse as a uuid rejects the token rather than
resolving to `None`, which would clear the job provenance and uncap it. Applies
to the internal JWT and the external `jwt_ext_` path.
- Defense in depth at store time: `validate_on_behalf_of` refuses the reserved
internal sentinels as an `on_behalf_of` on apps/flows/scripts/schedules/triggers,
and app execution refuses a policy carrying one — covering already-persisted and
forked-app rows that predate the cap. Deploying on behalf of a real user,
including a real superadmin, stays allowed; the cap handles that at execution.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(mcp): preserve job-token provenance when minting the proxy JWT
The MCP endpoint-tool proxy re-mints a JWT from the caller's ApiAuthed to
forward the proxied request, but passed job_id: None. A job's WM_TOKEN is
capped at workspace admin (GHSA-hfh4-cx4h-3fcr); dropping the job_id here
re-minted an uncapped token that satisfies require_super_admin /
require_devops_role on the proxied route (e.g. listWorkers exposing worker
IPs, job/workspace IDs, and sensitive tags).
Carry api_authed.job_id into create_jwt_token. Adds an in-module regression
that decodes the forwarded JWT and asserts the job_id is preserved for a job
caller and absent for a non-job caller.
Reported by Codex CI review (P1) on #10124.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: cap the admin-or-devops gate at workspace admin for job tokens
require_admin_or_devops (the EE critical-alerts endpoints) grants when the
caller is a workspace admin OR an instance devops. is_devops_email is true
for superadmins, so a WM_TOKEN running on-behalf of a superadmin who is not a
member of the target workspace could clear the devops branch and read/ack that
workspace's critical alerts (GHSA-hfh4-cx4h-3fcr). This gate takes a bare
email, not an ApiAuthed, so the token-layer cap could not see it.
Thread the caller's job-token provenance and reject the devops branch for job
tokens, matching require_devops_role. The workspace-admin branch stays allowed
— that is the cap ceiling. Adds an enterprise-gated regression proving the
bypass is closed and a real superadmin token still clears the gate.
Found while auditing the PR for bare-email gates the choke-point cap misses.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: cap instance-global is_admin gates at workspace admin for job tokens
Three instance-global routes gate on the caller's own `is_admin` claim, which
`ApiAuthed.is_admin` carries into a WM_TOKEN (it is a workspace-admin claim,
true for superadmins too). A job token is capped at workspace admin
(GHSA-hfh4-cx4h-3fcr), so its is_admin claim must not authorize instance
actions on a route with no workspace binding:
- `unarchive_workspace` — unarchive an arbitrary workspace by id
- `prune_concurrency_group` — delete a global concurrency group
- `list_worker_groups` — return unobfuscated `env_vars_static` (may hold secrets)
Add job-token-aware `is_instance_admin` / `require_instance_admin` helpers (the
same shape as `require_super_admin` / `require_devops_role`) and use them at
these three sites. Workspace-scoped `require_admin(authed.is_admin, ...)` gates
are intentionally left unchanged — a workspace-admin job token is within the
cap there. Regression added covering all three; verified it lets a WM_TOKEN
unarchive/leak without the fix and is blocked with it.
Reported by Codex CI review (P1) on #10124.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(mcp): drop orphaned path_field_renames from EndpointTool test helper
The merge with main adopted main's mcp path-substitution refactor (#10162),
which removed the `path_field_renames` field from `EndpointTool` and its
consumer (`substitute_path_params` no longer takes per-field path renames).
main's `runner.rs` `ep` test helper still constructed the struct with
`path_field_renames: None`, so the workspace test build (cargo test --all,
which compiles windmill-mcp's own #[cfg(test)] module under the `server`
feature) failed with E0560. A plain `cargo check` does not compile that test
module, so it only surfaced in CI's cargo_test.
Remove the orphaned field to match the struct.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test: describe the sentinel-rejection policy the forged-identity test asserts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: complete ApiAuthed initializers in feature-gated tests after merge
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: stop job tokens minting credentials that shed their provenance
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: cap the MCP OAuth approval mint at the same elevated-job-token gate
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: cap the self-service password reset at the elevated-job-token gate
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: cap app embed/SDK mints and scope widening at the elevated-job-token gate
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: keep job tokens from destroying the account they run on behalf of
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: deny job tokens a foreign-workspace admin claim and workspace ejection
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs: keep the follow-up inventory in the PR instead of the repo
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: make the session workspace status gate job-token aware
session_workspace_status derived its superadmin branch from a bare email
check, so a job token carrying a superadmin identity resolved the existence
of workspaces it has no relationship with rather than seeing them as
deleted. Switch to is_super_admin_authed, matching every other instance
gate reached from a request ApiAuthed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* revert: leave the global concurrency-group listing on the plain admin gate
The listing exposes concurrency keys across workspaces, which is metadata
rather than a capability, and it 401s rather than degrading. Keep the guard
on the prune route next to it, which is the destructive one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: keep the instance-admin gate on the global concurrency listing
The listing spans every workspace's concurrency keys, and the gate rejects
only job tokens: the !is_admin branch is the pre-existing check, so
workspaced tokens and interactive admins are unaffected.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* chore: update ee-repo-ref to d30af67d38954f9012f7bad08da23e347344b4c6
This commit updates the EE repository reference after PR #664 was merged in windmill-ee-private.
Previous ee-repo-ref: 7870573dbc3360f99bada143f094c67dce0d9e9c
New ee-repo-ref: d30af67d38954f9012f7bad08da23e347344b4c6
Automated by sync-ee-ref workflow.
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: hugocasa <hugo@casademont.ch>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
313 lines
9.5 KiB
Rust
313 lines
9.5 KiB
Rust
/*
|
|
* Author: Ruben Fiszel
|
|
* Copyright: Windmill Labs, Inc 2022
|
|
* This file and its contents are licensed under the AGPLv3 License.
|
|
* Please see the included NOTICE for copyright information and
|
|
* LICENSE-AGPL for a copy of the license.
|
|
*/
|
|
|
|
// Re-export everything from windmill-api-workspaces
|
|
pub use windmill_api_workspaces::workspaces::*;
|
|
use windmill_api_workspaces::workspaces::{build_copilot_settings_state, InstanceAISummary};
|
|
|
|
use crate::ai::{invalidate_ai_request_cache_for_workspace, AIConfig};
|
|
use crate::db::ApiAuthed;
|
|
#[cfg(feature = "oauth2")]
|
|
use crate::oauth2_oss::workspace_connect_slack;
|
|
use crate::teams_oss::{
|
|
connect_teams, edit_teams_command, run_teams_message_test_job,
|
|
workspaces_list_available_teams_channels, workspaces_list_available_teams_ids,
|
|
};
|
|
|
|
use axum::{
|
|
extract::{Extension, Path},
|
|
routing::{get, post},
|
|
Json, Router,
|
|
};
|
|
use windmill_audit::audit_oss::audit_log;
|
|
use windmill_audit::ActionKind;
|
|
use windmill_common::{
|
|
error::{Error, JsonResult},
|
|
utils::require_admin,
|
|
DB,
|
|
};
|
|
use windmill_git_sync::{handle_deployment_metadata, DeployedObject};
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
use axum::extract::Query;
|
|
#[cfg(feature = "enterprise")]
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
#[cfg(feature = "enterprise")]
|
|
use windmill_common::error::Result;
|
|
#[cfg(feature = "enterprise")]
|
|
use windmill_common::utils::require_admin_or_devops;
|
|
|
|
/// Wraps the subcrate's workspaced_service with routes that depend on windmill-api internals.
|
|
pub fn workspaced_service() -> Router {
|
|
let router = windmill_api_workspaces::workspaces::workspaced_service()
|
|
.route("/edit_teams_command", post(edit_teams_command))
|
|
.route(
|
|
"/available_teams_ids",
|
|
get(workspaces_list_available_teams_ids),
|
|
)
|
|
.route(
|
|
"/available_teams_channels",
|
|
get(workspaces_list_available_teams_channels),
|
|
)
|
|
.route("/connect_teams", post(connect_teams))
|
|
.route(
|
|
"/run_teams_message_test_job",
|
|
post(run_teams_message_test_job),
|
|
)
|
|
.route("/tarball", get(crate::workspaces_export::tarball_workspace))
|
|
.route("/edit_copilot_config", post(edit_copilot_config))
|
|
.route("/get_copilot_info", get(get_copilot_info))
|
|
.route("/critical_alerts", get(get_critical_alerts))
|
|
.route(
|
|
"/critical_alerts/{id}/acknowledge",
|
|
post(acknowledge_critical_alert),
|
|
)
|
|
.route(
|
|
"/critical_alerts/acknowledge_all",
|
|
post(acknowledge_all_critical_alerts),
|
|
)
|
|
.route("/critical_alerts/mute", post(mute_critical_alerts));
|
|
|
|
#[cfg(feature = "oauth2")]
|
|
let router = router.route("/connect_slack", post(workspace_connect_slack));
|
|
|
|
#[cfg(all(feature = "stripe", feature = "enterprise"))]
|
|
{
|
|
crate::stripe_oss::add_stripe_routes(router)
|
|
}
|
|
|
|
#[cfg(not(feature = "stripe"))]
|
|
router
|
|
}
|
|
|
|
async fn edit_copilot_config(
|
|
authed: ApiAuthed,
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
ApiAuthed { is_admin, username, .. }: ApiAuthed,
|
|
Json(ai_config): Json<AIConfig>,
|
|
) -> JsonResult<EditCopilotConfigResponse> {
|
|
require_admin(is_admin, &username)?;
|
|
|
|
if let Some(ref custom_prompts) = ai_config.custom_prompts {
|
|
for (mode, prompt) in custom_prompts.iter() {
|
|
if prompt.len() > MAX_CUSTOM_PROMPT_LENGTH {
|
|
return Err(Error::BadRequest(format!(
|
|
"Custom prompt for mode '{}' exceeds maximum length of {} characters (current: {})",
|
|
mode,
|
|
MAX_CUSTOM_PROMPT_LENGTH,
|
|
prompt.len()
|
|
)));
|
|
}
|
|
}
|
|
}
|
|
|
|
let mut tx = db.begin().await?;
|
|
|
|
sqlx::query!(
|
|
"UPDATE workspace_settings SET ai_config = $1 WHERE workspace_id = $2",
|
|
sqlx::types::Json(&ai_config) as sqlx::types::Json<&AIConfig>,
|
|
&w_id
|
|
)
|
|
.execute(&mut *tx)
|
|
.await?;
|
|
|
|
invalidate_ai_request_cache_for_workspace(&w_id);
|
|
|
|
audit_log(
|
|
&mut *tx,
|
|
&authed,
|
|
"workspaces.edit_copilot_config",
|
|
ActionKind::Update,
|
|
&w_id,
|
|
Some(&authed.email),
|
|
Some([("ai_config", &format!("{:?}", ai_config)[..])].into()),
|
|
)
|
|
.await?;
|
|
tx.commit().await?;
|
|
|
|
handle_deployment_metadata(
|
|
&authed.email,
|
|
&authed.username,
|
|
&db,
|
|
&w_id,
|
|
DeployedObject::Settings { setting_type: "ai_config".to_string() },
|
|
Some("AI configuration updated".to_string()),
|
|
false,
|
|
None,
|
|
)
|
|
.await?;
|
|
|
|
let workspace_has_config = ai_config.has_providers();
|
|
let instance_ai_config =
|
|
sqlx::query_scalar!("SELECT value FROM global_settings WHERE name = 'ai_config'")
|
|
.fetch_optional(&db)
|
|
.await?;
|
|
let settings_state =
|
|
build_copilot_settings_state(workspace_has_config, instance_ai_config.as_ref());
|
|
let effective_ai_config = if workspace_has_config {
|
|
ai_config
|
|
} else if let Some(instance_ai_config) = instance_ai_config {
|
|
serde_json::from_value::<AIConfig>(instance_ai_config).unwrap_or_default()
|
|
} else {
|
|
AIConfig::default()
|
|
};
|
|
|
|
Ok(Json(EditCopilotConfigResponse {
|
|
effective_ai_config,
|
|
has_instance_ai_config: settings_state.has_instance_ai_config,
|
|
uses_instance_ai_config: settings_state.uses_instance_ai_config,
|
|
instance_ai_summary: settings_state.instance_ai_summary,
|
|
}))
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
struct EditCopilotConfigResponse {
|
|
effective_ai_config: AIConfig,
|
|
has_instance_ai_config: bool,
|
|
uses_instance_ai_config: bool,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
instance_ai_summary: Option<InstanceAISummary>,
|
|
}
|
|
|
|
async fn get_copilot_info(
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
) -> JsonResult<AIConfig> {
|
|
let workspace_ai_config = sqlx::query_scalar!(
|
|
"SELECT ai_config as \"ai_config: sqlx::types::Json<AIConfig>\" FROM workspace_settings WHERE workspace_id = $1",
|
|
&w_id
|
|
)
|
|
.fetch_one(&db)
|
|
.await
|
|
.map_err(|e| {
|
|
Error::internal_err(format!(
|
|
"getting ai config: {e:#}"
|
|
))
|
|
})?;
|
|
|
|
if let Some(workspace_ai_config) = workspace_ai_config.filter(|c| c.0.has_providers()) {
|
|
Ok(Json(workspace_ai_config.0))
|
|
} else if let Some(instance_config) =
|
|
sqlx::query_scalar!("SELECT value FROM global_settings WHERE name = 'ai_config'")
|
|
.fetch_optional(&db)
|
|
.await?
|
|
{
|
|
Ok(Json(
|
|
serde_json::from_value::<AIConfig>(instance_config).unwrap_or_default(),
|
|
))
|
|
} else {
|
|
Ok(Json(AIConfig::default()))
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
pub async fn get_critical_alerts(
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
authed: ApiAuthed,
|
|
Query(params): Query<crate::utils::AlertQueryParams>,
|
|
) -> JsonResult<serde_json::Value> {
|
|
require_admin_or_devops(authed.is_admin, &authed.username, &authed.email, authed.job_id.is_some(), &db).await?;
|
|
|
|
crate::utils::get_critical_alerts(db, params, Some(w_id)).await
|
|
}
|
|
|
|
#[cfg(not(feature = "enterprise"))]
|
|
pub async fn get_critical_alerts() -> Error {
|
|
Error::NotFound("Critical Alerts require EE".to_string())
|
|
}
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
pub async fn acknowledge_critical_alert(
|
|
Extension(db): Extension<DB>,
|
|
Path((w_id, id)): Path<(String, i32)>,
|
|
authed: ApiAuthed,
|
|
) -> Result<String> {
|
|
require_admin_or_devops(authed.is_admin, &authed.username, &authed.email, authed.job_id.is_some(), &db).await?;
|
|
crate::utils::acknowledge_critical_alert(db, Some(w_id), id).await
|
|
}
|
|
|
|
#[cfg(not(feature = "enterprise"))]
|
|
pub async fn acknowledge_critical_alert() -> Error {
|
|
Error::NotFound("Critical Alerts require EE".to_string())
|
|
}
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
pub async fn acknowledge_all_critical_alerts(
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
authed: ApiAuthed,
|
|
) -> Result<String> {
|
|
require_admin(authed.is_admin, &authed.username)?;
|
|
crate::utils::acknowledge_all_critical_alerts(db, Some(w_id)).await
|
|
}
|
|
|
|
#[cfg(not(feature = "enterprise"))]
|
|
pub async fn acknowledge_all_critical_alerts() -> Error {
|
|
Error::NotFound("Critical Alerts require EE".to_string())
|
|
}
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
#[derive(Deserialize)]
|
|
pub struct MuteCriticalAlertRequest {
|
|
pub mute_critical_alerts: Option<bool>,
|
|
}
|
|
|
|
#[cfg(feature = "enterprise")]
|
|
async fn mute_critical_alerts(
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
authed: ApiAuthed,
|
|
Json(m_r): Json<MuteCriticalAlertRequest>,
|
|
) -> Result<String> {
|
|
require_admin(authed.is_admin, &authed.username)?;
|
|
|
|
let mute_alerts = m_r.mute_critical_alerts.unwrap_or(false);
|
|
|
|
if mute_alerts {
|
|
sqlx::query!(
|
|
"UPDATE alerts SET acknowledged_workspace = true, acknowledged = true WHERE workspace_id = $1",
|
|
&w_id
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
}
|
|
|
|
sqlx::query!(
|
|
"UPDATE workspace_settings SET mute_critical_alerts = $1 WHERE workspace_id = $2",
|
|
mute_alerts,
|
|
&w_id
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
|
|
handle_deployment_metadata(
|
|
&authed.email,
|
|
&authed.username,
|
|
&db,
|
|
&w_id,
|
|
DeployedObject::Settings { setting_type: "critical_alerts".to_string() },
|
|
None,
|
|
false,
|
|
None,
|
|
)
|
|
.await?;
|
|
|
|
Ok(format!(
|
|
"Updated mute criticital alert ui settings for workspace: {}",
|
|
&w_id
|
|
))
|
|
}
|
|
|
|
#[cfg(not(feature = "enterprise"))]
|
|
pub async fn mute_critical_alerts() -> Error {
|
|
Error::NotFound("Critical Alerts require EE".to_string())
|
|
}
|