deref everything but now with default constants

Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Jan Larwig
2025-11-16 22:38:56 +01:00
parent ceb9a387b1
commit 638fba417f
16 changed files with 116 additions and 52 deletions
+6 -1
View File
@@ -2,6 +2,11 @@ package options
import "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
const (
// DefaultHeaderPreserveRequestValue is the default value for Header.PreserveRequestValue
DefaultHeaderPreserveRequestValue bool = false
)
// Header represents an individual header that will be added to a request or
// response header.
type Header struct {
@@ -59,7 +64,7 @@ type ClaimSource struct {
// EnsureDefaults sets any default values for Header fields.
func (h *Header) EnsureDefaults() {
if h.PreserveRequestValue == nil {
h.PreserveRequestValue = ptr.Ptr(false)
h.PreserveRequestValue = ptr.Ptr(DefaultHeaderPreserveRequestValue)
}
for i := range h.Values {
h.Values[i].EnsureDefaults()
+49 -13
View File
@@ -4,10 +4,46 @@ import "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
const (
// OIDCEmailClaim is the generic email claim used by the OIDC provider.
OIDCEmailClaim = "email"
OIDCEmailClaim string = "email"
// OIDCGroupsClaim is the generic groups claim used by the OIDC provider.
OIDCGroupsClaim = "groups"
OIDCGroupsClaim string = "groups"
// DefaultSkipDiscovery is the default value
// for OIDCOptions.SkipDiscovery
DefaultSkipDiscovery bool = false
// DefaultInsecureSkipNonce is the default value
// for OIDCOptions.InsecureSkipNonce
DefaultInsecureSkipNonce bool = true
// DefaultInsecureAllowUnverifiedEmail is the default value
// for OIDCOptions.InsecureAllowUnverifiedEmail
DefaultInsecureAllowUnverifiedEmail bool = false
// DefaultInsecureSkipIssuerVerification is the default value
// for OIDCOptions.InsecureSkipIssuerVerification
DefaultInsecureSkipIssuerVerification bool = false
// DefaultSkipClaimsFromProfileURL is the default value
// for Provider.SkipClaimsFromProfileURL
DefaultSkipClaimsFromProfileURL bool = false
// DefaultADFSSkipScope is the default value
// for ADFSOptions.SkipScope
DefaultADFSSkipScope bool = false
// DefaultMicrosoftEntraIDUseFederatedToken is the default value
// for MicrosoftEntraIDOptions.FederatedTokenAuth
DefaultMicrosoftEntraIDUseFederatedToken bool = false
// DefaultGoogleUseApplicationDefaultCredentials is the default values
// for GoogleOptions.UseApplicationDefaultCredentials
DefaultUseApplicationDefaultCredentials bool = false
// DefaultUseSystemTrustStore is the default value
// for Provider.UseSystemTrustStore
DefaultUseSystemTrustStore bool = true
)
// OIDCAudienceClaims is the generic audience claim list used by the OIDC provider.
@@ -298,9 +334,9 @@ func providerDefaults() Providers {
Tenant: "common",
},
OIDCConfig: OIDCOptions{
InsecureAllowUnverifiedEmail: ptr.Ptr(false),
InsecureSkipNonce: ptr.Ptr(true),
SkipDiscovery: ptr.Ptr(false),
InsecureAllowUnverifiedEmail: ptr.Ptr(DefaultInsecureAllowUnverifiedEmail),
InsecureSkipNonce: ptr.Ptr(DefaultInsecureSkipNonce),
SkipDiscovery: ptr.Ptr(DefaultSkipDiscovery),
UserIDClaim: OIDCEmailClaim, // Deprecated: Use OIDCEmailClaim
EmailClaim: OIDCEmailClaim,
GroupsClaim: OIDCGroupsClaim,
@@ -322,10 +358,10 @@ func (p Providers) EnsureDefaults() {
// EnsureDefaults sets any default values for Provider fields.
func (p *Provider) EnsureDefaults() {
if p.SkipClaimsFromProfileURL == nil {
p.SkipClaimsFromProfileURL = ptr.Ptr(false)
p.SkipClaimsFromProfileURL = ptr.Ptr(DefaultSkipClaimsFromProfileURL)
}
if p.UseSystemTrustStore == nil {
p.UseSystemTrustStore = ptr.Ptr(true)
p.UseSystemTrustStore = ptr.Ptr(DefaultUseSystemTrustStore)
}
p.OIDCConfig.EnsureDefaults()
@@ -338,13 +374,13 @@ func (p *Provider) EnsureDefaults() {
func (o *OIDCOptions) EnsureDefaults() {
// Ensure OIDC defaults
if o.InsecureAllowUnverifiedEmail == nil {
o.InsecureAllowUnverifiedEmail = ptr.Ptr(false)
o.InsecureAllowUnverifiedEmail = ptr.Ptr(DefaultInsecureAllowUnverifiedEmail)
}
if o.InsecureSkipNonce == nil {
o.InsecureSkipNonce = ptr.Ptr(true)
o.InsecureSkipNonce = ptr.Ptr(DefaultInsecureSkipNonce)
}
if o.SkipDiscovery == nil {
o.SkipDiscovery = ptr.Ptr(false)
o.SkipDiscovery = ptr.Ptr(DefaultSkipDiscovery)
}
if o.UserIDClaim == "" {
o.UserIDClaim = OIDCEmailClaim
@@ -363,20 +399,20 @@ func (o *OIDCOptions) EnsureDefaults() {
// EnsureDefaults sets any default values for MicrosoftEntraIDOptions fields.
func (me *MicrosoftEntraIDOptions) EnsureDefaults() {
if me.FederatedTokenAuth == nil {
me.FederatedTokenAuth = ptr.Ptr(false)
me.FederatedTokenAuth = ptr.Ptr(DefaultMicrosoftEntraIDUseFederatedToken)
}
}
// EnsureDefaults sets any default values for ADFSOptions fields.
func (a *ADFSOptions) EnsureDefaults() {
if a.SkipScope == nil {
a.SkipScope = ptr.Ptr(false)
a.SkipScope = ptr.Ptr(DefaultADFSSkipScope)
}
}
// EnsureDefaults sets any default values for GoogleOptions fields.
func (g *GoogleOptions) EnsureDefaults() {
if g.UseApplicationDefaultCredentials == nil {
g.UseApplicationDefaultCredentials = ptr.Ptr(false)
g.UseApplicationDefaultCredentials = ptr.Ptr(DefaultUseApplicationDefaultCredentials)
}
}
+30 -8
View File
@@ -1,6 +1,7 @@
package options
import (
"net/http"
"time"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
@@ -8,10 +9,31 @@ import (
const (
// DefaultUpstreamFlushInterval is the default value for the Upstream FlushInterval.
DefaultUpstreamFlushInterval = 1 * time.Second
DefaultUpstreamFlushInterval time.Duration = 1 * time.Second
// DefaultUpstreamTimeout is the maximum duration a network dial to a upstream server for a response.
DefaultUpstreamTimeout = 30 * time.Second
DefaultUpstreamTimeout time.Duration = 30 * time.Second
// DefaultUpstreamStatic determines if upstreams are static by default.
DefaultUpstreamStatic bool = false
// DefaultUpstreamStaticCode is the default response code for static upstreams.
DefaultUpstreamStaticCode int = http.StatusOK // 200
// DefaultUpstreamProxyRawPath determines if upstreams will proxy the raw url path by default.
DefaultUpstreamProxyRawPath bool = false
// DefaultUpstreamInsecureSkipTLSVerify determines if upstreams will skip TLS verification by default.
DefaultUpsteamInsecureSkipTLSVerify bool = false
// DefaultUpstreamPassHostHeader determines if upstreams will pass the host header by default.
DefaultUpstreamPassHostHeader bool = true
// DefaultUpstreamProxyWebSockets determines if upstreams will proxy websockets by default.
DefaultUpstreamProxyWebSockets bool = true
// DefaultUpstreamDisableKeepAlives determines if upstreams will disable keep-alives by default.
DefaultUpstreamDisableKeepAlives bool = false
)
// UpstreamConfig is a collection of definitions for upstream servers.
@@ -106,7 +128,7 @@ type Upstream struct {
// EnsureDefaults sets any default values for UpstreamConfig fields.
func (uc *UpstreamConfig) EnsureDefaults() {
if uc.ProxyRawPath == nil {
uc.ProxyRawPath = ptr.Ptr(false)
uc.ProxyRawPath = ptr.Ptr(DefaultUpstreamProxyRawPath)
}
for i := range uc.Upstreams {
uc.Upstreams[i].EnsureDefaults()
@@ -116,24 +138,24 @@ func (uc *UpstreamConfig) EnsureDefaults() {
// EnsureDefaults sets any default values for Upstream fields.
func (u *Upstream) EnsureDefaults() {
if u.InsecureSkipTLSVerify == nil {
u.InsecureSkipTLSVerify = ptr.Ptr(false)
u.InsecureSkipTLSVerify = ptr.Ptr(DefaultUpsteamInsecureSkipTLSVerify)
}
if u.Static == nil {
u.Static = ptr.Ptr(false)
u.Static = ptr.Ptr(DefaultUpstreamStatic)
}
if u.FlushInterval == nil {
u.FlushInterval = ptr.Ptr(DefaultUpstreamFlushInterval)
}
if u.PassHostHeader == nil {
u.PassHostHeader = ptr.Ptr(true)
u.PassHostHeader = ptr.Ptr(DefaultUpstreamPassHostHeader)
}
if u.ProxyWebSockets == nil {
u.ProxyWebSockets = ptr.Ptr(true)
u.ProxyWebSockets = ptr.Ptr(DefaultUpstreamProxyWebSockets)
}
if u.Timeout == nil {
u.Timeout = ptr.Ptr(DefaultUpstreamTimeout)
}
if u.DisableKeepAlives == nil {
u.DisableKeepAlives = ptr.Ptr(false)
u.DisableKeepAlives = ptr.Ptr(DefaultUpstreamDisableKeepAlives)
}
}