Skip to content

Allow setting can_request_admin dynamically by claims of upstream IDP #4802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions crates/cli/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ fn map_claims_imports(
account_name: mas_data_model::UpstreamOAuthProviderSubjectPreference {
template: config.account_name.template.clone(),
},
is_admin: mas_data_model::UpstreamOAuthProviderImportPreference {
action: map_import_action(config.is_admin.action),
template: config.is_admin.template.clone(),
},
}
}

Expand Down
25 changes: 25 additions & 0 deletions crates/config/src/sections/upstream_oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ impl AccountNameImportPreference {
}
}

/// What should be done for the `ìs_admin` attribute
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default, JsonSchema)]
pub struct IsAdminImportPreference {
/// How to handle the claim
#[serde(default, skip_serializing_if = "ImportAction::is_default")]
pub action: ImportAction,

/// The Jinja2 template to use for the admin attribute.
///
/// If not provided, it will be ignored.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub template: Option<String>,
}

impl IsAdminImportPreference {
const fn is_default(&self) -> bool {
self.action.is_default() && self.template.is_none()
}
}

/// How claims should be imported
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default, JsonSchema)]
pub struct ClaimsImports {
Expand Down Expand Up @@ -312,6 +332,11 @@ pub struct ClaimsImports {
skip_serializing_if = "AccountNameImportPreference::is_default"
)]
pub account_name: AccountNameImportPreference,

/// Import the `can_request_admin` attribute of the user based on the
/// defined claim (i.e. `is_admin`)
#[serde(default, skip_serializing_if = "IsAdminImportPreference::is_default")]
pub is_admin: IsAdminImportPreference,
}

impl ClaimsImports {
Expand Down
3 changes: 3 additions & 0 deletions crates/data-model/src/upstream_oauth2/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ pub struct ClaimsImports {

#[serde(default)]
pub account_name: SubjectPreference,

#[serde(default)]
pub is_admin: ImportPreference,
}

// XXX: this should have another name
Expand Down
Loading