Skip to content

Commit 280f889

Browse files
authored
feat: Add enabled to federation resources (#423)
Add possibility to disable federated authentication by setting the idp or mapping enabled status. Closes: #269
1 parent 5e10cc1 commit 280f889

File tree

30 files changed

+165
-68
lines changed

30 files changed

+165
-68
lines changed

doc/src/federation/intro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ Following tables are added:
5959
- federated_identity_provider
6060

6161
```rust
62-
{{#rustdoc_include ../../src/db/entity/federated_identity_provider.rs:9:22}}
62+
{{#rustdoc_include ../../../src/db/entity/federated_identity_provider.rs:15:30}}
6363
```
6464

6565
- federated_mapping
6666

6767
```rust
68-
{{#include ../../src/db/entity/federated_mapping.rs:10:26}}
68+
{{#include ../../../src/db/entity/federated_mapping.rs:15:32}}
6969
```
7070

7171
- federated_auth_state
7272

7373
```rust
74-
{{#include ../../src/db/entity/federated_auth_state.rs:8:16}}
74+
{{#include ../../../src/db/entity/federated_auth_state.rs:8:16}}
7575
```
7676

7777
## Compatibility notes

rustfmt.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
format_code_in_doc_comments = true
2-
unstable_features = true
3-
wrap_comments = true
1+
# format_code_in_doc_comments = true
2+
# unstable_features = true
3+
# wrap_comments = true

src/api/v4/federation/auth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ pub async fn post(
137137
return Err(OidcError::MappingRequired)?;
138138
};
139139

140+
// Check for IdP and mapping `enabled` state
141+
if !idp.enabled {
142+
return Err(OidcError::IdentityProviderDisabled)?;
143+
}
144+
if !mapping.enabled {
145+
return Err(OidcError::MappingDisabled)?;
146+
}
147+
140148
let client = if let Some(discovery_url) = &idp.oidc_discovery_url {
141149
let http_client = reqwest::ClientBuilder::new()
142150
// Following redirects opens the client up to SSRF vulnerabilities.

src/api/v4/federation/error.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ pub enum OidcError {
4343
#[error("groups claim must be an array of strings")]
4444
GroupsClaimNotArrayOfStrings,
4545

46+
/// IdP is disabled.
47+
#[error("identity provider is disabled")]
48+
IdentityProviderDisabled,
49+
50+
/// Mapping is disabled.
51+
#[error("mapping is disabled")]
52+
MappingDisabled,
53+
4654
#[error("request token error")]
4755
RequestToken { msg: String },
4856

@@ -153,6 +161,12 @@ impl From<OidcError> for KeystoneApiError {
153161
e @ OidcError::ClientWithoutDiscoveryNotSupported => {
154162
KeystoneApiError::InternalError(e.to_string())
155163
}
164+
OidcError::IdentityProviderDisabled => {
165+
KeystoneApiError::BadRequest("Federated Identity Provider is disabled.".to_string())
166+
}
167+
OidcError::MappingDisabled => {
168+
KeystoneApiError::BadRequest("Federated Identity Provider mapping is disabled.".to_string())
169+
}
156170
OidcError::MappingRequired => {
157171
KeystoneApiError::BadRequest("Federated authentication requires mapping being specified in the payload or default set on the identity provider.".to_string())
158172
}

src/api/v4/federation/identity_provider/list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ mod tests {
133133
id: "id".into(),
134134
name: "name".into(),
135135
domain_id: Some("did".into()),
136+
enabled: true,
136137
default_mapping_name: Some("dummy".into()),
137138
..Default::default()
138139
}])
@@ -164,6 +165,7 @@ mod tests {
164165
id: "id".into(),
165166
name: "name".into(),
166167
domain_id: Some("did".into()),
168+
enabled: true,
167169
oidc_discovery_url: None,
168170
oidc_client_id: None,
169171
oidc_response_mode: None,

src/api/v4/federation/identity_provider/show.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ mod tests {
115115
id: "bar".into(),
116116
name: "name".into(),
117117
domain_id: Some("did".into()),
118+
enabled: true,
118119
default_mapping_name: Some("dummy".into()),
119120
..Default::default()
120121
}))
@@ -161,6 +162,7 @@ mod tests {
161162
id: "bar".into(),
162163
name: "name".into(),
163164
domain_id: Some("did".into()),
165+
enabled: true,
164166
oidc_discovery_url: None,
165167
oidc_client_id: None,
166168
oidc_response_mode: None,

src/api/v4/federation/jwt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ pub async fn login(
162162
})?
163163
.to_owned();
164164

165+
// Check for IdP and mapping `enabled` state
166+
if !idp.enabled {
167+
return Err(OidcError::IdentityProviderDisabled)?;
168+
}
169+
if !mapping.enabled {
170+
return Err(OidcError::MappingDisabled)?;
171+
}
172+
165173
tracing::debug!("Mapping is {:?}", mapping);
166174
let token_restriction = if let Some(tr_id) = &mapping.token_restriction_id {
167175
state

src/api/v4/federation/mapping/list.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ mod tests {
107107
name: "name".into(),
108108
domain_id: Some("did".into()),
109109
idp_id: "idp_id".into(),
110+
enabled: true,
110111
user_id_claim: "sub".into(),
111112
user_name_claim: "preferred_username".into(),
112113
domain_id_claim: Some("domain_id".into()),
@@ -143,6 +144,7 @@ mod tests {
143144
domain_id: Some("did".into()),
144145
idp_id: "idp_id".into(),
145146
r#type: MappingType::default(),
147+
enabled: true,
146148
allowed_redirect_uris: None,
147149
user_id_claim: "sub".into(),
148150
user_name_claim: "preferred_username".into(),
@@ -180,6 +182,7 @@ mod tests {
180182
domain_id: Some("did".into()),
181183
idp_id: "idp".into(),
182184
r#type: MappingType::default().into(),
185+
enabled: true,
183186
allowed_redirect_uris: None,
184187
user_id_claim: "sub".into(),
185188
user_name_claim: "preferred_username".into(),

src/api/v4/federation/mapping/show.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ mod tests {
116116
name: "name".into(),
117117
domain_id: Some("did".into()),
118118
idp_id: "idp_id".into(),
119+
enabled: true,
119120
user_id_claim: "sub".into(),
120121
user_name_claim: "preferred_username".into(),
121122
domain_id_claim: Some("domain_id".into()),
@@ -166,6 +167,7 @@ mod tests {
166167
domain_id: Some("did".into()),
167168
idp_id: "idp_id".into(),
168169
r#type: MappingType::default(),
170+
enabled: true,
169171
allowed_redirect_uris: None,
170172
user_id_claim: "sub".into(),
171173
user_name_claim: "preferred_username".into(),

src/api/v4/federation/oidc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ pub async fn callback(
121121
})
122122
})??;
123123

124+
// Check for IdP and mapping `enabled` state
125+
if !idp.enabled {
126+
return Err(OidcError::IdentityProviderDisabled)?;
127+
}
128+
if !mapping.enabled {
129+
return Err(OidcError::MappingDisabled)?;
130+
}
131+
124132
let token_restrictions = if let Some(tr_id) = &mapping.token_restriction_id {
125133
state
126134
.provider

0 commit comments

Comments
 (0)