mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
feat: add a Require SSO workspace protection rule (#12681)
* feat: add a Require SSO workspace protection rule Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: serialize the sso checks per email and count new members in all Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: describe what the Require SSO rule refuses in the AI guidance Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: lock the account row instead of an advisory lock for sso checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: serialize sso checks for emails that have no account yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: check a password transition after the update locks the account Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: serialize every sso transition on one per-email lock Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: lock sso transitions only under a rule, in bounded buckets Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: drop the locks around the sso checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: say what the password-login members listing returns Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 04fb511569ecb790b24e0a2f70e316de34cbb067 This commit updates the EE repository reference after PR #1012 was merged in windmill-ee-private. Previous ee-repo-ref: b9eb85d7908eecfc3e22612db7e8028e458f208e New ee-repo-ref: 04fb511569ecb790b24e0a2f70e316de34cbb067 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
windmill-internal-app[bot]
parent
cc855e6fd9
commit
71f22fc6e9
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT u.username, u.email,\n COALESCE(array_agg(g.group_) FILTER (WHERE g.group_ IS NOT NULL), '{}') AS \"groups!\"\n FROM usr u\n JOIN password p ON p.email = u.email AND p.login_type = 'password'\n LEFT JOIN usr_to_group g ON g.workspace_id = u.workspace_id AND g.usr = u.username\n WHERE u.workspace_id = $1 AND NOT u.is_service_account\n GROUP BY u.username, u.email\n ORDER BY u.username",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "username",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "email",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "groups!",
|
||||
"type_info": "VarcharArray"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "1816ab8f23338f3e01d01bf4e1ba67e1c180bd4c81b17db1ae2619e2e73fef28"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT login_type, username FROM password WHERE email = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "login_type",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "username",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "22b6a5e8d05d47c86713ff804857e037112aac008865934fa3419581034e69d3"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT name, bypass_users, bypass_groups FROM workspace_protection_rule\n WHERE workspace_id = $1 AND (rules & $2) <> 0 ORDER BY name",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "name",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "bypass_users",
|
||||
"type_info": "TextArray"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "bypass_groups",
|
||||
"type_info": "TextArray"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "8c8ab1f498ca1460d2b58d95c09af1e3230e8f7cfd7a49b4fec87110e31470fa"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT i.email FROM workspace_invite i\n JOIN password p ON p.email = i.email AND p.login_type = 'password'\n WHERE i.workspace_id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "email",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "a5ddda3592c30ad7ccb1bf4215bb5271e1563ce19cb252837f9e26d5b8502667"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT u.workspace_id, u.username,\n COALESCE(array_agg(g.group_) FILTER (WHERE g.group_ IS NOT NULL), '{}') AS \"groups!\"\n FROM usr u\n LEFT JOIN usr_to_group g ON g.workspace_id = u.workspace_id AND g.usr = u.username\n WHERE u.email = $1 AND NOT u.is_service_account\n AND EXISTS (SELECT 1 FROM workspace_protection_rule r\n WHERE r.workspace_id = u.workspace_id AND (r.rules & $2) <> 0)\n GROUP BY u.workspace_id, u.username",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "workspace_id",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "username",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "groups!",
|
||||
"type_info": "VarcharArray"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "c901b1954818bfa402d2ded9f020c0862421001e10a5ac8cb3d1c1791b6ca597"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
8604f6779f08ff2208e85628503877edce8e2343
|
||||
04fb511569ecb790b24e0a2f70e316de34cbb067
|
||||
|
||||
@@ -801,3 +801,83 @@ async fn test_require_isolated_forks(db: Pool<Postgres>) -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx::test(fixtures("base"))]
|
||||
async fn test_require_sso(db: Pool<Postgres>) -> anyhow::Result<()> {
|
||||
sqlx::raw_sql(
|
||||
"INSERT INTO workspace (id, name, owner) VALUES ('sso-ws', 'sso-ws', 'test-user');
|
||||
INSERT INTO workspace_settings (workspace_id) VALUES ('sso-ws');
|
||||
INSERT INTO group_ (workspace_id, name, summary, extra_perms) VALUES
|
||||
('sso-ws', 'all', 'All users', '{}');
|
||||
INSERT INTO usr (workspace_id, email, username, is_admin, role) VALUES
|
||||
('sso-ws', 'test@windmill.dev', 'test-user', true, 'Admin');
|
||||
INSERT INTO password (email, login_type, verified, username) VALUES
|
||||
('sso@windmill.dev', 'google', true, 'sso-user'),
|
||||
('pw@windmill.dev', 'password', true, 'pw-user'),
|
||||
('pw-bypass@windmill.dev', 'password', true, 'pw-bypass')",
|
||||
)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
let server = ApiServer::start(db.clone()).await?;
|
||||
let api = format!("http://localhost:{}/api", server.addr.port());
|
||||
let post = |path: String, body: serde_json::Value| {
|
||||
authed(client().post(format!("{api}{path}")), "SECRET_TOKEN").json(&body)
|
||||
};
|
||||
let add = |email: &str| {
|
||||
post(
|
||||
"/w/sso-ws/workspaces/add_user".to_string(),
|
||||
json!({"email": email, "is_admin": false, "operator": false}),
|
||||
)
|
||||
};
|
||||
|
||||
let resp = post(
|
||||
"/w/sso-ws/workspaces/protection_rules".to_string(),
|
||||
json!({"name": "sso", "rules": ["RequireSso"], "bypass_groups": [], "bypass_users": ["pw-bypass"]}),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
|
||||
|
||||
let resp = add("pw@windmill.dev").send().await?;
|
||||
let status = resp.status();
|
||||
let text = resp.text().await?;
|
||||
assert_eq!(status, 400, "a password account must not join: {text}");
|
||||
assert!(text.contains("requires SSO"), "{text}");
|
||||
|
||||
for email in ["sso@windmill.dev", "pw-bypass@windmill.dev"] {
|
||||
let resp = add(email).send().await?;
|
||||
assert_eq!(resp.status(), 201, "{email}: {}", resp.text().await?);
|
||||
}
|
||||
|
||||
let to_password = |email: &str| {
|
||||
post(
|
||||
format!("/users/set_login_type/{email}"),
|
||||
json!({"login_type": "password"}),
|
||||
)
|
||||
};
|
||||
let resp = to_password("sso@windmill.dev").send().await?;
|
||||
assert_eq!(resp.status(), 400, "{}", resp.text().await?);
|
||||
let login_type: String =
|
||||
sqlx::query_scalar("SELECT login_type FROM password WHERE email = 'sso@windmill.dev'")
|
||||
.fetch_one(&db)
|
||||
.await?;
|
||||
assert_eq!(login_type, "google");
|
||||
|
||||
// A bypasser is not held by the rule.
|
||||
let resp = to_password("pw-bypass@windmill.dev").send().await?;
|
||||
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
|
||||
|
||||
// Every new member is in `all`, so bypassing it admits anyone.
|
||||
let resp = post(
|
||||
"/w/sso-ws/workspaces/protection_rules/sso".to_string(),
|
||||
json!({"name": "sso", "rules": ["RequireSso"], "bypass_groups": ["all"], "bypass_users": []}),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
|
||||
let resp = add("pw@windmill.dev").send().await?;
|
||||
assert_eq!(resp.status(), 201, "{}", resp.text().await?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1278,6 +1278,14 @@ async fn join_workspace<'c>(
|
||||
)));
|
||||
}
|
||||
|
||||
windmill_common::workspaces::check_new_member_sso(
|
||||
&mut *tx,
|
||||
&w_id,
|
||||
&authed.email,
|
||||
Some(&username),
|
||||
)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT INTO usr
|
||||
(workspace_id, email, username, is_admin, operator)
|
||||
@@ -2846,6 +2854,10 @@ async fn set_login_type(
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
if et.login_type == "password" {
|
||||
windmill_common::workspaces::check_password_login_allowed(&mut *tx, &email).await?;
|
||||
}
|
||||
|
||||
audit_log(
|
||||
&mut *tx,
|
||||
&authed,
|
||||
|
||||
@@ -239,6 +239,7 @@ pub fn workspaced_service() -> Router {
|
||||
"/protection_rules/{rule_name}",
|
||||
post(update_protection_rule).delete(delete_protection_rule),
|
||||
)
|
||||
.route("/password_login_members", get(list_password_login_members))
|
||||
.route("/log_feature_usage", post(log_feature_usage))
|
||||
.route("/cloud_quotas", get(get_cloud_quotas))
|
||||
.route("/prune_versions", post(prune_versions))
|
||||
@@ -12055,6 +12056,8 @@ async fn invite_user(
|
||||
)));
|
||||
}
|
||||
|
||||
windmill_common::workspaces::check_new_member_sso(&mut *tx, &w_id, &nu.email, None).await?;
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT INTO workspace_invite
|
||||
(workspace_id, email, is_admin, operator, workspace_role)
|
||||
@@ -12266,6 +12269,9 @@ async fn add_user(
|
||||
username
|
||||
};
|
||||
|
||||
windmill_common::workspaces::check_new_member_sso(&mut *tx, &w_id, &nu.email, Some(&username))
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT INTO usr
|
||||
(workspace_id, email, username, is_admin, operator, workspace_role)
|
||||
@@ -12852,6 +12858,38 @@ async fn list_protection_rules(
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PasswordLoginMember {
|
||||
username: String,
|
||||
email: String,
|
||||
groups: Vec<String>,
|
||||
}
|
||||
|
||||
/// Members other than service accounts whose account signs in with a password, with their groups
|
||||
/// so the caller can leave out a rule's bypassers. A `RequireSso` rule does not remove them.
|
||||
async fn list_password_login_members(
|
||||
authed: ApiAuthed,
|
||||
Extension(db): Extension<DB>,
|
||||
Path(w_id): Path<String>,
|
||||
) -> JsonResult<Vec<PasswordLoginMember>> {
|
||||
require_admin(authed.is_admin, &authed.username)?;
|
||||
let members = sqlx::query_as!(
|
||||
PasswordLoginMember,
|
||||
r#"SELECT u.username, u.email,
|
||||
COALESCE(array_agg(g.group_) FILTER (WHERE g.group_ IS NOT NULL), '{}') AS "groups!"
|
||||
FROM usr u
|
||||
JOIN password p ON p.email = u.email AND p.login_type = 'password'
|
||||
LEFT JOIN usr_to_group g ON g.workspace_id = u.workspace_id AND g.usr = u.username
|
||||
WHERE u.workspace_id = $1 AND NOT u.is_service_account
|
||||
GROUP BY u.username, u.email
|
||||
ORDER BY u.username"#,
|
||||
&w_id,
|
||||
)
|
||||
.fetch_all(&db)
|
||||
.await?;
|
||||
Ok(Json(members))
|
||||
}
|
||||
|
||||
/// Insert or replace a protection ruleset within an existing transaction. Unlike the
|
||||
/// `create_protection_rule` handler (which rejects an existing name), this upserts, so it is safe to
|
||||
/// call programmatically when designating a dev/prod pair. Callers MUST invalidate the
|
||||
|
||||
@@ -8317,6 +8317,37 @@ paths:
|
||||
"400":
|
||||
description: rule with this name already exists
|
||||
|
||||
/w/{workspace}/workspaces/password_login_members:
|
||||
get:
|
||||
summary: list the members other than service accounts that sign in with a password
|
||||
operationId: listPasswordLoginMembers
|
||||
tags:
|
||||
- workspace
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/WorkspaceId"
|
||||
responses:
|
||||
"200":
|
||||
description: members signing in with a password, with their groups
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
required:
|
||||
- username
|
||||
- email
|
||||
- groups
|
||||
properties:
|
||||
username:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
groups:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
/w/{workspace}/workspaces/protection_rules/{rule_name}:
|
||||
post:
|
||||
summary: update an existing protection rule
|
||||
@@ -41680,6 +41711,7 @@ components:
|
||||
- RestrictPublicRunSharing
|
||||
- RestrictGuestAppDeployment
|
||||
- RequireIsolatedForks
|
||||
- RequireSso
|
||||
RuleBypasserGroups:
|
||||
type: array
|
||||
description: Groups that can bypass this ruleset
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -81,6 +81,7 @@ bitflags::bitflags! {
|
||||
const RESTRICT_PUBLIC_RUN_SHARING = 1 << 4;
|
||||
const RESTRICT_GUEST_APP_DEPLOYMENT = 1 << 5;
|
||||
const REQUIRE_ISOLATED_FORKS = 1 << 6;
|
||||
const REQUIRE_SSO = 1 << 7;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +96,7 @@ pub enum ProtectionRuleKind {
|
||||
RestrictPublicRunSharing,
|
||||
RestrictGuestAppDeployment,
|
||||
RequireIsolatedForks,
|
||||
RequireSso,
|
||||
}
|
||||
|
||||
impl ProtectionRuleKind {
|
||||
@@ -119,6 +121,7 @@ impl ProtectionRuleKind {
|
||||
ProtectionRules::RESTRICT_GUEST_APP_DEPLOYMENT
|
||||
}
|
||||
ProtectionRuleKind::RequireIsolatedForks => ProtectionRules::REQUIRE_ISOLATED_FORKS,
|
||||
ProtectionRuleKind::RequireSso => ProtectionRules::REQUIRE_SSO,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +146,9 @@ impl ProtectionRuleKind {
|
||||
ProtectionRuleKind::RequireIsolatedForks => {
|
||||
"Forks of this workspace must isolate its data: no shared object storage or ducklake, and every data table cloned"
|
||||
}
|
||||
ProtectionRuleKind::RequireSso => {
|
||||
"Every member of this workspace other than a service account must sign in with SSO"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1555,6 +1561,117 @@ pub async fn check_user_against_rule(
|
||||
Ok(RuleCheckResult::Allowed)
|
||||
}
|
||||
|
||||
struct SsoRuleset {
|
||||
name: String,
|
||||
bypass_users: Vec<String>,
|
||||
bypass_groups: Vec<String>,
|
||||
}
|
||||
|
||||
/// `workspace_id`'s `RequireSso` rulesets, read uncached so a rule just turned on already
|
||||
/// refuses the next join.
|
||||
async fn sso_rulesets(
|
||||
conn: &mut sqlx::PgConnection,
|
||||
workspace_id: &str,
|
||||
) -> Result<Vec<SsoRuleset>> {
|
||||
Ok(sqlx::query_as!(
|
||||
SsoRuleset,
|
||||
"SELECT name, bypass_users, bypass_groups FROM workspace_protection_rule
|
||||
WHERE workspace_id = $1 AND (rules & $2) <> 0 ORDER BY name",
|
||||
workspace_id,
|
||||
ProtectionRules::REQUIRE_SSO.bits(),
|
||||
)
|
||||
.fetch_all(&mut *conn)
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// The first of `rulesets` that holds a member named `username` in `groups`.
|
||||
fn sso_ruleset_holding<'a>(
|
||||
rulesets: &'a [SsoRuleset],
|
||||
username: Option<&str>,
|
||||
groups: &[String],
|
||||
) -> Option<&'a str> {
|
||||
rulesets
|
||||
.iter()
|
||||
.find(|r| {
|
||||
!(username.is_some_and(|u| r.bypass_users.iter().any(|b| b == u))
|
||||
|| r.bypass_groups.iter().any(|g| groups.contains(g)))
|
||||
})
|
||||
.map(|r| r.name.as_str())
|
||||
}
|
||||
|
||||
/// Refuses seating `email` in `workspace_id` while a `RequireSso` rule there holds them and their
|
||||
/// account signs in with a password. `pending_oauth` passes: it can only become a password
|
||||
/// account through [`check_password_login_allowed`]. An email with no account yet passes too, for
|
||||
/// the same reason. `username` is the one they get in the workspace; without it their instance
|
||||
/// username is what bypass lists are matched against. A new member is in `all` and nothing else.
|
||||
///
|
||||
/// This and [`check_password_login_allowed`] each read what the other writes without locking, so
|
||||
/// a join and a password switch of the same account committing at the same instant can both pass.
|
||||
/// A lock shared by both would have to be taken in one order with the invite, membership and
|
||||
/// `password` row locks of every member path, bulk joins included, or it deadlocks them.
|
||||
pub async fn check_new_member_sso(
|
||||
conn: &mut sqlx::PgConnection,
|
||||
workspace_id: &str,
|
||||
email: &str,
|
||||
username: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let rulesets = sso_rulesets(conn, workspace_id).await?;
|
||||
if rulesets.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let account = sqlx::query!(
|
||||
"SELECT login_type, username FROM password WHERE email = $1",
|
||||
email
|
||||
)
|
||||
.fetch_optional(&mut *conn)
|
||||
.await?;
|
||||
let Some(account) = account.filter(|a| a.login_type == "password") else {
|
||||
return Ok(());
|
||||
};
|
||||
let username = username.or(account.username.as_deref());
|
||||
let groups = ["all".to_string()];
|
||||
if let Some(ruleset) = sso_ruleset_holding(&rulesets, username, &groups) {
|
||||
return Err(Error::BadRequest(format!(
|
||||
"Ruleset {ruleset} of {workspace_id} requires SSO: {email} signs in with a password, \
|
||||
so it cannot join this workspace"
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Refuses giving `email` a password login while a `RequireSso` rule of a workspace they are a
|
||||
/// non-service-account member of holds them.
|
||||
pub async fn check_password_login_allowed(
|
||||
conn: &mut sqlx::PgConnection,
|
||||
email: &str,
|
||||
) -> Result<()> {
|
||||
let memberships = sqlx::query!(
|
||||
r#"SELECT u.workspace_id, u.username,
|
||||
COALESCE(array_agg(g.group_) FILTER (WHERE g.group_ IS NOT NULL), '{}') AS "groups!"
|
||||
FROM usr u
|
||||
LEFT JOIN usr_to_group g ON g.workspace_id = u.workspace_id AND g.usr = u.username
|
||||
WHERE u.email = $1 AND NOT u.is_service_account
|
||||
AND EXISTS (SELECT 1 FROM workspace_protection_rule r
|
||||
WHERE r.workspace_id = u.workspace_id AND (r.rules & $2) <> 0)
|
||||
GROUP BY u.workspace_id, u.username"#,
|
||||
email,
|
||||
ProtectionRules::REQUIRE_SSO.bits(),
|
||||
)
|
||||
.fetch_all(&mut *conn)
|
||||
.await?;
|
||||
for m in memberships {
|
||||
let rulesets = sso_rulesets(conn, &m.workspace_id).await?;
|
||||
if let Some(ruleset) = sso_ruleset_holding(&rulesets, Some(&m.username), &m.groups) {
|
||||
return Err(Error::BadRequest(format!(
|
||||
"Ruleset {ruleset} of {} requires SSO for its members, so {email} cannot sign in \
|
||||
with a password",
|
||||
m.workspace_id
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The roles members of `workspace_id` get in a fork of it, merged across its rulesets: where two
|
||||
/// rulesets map the same role, the first by name wins. Unmapped roles carry over unchanged.
|
||||
pub async fn fork_role_mapping(
|
||||
|
||||
Generated
+1
-1
@@ -8659,7 +8659,7 @@ write a secret you were not given: keep the placeholder.
|
||||
| \`git_sync\` | \`{ repositories: [...] }\`, each with \`git_repo_resource_path\`, \`script_path\` and \`settings\` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
|
||||
| \`datatable\` | \`{ datatables: { <name>: { database: { resource_type, resource_path } } } }\`, both required: \`resource_type: postgresql\` with \`resource_path\` a Postgres resource's path, or \`instance\`, or \`external_instance\` (Enterprise only), with \`resource_path\` the name of a database a superadmin set up. A fork's entry can instead be \`{ reference: { workspace_id, datatable } }\`, pointing at its parent's data table; keep it as is. \`main\` is the one scripts use by default. Role permissions are \`datatable_permissions\`. |
|
||||
| \`datatable_permissions\` | \`{ <data table>: { default_role, roles: { <role>: [tenants] } } }\`: who may connect to each data table as which role. Tenants are \`u/<user>\`, \`g/<group>\`, \`f/<folder>\` or \`*\`; \`admin\` is always a role, and \`default_role: null\` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
|
||||
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`, \`RequireSso\` (an account signing in with a password, other than a bypasser, cannot join, and no member can be switched to a password login; members already signing in with a password are not removed). A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| \`ducklake\` | \`{ ducklakes: { <name>: { catalog, storage, ... } } }\`. |
|
||||
| \`dbt_warehouses\` | dbt warehouse connections. |
|
||||
| \`default_app\` | Path of the app shown as the workspace home. |
|
||||
|
||||
@@ -164,6 +164,18 @@ Symbols, not line numbers, are cited: they drift less.
|
||||
reset require `login_type = 'password'`; `set_password` also accepts `pending_oauth` and turns
|
||||
the account into a `password` one in the same statement (an account created ahead of its owner
|
||||
gets its first credential that way, or through the OAuth claim below).
|
||||
- **`RequireSso` protection rule** (workspace-level, `check_new_member_sso` /
|
||||
`check_password_login_allowed` in `windmill-common/src/workspaces.rs`): a `password` account
|
||||
held by it (not a service account, not a bypasser by username or group, admins included) cannot
|
||||
join the workspace, and no member it holds can become a `password` account. It gates both
|
||||
transitions, never sign-in: password members already in the workspace keep logging in, which only
|
||||
the instance's `disable_password_login` stops. A new path that seats a member or writes
|
||||
`login_type = 'password'` (or a password on a `pending_oauth` account) must call the matching
|
||||
check in the transaction that writes. The two checks take no lock, so a join and a password
|
||||
switch of the same account at the same instant can both pass; the automatic joins (domain auto-add and auto-invite,
|
||||
instance groups) skip the user instead of failing, and a git sync pull into a fork fails rather
|
||||
than seat a held sync identity. The
|
||||
superadmin instance import (`POST /users/overwrite`) restores accounts as given, unchecked.
|
||||
- **Login links** (`login_link` table, `POST /users/login_links` superadmin-only,
|
||||
`GET /auth/login_link/{token}` unauthenticated): single-use, ≤15 min, a session cookie and a
|
||||
302 to a same-origin `rd`. `require_login_type` on the mint refuses (409) an account whose
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { Section, Button, DrawerContent } from '$lib/components/common'
|
||||
import { Section, Button, DrawerContent, Alert } from '$lib/components/common'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import Label from '$lib/components/Label.svelte'
|
||||
import ManageGroupsLink from '$lib/components/ManageGroupsLink.svelte'
|
||||
import MultiSelect from '$lib/components/select/MultiSelect.svelte'
|
||||
import TextInput from '$lib/components/text_input/TextInput.svelte'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { superadmin, workspaceStore } from '$lib/stores'
|
||||
import { isCloudHosted } from '$lib/cloud'
|
||||
import { goto } from '$app/navigation'
|
||||
import { resource } from 'runed'
|
||||
import {
|
||||
GroupService,
|
||||
UserService,
|
||||
@@ -48,6 +51,7 @@
|
||||
let restrictPublicRunSharing = $state(hasRule('RestrictPublicRunSharing'))
|
||||
let restrictGuestAppDeployment = $state(hasRule('RestrictGuestAppDeployment'))
|
||||
let requireIsolatedForks = $state(hasRule('RequireIsolatedForks'))
|
||||
let requireSso = $state(hasRule('RequireSso'))
|
||||
let selectedGroups = $state<string[]>(
|
||||
untrack(() => rule)?.bypass_groups?.map((g) => g.replace('g/', '')) ?? []
|
||||
)
|
||||
@@ -68,6 +72,7 @@
|
||||
let initialRestrictPublicRunSharing = $state(hasRule('RestrictPublicRunSharing'))
|
||||
let initialRestrictGuestAppDeployment = $state(hasRule('RestrictGuestAppDeployment'))
|
||||
let initialRequireIsolatedForks = $state(hasRule('RequireIsolatedForks'))
|
||||
let initialRequireSso = $state(hasRule('RequireSso'))
|
||||
let initialSelectedGroups = $state<string[]>(
|
||||
untrack(() => rule)?.bypass_groups
|
||||
? untrack(() => rule)!.bypass_groups.map((g) => g.replace('g/', ''))
|
||||
@@ -115,6 +120,23 @@
|
||||
}
|
||||
})
|
||||
|
||||
// The rule only refuses new password members; these already in the workspace stay held by it.
|
||||
const passwordMembers = resource(
|
||||
() => (requireSso ? $workspaceStore : undefined),
|
||||
async (workspace) =>
|
||||
workspace ? await WorkspaceService.listPasswordLoginMembers({ workspace }) : []
|
||||
)
|
||||
const heldPasswordMembers = $derived(
|
||||
(passwordMembers.current ?? []).filter(
|
||||
(m) =>
|
||||
!selectedUsers.includes(m.username) && !m.groups.some((g) => selectedGroups.includes(g))
|
||||
)
|
||||
)
|
||||
const passwordLoginDisabled = resource(
|
||||
() => requireSso && !isCloudHosted(),
|
||||
async (shown) => (shown ? await UserService.isPasswordLoginDisabled() : undefined)
|
||||
)
|
||||
|
||||
// Computed properties
|
||||
const hasUnsavedChanges = $derived(
|
||||
isCreateMode
|
||||
@@ -126,6 +148,7 @@
|
||||
restrictPublicRunSharing ||
|
||||
restrictGuestAppDeployment ||
|
||||
requireIsolatedForks ||
|
||||
requireSso ||
|
||||
selectedGroups.length > 0 ||
|
||||
selectedUsers.length > 0 ||
|
||||
forkRoleMapping.length > 0
|
||||
@@ -137,6 +160,7 @@
|
||||
restrictPublicRunSharing !== initialRestrictPublicRunSharing ||
|
||||
restrictGuestAppDeployment !== initialRestrictGuestAppDeployment ||
|
||||
requireIsolatedForks !== initialRequireIsolatedForks ||
|
||||
requireSso !== initialRequireSso ||
|
||||
JSON.stringify([...selectedGroups].sort()) !==
|
||||
JSON.stringify([...initialSelectedGroups].sort()) ||
|
||||
JSON.stringify([...selectedUsers].sort()) !==
|
||||
@@ -193,7 +217,8 @@
|
||||
...(restrictGuestAppDeployment
|
||||
? ['RestrictGuestAppDeployment' as ProtectionRuleKind]
|
||||
: []),
|
||||
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : [])
|
||||
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : []),
|
||||
...(requireSso ? ['RequireSso' as ProtectionRuleKind] : [])
|
||||
],
|
||||
bypass_groups: selectedGroups,
|
||||
bypass_users: selectedUsers,
|
||||
@@ -234,7 +259,8 @@
|
||||
...(restrictGuestAppDeployment
|
||||
? ['RestrictGuestAppDeployment' as ProtectionRuleKind]
|
||||
: []),
|
||||
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : [])
|
||||
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : []),
|
||||
...(requireSso ? ['RequireSso' as ProtectionRuleKind] : [])
|
||||
],
|
||||
bypass_groups: selectedGroups,
|
||||
bypass_users: selectedUsers,
|
||||
@@ -253,6 +279,7 @@
|
||||
initialRestrictPublicRunSharing = restrictPublicRunSharing
|
||||
initialRestrictGuestAppDeployment = restrictGuestAppDeployment
|
||||
initialRequireIsolatedForks = requireIsolatedForks
|
||||
initialRequireSso = requireSso
|
||||
initialSelectedGroups = clone(selectedGroups)
|
||||
initialSelectedUsers = clone(selectedUsers)
|
||||
initialForkRoleMapping = clone(forkRoleMapping)
|
||||
@@ -383,6 +410,46 @@
|
||||
'Only workspace admins and bypassers can mint a public link to a run (readable without login). The read-only link for workspace members stays available to everyone.'
|
||||
)}
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<Toggle bind:checked={requireSso} options={{ right: 'Require SSO' }} />
|
||||
{@render description(
|
||||
'Every member other than a service account or a bypasser must sign in with SSO: a user signing in with a password cannot be added, invited or auto-added, and no member can be switched to a password login. Admins are held too.'
|
||||
)}
|
||||
{#if requireSso}
|
||||
<div class="flex flex-col gap-2 pl-11 pt-1">
|
||||
{#if heldPasswordMembers.length > 0}
|
||||
<Alert
|
||||
type="warning"
|
||||
size="xs"
|
||||
title={`${heldPasswordMembers.length} ${heldPasswordMembers.length === 1 ? 'member signs' : 'members sign'} in with a password`}
|
||||
>
|
||||
The rule does not remove existing members. Move them to SSO, remove them, or add
|
||||
them as bypassers: {heldPasswordMembers
|
||||
.map((m) => `${m.username} (${m.email})`)
|
||||
.join(', ')}.
|
||||
</Alert>
|
||||
{/if}
|
||||
{#if !isCloudHosted()}
|
||||
<Alert
|
||||
type="info"
|
||||
size="xs"
|
||||
title="Usually better set on the instance"
|
||||
actions={$superadmin
|
||||
? [{ label: 'Open instance settings', onClick: () => goto('#superadmin-settings') }]
|
||||
: undefined}
|
||||
>
|
||||
Disable password login in the instance settings to require SSO of every user in
|
||||
every workspace: it also stops password sign-in itself, which this rule does not.
|
||||
{#if passwordLoginDisabled.current === true}
|
||||
Password login is already disabled on this instance.
|
||||
{:else if passwordLoginDisabled.current === false}
|
||||
Password login is currently enabled on this instance.
|
||||
{/if}
|
||||
</Alert>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section
|
||||
|
||||
@@ -1633,7 +1633,7 @@ write a secret you were not given: keep the placeholder.
|
||||
| \`git_sync\` | \`{ repositories: [...] }\`, each with \`git_repo_resource_path\`, \`script_path\` and \`settings\` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
|
||||
| \`datatable\` | \`{ datatables: { <name>: { database: { resource_type, resource_path } } } }\`, both required: \`resource_type: postgresql\` with \`resource_path\` a Postgres resource's path, or \`instance\`, or \`external_instance\` (Enterprise only), with \`resource_path\` the name of a database a superadmin set up. A fork's entry can instead be \`{ reference: { workspace_id, datatable } }\`, pointing at its parent's data table; keep it as is. \`main\` is the one scripts use by default. Role permissions are \`datatable_permissions\`. |
|
||||
| \`datatable_permissions\` | \`{ <data table>: { default_role, roles: { <role>: [tenants] } } }\`: who may connect to each data table as which role. Tenants are \`u/<user>\`, \`g/<group>\`, \`f/<folder>\` or \`*\`; \`admin\` is always a role, and \`default_role: null\` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
|
||||
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`, \`RequireSso\` (an account signing in with a password, other than a bypasser, cannot join, and no member can be switched to a password login; members already signing in with a password are not removed). A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| \`ducklake\` | \`{ ducklakes: { <name>: { catalog, storage, ... } } }\`. |
|
||||
| \`dbt_warehouses\` | dbt warehouse connections. |
|
||||
| \`default_app\` | Path of the app shown as the workspace home. |
|
||||
|
||||
@@ -47,7 +47,7 @@ write a secret you were not given: keep the placeholder.
|
||||
| `git_sync` | `{ repositories: [...] }`, each with `git_repo_resource_path`, `script_path` and `settings` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
|
||||
| `datatable` | `{ datatables: { <name>: { database: { resource_type, resource_path } } } }`, both required: `resource_type: postgresql` with `resource_path` a Postgres resource's path, or `instance`, or `external_instance` (Enterprise only), with `resource_path` the name of a database a superadmin set up. A fork's entry can instead be `{ reference: { workspace_id, datatable } }`, pointing at its parent's data table; keep it as is. `main` is the one scripts use by default. Role permissions are `datatable_permissions`. |
|
||||
| `datatable_permissions` | `{ <data table>: { default_role, roles: { <role>: [tenants] } } }`: who may connect to each data table as which role. Tenants are `u/<user>`, `g/<group>`, `f/<folder>` or `*`; `admin` is always a role, and `default_role: null` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
|
||||
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`, `RequireSso` (an account signing in with a password, other than a bypasser, cannot join, and no member can be switched to a password login; members already signing in with a password are not removed). A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| `ducklake` | `{ ducklakes: { <name>: { catalog, storage, ... } } }`. |
|
||||
| `dbt_warehouses` | dbt warehouse connections. |
|
||||
| `default_app` | Path of the app shown as the workspace home. |
|
||||
|
||||
@@ -42,7 +42,7 @@ write a secret you were not given: keep the placeholder.
|
||||
| `git_sync` | `{ repositories: [...] }`, each with `git_repo_resource_path`, `script_path` and `settings` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
|
||||
| `datatable` | `{ datatables: { <name>: { database: { resource_type, resource_path } } } }`, both required: `resource_type: postgresql` with `resource_path` a Postgres resource's path, or `instance`, or `external_instance` (Enterprise only), with `resource_path` the name of a database a superadmin set up. A fork's entry can instead be `{ reference: { workspace_id, datatable } }`, pointing at its parent's data table; keep it as is. `main` is the one scripts use by default. Role permissions are `datatable_permissions`. |
|
||||
| `datatable_permissions` | `{ <data table>: { default_role, roles: { <role>: [tenants] } } }`: who may connect to each data table as which role. Tenants are `u/<user>`, `g/<group>`, `f/<folder>` or `*`; `admin` is always a role, and `default_role: null` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
|
||||
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`, `RequireSso` (an account signing in with a password, other than a bypasser, cannot join, and no member can be switched to a password login; members already signing in with a password are not removed). A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
|
||||
| `ducklake` | `{ ducklakes: { <name>: { catalog, storage, ... } } }`. |
|
||||
| `dbt_warehouses` | dbt warehouse connections. |
|
||||
| `default_app` | Path of the app shown as the workspace home. |
|
||||
|
||||
Reference in New Issue
Block a user