Skip to content
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

OAuth: Introduce user_refresh_token setting and make it default for the selected providers #71533

Merged
merged 9 commits into from
Jul 14, 2023

Conversation

mgyongyosi
Copy link
Contributor

@mgyongyosi mgyongyosi commented Jul 13, 2023

What is this feature?
This PR introduces the use_refresh_token configuration parameter to each of the OAuth providers and extend the defaults.ini file with the default value for each provider.

It would be enabled by default for the following providers (check the documentation in case you would like to enable it for other providers):

  • AzureAD
  • GitLab
  • Google

Currently this functionality is behind a feature toggle called accessTokenExpirationCheck which means that the feature toggle must be enabled to use refresh tokens. accessTokenExpirationCheck feature toggle will be removed in Grafana v10.2 and only the use_refresh_token setting of the providers will be used to specify whether an OAuth provider should use refresh tokens and check the access token expiration.

Why do we need this feature?
We need this to improve the security of Grafana, because currently the OAuth providers are used only for logging users in. With Grafana v9.3 we introduced a feature toggle accessTokenExpirationCheck that enables the access token expiration check and refreshes the access token using the refresh token. However, we decided that it would be more convenient to set the expiration check and refresh token fetching by OAuth providers and to enable it by default for the providers that either provides a refresh token by default or getting the refresh token is controlled by the client.

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@mgyongyosi mgyongyosi requested a review from kalleep July 13, 2023 11:47
To enable a refresh token for AzureAD, extend the `scopes` in `[auth.azuread]` with `offline_access`.
Refresh token fetching and access token expiration check is enabled by default for the AzureAD provider since Grafana v10.1.0 if the `accessTokenExpirationCheck` feature toggle is enabled. If you would like to disable access token expiration check then set the `use_refresh_token` configuration value to `false`.

> **Note:** The `accessTokenExpirationCheck` feature toggle will be removed in Grafana v10.2.0 and the `use_refresh_token` configuration value will be used instead for configuring refresh token fetching and access token expiration check.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: review deployment plan

Copy link
Contributor

@kalleep kalleep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, have not reviewed any of the doc updates

@@ -114,7 +114,7 @@ func (s *SocialGoogle) extractFromAPI(ctx context.Context, client *http.Client)
}

func (s *SocialGoogle) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string {
if s.features.IsEnabled(featuremgmt.FlagAccessTokenExpirationCheck) {
if s.features.IsEnabled(featuremgmt.FlagAccessTokenExpirationCheck) && s.useRefreshToken {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any plans on removing the feature toggle and only check useRefreshToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, that's the plan! (having a setting by auth provider, instead of having a global setting)

@mgyongyosi mgyongyosi requested a review from linoman July 14, 2023 07:43
@mgyongyosi mgyongyosi changed the title WIP OAuth: Introduce user_refresh_token setting and make it default for the selected providers OAuth: Introduce user_refresh_token setting and make it default for the selected providers Jul 14, 2023
@mgyongyosi mgyongyosi marked this pull request as ready for review July 14, 2023 07:43
@mgyongyosi mgyongyosi requested review from torkelo, a team and chri2547 as code owners July 14, 2023 07:43
Copy link
Contributor

@linoman linoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @mgyongyosi!!

@mgyongyosi mgyongyosi merged commit dcf2656 into main Jul 14, 2023
12 checks passed
@mgyongyosi mgyongyosi deleted the mgyongyosi/use-refresh-token-by-default branch July 14, 2023 12:03
@ricky-undeadcoders ricky-undeadcoders removed this from the 10.1.x milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants