Skip to content

Commit ce18015

Browse files
committed
Merge branch 'main' into githubteams
2 parents 7d72da3 + bacfd63 commit ce18015

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ test-postgres: test-clean test-postgres-docker
175175
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum --junitfile="gotests.xml" --packages="./..." -- \
176176
-covermode=atomic -coverprofile="gotests.coverage" -timeout=30m \
177177
-coverpkg=./...,github.com/coder/coder/codersdk \
178-
-count=2 -race -failfast
178+
-count=1 -race -failfast
179179
.PHONY: test-postgres
180180

181181
test-postgres-docker:

cli/server.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,22 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
722722
return tls.NewListener(listener, tlsConfig), nil
723723
}
724724

725-
func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, allowSignups bool, allowOrgs []string, allowTeams []string) (*coderd.GithubOAuth2Config, error) {
725+
func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, allowSignups bool, allowOrgs []string, rawTeams []string) (*coderd.GithubOAuth2Config, error) {
726726
redirectURL, err := accessURL.Parse("/api/v2/users/oauth2/github/callback")
727727
if err != nil {
728728
return nil, xerrors.Errorf("parse github oauth callback url: %w", err)
729729
}
730+
allowTeams := make([]coderd.GithubOAuth2Team, 0, len(rawTeams))
731+
for _, rawTeam := range rawTeams {
732+
parts := strings.SplitN(rawTeam, "/", 2)
733+
if len(parts) != 2 {
734+
return nil, xerrors.Errorf("github team allowlist is formatted incorrectly. got %s; wanted <organization>/<team>", rawTeam)
735+
}
736+
allowTeams = append(allowTeams, coderd.GithubOAuth2Team{
737+
Organization: parts[0],
738+
Slug: parts[1],
739+
})
740+
}
730741
return &coderd.GithubOAuth2Config{
731742
OAuth2Config: &oauth2.Config{
732743
ClientID: clientID,

coderd/database/db_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414

1515
func TestNestedInTx(t *testing.T) {
1616
t.Parallel()
17+
if testing.Short() {
18+
t.SkipNow()
19+
}
1720

1821
uid := uuid.New()
1922
sqlDB := testSQLDB(t)

coderd/userauth.go

+10-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9-
"strings"
109

1110
"github.com/google/go-github/v43/github"
1211
"github.com/google/uuid"
@@ -18,6 +17,12 @@ import (
1817
"github.com/coder/coder/codersdk"
1918
)
2019

20+
// GithubOAuth2Team represents a team scoped to an organization.
21+
type GithubOAuth2Team struct {
22+
Organization string
23+
Slug string
24+
}
25+
2126
// GithubOAuth2Provider exposes required functions for the Github authentication flow.
2227
type GithubOAuth2Config struct {
2328
httpmw.OAuth2Config
@@ -28,7 +33,7 @@ type GithubOAuth2Config struct {
2833

2934
AllowSignups bool
3035
AllowOrganizations []string
31-
AllowTeams []string
36+
AllowTeams []GithubOAuth2Team
3237
}
3338

3439
func (api *API) userAuthMethods(rw http.ResponseWriter, _ *http.Request) {
@@ -80,21 +85,13 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
8085

8186
var allowedTeam *github.Team
8287
for _, team := range teams {
83-
for _, organizationAndTeam := range api.GithubOAuth2Config.AllowTeams {
84-
parts := strings.SplitN(organizationAndTeam, "/", 2)
85-
if len(parts) != 2 {
86-
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
87-
Message: "Team allowlist isn't formatted correctly.",
88-
Detail: fmt.Sprintf("Got %s, wanted <organization>/<team>", organizationAndTeam),
89-
})
90-
return
91-
}
92-
if parts[0] != *selectedMembership.Organization.Login {
88+
for _, allowTeam := range api.GithubOAuth2Config.AllowTeams {
89+
if allowTeam.Organization != *selectedMembership.Organization.Login {
9390
// This needs to continue because multiple organizations
9491
// could exist in the allow/team listings.
9592
continue
9693
}
97-
if parts[1] != *team.Slug {
94+
if allowTeam.Slug != *team.Slug {
9895
continue
9996
}
10097
allowedTeam = team

coderd/userauth_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestUserOAuth2Github(t *testing.T) {
7878
client := coderdtest.New(t, &coderdtest.Options{
7979
GithubOAuth2Config: &coderd.GithubOAuth2Config{
8080
AllowOrganizations: []string{"coder"},
81-
AllowTeams: []string{"another/something", "coder/frontend"},
81+
AllowTeams: []coderd.GithubOAuth2Team{{"another", "something"}, {"coder", "frontend"}},
8282
OAuth2Config: &oauth2Config{},
8383
ListOrganizationMemberships: func(ctx context.Context, client *http.Client) ([]*github.Membership, error) {
8484
return []*github.Membership{{
@@ -214,7 +214,7 @@ func TestUserOAuth2Github(t *testing.T) {
214214
GithubOAuth2Config: &coderd.GithubOAuth2Config{
215215
AllowSignups: true,
216216
AllowOrganizations: []string{"coder"},
217-
AllowTeams: []string{"coder/frontend"},
217+
AllowTeams: []coderd.GithubOAuth2Team{{"coder", "frontend"}},
218218
OAuth2Config: &oauth2Config{},
219219
ListOrganizationMemberships: func(ctx context.Context, client *http.Client) ([]*github.Membership, error) {
220220
return []*github.Membership{{

coderd/workspaces_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ func TestWorkspaceByOwnerAndName(t *testing.T) {
343343
// to run various filters against for testing.
344344
func TestWorkspaceFilter(t *testing.T) {
345345
t.Parallel()
346+
// Manual tests still occur below, so this is safe to disable.
347+
t.Skip("This test is slow and flaky. See: https://github.com/coder/coder/issues/2854")
348+
// nolint:unused
346349
type coderUser struct {
347350
*codersdk.Client
348351
User codersdk.User

0 commit comments

Comments
 (0)