Skip to content

Commit

Permalink
feat: ability to disable passing of authorization header to downstrea…
Browse files Browse the repository at this point in the history
…m service
  • Loading branch information
lsjostro committed Sep 3, 2024
1 parent 9989e24 commit 042c44f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
15 changes: 11 additions & 4 deletions authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *Service) Check(ctx context.Context, req *connect.Request[auth.CheckRequ
attribute.String("cookie_name_prefix", provider.CookieNamePrefix),
attribute.String("pre_auth_policy", provider.PreAuthPolicy),
attribute.String("post_auth_policy", provider.PostAuthPolicy),
attribute.Bool("secure_cookie", provider.SecureCookie),
attribute.Bool("secure_cookie", provider.DisableSecureCookie),
attribute.StringSlice("scopes", provider.Scopes),
attribute.String("header_match_name", provider.HeaderMatch.Name),
),
Expand Down Expand Up @@ -283,9 +283,11 @@ func (s *Service) authProcess(ctx context.Context, req *auth.AttributeContext_Ht
return s.authResponse(false, envoy_type.StatusCode_Found, headers, nil, "redirect to Idp"), nil
}

slog.Debug("setting authorization header to upstream request")
if !provider.DisablePassAuthorizationHeader {
slog.Debug("setting authorization header to upstream request")
headers = append(headers, s.setAuthorizationHeader(sessionData.IdToken))
}
span.SetStatus(codes.Ok, "success")
headers = append(headers, s.setAuthorizationHeader(sessionData.IdToken))
return s.authResponse(true, envoy_type.StatusCode_OK, headers, nil, "success"), nil
}

Expand Down Expand Up @@ -394,13 +396,18 @@ func (s *Service) newSession(ctx context.Context, requestedURL, sessionCookieNam
codeChallenge := storeKey[43:]
idpAuthURL := provider.p.IdpAuthURL(codeChallenge)
headers = append(headers, s.setRedirectHeader(idpAuthURL))

// set cookie with session id and redirect to Idp
var secureCookie bool
if !provider.DisableSecureCookie {
secureCookie = true
}
cookie := &http.Cookie{
Name: sessionCookieName,
Value: sessionToken,
Path: "/",
HttpOnly: true,
Secure: provider.SecureCookie,
Secure: secureCookie,
SameSite: http.SameSiteLaxMode,
}

Expand Down
23 changes: 12 additions & 11 deletions authz/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ type OIDCProvider struct {
preAuthPolicy *policy.Policy
postAuthPolicy *policy.Policy

HeaderMatch HeaderMatch `yaml:"headerMatch"`
Logout LogoutConfig `yaml:"logout"`
ClientID string `yaml:"clientID"`
CallbackURI string `yaml:"callbackURI"`
ClientSecret string `yaml:"clientSecret"`
CookieNamePrefix string `yaml:"cookieNamePrefix"`
PreAuthPolicy string `yaml:"preAuthPolicy"`
PostAuthPolicy string `yaml:"postAuthPolicy"`
IssuerURL string `yaml:"issuerURL"`
Scopes []string `yaml:"scopes"`
SecureCookie bool `yaml:"secureCookie"`
HeaderMatch HeaderMatch `yaml:"headerMatch"`
Logout LogoutConfig `yaml:"logout"`
ClientID string `yaml:"clientID"`
CallbackURI string `yaml:"callbackURI"`
ClientSecret string `yaml:"clientSecret"`
CookieNamePrefix string `yaml:"cookieNamePrefix"`
PreAuthPolicy string `yaml:"preAuthPolicy"`
PostAuthPolicy string `yaml:"postAuthPolicy"`
IssuerURL string `yaml:"issuerURL"`
Scopes []string `yaml:"scopes"`
DisableSecureCookie bool `yaml:"disableSecureCookie"`
DisablePassAuthorizationHeader bool `yaml:"disablePassAuthorizationHeader"`
}

type HeaderMatch struct {
Expand Down
3 changes: 2 additions & 1 deletion run/config/providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ providers:
clientID: podinfo
# clientSecret: test1234 # omit for PKCE auth
cookieNamePrefix: podinfo
# secureCookie: true # disable for local development
disableSecureCookie: true # disable for local development
# disablePassAuthorizationHeader: true # disable Authorization header passing to downstream service
logout:
redirectURI: http://localhost:5556/dex/end-session
path: /_authz/logout
Expand Down
1 change: 0 additions & 1 deletion run/k8s/manifests/oidc-providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ providers:
# clientID: client-id
# clientSecret: secret
# cookieNamePrefix: test
# secureCookie: true
# scopes:
# - openid
# - profile
Expand Down

0 comments on commit 042c44f

Please sign in to comment.