@@ -52,17 +52,21 @@ func start() *cobra.Command {
52
52
dev bool
53
53
postgresURL string
54
54
// provisionerDaemonCount is a uint8 to ensure a number > 0.
55
- provisionerDaemonCount uint8
56
- tlsCertFile string
57
- tlsClientCAFile string
58
- tlsClientAuth string
59
- tlsEnable bool
60
- tlsKeyFile string
61
- tlsMinVersion string
62
- skipTunnel bool
63
- traceDatadog bool
64
- secureAuthCookie bool
65
- sshKeygenAlgorithmRaw string
55
+ provisionerDaemonCount uint8
56
+ oauth2GithubClientID string
57
+ oauth2GithubClientSecret string
58
+ oauth2GithubAllowedOrganizations []string
59
+ oauth2GithubAllowSignups bool
60
+ tlsCertFile string
61
+ tlsClientCAFile string
62
+ tlsClientAuth string
63
+ tlsEnable bool
64
+ tlsKeyFile string
65
+ tlsMinVersion string
66
+ skipTunnel bool
67
+ traceDatadog bool
68
+ secureAuthCookie bool
69
+ sshKeygenAlgorithmRaw string
66
70
)
67
71
root := & cobra.Command {
68
72
Use : "start" ,
@@ -156,23 +160,24 @@ func start() *cobra.Command {
156
160
return xerrors .Errorf ("parse ssh keygen algorithm %s: %w" , sshKeygenAlgorithmRaw , err )
157
161
}
158
162
159
- githubOAuth2Config , err := configureGithubOAuth2 (accessURLParsed , "" , "" )
160
- if err != nil {
161
- return xerrors .Errorf ("configure github oauth2: %w" , err )
162
- }
163
-
164
163
logger := slog .Make (sloghuman .Sink (os .Stderr ))
165
164
options := & coderd.Options {
166
165
AccessURL : accessURLParsed ,
167
166
Logger : logger .Named ("coderd" ),
168
167
Database : databasefake .New (),
169
168
Pubsub : database .NewPubsubInMemory (),
170
169
GoogleTokenValidator : validator ,
171
- GithubOAuth2Config : githubOAuth2Config ,
172
170
SecureAuthCookie : secureAuthCookie ,
173
171
SSHKeygenAlgorithm : sshKeygenAlgorithm ,
174
172
}
175
173
174
+ if oauth2GithubClientSecret != "" {
175
+ options .GithubOAuth2Config , err = configureGithubOAuth2 (accessURLParsed , oauth2GithubClientID , oauth2GithubClientSecret , oauth2GithubAllowSignups , oauth2GithubAllowedOrganizations )
176
+ if err != nil {
177
+ return xerrors .Errorf ("configure github oauth2: %w" , err )
178
+ }
179
+ }
180
+
176
181
_ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "access-url: %s\n " , accessURL )
177
182
_ , _ = fmt .Fprintf (cmd .ErrOrStderr (), "provisioner-daemons: %d\n " , provisionerDaemonCount )
178
183
_ , _ = fmt .Fprintln (cmd .ErrOrStderr ())
@@ -366,6 +371,14 @@ func start() *cobra.Command {
366
371
cliflag .BoolVarP (root .Flags (), & dev , "dev" , "" , "CODER_DEV_MODE" , false , "Serve Coder in dev mode for tinkering" )
367
372
cliflag .StringVarP (root .Flags (), & postgresURL , "postgres-url" , "" , "CODER_PG_CONNECTION_URL" , "" , "URL of a PostgreSQL database to connect to" )
368
373
cliflag .Uint8VarP (root .Flags (), & provisionerDaemonCount , "provisioner-daemons" , "" , "CODER_PROVISIONER_DAEMONS" , 1 , "The amount of provisioner daemons to create on start." )
374
+ cliflag .StringVarP (root .Flags (), & oauth2GithubClientID , "oauth2-github-client-id" , "" , "CODER_OAUTH2_GITHUB_CLIENT_ID" , "" ,
375
+ "Specifies a client ID to use for oauth2 with GitHub." )
376
+ cliflag .StringVarP (root .Flags (), & oauth2GithubClientSecret , "oauth2-github-client-secret" , "" , "CODER_OAUTH2_GITHUB_CLIENT_SECRET" , "" ,
377
+ "Specifies a client secret to use for oauth2 with GitHub." )
378
+ cliflag .StringArrayVarP (root .Flags (), & oauth2GithubAllowedOrganizations , "oauth2-github-allowed-orgs" , "" , "CODER_OAUTH2_GITHUB_ALLOWED_ORGS" , nil ,
379
+ "Specifies organizations the user must be a member of to authenticate with GitHub." )
380
+ cliflag .BoolVarP (root .Flags (), & oauth2GithubAllowSignups , "oauth2-github-allow-signups" , "" , "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" , false ,
381
+ "Specifies whether new users can sign up with GitHub." )
369
382
cliflag .BoolVarP (root .Flags (), & tlsEnable , "tls-enable" , "" , "CODER_TLS_ENABLE" , false , "Specifies if TLS will be enabled" )
370
383
cliflag .StringVarP (root .Flags (), & tlsCertFile , "tls-cert-file" , "" , "CODER_TLS_CERT_FILE" , "" ,
371
384
"Specifies the path to the certificate for TLS. It requires a PEM-encoded file. " +
@@ -544,7 +557,7 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
544
557
return tls .NewListener (listener , tlsConfig ), nil
545
558
}
546
559
547
- func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string ) (* coderd.GithubOAuth2Config , error ) {
560
+ func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups bool , allowOrgs [] string ) (* coderd.GithubOAuth2Config , error ) {
548
561
redirectURL , err := accessURL .Parse ("/api/v2/users/oauth2/github/callback" )
549
562
if err != nil {
550
563
return nil , xerrors .Errorf ("parse github oauth callback url: %w" , err )
@@ -561,8 +574,8 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string) (*
561
574
"user:email" ,
562
575
},
563
576
},
564
- AllowSignups : true ,
565
- AllowOrganizations : [] string { "coder" } ,
577
+ AllowSignups : allowSignups ,
578
+ AllowOrganizations : allowOrgs ,
566
579
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
567
580
user , _ , err := github .NewClient (client ).Users .Get (ctx , "" )
568
581
return user , err
0 commit comments