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

Auth: Support Gitlab OIDC scopes #69890

Merged
merged 11 commits into from
Jun 14, 2023
Merged

Auth: Support Gitlab OIDC scopes #69890

merged 11 commits into from
Jun 14, 2023

Conversation

Jguer
Copy link
Contributor

@Jguer Jguer commented Jun 12, 2023

What is this feature?

  • Support Gitlab OIDC scopes

Why do we need this feature?

Reduces the amount of access Grafana requires to GitLab.

Who is this feature for?

Instances using GitLab OAuth

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.

@Jguer Jguer added this to the 10.1.x milestone Jun 12, 2023
@Jguer Jguer self-assigned this Jun 12, 2023
@Jguer Jguer requested review from a team and chri2547 as code owners June 12, 2023 08:38
@Jguer Jguer requested review from alexanderzobnin and gamab and removed request for a team June 12, 2023 08:38
@@ -218,64 +214,16 @@ func (s *SocialGenericOAuth) extractFromToken(token *oauth2.Token) *UserInfoJson

idToken := token.Extra(idTokenAttribute)
if idToken == nil {
s.log.Debug("No id_token found", "token", token)
s.log.Debug("No id_token found", "token", idToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to log empty token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typo, thanks for pointing it out

@Jguer Jguer requested a review from a team June 13, 2023 09:05
}
}()

rawJSON, err = io.ReadAll(fr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also validate the format of the uncompressed data ?

Copy link
Contributor

@jmatosgrafana jmatosgrafana left a comment

Choose a reason for hiding this comment

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

LGTM from a security point of view.
From old memories what really matters for GitLab SSO is email_verified AND active account.

Copy link
Contributor

@IevaVasiljeva IevaVasiljeva left a comment

Choose a reason for hiding this comment

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

Looks good! Left some minor comments.

}

rawJSON, err := base64.RawURLEncoding.DecodeString(matched[2])
rawJSON, err := s.retrieveRawIDToken(idToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! It's much neater with ID token parsing logic tucked away.

Comment on lines +217 to +234
payload: `{
"iss": "https://gitlab.com",
"sub": "12345678",
"aud": "d77db857f4696c5c5ff6cee64f3ed26e709aac8f1c644dc4b9d5fd64f825d583",
"exp": 1686124040,
"iat": 1686123920,
"auth_time": 1686119303,
"sub_legacy": "b4359d63eaf90d4b1f3d71d291353b75a676bf73fdf734d4ff009eca5c69bb70",
"name": "John Doe",
"nickname": "johndoe",
"preferred_username": "johndoe",
"email": "johndoe@example.com",
"email_verified": true,
"profile": "https://gitlab.com/johndoe",
"picture": "https://gitlab.com/uploads/-/system/user/avatar/1234567/avatar.png",
"groups_direct": [
"admins"
]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could you only specify whether the email has or has not been verified for each test instead of specifying the full payload? Just to make them more readable.

Copy link
Contributor

@alexanderzobnin alexanderzobnin left a comment

Choose a reason for hiding this comment

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

Looks good

@Jguer Jguer force-pushed the jguer/gitlab-oauth-openid branch from 3383bed to b8ca0e9 Compare June 14, 2023 13:00
@Jguer Jguer merged commit 26b66fd into main Jun 14, 2023
7 checks passed
@Jguer Jguer deleted the jguer/gitlab-oauth-openid branch June 14, 2023 13:38
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 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