@@ -80,6 +80,7 @@ import (
80
80
"github.com/coder/coder/v2/coderd/oauthpki"
81
81
"github.com/coder/coder/v2/coderd/prometheusmetrics"
82
82
"github.com/coder/coder/v2/coderd/prometheusmetrics/insights"
83
+ "github.com/coder/coder/v2/coderd/promoauth"
83
84
"github.com/coder/coder/v2/coderd/schedule"
84
85
"github.com/coder/coder/v2/coderd/telemetry"
85
86
"github.com/coder/coder/v2/coderd/tracing"
@@ -102,7 +103,7 @@ import (
102
103
"github.com/coder/wgtunnel/tunnelsdk"
103
104
)
104
105
105
- func createOIDCConfig (ctx context.Context , vals * codersdk.DeploymentValues ) (* coderd.OIDCConfig , error ) {
106
+ func createOIDCConfig (ctx context.Context , instrument * promoauth. Factory , vals * codersdk.DeploymentValues ) (* coderd.OIDCConfig , error ) {
106
107
if vals .OIDC .ClientID == "" {
107
108
return nil , xerrors .Errorf ("OIDC client ID must be set!" )
108
109
}
@@ -133,7 +134,7 @@ func createOIDCConfig(ctx context.Context, vals *codersdk.DeploymentValues) (*co
133
134
Scopes : vals .OIDC .Scopes ,
134
135
}
135
136
136
- var useCfg httpmw .OAuth2Config = oauthCfg
137
+ var useCfg promoauth .OAuth2Config = oauthCfg
137
138
if vals .OIDC .ClientKeyFile != "" {
138
139
// PKI authentication is done in the params. If a
139
140
// counter example is found, we can add a config option to
@@ -159,7 +160,7 @@ func createOIDCConfig(ctx context.Context, vals *codersdk.DeploymentValues) (*co
159
160
}
160
161
161
162
return & coderd.OIDCConfig {
162
- OAuth2Config : useCfg ,
163
+ OAuth2Config : instrument . New ( "oidc-login" , useCfg ) ,
163
164
Provider : oidcProvider ,
164
165
Verifier : oidcProvider .Verifier (& oidc.Config {
165
166
ClientID : vals .OIDC .ClientID .String (),
@@ -523,8 +524,11 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
523
524
return xerrors .Errorf ("read external auth providers from env: %w" , err )
524
525
}
525
526
527
+ promRegistry := prometheus .NewRegistry ()
528
+ oauthIntrument := promoauth .NewFactory (promRegistry )
526
529
vals .ExternalAuthConfigs .Value = append (vals .ExternalAuthConfigs .Value , extAuthEnv ... )
527
530
externalAuthConfigs , err := externalauth .ConvertConfig (
531
+ oauthIntrument ,
528
532
vals .ExternalAuthConfigs .Value ,
529
533
vals .AccessURL .Value (),
530
534
)
@@ -571,7 +575,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
571
575
// the DeploymentValues instead, this just serves to indicate the source of each
572
576
// option. This is just defensive to prevent accidentally leaking.
573
577
DeploymentOptions : codersdk .DeploymentOptionsWithoutSecrets (opts ),
574
- PrometheusRegistry : prometheus . NewRegistry () ,
578
+ PrometheusRegistry : promRegistry ,
575
579
APIRateLimit : int (vals .RateLimit .API .Value ()),
576
580
LoginRateLimit : loginRateLimit ,
577
581
FilesRateLimit : filesRateLimit ,
@@ -617,7 +621,9 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
617
621
}
618
622
619
623
if vals .OAuth2 .Github .ClientSecret != "" {
620
- options .GithubOAuth2Config , err = configureGithubOAuth2 (vals .AccessURL .Value (),
624
+ options .GithubOAuth2Config , err = configureGithubOAuth2 (
625
+ oauthIntrument ,
626
+ vals .AccessURL .Value (),
621
627
vals .OAuth2 .Github .ClientID .String (),
622
628
vals .OAuth2 .Github .ClientSecret .String (),
623
629
vals .OAuth2 .Github .AllowSignups .Value (),
@@ -636,7 +642,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
636
642
logger .Warn (ctx , "coder will not check email_verified for OIDC logins" )
637
643
}
638
644
639
- oc , err := createOIDCConfig (ctx , vals )
645
+ oc , err := createOIDCConfig (ctx , oauthIntrument , vals )
640
646
if err != nil {
641
647
return xerrors .Errorf ("create oidc config: %w" , err )
642
648
}
@@ -1737,7 +1743,7 @@ func configureCAPool(tlsClientCAFile string, tlsConfig *tls.Config) error {
1737
1743
}
1738
1744
1739
1745
//nolint:revive // Ignore flag-parameter: parameter 'allowEveryone' seems to be a control flag, avoid control coupling (revive)
1740
- func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups , allowEveryone bool , allowOrgs []string , rawTeams []string , enterpriseBaseURL string ) (* coderd.GithubOAuth2Config , error ) {
1746
+ func configureGithubOAuth2 (instrument * promoauth. Factory , accessURL * url.URL , clientID , clientSecret string , allowSignups , allowEveryone bool , allowOrgs []string , rawTeams []string , enterpriseBaseURL string ) (* coderd.GithubOAuth2Config , error ) {
1741
1747
redirectURL , err := accessURL .Parse ("/api/v2/users/oauth2/github/callback" )
1742
1748
if err != nil {
1743
1749
return nil , xerrors .Errorf ("parse github oauth callback url: %w" , err )
@@ -1790,7 +1796,7 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
1790
1796
}
1791
1797
1792
1798
return & coderd.GithubOAuth2Config {
1793
- OAuth2Config : & oauth2.Config {
1799
+ OAuth2Config : instrument . New ( "github-login" , & oauth2.Config {
1794
1800
ClientID : clientID ,
1795
1801
ClientSecret : clientSecret ,
1796
1802
Endpoint : endpoint ,
@@ -1800,7 +1806,7 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
1800
1806
"read:org" ,
1801
1807
"user:email" ,
1802
1808
},
1803
- },
1809
+ }) ,
1804
1810
AllowSignups : allowSignups ,
1805
1811
AllowEveryone : allowEveryone ,
1806
1812
AllowOrganizations : allowOrgs ,
0 commit comments