feat: migrate google used organization id and header normalization booleans to pointers

Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Jan Larwig
2025-11-16 22:39:01 +01:00
parent 0eec65e230
commit 15041dd116
8 changed files with 19 additions and 8 deletions
+2 -1
View File
@@ -169,8 +169,9 @@ redirect_url="http://localhost:4180/oauth2/callback"
SkipClaimsFromProfileURL: ptr.To(false),
GoogleConfig: options.GoogleOptions{
AdminEmail: "admin@example.com",
UseApplicationDefaultCredentials: ptr.To(false),
TargetPrincipal: "principal",
UseOrganizationID: ptr.To(false),
UseApplicationDefaultCredentials: ptr.To(false),
},
AzureConfig: options.AzureOptions{
Tenant: "common",
+3 -1
View File
@@ -5,6 +5,8 @@ import "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
const (
// DefaultHeaderPreserveRequestValue is the default value for Header.PreserveRequestValue
DefaultHeaderPreserveRequestValue bool = false
// DefaultInsecureSkipHeaderNormalization is the default value for Header.InsecureSkipHeaderNormalization
DefaultInsecureSkipHeaderNormalization bool = false
)
// Header represents an individual header that will be added to a request or
@@ -28,7 +30,7 @@ type Header struct {
// treated as the same header. Additionally underscores (_) in header names
// will be converted to dashes (-) when normalizing.
// Defaults to false (header names will be normalized).
InsecureSkipHeaderNormalization bool `json:"InsecureSkipHeaderNormalization,omitempty"`
InsecureSkipHeaderNormalization *bool `yaml:"InsecureSkipHeaderNormalization,omitempty"`
// Values contains the desired values for this header
Values []HeaderValue `yaml:"values,omitempty"`
+1 -1
View File
@@ -789,7 +789,7 @@ func (l *LegacyProvider) convert() (Providers, error) {
ServiceAccountJSON: l.GoogleServiceAccountJSON,
UseApplicationDefaultCredentials: &l.GoogleUseApplicationDefaultCredentials,
TargetPrincipal: l.GoogleTargetPrincipal,
UseOrganizationID: l.GoogleUseOrganizationID,
UseOrganizationID: &l.GoogleUseOrganizationID,
AdminAPIUserScope: l.GoogleAdminAPIUserScope,
}
case "entra-id":
+2
View File
@@ -955,6 +955,7 @@ var _ = Describe("Legacy Options", func() {
}
defaultGoogleOptions := GoogleOptions{
UseOrganizationID: ptr.To(false),
UseApplicationDefaultCredentials: ptr.To(false),
}
@@ -1020,6 +1021,7 @@ var _ = Describe("Legacy Options", func() {
AdminEmail: "email@email.com",
ServiceAccountJSON: "test.json",
Groups: []string{"1", "2"},
UseOrganizationID: ptr.To(false),
UseApplicationDefaultCredentials: ptr.To(false),
},
LoginURLParameters: defaultURLParams,
+7 -1
View File
@@ -37,6 +37,10 @@ const (
// for MicrosoftEntraIDOptions.FederatedTokenAuth
DefaultMicrosoftEntraIDUseFederatedToken bool = false
// DefaultGoogleUseOrganizationID is the default value
// for GoogleOptions.UseOrganizationID
DefaultGoogleUseOrganizationID bool = false
// DefaultGoogleUseApplicationDefaultCredentials is the default values
// for GoogleOptions.UseApplicationDefaultCredentials
DefaultUseApplicationDefaultCredentials bool = false
@@ -269,7 +273,7 @@ type GoogleOptions struct {
// TargetPrincipal is the Google Service Account used for Application Default Credentials
TargetPrincipal string `yaml:"targetPrincipal,omitempty"`
// UseOrganizationId indicates whether to use the organization ID as the UserName claim
UseOrganizationID bool `yaml:"useOrganizationID,omitempty"`
UseOrganizationID *bool `yaml:"useOrganizationID,omitempty"`
// admin scope needed for fetching user organization information from admin api, can be one of cloud, user or defaults to readonly
AdminAPIUserScope string `yaml:"adminAPIUserScope,omitempty"`
}
@@ -412,6 +416,8 @@ func (a *ADFSOptions) EnsureDefaults() {
// EnsureDefaults sets any default values for GoogleOptions fields.
func (g *GoogleOptions) EnsureDefaults() {
g.UseOrganizationID = ptr.To(DefaultGoogleUseOrganizationID)
if g.UseApplicationDefaultCredentials == nil {
g.UseApplicationDefaultCredentials = ptr.To(DefaultUseApplicationDefaultCredentials)
}
+1 -1
View File
@@ -54,7 +54,7 @@ func flattenHeaders(headers http.Header) {
func stripHeaders(headers []options.Header, next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
for _, header := range headers {
if header.InsecureSkipHeaderNormalization {
if ptr.Deref(header.InsecureSkipHeaderNormalization, options.DefaultInsecureSkipHeaderNormalization) {
req.Header.Del(header.Name)
continue
}
+1 -1
View File
@@ -231,7 +231,7 @@ var _ = Describe("Headers Suite", func() {
headers: []options.Header{
{
Name: "X-Auth-Request-User",
InsecureSkipHeaderNormalization: true,
InsecureSkipHeaderNormalization: ptr.To(true),
Values: []options.HeaderValue{
{
ClaimSource: &options.ClaimSource{Claim: "user"},
+2 -2
View File
@@ -109,11 +109,11 @@ func NewGoogleProvider(p *ProviderData, opts options.GoogleOptions) (*GoogleProv
},
}
if opts.UseOrganizationID || opts.ServiceAccountJSON != "" || ptr.Deref(opts.UseApplicationDefaultCredentials, options.DefaultUseApplicationDefaultCredentials) {
if ptr.Deref(opts.UseOrganizationID, options.DefaultGoogleUseOrganizationID) || opts.ServiceAccountJSON != "" || ptr.Deref(opts.UseApplicationDefaultCredentials, options.DefaultUseApplicationDefaultCredentials) {
// reuse admin service to avoid multiple calls for token
var adminService *admin.Service
if opts.UseOrganizationID {
if ptr.Deref(opts.UseOrganizationID, options.DefaultGoogleUseOrganizationID) {
// add user scopes to admin api
userScope := getAdminAPIUserScope(opts.AdminAPIUserScope)
for index, scope := range possibleScopesList {