-
Notifications
You must be signed in to change notification settings - Fork 61
Add experimental and preliminary policy-driven session limiting when logging in OAuth 2 sessions. #5221
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
base: main
Are you sure you want to change the base?
Add experimental and preliminary policy-driven session limiting when logging in OAuth 2 sessions. #5221
Changes from 8 commits
87c897c
2d490d0
efbc33a
a73d655
21fa107
20eb2ac
26d76db
071830e
604ed54
fde8dc6
e7b538c
a9de093
08959fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,13 @@ pub struct ExperimentalConfig { | |
| /// validation. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub plan_management_iframe_uri: Option<String>, | ||
|
|
||
| /// Experimental feature to limit the number of application sessions per | ||
| /// user. | ||
| /// | ||
| /// Disabled by default. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub session_limit: Option<SessionLimitConfig>, | ||
| } | ||
|
|
||
| impl Default for ExperimentalConfig { | ||
|
|
@@ -90,6 +97,7 @@ impl Default for ExperimentalConfig { | |
| compat_token_ttl: default_token_ttl(), | ||
| inactive_session_expiration: None, | ||
| plan_management_iframe_uri: None, | ||
| session_limit: None, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -106,3 +114,10 @@ impl ExperimentalConfig { | |
| impl ConfigurationSection for ExperimentalConfig { | ||
| const PATH: Option<&'static str> = Some("experimental"); | ||
| } | ||
|
|
||
| /// Configuration options for the inactive session expiration feature | ||
| #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] | ||
| pub struct SessionLimitConfig { | ||
| pub soft_limit: u64, | ||
| pub hard_limit: u64, | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ use super::callback::CallbackDestination; | |
| use crate::{ | ||
| BoundActivityTracker, PreferredLanguage, impl_from_error_for_route, | ||
| oauth2::generate_id_token, | ||
| session::{SessionOrFallback, load_session_or_fallback}, | ||
| session::{SessionOrFallback, count_user_sessions_for_limiting, load_session_or_fallback}, | ||
| }; | ||
|
|
||
| #[derive(Debug, Error)] | ||
|
|
@@ -136,10 +136,15 @@ pub(crate) async fn get( | |
|
|
||
| let (csrf_token, cookie_jar) = cookie_jar.csrf_token(&clock, &mut rng); | ||
|
|
||
| let session_counts = count_user_sessions_for_limiting(&mut repo, &session.user) | ||
| .await | ||
| .map_err(|e| RouteError::Internal(e.into()))?; | ||
|
||
|
|
||
| let res = policy | ||
| .evaluate_authorization_grant(mas_policy::AuthorizationGrantInput { | ||
| user: Some(&session.user), | ||
| client: &client, | ||
| session_counts: Some(session_counts), | ||
| scope: &grant.scope, | ||
| grant_type: mas_policy::GrantType::AuthorizationCode, | ||
| requester: mas_policy::Requester { | ||
|
|
@@ -235,10 +240,15 @@ pub(crate) async fn post( | |
| return Err(RouteError::GrantNotPending(grant.id)); | ||
| } | ||
|
|
||
| let session_counts = count_user_sessions_for_limiting(&mut repo, &browser_session.user) | ||
| .await | ||
| .map_err(|e| RouteError::Internal(e.into()))?; | ||
|
|
||
| let res = policy | ||
| .evaluate_authorization_grant(mas_policy::AuthorizationGrantInput { | ||
| user: Some(&browser_session.user), | ||
| client: &client, | ||
| session_counts: Some(session_counts), | ||
| scope: &grant.scope, | ||
| grant_type: mas_policy::GrantType::AuthorizationCode, | ||
| requester: mas_policy::Requester { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.