From ebfdc5a2359aa3c272747d7e512cfd9e0476588b Mon Sep 17 00:00:00 2001 From: Bogdan Szabo Date: Wed, 18 Nov 2026 15:01:10 +0100 Subject: [PATCH] A Microsoft Entra email counts as verified when its domain owner is, so listed domains sign in on first visit Co-Authored-By: Claude Fable 5.2 Signed-off-by: Bogdan Szabo --- crates/utopia-server/src/api/oidc_routes.rs | 38 ++++++++++++++++++++- deploy/README.md | 11 ++++++ deploy/chart/values.yaml | 3 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/crates/utopia-server/src/api/oidc_routes.rs b/crates/utopia-server/src/api/oidc_routes.rs index b218fd276..72d20eaeb 100644 --- a/crates/utopia-server/src/api/oidc_routes.rs +++ b/crates/utopia-server/src/api/oidc_routes.rs @@ -454,6 +454,10 @@ struct Claims { /// 都登不进来。只有 `true` / `"true"` 算核实过,其它一律不算 #[serde(default, deserialize_with = "lenient_true")] email_verified: bool, + /// Microsoft Entra sends no `email_verified`. Its optional claim `xms_edov` says the + /// owner of the email's domain is verified, which is what an allowed domain needs. + #[serde(default, rename = "xms_edov", deserialize_with = "lenient_true")] + email_domain_owner_verified: bool, #[serde(default)] name: Option, } @@ -481,7 +485,8 @@ fn display_name(claim: Option<&str>, email: &str) -> String { fn provisioned_email(claims: &Claims, allowed_domains: &[String]) -> Option { let email = claims.email.as_deref()?.trim().to_lowercase(); let (_, domain) = email.rsplit_once('@')?; - (claims.email_verified && allowed_domains.iter().any(|d| d == domain)).then_some(email) + let verified = claims.email_verified || claims.email_domain_owner_verified; + (verified && allowed_domains.iter().any(|d| d == domain)).then_some(email) } /// 按 `kid` 找钥匙;令牌不带 `kid` 时,只有 JWKS 里恰好一把 RSA 钥匙才用它 @@ -1123,6 +1128,37 @@ mod tests { ); } + #[test] + fn an_entra_email_counts_as_verified_only_when_its_domain_owner_is_verified() { + let provisioned = |domain_owner_verified: serde_json::Value| { + let mut claims = serde_json::json!({ + "sub": "person-1", "iat": 0, "aud": "utopia-test", "email": "ann@re-cinq.com", + }); + if !domain_owner_verified.is_null() { + claims["xms_edov"] = domain_owner_verified; + } + super::provisioned_email( + &serde_json::from_value::(claims).unwrap(), + &["re-cinq.com".to_string()], + ) + }; + assert_eq!( + [ + serde_json::json!(true), + serde_json::json!("true"), + serde_json::json!(false), + serde_json::Value::Null, + ] + .map(provisioned), + [ + Some("ann@re-cinq.com".to_string()), + Some("ann@re-cinq.com".to_string()), + None, + None + ] + ); + } + fn config() -> super::Config { super::Config { issuer: "https://id.example.test".into(), diff --git a/deploy/README.md b/deploy/README.md index 2ed83efc7..795bff276 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -12,6 +12,17 @@ Render locally: helm template utopia deploy/chart -n utopia -f deploy/clusters/internal-cluster.values.yaml ``` +## Sign-in with Microsoft Entra + +Not yet run against a real Entra tenant. What the code needs from it: + +- `oidc.issuer` is `https://login.microsoftonline.com//v2.0`, with the tenant's GUID and not its domain name: the tokens carry the GUID. +- `oidc.allowedDomains` lists the email domains whose people get an account on first sign-in. +- The app registration is single-tenant, has the redirect URI `https:///api/v1/auth/oidc/callback`, and its client id and secret go in the `utopia-oauth` Secret. +- Under Token configuration, the ID token carries the optional claims `email` and `xms_edov`. Entra sends no `email_verified`; `xms_edov` is its statement that the owner of the email's domain is verified, and Utopia opens an account only when it is true. + +A person whose token has no `email`, or no true `xms_edov`, is sent back to the login page and gets no account. + ## Backups and restore `database.backup.objectStore` (a barman ObjectStore `configuration`, here GCS) sends a nightly base backup and continuous WAL through the barman-cloud plugin. The cluster's Kubernetes service account `utopia-db` reaches the bucket through Workload Identity; the Google service account and the bucket are defined in re-cinq/infrastructure, `projects/internal/database-backups.tf`. diff --git a/deploy/chart/values.yaml b/deploy/chart/values.yaml index e89e78be1..3ca06038d 100644 --- a/deploy/chart/values.yaml +++ b/deploy/chart/values.yaml @@ -20,7 +20,8 @@ image: hostname: utopia.example.com -# Google sign-in is the only way in. Password login and open registration stay off. +# Single sign-on is the only way in. Password login and open registration stay off. +# Any OpenID Connect issuer works; for Microsoft Entra see deploy/README.md. oidc: issuer: https://accounts.google.com allowedDomains: re-cinq.com