mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
fix: harden role_overrides apply from the settings document (#12255)
* fix: refuse unknown roles and stale operator_settings in settings apply Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep omitted-key clears when a push only removes a workspace role Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: load instance roles on the held connection in the settings document 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:
co-authored by
Claude Opus 5.5
parent
f80d0ee265
commit
84a7672b4e
@@ -7125,17 +7125,9 @@ async fn user_workspaces(
|
||||
};
|
||||
// The pre-roles shape the frontend gates on: present exactly for a restricted member.
|
||||
let operator_settings = (capabilities.is_restricted()).then(|| {
|
||||
let v = &capabilities.visibility;
|
||||
Some(serde_json::json!({
|
||||
"runs": v.runs, "schedules": v.schedules, "resources": v.resources,
|
||||
"variables": v.variables, "assets": v.assets, "triggers": v.triggers,
|
||||
"audit_logs": v.audit_logs, "groups": v.groups, "folders": v.folders,
|
||||
"workers": v.workers,
|
||||
"builder_flows": capabilities.flows != windmill_common::roles::AuthorLevel::None,
|
||||
"builder_apps": capabilities.apps != windmill_common::roles::AuthorLevel::None,
|
||||
"manage_schedules": capabilities.manage_schedules,
|
||||
"manage_triggers": capabilities.manage_triggers,
|
||||
}))
|
||||
Some(windmill_common::roles::legacy_operator_settings(
|
||||
&capabilities,
|
||||
))
|
||||
});
|
||||
workspaces.push(UserWorkspace {
|
||||
id: r.id,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -25,7 +25,7 @@ use windmill_common::{
|
||||
read_role_catalog, DatatableRoleCluster, ADMIN_DATATABLE_ROLE, NO_DEFAULT_DATATABLE_ROLE,
|
||||
},
|
||||
error::{Error, JsonResult, Result},
|
||||
roles::{load_role_overrides, RoleOverrides},
|
||||
roles::{self, load_role_overrides, RoleDefinition, RoleOverride, RoleOverrides},
|
||||
utils::require_admin,
|
||||
variables::build_crypt,
|
||||
workspaces::{
|
||||
@@ -260,14 +260,48 @@ fn datatable_permissions_document(datatable: Option<&Value>, roles: &DatatableNa
|
||||
Value::Object(doc)
|
||||
}
|
||||
|
||||
/// Protection rules by name, their rules in a fixed order so a reordered file is no change. The
|
||||
/// dev workspace lock is left out: the dev workspace setting creates and removes it.
|
||||
/// The workspace's role overrides keyed by role name, sorted so a pulled file is stable.
|
||||
fn role_overrides_document(overrides: &RoleOverrides) -> Value {
|
||||
let sorted: BTreeMap<&String, _> = overrides.iter().collect();
|
||||
serde_json::to_value(sorted).unwrap_or_else(|_| json!({}))
|
||||
/// The workspace's role overrides keyed by role name, sorted so a pulled file is stable. The stored
|
||||
/// map does not tell an override of instance role X from adding role X, so the entry of a role
|
||||
/// the instance does not define carries [`WORKSPACE_ONLY`]: without it, the target instance
|
||||
/// lacking X would silently turn the override into a new role.
|
||||
fn role_overrides_document(overrides: &RoleOverrides, instance: &[RoleDefinition]) -> Value {
|
||||
let sorted: BTreeMap<&String, &RoleOverride> = overrides.iter().collect();
|
||||
let mut doc = serde_json::to_value(sorted).unwrap_or_else(|_| json!({}));
|
||||
if let Some(doc) = doc.as_object_mut() {
|
||||
for (name, entry) in doc.iter_mut() {
|
||||
if !instance.iter().any(|d| &d.name == name) {
|
||||
entry[WORKSPACE_ONLY] = Value::Bool(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
doc
|
||||
}
|
||||
|
||||
const WORKSPACE_ONLY: &str = "workspace_only";
|
||||
|
||||
/// A `role_overrides` entry as the document states it.
|
||||
#[derive(Deserialize)]
|
||||
struct DocumentRoleOverride {
|
||||
#[serde(flatten)]
|
||||
role: RoleOverride,
|
||||
#[serde(default)]
|
||||
workspace_only: bool,
|
||||
}
|
||||
|
||||
/// What `operator_settings` holds for the effective `operator` role: the column is rewritten only
|
||||
/// by the legacy endpoint, so after a role edit it holds stale flags.
|
||||
fn implied_operator_settings(
|
||||
instance: &[RoleDefinition],
|
||||
overrides: &RoleOverrides,
|
||||
) -> Result<Option<Value>> {
|
||||
Ok(roles::effective_roles(instance, overrides)?
|
||||
.iter()
|
||||
.find(|r| r.name == roles::OPERATOR_ROLE)
|
||||
.map(|r| roles::legacy_operator_settings(&r.capabilities)))
|
||||
}
|
||||
|
||||
/// Protection rules by name, their rules in a fixed order so a reordered file is no change. The
|
||||
/// dev workspace lock is left out: the dev workspace setting creates and removes it.
|
||||
async fn protection_rules_document(conn: &mut PgConnection, w_id: &str) -> Result<Value> {
|
||||
let rows = sqlx::query_as::<_, (String, i32, Vec<String>, Vec<String>, Value)>(
|
||||
"SELECT name, rules, bypass_groups, bypass_users, fork_role_mapping FROM workspace_protection_rule
|
||||
@@ -360,7 +394,14 @@ pub async fn load_settings_document(
|
||||
};
|
||||
let datatable_permissions = datatable_permissions_document(row.datatable.as_ref(), &role_names);
|
||||
let protection_rules = protection_rules_document(&mut *conn, w_id).await?;
|
||||
let role_overrides = role_overrides_document(&load_role_overrides(&mut *conn, w_id).await?);
|
||||
let instance = roles::instance_roles_on(&mut *conn).await?;
|
||||
let overrides = load_role_overrides(&mut *conn, w_id).await?;
|
||||
let role_overrides = role_overrides_document(&overrides, &instance);
|
||||
// Present exactly when the column is, as it always was.
|
||||
let operator_settings = match row.operator_settings {
|
||||
Some(stored) => Some(implied_operator_settings(&instance, &overrides)?.unwrap_or(stored)),
|
||||
None => None,
|
||||
};
|
||||
let git_sync = redact_git_sync(row.git_sync);
|
||||
let git_sync = match fork_parent(&mut *conn, w_id).await? {
|
||||
Some(parent) => fork_git_sync_document(git_sync, parent.git_sync),
|
||||
@@ -393,7 +434,7 @@ pub async fn load_settings_document(
|
||||
false,
|
||||
),
|
||||
("color", row.color.map(Value::String), false),
|
||||
("operator_settings", row.operator_settings, false),
|
||||
("operator_settings", operator_settings, false),
|
||||
("role_overrides", Some(role_overrides), true),
|
||||
(
|
||||
"datatable",
|
||||
@@ -923,12 +964,29 @@ async fn plan(db: &DB, w_id: &str, mut desired: Map<String, Value>, replace: boo
|
||||
None => current.remove("git_sync"),
|
||||
};
|
||||
}
|
||||
if !desired.contains_key("role_overrides") {
|
||||
// A file without the roles applies `operator_settings` as it always did: diffed against
|
||||
// the column, since against the value the document derives, an unchanged file with a
|
||||
// stale column would undo a role edit made since.
|
||||
let column: Option<Value> = sqlx::query_scalar(
|
||||
"SELECT operator_settings FROM workspace_settings WHERE workspace_id = $1",
|
||||
)
|
||||
.bind(w_id)
|
||||
.fetch_optional(db)
|
||||
.await?
|
||||
.flatten();
|
||||
match column {
|
||||
Some(column) => current.insert("operator_settings".to_string(), column),
|
||||
None => current.remove("operator_settings"),
|
||||
};
|
||||
}
|
||||
let mc = build_crypt(db, w_id).await?;
|
||||
let names = match desired.get("datatable_permissions") {
|
||||
Some(v) if !v.is_null() => DatatableNames::load(db, w_id, v).await?,
|
||||
_ => DatatableNames::default(),
|
||||
};
|
||||
plan_document(current, desired, replace, &mc, &names)
|
||||
let instance = roles::instance_roles(db).await?;
|
||||
plan_document(current, desired, replace, &mc, &names, &instance)
|
||||
}
|
||||
|
||||
/// A fork's parent, read for its `git_sync`.
|
||||
@@ -1078,6 +1136,7 @@ fn plan_document(
|
||||
replace: bool,
|
||||
mc: &windmill_common::variables::WorkspaceCrypt,
|
||||
names: &DatatableNames,
|
||||
instance: &[RoleDefinition],
|
||||
) -> Result<Plan> {
|
||||
let mut warnings = vec![];
|
||||
let unknown: Vec<&str> = desired
|
||||
@@ -1230,6 +1289,10 @@ fn plan_document(
|
||||
let stated: Vec<String> = desired.keys().cloned().collect();
|
||||
let mut p = Plan { current, desired, replace, changes: vec![], writes: vec![], warnings };
|
||||
|
||||
// Before every other setting, so an instance group mapping or invite can name a role the
|
||||
// file adds; a workspace-only role it removes is dropped last, after whatever named it.
|
||||
let deferred_roles = plan_role_overrides(&mut p, instance)?;
|
||||
|
||||
let webhook = p.legacy("webhook");
|
||||
// The endpoint clears the URL when the body omits it, so the events write sends it along.
|
||||
let url = webhook
|
||||
@@ -1443,7 +1506,13 @@ fn plan_document(
|
||||
|v| json!({ "color": v }),
|
||||
);
|
||||
|
||||
if let Some(desired) = p.managed("operator_settings").filter(|o| !o.is_null()) {
|
||||
// A file that states the roles applies the operator role through them alone: the legacy key
|
||||
// beside them would otherwise re-grant or withdraw flags the file's roles do not hold.
|
||||
let roles_stated = p.managed("role_overrides").is_some();
|
||||
if let Some(desired) = p
|
||||
.managed("operator_settings")
|
||||
.filter(|o| !o.is_null() && !roles_stated)
|
||||
{
|
||||
// The endpoint keeps the stored value of a write right the document omits, so an
|
||||
// older document must not count as differing on those keys.
|
||||
let mut compared = desired.clone();
|
||||
@@ -1472,23 +1541,6 @@ fn plan_document(
|
||||
}
|
||||
}
|
||||
|
||||
// Stated as a whole, after `operator_settings`: a role the map omits loses its override, and
|
||||
// the `operator` override it states wins over the legacy key.
|
||||
if let Some(desired) = p.managed("role_overrides") {
|
||||
let desired = if desired.is_null() {
|
||||
json!({})
|
||||
} else {
|
||||
desired
|
||||
};
|
||||
let overrides: RoleOverrides = serde_json::from_value(desired)
|
||||
.map_err(|e| Error::BadRequest(format!("Invalid role_overrides: {e}")))?;
|
||||
let desired = role_overrides_document(&overrides);
|
||||
if p.differs("role_overrides", &desired) {
|
||||
p.record("role_overrides", desired.clone());
|
||||
p.write(Target::Edit(SettingsEdit::RoleOverrides), desired);
|
||||
}
|
||||
}
|
||||
|
||||
let datatable = p.legacy("datatable");
|
||||
p.simple(
|
||||
"datatable",
|
||||
@@ -1648,11 +1700,25 @@ fn plan_document(
|
||||
.iter()
|
||||
.any(|k| c.key == *k || c.key.starts_with(&format!("{k}.")))
|
||||
});
|
||||
if replace && !changes_stated {
|
||||
if replace && !changes_stated && deferred_roles.is_none() {
|
||||
p.changes.clear();
|
||||
p.writes.clear();
|
||||
}
|
||||
|
||||
match deferred_roles {
|
||||
Some((Some(after), body)) => {
|
||||
p.record("role_overrides", after);
|
||||
p.write(Target::Edit(SettingsEdit::RoleOverrides), body);
|
||||
}
|
||||
// Recorded with the staged write.
|
||||
Some((None, body)) => p.writes.push(Write {
|
||||
target: Target::Edit(SettingsEdit::RoleOverrides),
|
||||
body,
|
||||
keys: vec![],
|
||||
}),
|
||||
None => {}
|
||||
}
|
||||
|
||||
// Refused here rather than by the endpoint, so a dry run already says so.
|
||||
let unavailable: Vec<String> = p
|
||||
.writes
|
||||
@@ -1670,6 +1736,117 @@ fn plan_document(
|
||||
Ok(p)
|
||||
}
|
||||
|
||||
/// Plans `role_overrides`, stated as a whole: a role the map omits loses its override. Refuses,
|
||||
/// before any setting is written, an override of a role the instance does not define. When the
|
||||
/// file removes a workspace-only role, the role is kept until the final write it returns (with
|
||||
/// the change still to record, unless a staged write recorded it), so the in-use check passes
|
||||
/// once the settings naming the role have been rewritten.
|
||||
fn plan_role_overrides(
|
||||
p: &mut Plan,
|
||||
instance: &[RoleDefinition],
|
||||
) -> Result<Option<(Option<Value>, Value)>> {
|
||||
let Some(desired) = p.managed("role_overrides") else {
|
||||
return Ok(None);
|
||||
};
|
||||
let stated: BTreeMap<String, DocumentRoleOverride> = if desired.is_null() {
|
||||
BTreeMap::new()
|
||||
} else {
|
||||
serde_json::from_value(desired)
|
||||
.map_err(|e| Error::BadRequest(format!("Invalid role_overrides: {e}")))?
|
||||
};
|
||||
let previous: RoleOverrides = object_of(p.current.get("role_overrides"))
|
||||
.into_iter()
|
||||
.filter_map(|(name, v)| {
|
||||
Some((
|
||||
name,
|
||||
serde_json::from_value::<DocumentRoleOverride>(v).ok()?.role,
|
||||
))
|
||||
})
|
||||
.collect();
|
||||
let defined = |name: &str| instance.iter().any(|d| d.name == name);
|
||||
let mut errors = vec![];
|
||||
for (name, o) in &stated {
|
||||
match (defined(name), o.workspace_only) {
|
||||
(true, true) => errors.push(format!(
|
||||
"role_overrides marks `{name}` as workspace_only, but this instance defines it: \
|
||||
remove `workspace_only` to override the instance role"
|
||||
)),
|
||||
// An unmarked entry from a file pulled before the marker existed still round-trips
|
||||
// a role the workspace already has.
|
||||
(false, false) if !previous.contains_key(name) => errors.push(format!(
|
||||
"role_overrides overrides role `{name}`, which this instance does not define: \
|
||||
define it in the instance settings (Workspace roles) first, or set \
|
||||
`workspace_only: true` on the entry to add it as a role of this workspace only"
|
||||
)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if !errors.is_empty() {
|
||||
return Err(Error::BadRequest(errors.join("; ")));
|
||||
}
|
||||
let next: RoleOverrides = stated.into_iter().map(|(n, o)| (n, o.role)).collect();
|
||||
|
||||
// Silent only for a legacy key left as pulled, or agreeing with the role it is not applied to.
|
||||
if let (Some(legacy), Some(implied)) = (
|
||||
p.managed("operator_settings").filter(Value::is_object),
|
||||
implied_operator_settings(instance, &next)?,
|
||||
) {
|
||||
let pulled = implied_operator_settings(instance, &previous)?;
|
||||
if legacy_operator_settings_differ(&legacy, &implied)
|
||||
&& pulled.is_none_or(|b| legacy_operator_settings_differ(&legacy, &b))
|
||||
{
|
||||
p.warnings.push(
|
||||
"operator_settings was not applied: role_overrides.operator is what applies. \
|
||||
Edit the operator role there, or pull again to refresh operator_settings."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let after = role_overrides_document(&next, instance);
|
||||
if !p.differs("role_overrides", &after) {
|
||||
return Ok(None);
|
||||
}
|
||||
roles::validate_overrides(instance, &next)?;
|
||||
roles::check_frozen_overrides(instance, &previous, &next)?;
|
||||
let body = |o: &RoleOverrides| {
|
||||
serde_json::to_value(o)
|
||||
.map_err(|e| Error::internal_err(format!("serializing role overrides: {e:#}")))
|
||||
};
|
||||
let mut staged = next.clone();
|
||||
for (name, o) in &previous {
|
||||
if !next.contains_key(name) && !defined(name) {
|
||||
staged.insert(name.clone(), o.clone());
|
||||
}
|
||||
}
|
||||
if staged == next {
|
||||
p.record("role_overrides", after);
|
||||
p.write(Target::Edit(SettingsEdit::RoleOverrides), body(&next)?);
|
||||
return Ok(None);
|
||||
}
|
||||
if staged == previous {
|
||||
return Ok(Some((Some(after), body(&next)?)));
|
||||
}
|
||||
p.record("role_overrides", after);
|
||||
p.write(Target::Edit(SettingsEdit::RoleOverrides), body(&staged)?);
|
||||
Ok(Some((None, body(&next)?)))
|
||||
}
|
||||
|
||||
/// Whether the endpoint would apply `stated` as something other than `reference`: it keeps the
|
||||
/// stored value of an omitted write right, and reads an omitted visibility flag as `false`.
|
||||
fn legacy_operator_settings_differ(stated: &Value, reference: &Value) -> bool {
|
||||
object_of(Some(reference)).iter().any(|(key, value)| {
|
||||
let kept = matches!(
|
||||
key.as_str(),
|
||||
"builder_flows" | "builder_apps" | "manage_schedules" | "manage_triggers"
|
||||
);
|
||||
match stated.get(key) {
|
||||
Some(v) => v != value,
|
||||
None => !kept && value != &Value::Bool(false),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn object_of(v: Option<&Value>) -> Map<String, Value> {
|
||||
v.and_then(Value::as_object).cloned().unwrap_or_default()
|
||||
}
|
||||
@@ -1989,6 +2166,23 @@ mod tests {
|
||||
v.as_object().unwrap().clone()
|
||||
}
|
||||
|
||||
fn plan_document(
|
||||
current: Map<String, Value>,
|
||||
desired: Map<String, Value>,
|
||||
replace: bool,
|
||||
mc: &WorkspaceCrypt,
|
||||
names: &DatatableNames,
|
||||
) -> Result<Plan> {
|
||||
super::plan_document(
|
||||
current,
|
||||
desired,
|
||||
replace,
|
||||
mc,
|
||||
names,
|
||||
&roles::default_instance_roles(),
|
||||
)
|
||||
}
|
||||
|
||||
fn keys(p: &Plan) -> Vec<&str> {
|
||||
p.changes.iter().map(|c| c.key.as_str()).collect()
|
||||
}
|
||||
@@ -2266,48 +2460,104 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn role_overrides_are_applied_as_a_whole_after_operator_settings() {
|
||||
fn role_overrides_name_only_roles_the_instance_defines_or_marks() {
|
||||
let mc = WorkspaceCrypt::new("k");
|
||||
let names = DatatableNames::default();
|
||||
let mut cur = current();
|
||||
cur.insert(
|
||||
"role_overrides".into(),
|
||||
json!({ "auditor": { "workspace_only": true, "capabilities": { "code": false } } }),
|
||||
);
|
||||
let plan = |roles: Value| {
|
||||
plan_document(
|
||||
cur.clone(),
|
||||
doc(json!({ "webhook": "https://b", "role_overrides": roles })),
|
||||
false,
|
||||
&mc,
|
||||
&names,
|
||||
)
|
||||
};
|
||||
|
||||
// An override of a role the instance lacks refuses the whole document.
|
||||
let err = plan(json!({ "reviewer": { "capabilities": { "code": false } } }))
|
||||
.err()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
assert!(err.contains("`reviewer`"), "{err}");
|
||||
assert!(plan(json!({ "operator": { "workspace_only": true } })).is_err());
|
||||
|
||||
// A file pulled before the marker still states the workspace's own role.
|
||||
let p = plan(json!({ "auditor": { "capabilities": { "code": false } } })).unwrap();
|
||||
assert_eq!(keys(&p), ["webhook"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn operator_settings_is_not_applied_beside_the_roles() {
|
||||
let mc = WorkspaceCrypt::new("k");
|
||||
let names = DatatableNames::default();
|
||||
let mut cur = current();
|
||||
cur.insert("role_overrides".into(), json!({}));
|
||||
let pulled = roles::legacy_operator_settings(&roles::RoleCapabilities::OPERATOR);
|
||||
let mut edited = pulled.clone();
|
||||
edited["builder_flows"] = json!(true);
|
||||
let plan = |legacy: &Value, roles: Value| {
|
||||
let d = doc(json!({ "operator_settings": legacy, "role_overrides": roles }));
|
||||
plan_document(cur.clone(), d, false, &mc, &names).unwrap()
|
||||
};
|
||||
|
||||
let p = plan(&pulled, json!({}));
|
||||
assert!(p.writes.is_empty() && p.warnings.is_empty());
|
||||
|
||||
let p = plan(
|
||||
&pulled,
|
||||
json!({ "operator": { "capabilities": { "flows": "compose" } } }),
|
||||
);
|
||||
assert_eq!(keys(&p), ["role_overrides"]);
|
||||
assert!(p.warnings.is_empty());
|
||||
|
||||
let p = plan(&edited, json!({}));
|
||||
assert!(p.writes.is_empty());
|
||||
assert_eq!(p.warnings.len(), 1);
|
||||
}
|
||||
|
||||
#[cfg(feature = "enterprise")]
|
||||
#[test]
|
||||
fn workspace_only_roles_are_added_first_and_removed_last() {
|
||||
let mc = WorkspaceCrypt::new("k");
|
||||
let mut cur = current();
|
||||
cur.insert(
|
||||
"role_overrides".into(),
|
||||
json!({ "operator": { "capabilities": { "manage_schedules": false } } }),
|
||||
json!({ "auditor": { "workspace_only": true, "capabilities": {} } }),
|
||||
);
|
||||
cur.insert(
|
||||
"auto_invite".into(),
|
||||
json!({ "instance_groups": ["g"], "instance_groups_roles": { "g": "auditor" } }),
|
||||
);
|
||||
cur.insert("operator_settings".into(), json!({ "runs": true }));
|
||||
|
||||
// Unchanged: no write.
|
||||
let d = doc(json!({ "role_overrides": {
|
||||
"operator": { "capabilities": { "manage_schedules": false } },
|
||||
} }));
|
||||
let p = plan_document(cur.clone(), d, false, &mc, &DatatableNames::default()).unwrap();
|
||||
assert!(keys(&p).is_empty());
|
||||
|
||||
// A custom role added next to the legacy key: role_overrides is written last.
|
||||
let d = doc(json!({
|
||||
"operator_settings": { "runs": false },
|
||||
"role_overrides": {
|
||||
"operator": { "capabilities": { "manage_schedules": false } },
|
||||
"reviewer": { "label": "Reviewer", "capabilities": { "code": false } },
|
||||
},
|
||||
"role_overrides": { "reviewer": { "workspace_only": true, "capabilities": {} } },
|
||||
"auto_invite": { "instance_groups": ["g"], "instance_groups_roles": { "g": "reviewer" } },
|
||||
}));
|
||||
let p = plan_document(cur.clone(), d, false, &mc, &DatatableNames::default()).unwrap();
|
||||
assert_eq!(keys(&p), ["operator_settings", "role_overrides"]);
|
||||
assert_eq!(keys(&p), ["role_overrides", "auto_invite.instance_groups"]);
|
||||
let bodies: Vec<_> = p.writes.iter().map(|w| (&w.target, &w.body)).collect();
|
||||
assert!(matches!(
|
||||
bodies.as_slice(),
|
||||
[
|
||||
(Target::Edit(SettingsEdit::RoleOverrides), staged),
|
||||
(Target::Edit(SettingsEdit::InstanceGroups), _),
|
||||
(Target::Edit(SettingsEdit::RoleOverrides), last),
|
||||
] if staged.get("auditor").is_some() && staged.get("reviewer").is_some()
|
||||
&& last.get("auditor").is_none()
|
||||
));
|
||||
|
||||
// A push removing only the role still clears what the file omits.
|
||||
let d = doc(json!({ "role_overrides": {} }));
|
||||
let p = plan_document(cur, d, true, &mc, &DatatableNames::default()).unwrap();
|
||||
assert!(keys(&p).contains(&"webhook"));
|
||||
assert!(matches!(
|
||||
p.writes.last().unwrap().target,
|
||||
Target::Edit(SettingsEdit::RoleOverrides)
|
||||
));
|
||||
|
||||
// An empty map is stated, so it clears the workspace's overrides.
|
||||
let p = plan_document(
|
||||
cur,
|
||||
doc(json!({ "role_overrides": {} })),
|
||||
false,
|
||||
&mc,
|
||||
&DatatableNames::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(keys(&p), ["role_overrides"]);
|
||||
assert_eq!(p.writes[0].body, json!({}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -323,6 +323,21 @@ pub fn diff_capabilities(
|
||||
}
|
||||
}
|
||||
|
||||
/// A role's capabilities in the pre-roles `operator_settings` shape, which older clients gate on.
|
||||
pub fn legacy_operator_settings(c: &RoleCapabilities) -> serde_json::Value {
|
||||
let v = &c.visibility;
|
||||
serde_json::json!({
|
||||
"runs": v.runs, "schedules": v.schedules, "resources": v.resources,
|
||||
"variables": v.variables, "assets": v.assets, "triggers": v.triggers,
|
||||
"audit_logs": v.audit_logs, "groups": v.groups, "folders": v.folders,
|
||||
"workers": v.workers,
|
||||
"builder_flows": c.flows != AuthorLevel::None,
|
||||
"builder_apps": c.apps != AuthorLevel::None,
|
||||
"manage_schedules": c.manage_schedules,
|
||||
"manage_triggers": c.manage_triggers,
|
||||
})
|
||||
}
|
||||
|
||||
/// One entry of the instance's [`WORKSPACE_ROLES_SETTING`].
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RoleDefinition {
|
||||
@@ -573,7 +588,8 @@ fn cached_instance_roles() -> Option<Arc<Vec<RoleDefinition>>> {
|
||||
.map(|(r, _)| r)
|
||||
}
|
||||
|
||||
async fn instance_roles_on(conn: &mut sqlx::PgConnection) -> Result<Arc<Vec<RoleDefinition>>> {
|
||||
/// [`instance_roles`] on a connection the caller already holds.
|
||||
pub async fn instance_roles_on(conn: &mut sqlx::PgConnection) -> Result<Arc<Vec<RoleDefinition>>> {
|
||||
if let Some(roles) = cached_instance_roles() {
|
||||
return Ok(roles);
|
||||
}
|
||||
|
||||
Generated
+3
-2
@@ -8514,7 +8514,8 @@ write a secret you were not given: keep the placeholder.
|
||||
| \`default_app\` | Path of the app shown as the workspace home. |
|
||||
| \`default_scripts\` | \`{ order?, hidden?, default_script_content? }\` for the script language picker. |
|
||||
| \`deploy_ui\` | \`{ include_path?, include_type? }\`: what the deploy-to-workspace UI offers. |
|
||||
| \`operator_settings\` | What operators see and do: page visibility flags (\`runs\`, \`schedules\`, \`resources\`, \`variables\`, \`assets\`, \`audit_logs\`, \`groups\`, \`folders\`, \`workers\`, \`triggers\`) and write rights (\`manage_schedules\`, \`manage_triggers\`, \`builder_flows\`, \`builder_apps\`). A write right the value omits keeps its stored value. |
|
||||
| \`role_overrides\` | \`{ <role>: { label?, capabilities, workspace_only? } }\`: the workspace's overrides of the instance's roles, and with \`workspace_only: true\` a role of this workspace only (Enterprise). A role the value omits loses its override. Overriding a role the instance does not define is refused. Edit operator rights in \`role_overrides.operator\`. |
|
||||
| \`operator_settings\` | Legacy view of the \`operator\` role, kept for older servers: page visibility flags (\`runs\`, \`schedules\`, \`resources\`, \`variables\`, \`assets\`, \`audit_logs\`, \`groups\`, \`folders\`, \`workers\`, \`triggers\`) and write rights (\`manage_schedules\`, \`manage_triggers\`, \`builder_flows\`, \`builder_apps\`). Not applied when the document also states \`role_overrides\`. |
|
||||
| \`mute_critical_alerts\` | Mute the workspace's critical alerts. |
|
||||
| \`slack_team_id\`, \`slack_name\` | Read only: set by connecting Slack on the settings page. |
|
||||
| \`slack_command_script\` / \`teams_command_script\` | Script or flow handling the Slack / Teams command. |
|
||||
@@ -8536,7 +8537,7 @@ only show them, \`-y\` to skip the question, \`--replace\` to clear what the fil
|
||||
With \`includeSettings: true\` in \`wmill.yaml\`, \`wmill sync pull\` writes the document to
|
||||
\`settings.yaml\`, secrets encrypted with the workspace key (plaintext only with \`plainSecrets\`), and
|
||||
\`wmill sync push\` applies it. Unlike a partial apply, a push treats the file as the whole
|
||||
document: a setting the file omits is cleared, except \`operator_settings\`, \`color\`, the auto-invite
|
||||
document: a setting the file omits is cleared, except \`operator_settings\`, \`role_overrides\`, \`color\`, the auto-invite
|
||||
instance groups, and the keys \`ducklake\`, \`dbt_warehouses\`, \`deploy_ui\`, \`teams_command_script\`,
|
||||
\`public_app_execution_limit_per_minute\`, \`guest_jwt_public_key\`, \`guest_jwt_jwks_url\`,
|
||||
\`error_handler_fallback_to_instance_alerts\` and
|
||||
|
||||
@@ -101,3 +101,25 @@ key equal to what the instance gives that role, and the payload is mirrored into
|
||||
workspace had changed from its default into `role_overrides.operator` the same way. The workspace
|
||||
list still returns an `operator_settings` object for a restricted member, synthesized from its
|
||||
role, alongside `role` and `capabilities`.
|
||||
|
||||
## In the settings document
|
||||
|
||||
`role_overrides` in the settings document (export `settings.json`, `settings.yaml`, git sync) is
|
||||
the stored map, except that the entry of a role the instance does not define carries
|
||||
`workspace_only: true`. The stored map cannot tell an override of instance role X from adding role
|
||||
X, and the target of a promotion may lack X. So the apply refuses the whole document, dry run
|
||||
included, before writing anything, if:
|
||||
|
||||
- an unmarked entry names a role the target instance does not define, unless the target workspace
|
||||
already has it as a workspace-only role (a file pulled before the marker existed), or
|
||||
- a marked entry names a role the target instance defines.
|
||||
|
||||
The marker is never stored. Roles are written before every other setting, so an instance group
|
||||
mapping in the same file can name a role it adds. A workspace-only role the file removes is kept
|
||||
until a final write, after whatever named it has been rewritten, so the in-use check passes.
|
||||
|
||||
The document's `operator_settings` is derived from the effective `operator` role, not read from
|
||||
the column: only the legacy endpoint rewrites the column, so after a role edit it holds stale
|
||||
flags. A document that states `role_overrides` never applies `operator_settings`, and warns when
|
||||
it was edited to disagree with the operator role. A document without `role_overrides` (pulled
|
||||
before roles existed) applies it as before, diffed against the column.
|
||||
|
||||
@@ -1622,7 +1622,8 @@ write a secret you were not given: keep the placeholder.
|
||||
| \`default_app\` | Path of the app shown as the workspace home. |
|
||||
| \`default_scripts\` | \`{ order?, hidden?, default_script_content? }\` for the script language picker. |
|
||||
| \`deploy_ui\` | \`{ include_path?, include_type? }\`: what the deploy-to-workspace UI offers. |
|
||||
| \`operator_settings\` | What operators see and do: page visibility flags (\`runs\`, \`schedules\`, \`resources\`, \`variables\`, \`assets\`, \`audit_logs\`, \`groups\`, \`folders\`, \`workers\`, \`triggers\`) and write rights (\`manage_schedules\`, \`manage_triggers\`, \`builder_flows\`, \`builder_apps\`). A write right the value omits keeps its stored value. |
|
||||
| \`role_overrides\` | \`{ <role>: { label?, capabilities, workspace_only? } }\`: the workspace's overrides of the instance's roles, and with \`workspace_only: true\` a role of this workspace only (Enterprise). A role the value omits loses its override. Overriding a role the instance does not define is refused. Edit operator rights in \`role_overrides.operator\`. |
|
||||
| \`operator_settings\` | Legacy view of the \`operator\` role, kept for older servers: page visibility flags (\`runs\`, \`schedules\`, \`resources\`, \`variables\`, \`assets\`, \`audit_logs\`, \`groups\`, \`folders\`, \`workers\`, \`triggers\`) and write rights (\`manage_schedules\`, \`manage_triggers\`, \`builder_flows\`, \`builder_apps\`). Not applied when the document also states \`role_overrides\`. |
|
||||
| \`mute_critical_alerts\` | Mute the workspace's critical alerts. |
|
||||
| \`slack_team_id\`, \`slack_name\` | Read only: set by connecting Slack on the settings page. |
|
||||
| \`slack_command_script\` / \`teams_command_script\` | Script or flow handling the Slack / Teams command. |
|
||||
|
||||
@@ -52,7 +52,8 @@ write a secret you were not given: keep the placeholder.
|
||||
| `default_app` | Path of the app shown as the workspace home. |
|
||||
| `default_scripts` | `{ order?, hidden?, default_script_content? }` for the script language picker. |
|
||||
| `deploy_ui` | `{ include_path?, include_type? }`: what the deploy-to-workspace UI offers. |
|
||||
| `operator_settings` | What operators see and do: page visibility flags (`runs`, `schedules`, `resources`, `variables`, `assets`, `audit_logs`, `groups`, `folders`, `workers`, `triggers`) and write rights (`manage_schedules`, `manage_triggers`, `builder_flows`, `builder_apps`). A write right the value omits keeps its stored value. |
|
||||
| `role_overrides` | `{ <role>: { label?, capabilities, workspace_only? } }`: the workspace's overrides of the instance's roles, and with `workspace_only: true` a role of this workspace only (Enterprise). A role the value omits loses its override. Overriding a role the instance does not define is refused. Edit operator rights in `role_overrides.operator`. |
|
||||
| `operator_settings` | Legacy view of the `operator` role, kept for older servers: page visibility flags (`runs`, `schedules`, `resources`, `variables`, `assets`, `audit_logs`, `groups`, `folders`, `workers`, `triggers`) and write rights (`manage_schedules`, `manage_triggers`, `builder_flows`, `builder_apps`). Not applied when the document also states `role_overrides`. |
|
||||
| `mute_critical_alerts` | Mute the workspace's critical alerts. |
|
||||
| `slack_team_id`, `slack_name` | Read only: set by connecting Slack on the settings page. |
|
||||
| `slack_command_script` / `teams_command_script` | Script or flow handling the Slack / Teams command. |
|
||||
@@ -74,7 +75,7 @@ only show them, `-y` to skip the question, `--replace` to clear what the file om
|
||||
With `includeSettings: true` in `wmill.yaml`, `wmill sync pull` writes the document to
|
||||
`settings.yaml`, secrets encrypted with the workspace key (plaintext only with `plainSecrets`), and
|
||||
`wmill sync push` applies it. Unlike a partial apply, a push treats the file as the whole
|
||||
document: a setting the file omits is cleared, except `operator_settings`, `color`, the auto-invite
|
||||
document: a setting the file omits is cleared, except `operator_settings`, `role_overrides`, `color`, the auto-invite
|
||||
instance groups, and the keys `ducklake`, `dbt_warehouses`, `deploy_ui`, `teams_command_script`,
|
||||
`public_app_execution_limit_per_minute`, `guest_jwt_public_key`, `guest_jwt_jwks_url`,
|
||||
`error_handler_fallback_to_instance_alerts` and
|
||||
|
||||
@@ -47,7 +47,8 @@ write a secret you were not given: keep the placeholder.
|
||||
| `default_app` | Path of the app shown as the workspace home. |
|
||||
| `default_scripts` | `{ order?, hidden?, default_script_content? }` for the script language picker. |
|
||||
| `deploy_ui` | `{ include_path?, include_type? }`: what the deploy-to-workspace UI offers. |
|
||||
| `operator_settings` | What operators see and do: page visibility flags (`runs`, `schedules`, `resources`, `variables`, `assets`, `audit_logs`, `groups`, `folders`, `workers`, `triggers`) and write rights (`manage_schedules`, `manage_triggers`, `builder_flows`, `builder_apps`). A write right the value omits keeps its stored value. |
|
||||
| `role_overrides` | `{ <role>: { label?, capabilities, workspace_only? } }`: the workspace's overrides of the instance's roles, and with `workspace_only: true` a role of this workspace only (Enterprise). A role the value omits loses its override. Overriding a role the instance does not define is refused. Edit operator rights in `role_overrides.operator`. |
|
||||
| `operator_settings` | Legacy view of the `operator` role, kept for older servers: page visibility flags (`runs`, `schedules`, `resources`, `variables`, `assets`, `audit_logs`, `groups`, `folders`, `workers`, `triggers`) and write rights (`manage_schedules`, `manage_triggers`, `builder_flows`, `builder_apps`). Not applied when the document also states `role_overrides`. |
|
||||
| `mute_critical_alerts` | Mute the workspace's critical alerts. |
|
||||
| `slack_team_id`, `slack_name` | Read only: set by connecting Slack on the settings page. |
|
||||
| `slack_command_script` / `teams_command_script` | Script or flow handling the Slack / Teams command. |
|
||||
@@ -70,7 +71,7 @@ only show them, `-y` to skip the question, `--replace` to clear what the file om
|
||||
With `includeSettings: true` in `wmill.yaml`, `wmill sync pull` writes the document to
|
||||
`settings.yaml`, secrets encrypted with the workspace key (plaintext only with `plainSecrets`), and
|
||||
`wmill sync push` applies it. Unlike a partial apply, a push treats the file as the whole
|
||||
document: a setting the file omits is cleared, except `operator_settings`, `color`, the auto-invite
|
||||
document: a setting the file omits is cleared, except `operator_settings`, `role_overrides`, `color`, the auto-invite
|
||||
instance groups, and the keys `ducklake`, `dbt_warehouses`, `deploy_ui`, `teams_command_script`,
|
||||
`public_app_execution_limit_per_minute`, `guest_jwt_public_key`, `guest_jwt_jwks_url`,
|
||||
`error_handler_fallback_to_instance_alerts` and
|
||||
|
||||
Reference in New Issue
Block a user