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
6 changes: 6 additions & 0 deletions changelog.d/387.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Changing whom ORBIT trusts for sign-in through `PUT /api/v1/settings/oidc` (issuer,
JWKS URL, audience, client id, redirect URI, identity and role claims, provisioning,
role sync, verified-email and mapped-group rules, team mappings) now needs every
permission (an Owner). A delegated `settings:write` role could previously point sign-in
at an identity provider it controls (#387). See
[the OIDC guide](docs/development/oidc.md#configure-from-the-ui).
121 changes: 121 additions & 0 deletions crates/orbit-api/src/handlers/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ pub async fn update_oidc(
if !issues.is_empty() {
return Err(ApiError::validation(issues));
}
let trust_changes = changed_oidc_trust_fields(previous.as_ref(), &merged);
if !trust_changes.is_empty() {
require_full_authority(
&auth,
&format!(
"the OIDC sign-in trust settings ({})",
trust_changes.join(", ")
),
)?;
}
require_oidc_role_ceiling(&auth, previous.as_ref(), &merged)?;
let value = serde_json::to_value(&merged).map_err(|e| ApiError::bad_request(e.to_string()))?;
let stored = state
Expand All @@ -256,6 +266,65 @@ pub async fn update_oidc(
Ok(Json(settings))
}

/// Fields that decide whom ORBIT trusts for sign-in and how identities are linked and
/// provisioned (#387). Changing any of them needs full authority, like the other
/// installation-wide security switches: a new issuer locks out every existing user and
/// lets the new identity provider link never-signed-in accounts (Owners included) by
/// email, and team mappings can grant access-team roles the role ceiling does not cover.
/// Returns the API names of the fields that change; nothing stored yet counts as the
/// defaults.
fn changed_oidc_trust_fields(
previous: Option<&OidcSettings>,
next: &OidcSettings,
) -> Vec<&'static str> {
let defaults;
let previous = match previous {
Some(previous) => previous,
None => {
defaults = serde_json::from_value::<OidcSettings>(serde_json::json!({}))
.expect("every OIDC setting has a default");
&defaults
}
};
let text = |a: &str, b: &str| a.trim() != b.trim();
let mut changed = Vec::new();
for (name, differs) in [
("issuer", text(&previous.issuer, &next.issuer)),
("jwksUrl", text(&previous.jwks_url, &next.jwks_url)),
("audience", text(&previous.audience, &next.audience)),
("clientId", text(&previous.client_id, &next.client_id)),
(
"redirectUri",
text(&previous.redirect_uri, &next.redirect_uri),
),
("emailClaim", text(&previous.email_claim, &next.email_claim)),
("roleClaim", text(&previous.role_claim, &next.role_claim)),
(
"autoProvision",
previous.auto_provision != next.auto_provision,
),
("syncRoles", previous.sync_roles != next.sync_roles),
(
"requireVerifiedEmail",
previous.require_verified_email != next.require_verified_email,
),
(
"requireMappedGroup",
previous.require_mapped_group != next.require_mapped_group,
),
("teamGroups", previous.team_groups != next.team_groups),
(
"autoCreateTeams",
previous.auto_create_teams != next.auto_create_teams,
),
] {
if differs {
changed.push(name);
}
}
changed
}

/// Grant ceiling for OIDC role mappings (#324). A user with `settings:write` must not be
/// able to give sign-ins a role with permissions they do not hold themselves, for example
/// by mapping their own IdP group to `owner`. Only mappings that change are checked, so
Expand Down Expand Up @@ -791,6 +860,58 @@ mod ceiling_tests {
assert!(require_oidc_role_ceiling(&delegated_admin(), Some(&before), &next).is_err());
}

/// #387: whom ORBIT trusts for sign-in is an Owner decision, not a settings:write one.
#[test]
fn trust_fields_need_full_authority() {
let before = settings("viewer", &[]);
assert!(changed_oidc_trust_fields(Some(&before), &before.clone()).is_empty());
type Edit = fn(&mut OidcSettings);
let edits: [(&str, Edit); 13] = [
("issuer", |s| s.issuer = "https://evil.example.com".into()),
("jwksUrl", |s| {
s.jwks_url = "https://evil.example.com/jwks".into()
}),
("audience", |s| s.audience = "other".into()),
("clientId", |s| s.client_id = "other".into()),
("redirectUri", |s| {
s.redirect_uri = "https://evil.example.com/cb".into()
}),
("emailClaim", |s| {
s.email_claim = "preferred_username".into()
}),
("roleClaim", |s| s.role_claim = "roles".into()),
("autoProvision", |s| s.auto_provision = !s.auto_provision),
("syncRoles", |s| s.sync_roles = !s.sync_roles),
("requireVerifiedEmail", |s| {
s.require_verified_email = !s.require_verified_email
}),
("requireMappedGroup", |s| {
s.require_mapped_group = !s.require_mapped_group
}),
("teamGroups", |s| {
s.team_groups.insert("mine".into(), "ops:lead".into());
}),
("autoCreateTeams", |s| {
s.auto_create_teams = !s.auto_create_teams
}),
];
for (field, edit) in edits {
let mut next = before.clone();
edit(&mut next);
assert_eq!(changed_oidc_trust_fields(Some(&before), &next), vec![field]);
}
// Whitespace-only differences are not a change.
let mut next = before.clone();
next.issuer = format!(" {} ", before.issuer);
assert!(changed_oidc_trust_fields(Some(&before), &next).is_empty());
// Role mappings and scopes stay under the #324 ceiling instead.
let mut next = settings("operator", &[("ops", "viewer")]);
next.scopes = "openid email".into();
assert!(changed_oidc_trust_fields(Some(&before), &next).is_empty());
// Nothing stored yet: configuring an issuer is a change.
assert_eq!(changed_oidc_trust_fields(None, &before), vec!["issuer"]);
}

#[test]
fn organization_toggles_need_every_permission() {
assert!(require_full_authority(&delegated_admin(), "team isolation").is_err());
Expand Down
34 changes: 34 additions & 0 deletions crates/orbit-api/tests/api_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11617,6 +11617,40 @@ async fn settings_write_has_a_ceiling_for_toggles_and_access_teams() {
.await;
assert_eq!(status, StatusCode::FORBIDDEN, "{body}");

// #387: whom ORBIT trusts for sign-in is an Owner decision. A delegated
// settings:write holder cannot swap the issuer or the team mappings.
for settings in [
json!({ "issuer": "https://idp-387.example.com", "jwksUrl": "https://idp-387.example.com/jwks" }),
json!({ "teamGroups": { format!("g-{}", Uuid::now_v7()): "ops:lead" }, "autoCreateTeams": true }),
// A unique value, so the edit is a change whatever other tests stored.
json!({ "audience": format!("aud-{}", Uuid::now_v7()) }),
] {
let (status, body) = send(
&app.router,
put_json("/api/v1/settings/oidc", m, &json!({ "settings": settings })),
)
.await;
assert_eq!(status, StatusCode::FORBIDDEN, "{settings}: {body}");
assert!(
body["error"]["message"]
.as_str()
.unwrap()
.contains("trust settings"),
"{body}"
);
}
// A role-mapping-only edit within the caller's own permissions still works (#324 ceiling).
let (status, body) = send(
&app.router,
put_json(
"/api/v1/settings/oidc",
m,
&json!({ "settings": { "groupRoles": { format!("g-{}", Uuid::now_v7()): "viewer" } } }),
),
)
.await;
assert_eq!(status, StatusCode::OK, "{body}");

// Mallory is not a lead of Team A: she cannot rename or delete it.
let team_path = format!("/api/v1/teams/{}", fx.team_a);
let (status, body) = send(
Expand Down
9 changes: 9 additions & 0 deletions docs/development/oidc.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ absent fields (role claim, `groupRoles`, `teamGroups`, `autoCreateTeams`,
before it is stored (422 and no change on error). To clear a mapping, send it explicitly,
for example `"groupRoles": {}`.

Changing whom ORBIT trusts for sign-in needs every permission (an Owner), not only
`settings:write`: `issuer`, `jwksUrl`, `audience`, `clientId`, `redirectUri`,
`emailClaim`, `roleClaim`, `autoProvision`, `syncRoles`, `requireVerifiedEmail`,
`requireMappedGroup`, `teamGroups` and `autoCreateTeams`. A new issuer locks out every user
who signed in before and lets the new identity provider link accounts that never signed in
by email. A delegated `settings:write` holder gets `403` naming the fields; they can still
edit `scopes`, `defaultRole` and `groupRoles` within the role ceiling described in
[rbac.md](rbac.md).

## Web flow

```text
Expand Down
4 changes: 4 additions & 0 deletions docs/development/rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ Nobody can give out more than they hold:
- The same applies to sign-in mappings: changing the OIDC default role or a group-to-role
mapping to a role with permissions the caller does not hold returns `403`. Mappings an
Owner set earlier do not block edits of other OIDC fields.
- Changing whom ORBIT trusts for sign-in (the OIDC issuer, JWKS URL, audience, client id,
redirect URI, identity and role claims, provisioning, role sync, verified-email and
mapped-group rules, and team mappings) needs every permission (an Owner). See
[oidc.md](oidc.md#configure-from-the-ui).
- Team isolation (`PUT /settings/access`) and four-eyes approvals
(`PUT /settings/approvals`) affect the whole organization and need every permission (an
Owner), not only `settings:write`.
Expand Down