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

Fix Missing RBAC configuration bug #4268

Merged
merged 1 commit into from
Mar 15, 2023
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
10 changes: 5 additions & 5 deletions pkg/app/server/httpapi/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (h *authHandler) handleCallback(w http.ResponseWriter, r *http.Request) {
return
}

if proj.Rbac == nil {
h.handleError(w, r, "Missing RBAC configuration", nil)
if proj.UserGroups == nil {
h.handleError(w, r, "Missing User Group configuration", nil)
return
}

Expand All @@ -83,7 +83,7 @@ func (h *authHandler) handleCallback(w http.ResponseWriter, r *http.Request) {
return
}
}
user, err := getUser(ctx, sso, proj.Rbac, proj, authCode)
user, err := getUser(ctx, sso, proj, authCode)
if err != nil {
h.handleError(w, r, "Unable to find user", err)
return
Expand Down Expand Up @@ -137,13 +137,13 @@ func checkState(r *http.Request, key string) error {
return nil
}

func getUser(ctx context.Context, sso *model.ProjectSSOConfig, rbac *model.ProjectRBACConfig, project *model.Project, code string) (*model.User, error) {
func getUser(ctx context.Context, sso *model.ProjectSSOConfig, project *model.Project, code string) (*model.User, error) {
switch sso.Provider {
case model.ProjectSSOConfig_GITHUB:
if sso.Github == nil {
return nil, fmt.Errorf("missing GitHub oauth in the SSO configuration")
}
cli, err := github.NewOAuthClient(ctx, sso.Github, rbac, project, code)
cli, err := github.NewOAuthClient(ctx, sso.Github, project, code)
if err != nil {
return nil, err
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/oauth/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,16 @@ type OAuthClient struct {
*github.Client

project *model.Project

adminTeam string
editorTeam string
viewerTeam string
}

// NewOAuthClient creates a new oauth client for GitHub.
func NewOAuthClient(ctx context.Context,
sso *model.ProjectSSOConfig_GitHub,
rbac *model.ProjectRBACConfig,
project *model.Project,
code string,
) (*OAuthClient, error) {
c := &OAuthClient{
project: project,
adminTeam: rbac.Admin,
editorTeam: rbac.Editor,
viewerTeam: rbac.Viewer,
project: project,
}
cfg := oauth2.Config{
ClientID: sso.ClientId,
Expand Down
15 changes: 0 additions & 15 deletions pkg/oauth/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func TestDecideRole(t *testing.T) {
name: "nothing",
username: "foo",
oc: &OAuthClient{
adminTeam: "org/team-admin",
editorTeam: "org/team-editor",
viewerTeam: "org/team-viewer",
project: &model.Project{
Id: "id",
AllowStrayAsViewer: false,
Expand Down Expand Up @@ -72,9 +69,6 @@ func TestDecideRole(t *testing.T) {
name: "viewer as default",
username: "foo",
oc: &OAuthClient{
adminTeam: "org/team-admin",
editorTeam: "org/team-editor",
viewerTeam: "org/team-viewer",
project: &model.Project{
Id: "id",
AllowStrayAsViewer: true,
Expand Down Expand Up @@ -112,9 +106,6 @@ func TestDecideRole(t *testing.T) {
name: "admin",
username: "foo",
oc: &OAuthClient{
adminTeam: "org/team-admin",
editorTeam: "org/team-editor",
viewerTeam: "org/team-viewer",
project: &model.Project{
Id: "id",
AllowStrayAsViewer: false,
Expand Down Expand Up @@ -162,9 +153,6 @@ func TestDecideRole(t *testing.T) {
name: "editor",
username: "foo",
oc: &OAuthClient{
adminTeam: "org/team-admin",
editorTeam: "org/team-editor",
viewerTeam: "org/team-viewer",
project: &model.Project{
Id: "id",
AllowStrayAsViewer: false,
Expand Down Expand Up @@ -211,9 +199,6 @@ func TestDecideRole(t *testing.T) {
name: "viewer",
username: "foo",
oc: &OAuthClient{
adminTeam: "org/team-admin",
editorTeam: "org/team-editor",
viewerTeam: "org/team-viewer",
project: &model.Project{
Id: "id",
AllowStrayAsViewer: false,
Expand Down