Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion crates/utopia-server/src/api/oidc_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
Expand Down Expand Up @@ -481,7 +485,8 @@ fn display_name(claim: Option<&str>, email: &str) -> String {
fn provisioned_email(claims: &Claims, allowed_domains: &[String]) -> Option<String> {
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 钥匙才用它
Expand Down Expand Up @@ -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::<super::Claims>(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(),
Expand Down
11 changes: 11 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<tenant id>/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://<hostname>/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`.
Expand Down
3 changes: 2 additions & 1 deletion deploy/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading