@@ -82,6 +82,7 @@ func server() *cobra.Command {
82
82
oauth2GithubClientID string
83
83
oauth2GithubClientSecret string
84
84
oauth2GithubAllowedOrganizations []string
85
+ oauth2GithubAllowedTeams []string
85
86
oauth2GithubAllowSignups bool
86
87
telemetryEnable bool
87
88
telemetryURL string
@@ -264,7 +265,7 @@ func server() *cobra.Command {
264
265
}
265
266
266
267
if oauth2GithubClientSecret != "" {
267
- options .GithubOAuth2Config , err = configureGithubOAuth2 (accessURLParsed , oauth2GithubClientID , oauth2GithubClientSecret , oauth2GithubAllowSignups , oauth2GithubAllowedOrganizations )
268
+ options .GithubOAuth2Config , err = configureGithubOAuth2 (accessURLParsed , oauth2GithubClientID , oauth2GithubClientSecret , oauth2GithubAllowSignups , oauth2GithubAllowedOrganizations , oauth2GithubAllowedTeams )
268
269
if err != nil {
269
270
return xerrors .Errorf ("configure github oauth2: %w" , err )
270
271
}
@@ -535,6 +536,8 @@ func server() *cobra.Command {
535
536
"Specifies a client secret to use for oauth2 with GitHub." )
536
537
cliflag .StringArrayVarP (root .Flags (), & oauth2GithubAllowedOrganizations , "oauth2-github-allowed-orgs" , "" , "CODER_OAUTH2_GITHUB_ALLOWED_ORGS" , nil ,
537
538
"Specifies organizations the user must be a member of to authenticate with GitHub." )
539
+ cliflag .StringArrayVarP (root .Flags (), & oauth2GithubAllowedTeams , "oauth2-github-allowed-teams" , "" , "CODER_OAUTH2_GITHUB_ALLOWED_TEAMS" , nil ,
540
+ "Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: <organization-name>/<team-slug>." )
538
541
cliflag .BoolVarP (root .Flags (), & oauth2GithubAllowSignups , "oauth2-github-allow-signups" , "" , "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" , false ,
539
542
"Specifies whether new users can sign up with GitHub." )
540
543
cliflag .BoolVarP (root .Flags (), & telemetryEnable , "telemetry" , "" , "CODER_TELEMETRY" , true , "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product." )
@@ -719,11 +722,22 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
719
722
return tls .NewListener (listener , tlsConfig ), nil
720
723
}
721
724
722
- func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups bool , allowOrgs []string ) (* coderd.GithubOAuth2Config , error ) {
725
+ func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups bool , allowOrgs []string , rawTeams [] string ) (* coderd.GithubOAuth2Config , error ) {
723
726
redirectURL , err := accessURL .Parse ("/api/v2/users/oauth2/github/callback" )
724
727
if err != nil {
725
728
return nil , xerrors .Errorf ("parse github oauth callback url: %w" , err )
726
729
}
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
+ }
727
741
return & coderd.GithubOAuth2Config {
728
742
OAuth2Config : & oauth2.Config {
729
743
ClientID : clientID ,
@@ -738,6 +752,7 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
738
752
},
739
753
AllowSignups : allowSignups ,
740
754
AllowOrganizations : allowOrgs ,
755
+ AllowTeams : allowTeams ,
741
756
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
742
757
user , _ , err := github .NewClient (client ).Users .Get (ctx , "" )
743
758
return user , err
@@ -749,9 +764,18 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
749
764
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
750
765
memberships , _ , err := github .NewClient (client ).Organizations .ListOrgMemberships (ctx , & github.ListOrgMembershipsOptions {
751
766
State : "active" ,
767
+ ListOptions : github.ListOptions {
768
+ PerPage : 100 ,
769
+ },
752
770
})
753
771
return memberships , err
754
772
},
773
+ ListTeams : func (ctx context.Context , client * http.Client , org string ) ([]* github.Team , error ) {
774
+ teams , _ , err := github .NewClient (client ).Teams .ListTeams (ctx , org , & github.ListOptions {
775
+ PerPage : 100 ,
776
+ })
777
+ return teams , err
778
+ },
755
779
}, nil
756
780
}
757
781
0 commit comments