-
Notifications
You must be signed in to change notification settings - Fork 48
fix: configurable oauth scope instead of hardcoded 'openid' scope #2566
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
Merged
+50
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,10 @@ pub struct OpenIdTokenProviderConfigArguments { | |
| default_value = "false" | ||
| )] | ||
| pub tls_insecure: bool, | ||
| /// OAuth scope(s) to request in the client_credentials token request. | ||
| /// Space-separated when multiple scopes are needed. If unset, no scope parameter is sent. | ||
| #[arg(id = "oidc_scope", long = "oidc-scope", env = "OIDC_PROVIDER_SCOPE")] | ||
| pub scope: Option<String>, | ||
| } | ||
|
|
||
| impl OpenIdTokenProviderConfigArguments { | ||
|
|
@@ -60,6 +64,7 @@ impl OpenIdTokenProviderConfigArguments { | |
| client_secret: Some(devmode::SSO_CLIENT_SECRET.to_string()), | ||
| refresh_before: Duration::from_secs(30).into(), | ||
| tls_insecure: false, | ||
| scope: None, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -89,6 +94,7 @@ pub struct OpenIdTokenProviderConfig { | |
| pub issuer_url: String, | ||
| pub refresh_before: humantime::Duration, | ||
| pub tls_insecure: bool, | ||
| pub scope: Option<String>, | ||
| } | ||
|
|
||
| impl OpenIdTokenProviderConfig { | ||
|
|
@@ -99,6 +105,7 @@ impl OpenIdTokenProviderConfig { | |
| client_secret: devmode::SSO_CLIENT_SECRET.to_string(), | ||
| refresh_before: Duration::from_secs(30).into(), | ||
| tls_insecure: false, | ||
| scope: None, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -132,6 +139,7 @@ impl OpenIdTokenProviderConfig { | |
| issuer_url, | ||
| refresh_before: arguments.refresh_before, | ||
| tls_insecure: arguments.tls_insecure, | ||
| scope: arguments.scope, | ||
| }) | ||
| } | ||
| _ => None, | ||
|
|
@@ -151,6 +159,7 @@ pub struct OpenIdTokenProvider { | |
| client: Arc<openid::Client>, | ||
| current_token: Arc<RwLock<Option<openid::TemporalBearerGuard>>>, | ||
| refresh_before: chrono::Duration, | ||
| scope: Option<String>, | ||
| } | ||
|
|
||
| impl Debug for OpenIdTokenProvider { | ||
|
|
@@ -167,11 +176,16 @@ impl Debug for OpenIdTokenProvider { | |
|
|
||
| impl OpenIdTokenProvider { | ||
| /// Create a new provider using the provided client. | ||
| pub fn new(client: openid::Client, refresh_before: chrono::Duration) -> Self { | ||
| pub fn new( | ||
| client: openid::Client, | ||
| refresh_before: chrono::Duration, | ||
| scope: Option<String>, | ||
| ) -> Self { | ||
| Self { | ||
| client: Arc::new(client), | ||
| current_token: Arc::new(RwLock::new(None)), | ||
| refresh_before, | ||
| scope, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -198,6 +212,7 @@ impl OpenIdTokenProvider { | |
| Ok(Self::new( | ||
| client, | ||
| chrono::Duration::from_std(config.refresh_before.into())?, | ||
| config.scope, | ||
| )) | ||
| } | ||
|
|
||
|
|
@@ -243,7 +258,11 @@ impl OpenIdTokenProvider { | |
| Some(current_token) => { | ||
| log::debug!("Refreshing token ... "); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just noticed while in the area - I think this should be converted to tracing call (As per CONVENTIONS.md) |
||
| match current_token.as_ref().refresh_token.is_some() { | ||
| true => self.client.refresh_token(current_token, None).await?.into(), | ||
| true => self | ||
| .client | ||
| .refresh_token(current_token, self.scope.as_deref()) | ||
| .await? | ||
| .into(), | ||
| false => self.initial_token().await?, | ||
| } | ||
| } | ||
|
|
@@ -262,7 +281,7 @@ impl OpenIdTokenProvider { | |
| async fn initial_token(&self) -> Result<openid::TemporalBearerGuard, openid::error::Error> { | ||
| Ok(self | ||
| .client | ||
| .request_token_using_client_credentials(Some("openid")) | ||
| .request_token_using_client_credentials(self.scope.as_deref()) | ||
| .await? | ||
| .into()) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is a breaking change ? what happens with existing deployments (and have we tested )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is essentially building upon #2552, so there should be nothing breaking here. We're bringing back the default of no scope being explicitly requested, with an option to request scopes if necessary. What possible breaking change did you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my request is if we have tested with an existing env which has named scope and if there is any migration path concerns ... if you have none, then I have none ;)