OAuth (proto)
This extension has the qualified name envoy.filters.http.oauth2
Note
This extension is intended to be robust against untrusted downstream traffic. It assumes that the upstream is trusted.
Tip
This extension extends and can be used with the following extension category:
This extension must be configured with one of the following type URLs:
OAuth configuration overview.
extensions.filters.http.oauth2.v3.OAuth2Credentials
[extensions.filters.http.oauth2.v3.OAuth2Credentials proto]
{
"client_id": ...,
"token_secret": {...},
"hmac_secret": {...},
"cookie_names": {...},
"cookie_domain": ...
}
- client_id
(string, REQUIRED) The client_id to be used in the authorize calls. This value will be URL encoded when sent to the OAuth server.
- token_secret
(extensions.transport_sockets.tls.v3.SdsSecretConfig) The secret used to retrieve the access token. This value will be URL encoded when sent to the OAuth server. This field is required unless auth_type is set to
TLS_CLIENT_AUTH, in which case authentication is done via the client certificate. Whenauth_typeisPRIVATE_KEY_JWT, this field must contain the PEM-encoded private key used to sign the JWT client assertion.
- hmac_secret
(extensions.transport_sockets.tls.v3.SdsSecretConfig, REQUIRED) If present, the secret token will be a HMAC using the provided secret.
Configures how the secret token should be created.
- cookie_names
(extensions.filters.http.oauth2.v3.OAuth2Credentials.CookieNames) The cookie names used in OAuth filters flow.
- cookie_domain
(string) The domain to set the cookie on. If not set, the cookie will default to the host of the request, not including the subdomains. This is useful when token cookies need to be shared across multiple subdomains.
extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig
[extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig proto]
Configuration for PRIVATE_KEY_JWT client authentication (RFC 7523).
{
"signing_algorithm": ...,
"assertion_lifetime": {...}
}
- signing_algorithm
(extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig.SigningAlgorithm) The signing algorithm to use for the JWT assertion. The private key provided in
token_secretmust match the algorithm family: an RSA key for theRS*algorithms, or an EC key for theES*algorithms. Default:RS256.
- assertion_lifetime
(Duration) The lifetime of the JWT assertion. After this duration, the assertion expires. The value is truncated to whole seconds, so it must be at least
1swhen set. Default:60s.
Enum extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig.SigningAlgorithm
[extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig.SigningAlgorithm proto]
Supported JWT signing algorithms for the client assertion.
- RS256
(DEFAULT) ``RSASSA-PKCS1-v1_5`` using SHA-256.
- RS384
``RSASSA-PKCS1-v1_5`` using SHA-384.
- RS512
``RSASSA-PKCS1-v1_5`` using SHA-512.
- ES256
ECDSA using P-256 and SHA-256.
- ES384
ECDSA using P-384 and SHA-384.
- ES512
ECDSA using P-521 and SHA-512.
extensions.filters.http.oauth2.v3.OAuth2TokenForwarding
[extensions.filters.http.oauth2.v3.OAuth2TokenForwarding proto]
Defines how an OAuth token is forwarded upstream.
{
"header": ...
}
- header
(string, REQUIRED) The upstream request header that will carry the token. Pseudo-headers (names starting with
:) and theHostheader are not allowed.
extensions.filters.http.oauth2.v3.PostLogoutRedirectUri
[extensions.filters.http.oauth2.v3.PostLogoutRedirectUri proto]
Configuration for the post_logout_redirect_uri parameter used in OpenID Connect
RP-Initiated Logout requests.
This configuration is ignored if end_session_endpoint is not set.
{
"disabled": ...,
"uri": ...
}
- disabled
(bool) Do not include the
post_logout_redirect_uriparameter in requests to the configuredend_session_endpoint.
extensions.filters.http.oauth2.v3.OAuth2Config
[extensions.filters.http.oauth2.v3.OAuth2Config proto]
OAuth config
{
"token_endpoint": {...},
"retry_policy": {...},
"authorization_endpoint": ...,
"end_session_endpoint": ...,
"post_logout_redirect_uri": {...},
"credentials": {...},
"redirect_uri": ...,
"redirect_path_matcher": {...},
"signout_path": {...},
"forward_bearer_token": ...,
"forward_id_token": {...},
"preserve_authorization_header": ...,
"pass_through_matcher": [],
"auth_scopes": [],
"resources": [],
"auth_type": ...,
"use_refresh_token": {...},
"default_expires_in": {...},
"deny_redirect_matcher": [],
"default_refresh_token_expires_in": {...},
"disable_id_token_set_cookie": ...,
"disable_access_token_set_cookie": ...,
"disable_refresh_token_set_cookie": ...,
"cookie_configs": {...},
"stat_prefix": ...,
"csrf_token_expires_in": {...},
"code_verifier_token_expires_in": {...},
"disable_token_encryption": ...,
"allow_failed_matcher": [],
"original_request_uri": ...,
"allowed_redirect_domains": [],
"use_access_token_expiry_for_id_token_cookie": ...,
"private_key_jwt_config": {...}
}
- token_endpoint
(config.core.v3.HttpUri) Endpoint on the authorization server to retrieve the access token from.
- retry_policy
(config.core.v3.RetryPolicy) Specifies the retry policy for requests to the OAuth server. If not specified, then no retries will be performed.
- authorization_endpoint
(string, REQUIRED) The endpoint redirect to for authorization in response to unauthorized requests.
- end_session_endpoint
(string) The endpoint at the authorization server to request the user be logged out of the Authorization server. This field is optional and should be set only if openid is in the auth_scopes and the authorization server supports the OpenID Connect RP-Initiated Logout specification. For more information, see https://openid.net/specs/openid-connect-rpinitiated-1_0.html
If configured, the OAuth2 filter will redirect users to this endpoint when they access the signout_path.
- post_logout_redirect_uri
(extensions.filters.http.oauth2.v3.PostLogoutRedirectUri) Optional control for the
post_logout_redirect_uriparameter sent to theend_session_endpointwhen a user accesses thesignout_path. This field should be set only ifopenidis in theauth_scopes, theend_session_endpointis configured, and the authorization server supports the OpenID Connect RP-Initiated Logout specification.If unset, Envoy preserves the historical behavior and sends
<scheme>://<host>/, constructed from the inbound request, aspost_logout_redirect_uri.
- credentials
(extensions.filters.http.oauth2.v3.OAuth2Credentials, REQUIRED) Credentials used for OAuth.
- redirect_uri
(string, REQUIRED) The redirect URI passed to the authorization endpoint. Supports header formatting tokens. For more information, including details on header value syntax, see the documentation on custom request headers.
This URI should not contain any query parameters.
- redirect_path_matcher
(type.matcher.v3.PathMatcher, REQUIRED) Matching criteria used to determine whether a path appears to be the result of a redirect from the authorization server.
- signout_path
(type.matcher.v3.PathMatcher, REQUIRED) The path to sign a user out, clearing their credential cookies.
- forward_bearer_token
(bool) Forward the OAuth token as a Bearer to upstream web service.
- forward_id_token
(extensions.filters.http.oauth2.v3.OAuth2TokenForwarding) Forward the OIDC ID token to the upstream.
If the configured header is
Authorization, Envoy forwards the ID token using theBearerprefix. For any other header, Envoy forwards the raw token value. If not specified, the ID token will not be forwarded.This can not be configured with forward_bearer_token or preserve_authorization_header when the header is
Authorization.
- preserve_authorization_header
(bool) If set to true, preserve the existing authorization header. By default the client strips the existing authorization header before forwarding upstream. Can not be set to true if forward_bearer_token is already set to true. Default value is false.
- pass_through_matcher
(repeated config.route.v3.HeaderMatcher) Any request that matches any of the provided matchers will be passed through without OAuth validation.
- auth_scopes
(repeated string) Optional list of OAuth scopes to be claimed in the authorization request. If not specified, defaults to “user” scope. OAuth RFC https://tools.ietf.org/html/rfc6749#section-3.3
- resources
(repeated string) Optional resource parameter for authorization request RFC: https://tools.ietf.org/html/rfc8707
- auth_type
(extensions.filters.http.oauth2.v3.OAuth2Config.AuthType) Defines how
client_idandclient_secretare sent in OAuth client to OAuth server requests. RFC https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1
- use_refresh_token
(BoolValue) If set to true, allows automatic access token refresh using the associated refresh token (see RFC 6749 section 6), provided that the OAuth server supports that. Default value is true.
- default_expires_in
(Duration) The default lifetime in seconds of the access token, if omitted by the authorization server.
If this value is not set, it will default to
0s. In this case, the expiry must be set by the authorization server or the OAuth flow will fail.
- deny_redirect_matcher
(repeated config.route.v3.HeaderMatcher) Any request that matches any of the provided matchers won’t be redirected to OAuth server when tokens are not valid. Automatic access token refresh will be performed for these requests, if enabled. This behavior can be useful for AJAX requests.
- default_refresh_token_expires_in
(Duration) The default lifetime in seconds of the refresh token, if the exp (expiration time) claim is omitted in the refresh token or the refresh token is not JWT.
If this value is not set, it will default to
604800s. In this case, the cookie with the refresh token will be expired in a week. This setting is only considered ifuse_refresh_tokenis set to true, otherwise the authorization server expiration ordefault_expires_inis used.
- disable_id_token_set_cookie
(bool) If set to true, the client will not set a cookie for ID Token even if one is received from the Identity Provider. This may be useful in cases where the ID Token is too large for HTTP cookies (longer than 4096 characters). Enabling this option will only disable setting the cookie response header, the filter will still process incoming ID Tokens as part of the HMAC if they are there. This is to ensure compatibility while switching this setting on. Future sessions would not set the IdToken cookie header.
- disable_access_token_set_cookie
(bool) If set to true, the client will not set a cookie for Access Token even if one is received from the Identity Provider. Enabling this option will only disable setting the cookie response header, the filter will still process incoming Access Tokens as part of the HMAC if they are there. This is to ensure compatibility while switching this setting on. Future sessions would not set the Access Token cookie header.
- disable_refresh_token_set_cookie
(bool) If set to true, the client will not set a cookie for Refresh Token even if one is received from the Identity Provider. Enabling this option will only disable setting the cookie response header, the filter will still process incoming Refresh Tokens as part of the HMAC if they are there. This is to ensure compatibility while switching this setting on. Future sessions would not set the Refresh Token cookie header.
- cookie_configs
(extensions.filters.http.oauth2.v3.CookieConfigs) Controls for attributes that can be set on the cookies.
- stat_prefix
(string) Optional additional prefix to use when emitting statistics.
- csrf_token_expires_in
(Duration) Optional expiration time for the CSRF protection token cookie. The CSRF token prevents cross-site request forgery attacks during the OAuth2 flow. If not specified, defaults to
600s(10 minutes), which should provide sufficient time for users to complete the OAuth2 authorization flow.
- code_verifier_token_expires_in
(Duration) Optional expiration time for the code verifier cookie. The code verifier is stored in a secure, HTTP-only cookie during the OAuth2 authorization process. If not specified, defaults to
600s(10 minutes), which should provide sufficient time for users to complete the OAuth2 authorization flow.
- disable_token_encryption
(bool) Disable token encryption. When set to true, both the access token and the ID token will be stored in plain text. This option should only be used in secure environments where token encryption is not required. Default is false (tokens are encrypted).
- allow_failed_matcher
(repeated config.route.v3.HeaderMatcher) Any request that matches any of the provided matchers will be allowed to continue to upstream even if OAuth validation fails (missing, invalid, or expired credentials). This is useful for services that can handle both authenticated and unauthenticated requests, enabling graceful degradation patterns.
When triggered, all OAuth cookies are stripped from the request and the request proceeds as unauthenticated. Context headers
x-envoy-oauth-status: failedandx-envoy-oauth-failure-reasonare added to inform upstream.Note: If a request matches pass_through_matcher, it bypasses OAuth validation and this matcher won’t be evaluated. This matcher takes precedence over deny_redirect_matcher.
- original_request_uri
(string) Optional base URI (scheme + host, e.g.
https://app.example.com) used to build the original request URI that is encoded into the OAuth2stateparameter. This URI will be used later to redirect users on a successful OAuth.This is useful when Envoy sits behind a gateway or load balancer that terminates the user-facing hostname: In that case, the post-authentication redirect derived from
statewould send the user to an internal host they didn’t request.Supports request header formatting tokens.
Example:
original_request_uri: “%REQ(x-forwarded-proto?:scheme)%://%REQ(x-forwarded-host?:authority)%”
If not set, defaults to
<:scheme>://<:authority>of the incoming request.
- allowed_redirect_domains
(repeated string) Optional list of domains that are allowed as 1. redirect_uri: which is what the IdP calls after OAuth 2. original_request_uri: the one extracted from the state of an OAuth callback (where should the request go after OAuth)
This mitigates: - injecting a malicious x-forwarded-host or any header that is used to template the redirect urls - open redirect attacks where an attacker crafts a
statevalue pointing to an untrusted host.Each entry is matched against the host (with any port stripped) extracted from the formatted
redirect_uri, the formattedoriginal_request_uri, and the URL decoded from thestateparameter on callback. Matching is case-insensitive and supports two forms:Exact match, e.g.
example.commatches onlyexample.com.Wildcard subdomain match using a leading
*., e.g.*.example.commatchesfoo.example.comandbar.baz.example.combut notexample.comitself.
IPv6 literals must be configured without surrounding brackets (e.g.
::1, not[::1]).If this list is empty (the default), all hosts are allowed and no validation is performed.
- use_access_token_expiry_for_id_token_cookie
(bool) If set to true, the expiration time for the ID token cookie will always be derived from the
expires_infield of the access token response rather than from theexpclaim in the ID token JWT. This is useful when the access token response advertises a longer lifetime than the ID token and you want the ID token cookie to remain valid for that full duration. Default is false (use the ID token’s ownexpclaim when available).
- private_key_jwt_config
(extensions.filters.http.oauth2.v3.PrivateKeyJwtConfig) Configuration for
PRIVATE_KEY_JWTclient authentication. Only used when auth_type is set toPRIVATE_KEY_JWT.
Enum extensions.filters.http.oauth2.v3.OAuth2Config.AuthType
[extensions.filters.http.oauth2.v3.OAuth2Config.AuthType proto]
- URL_ENCODED_BODY
(DEFAULT) The
client_idandclient_secretwill be sent in the URL encoded request body. This type should only be used when Auth server does not support Basic authentication.
- BASIC_AUTH
The
client_idandclient_secretwill be sent using HTTP Basic authentication scheme.
- TLS_CLIENT_AUTH
The client will be authenticated using mutual TLS (mTLS) with a client certificate. The
client_secretis not required and will not be sent in the request to the authorization server. The client certificate must be configured in the cluster used bytoken_endpointvia transport socket configuration. This implements OAuth 2.0 Mutual-TLS Client Authentication as defined in RFC 8705.
- PRIVATE_KEY_JWT
The client authenticates using a signed JWT assertion (RFC 7523). The
token_secretin credentials must contain the PEM-encoded private key used to sign the assertion. The JWT assertion is sent asclient_assertionin the token request body along withclient_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer.
extensions.filters.http.oauth2.v3.OAuth2PerRoute
[extensions.filters.http.oauth2.v3.OAuth2PerRoute proto]
Per-route OAuth2 config.
This message supplies an OAuth2Config for the matched route. It overrides the filter-level config for requests matching the route. If neither the global config nor a per-route config is specified, OAuth2 is disabled for the route.
{
"config": {...}
}
- config
(extensions.filters.http.oauth2.v3.OAuth2Config, REQUIRED) Full OAuth2 config for this route.
extensions.filters.http.oauth2.v3.OAuth2
[extensions.filters.http.oauth2.v3.OAuth2 proto]
Filter config.
{
"config": {...}
}
- config
(extensions.filters.http.oauth2.v3.OAuth2Config) The OAuth2 filter config.