@@ -23,6 +23,7 @@ import (
23
23
"sync"
24
24
"time"
25
25
26
+ "github.com/coreos/go-oidc/v3/oidc"
26
27
"github.com/coreos/go-systemd/daemon"
27
28
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
28
29
"github.com/google/go-github/v43/github"
@@ -84,6 +85,12 @@ func server() *cobra.Command {
84
85
oauth2GithubAllowedOrganizations []string
85
86
oauth2GithubAllowedTeams []string
86
87
oauth2GithubAllowSignups bool
88
+ oidcAllowSignups bool
89
+ oidcClientID string
90
+ oidcClientSecret string
91
+ oidcEmailDomain string
92
+ oidcIssuerURL string
93
+ oidcScopes []string
87
94
telemetryEnable bool
88
95
telemetryURL string
89
96
tlsCertFile string
@@ -283,6 +290,38 @@ func server() *cobra.Command {
283
290
}
284
291
}
285
292
293
+ if oidcClientSecret != "" {
294
+ if oidcClientID == "" {
295
+ return xerrors .Errorf ("OIDC client ID be set!" )
296
+ }
297
+ if oidcIssuerURL == "" {
298
+ return xerrors .Errorf ("OIDC issuer URL must be set!" )
299
+ }
300
+
301
+ oidcProvider , err := oidc .NewProvider (ctx , oidcIssuerURL )
302
+ if err != nil {
303
+ return xerrors .Errorf ("configure oidc provider: %w" , err )
304
+ }
305
+ redirectURL , err := accessURLParsed .Parse ("/api/v2/users/oidc/callback" )
306
+ if err != nil {
307
+ return xerrors .Errorf ("parse oidc oauth callback url: %w" , err )
308
+ }
309
+ options .OIDCConfig = & coderd.OIDCConfig {
310
+ OAuth2Config : & oauth2.Config {
311
+ ClientID : oidcClientID ,
312
+ ClientSecret : oidcClientSecret ,
313
+ RedirectURL : redirectURL .String (),
314
+ Endpoint : oidcProvider .Endpoint (),
315
+ Scopes : oidcScopes ,
316
+ },
317
+ Verifier : oidcProvider .Verifier (& oidc.Config {
318
+ ClientID : oidcClientID ,
319
+ }),
320
+ EmailDomain : oidcEmailDomain ,
321
+ AllowSignups : oidcAllowSignups ,
322
+ }
323
+ }
324
+
286
325
if inMemoryDatabase {
287
326
options .Database = databasefake .New ()
288
327
options .Pubsub = database .NewPubsubInMemory ()
@@ -341,6 +380,8 @@ func server() *cobra.Command {
341
380
Logger : logger .Named ("telemetry" ),
342
381
URL : telemetryURL ,
343
382
GitHubOAuth : oauth2GithubClientID != "" ,
383
+ OIDCAuth : oidcClientID != "" ,
384
+ OIDCIssuerURL : oidcIssuerURL ,
344
385
Prometheus : promEnabled ,
345
386
STUN : len (stunServers ) != 0 ,
346
387
Tunnel : tunnel ,
@@ -637,6 +678,18 @@ func server() *cobra.Command {
637
678
"Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: <organization-name>/<team-slug>." )
638
679
cliflag .BoolVarP (root .Flags (), & oauth2GithubAllowSignups , "oauth2-github-allow-signups" , "" , "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" , false ,
639
680
"Specifies whether new users can sign up with GitHub." )
681
+ cliflag .BoolVarP (root .Flags (), & oidcAllowSignups , "oidc-allow-signups" , "" , "CODER_OIDC_ALLOW_SIGNUPS" , true ,
682
+ "Specifies whether new users can sign up with OIDC." )
683
+ cliflag .StringVarP (root .Flags (), & oidcClientID , "oidc-client-id" , "" , "CODER_OIDC_CLIENT_ID" , "" ,
684
+ "Specifies a client ID to use for OIDC." )
685
+ cliflag .StringVarP (root .Flags (), & oidcClientSecret , "oidc-client-secret" , "" , "CODER_OIDC_CLIENT_SECRET" , "" ,
686
+ "Specifies a client secret to use for OIDC." )
687
+ cliflag .StringVarP (root .Flags (), & oidcEmailDomain , "oidc-email-domain" , "" , "CODER_OIDC_EMAIL_DOMAIN" , "" ,
688
+ "Specifies an email domain that clients authenticating with OIDC must match." )
689
+ cliflag .StringVarP (root .Flags (), & oidcIssuerURL , "oidc-issuer-url" , "" , "CODER_OIDC_ISSUER_URL" , "" ,
690
+ "Specifies an issuer URL to use for OIDC." )
691
+ cliflag .StringArrayVarP (root .Flags (), & oidcScopes , "oidc-scopes" , "" , "CODER_OIDC_SCOPES" , []string {oidc .ScopeOpenID , "profile" , "email" },
692
+ "Specifies scopes to grant when authenticating with OIDC." )
640
693
enableTelemetryByDefault := ! isTest ()
641
694
cliflag .BoolVarP (root .Flags (), & telemetryEnable , "telemetry" , "" , "CODER_TELEMETRY" , enableTelemetryByDefault , "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product." )
642
695
cliflag .StringVarP (root .Flags (), & telemetryURL , "telemetry-url" , "" , "CODER_TELEMETRY_URL" , "https://telemetry.coder.com" , "Specifies a URL to send telemetry to." )
0 commit comments