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

gitlab oauth: account for role_attribute_path_strict #50088

Merged
merged 1 commit into from
Jun 3, 2022
Merged
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
11 changes: 8 additions & 3 deletions pkg/login/social/gitlab_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package social

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"regexp"
Expand All @@ -13,9 +14,10 @@ import (

type SocialGitlab struct {
*SocialBase
allowedGroups []string
apiUrl string
roleAttributePath string
allowedGroups []string
apiUrl string
roleAttributePath string
roleAttributeStrict bool
}

func (s *SocialGitlab) Type() int {
Expand Down Expand Up @@ -119,6 +121,9 @@ func (s *SocialGitlab) UserInfo(client *http.Client, token *oauth2.Token) (*Basi
if err != nil {
s.log.Error("Failed to extract role", "error", err)
}
if s.roleAttributeStrict && !models.RoleType(role).IsValid() {
return nil, errors.New("invalid role")
}

userInfo := &BasicUserInfo{
Id: fmt.Sprintf("%d", data.Id),
Expand Down
9 changes: 5 additions & 4 deletions pkg/login/social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ func ProvideService(cfg *setting.Cfg) *SocialService {
// GitLab.
if name == "gitlab" {
ss.socialMap["gitlab"] = &SocialGitlab{
SocialBase: newSocialBase(name, &config, info),
apiUrl: info.ApiUrl,
allowedGroups: util.SplitString(sec.Key("allowed_groups").String()),
roleAttributePath: info.RoleAttributePath,
SocialBase: newSocialBase(name, &config, info),
apiUrl: info.ApiUrl,
allowedGroups: util.SplitString(sec.Key("allowed_groups").String()),
roleAttributePath: info.RoleAttributePath,
roleAttributeStrict: info.RoleAttributeStrict,
}
}

Expand Down