Skip to content

Commit 4a63c71

Browse files
committed
chore: option to skip tls cert validation for oidc provider
1 parent 671994a commit 4a63c71

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ You can specify configuration options either via a config file (default: `config
204204
| `security.cookie_max_age` /<br> `WAKAPI_COOKIE_MAX_AGE` | `172800` | Lifetime of authentication cookies in seconds or `0` to use [Session](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Define_the_lifetime_of_a_cookie) cookies |
205205
| `security.allow_signup` /<br> `WAKAPI_ALLOW_SIGNUP` | `true` | Whether to enable local user registration |
206206
| `security.oidc_allow_signup` /<br> `WAKAPI_OIDC_ALLOW_SIGNUP` | `true` | Whether to enable user registration via OIDC |
207+
| `security.oidc_insecure` /<br> `WAKAPI_OIDC_INSECURE` | `false` | Skip TLS certificate validation for OIDC provider (only for debugging purposes!) |
207208
| `security.signup_captcha` /<br> `WAKAPI_SIGNUP_CAPTCHA` | `false` | Whether the registration form requires solving a CAPTCHA |
208209
| `security.invite_codes` /<br> `WAKAPI_INVITE_CODES` | `true` | Whether to enable registration by invite codes. Primarily useful if registration is disabled (invite-only server). |
209210
| `security.disable_frontpage` /<br> `WAKAPI_DISABLE_FRONTPAGE` | `false` | Whether to disable landing page (useful for personal instances) |

config.default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ security:
8989
cookie_max_age: 172800
9090
allow_signup: true # whether to allow new user creation at all
9191
oidc_allow_signup: true # allow registration of new users from oidc
92+
oidc_insecure: false # skip tls certificate validation for oidc provider
9293
disable_local_auth: false # disable login via local credentials (username and password) to enforce OIDC provider login
9394
disable_webauthn: true # disable login via webauthn (security keys, biometrics, etc.)
9495
signup_captcha: false

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ type appConfig struct {
127127
type securityConfig struct {
128128
AllowSignup bool `yaml:"allow_signup" default:"true" env:"WAKAPI_ALLOW_SIGNUP"`
129129
OidcAllowSignup bool `yaml:"oidc_allow_signup" default:"true" env:"WAKAPI_OIDC_ALLOW_SIGNUP"`
130+
OidcInsecure bool `yaml:"oidc_insecure" default:"false" env:"WAKAPI_OIDC_INSECURE"`
130131
DisableLocalAuth bool `yaml:"disable_local_auth" default:"false" env:"WAKAPI_DISABLE_LOCAL_AUTH"`
131132
DisableWebAuthn bool `yaml:"disable_webauthn" default:"true" env:"WAKAPI_DISABLE_WEBAUTHN"`
132133
SignupCaptcha bool `yaml:"signup_captcha" default:"false" env:"WAKAPI_SIGNUP_CAPTCHA"`

config/oidc.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package config
22

33
import (
44
"context"
5+
"crypto/tls"
56
"fmt"
7+
"net/http"
68
"strings"
79
"time"
810

@@ -74,10 +76,21 @@ func (token *IdTokenPayload) getClaimValue(claimName string) string {
7476

7577
var oidcProviders = make(map[string]*OidcProvider)
7678

79+
func GetOidcContext(ctx context.Context) context.Context {
80+
tp := http.DefaultTransport.(*http.Transport).Clone()
81+
tp.DisableCompression = true
82+
tp.TLSClientConfig = &tls.Config{
83+
InsecureSkipVerify: cfg.Security.OidcInsecure,
84+
}
85+
return oidc.ClientContext(ctx, &http.Client{
86+
Transport: tp,
87+
})
88+
}
89+
7790
func RegisterOidcProvider(providerCfg *oidcProviderConfig) {
7891
cfg := Get()
7992

80-
provider, err := oidc.NewProvider(context.Background(), providerCfg.Endpoint)
93+
provider, err := oidc.NewProvider(GetOidcContext(context.Background()), providerCfg.Endpoint)
8194
if err != nil {
8295
Log().Fatal(fmt.Sprintf("failed to initialize oidc provider at %s", providerCfg.Endpoint), "error", err)
8396
return

routes/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func (h *LoginHandler) GetOidcCallback(w http.ResponseWriter, r *http.Request) {
429429
routeutils.ClearOidcState(r, w)
430430

431431
// exchange auth code for access token and id token
432-
authToken, err := provider.OAuth2.Exchange(r.Context(), code)
432+
authToken, err := provider.OAuth2.Exchange(conf.GetOidcContext(r.Context()), code)
433433
if err != nil {
434434
errMsg := "failed to exchange authorization code for access token"
435435
conf.Log().Request(r).Error(errMsg, "provider", provider.Name)
@@ -449,7 +449,7 @@ func (h *LoginHandler) GetOidcCallback(w http.ResponseWriter, r *http.Request) {
449449
}
450450

451451
// verify id token
452-
idTokenPayload, err := routeutils.DecodeOidcIdToken(rawIdToken, provider, r.Context())
452+
idTokenPayload, err := routeutils.DecodeOidcIdToken(rawIdToken, provider, conf.GetOidcContext(r.Context()))
453453
if err != nil || idTokenPayload == nil {
454454
errMsg := "failed to verify and decode id_token"
455455
conf.Log().Request(r).Error(errMsg, "provider", provider.Name, "id_token", rawIdToken) // save to log, because does not grant any access

0 commit comments

Comments
 (0)