@@ -23,6 +23,7 @@ import (
2323 "sync"
2424 "time"
2525
26+ "github.com/coreos/go-oidc/v3/oidc"
2627 "github.com/coreos/go-systemd/daemon"
2728 embeddedpostgres "github.com/fergusstrange/embedded-postgres"
2829 "github.com/google/go-github/v43/github"
@@ -84,6 +85,12 @@ func server() *cobra.Command {
8485 oauth2GithubAllowedOrganizations []string
8586 oauth2GithubAllowedTeams []string
8687 oauth2GithubAllowSignups bool
88+ oidcAllowSignups bool
89+ oidcClientID string
90+ oidcClientSecret string
91+ oidcEmailDomain string
92+ oidcIssuerURL string
93+ oidcScopes []string
8794 telemetryEnable bool
8895 telemetryURL string
8996 tlsCertFile string
@@ -283,6 +290,38 @@ func server() *cobra.Command {
283290 }
284291 }
285292
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+
286325 if inMemoryDatabase {
287326 options .Database = databasefake .New ()
288327 options .Pubsub = database .NewPubsubInMemory ()
@@ -341,6 +380,8 @@ func server() *cobra.Command {
341380 Logger : logger .Named ("telemetry" ),
342381 URL : telemetryURL ,
343382 GitHubOAuth : oauth2GithubClientID != "" ,
383+ OIDCAuth : oidcClientID != "" ,
384+ OIDCIssuerURL : oidcIssuerURL ,
344385 Prometheus : promEnabled ,
345386 STUN : len (stunServers ) != 0 ,
346387 Tunnel : tunnel ,
@@ -637,6 +678,18 @@ func server() *cobra.Command {
637678 "Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: <organization-name>/<team-slug>." )
638679 cliflag .BoolVarP (root .Flags (), & oauth2GithubAllowSignups , "oauth2-github-allow-signups" , "" , "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" , false ,
639680 "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." )
640693 enableTelemetryByDefault := ! isTest ()
641694 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." )
642695 cliflag .StringVarP (root .Flags (), & telemetryURL , "telemetry-url" , "" , "CODER_TELEMETRY_URL" , "https://telemetry.coder.com" , "Specifies a URL to send telemetry to." )
0 commit comments