Skip to content

Commit

Permalink
oidc: preserve authorization header (#3567)
Browse files Browse the repository at this point in the history
* oidc preserve authorization header

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>

* do not preserve the original authorization header if ForwardAccessToken is true

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Co-authored-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zhaohuabing and zirain authored Jun 20, 2024
1 parent f2c9ec9 commit d49337b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/xds/translator/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func oauth2Config(oidc *ir.OIDC) (*oauth2v3.OAuth2, error) {
oidc.Provider.TokenEndpoint)
}

// Envoy OAuth2 filter deletes the HTTP authorization header by default, which surprises users.
preserveAuthorizationHeader := true

// If the user wants to forward the oauth2 access token to the upstream service,
// we should not preserve the original authorization header.
if oidc.ForwardAccessToken {
preserveAuthorizationHeader = false
}

oauth2 := &oauth2v3.OAuth2{
Config: &oauth2v3.OAuth2Config{
TokenEndpoint: &corev3.HttpUri{
Expand Down Expand Up @@ -172,6 +181,8 @@ func oauth2Config(oidc *ir.OIDC) (*oauth2v3.OAuth2, error) {
AuthType: oauth2v3.OAuth2Config_BASIC_AUTH,
AuthScopes: oidc.Scopes,
Resources: oidc.Resources,

PreserveAuthorizationHeader: preserveAuthorizationHeader,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
sdsConfig:
ads: {}
resourceApiVersion: V3
preserveAuthorizationHeader: true
redirectPathMatcher:
path:
exact: /foo/oauth2/callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
sdsConfig:
ads: {}
resourceApiVersion: V3
preserveAuthorizationHeader: true
redirectPathMatcher:
path:
exact: /bar/oauth2/callback
Expand Down

0 comments on commit d49337b

Please sign in to comment.