-
Notifications
You must be signed in to change notification settings - Fork 10
custom filter
Anker Tsaur edited this page Jan 3, 2024
·
1 revision
How to add a envoy filter which titan currently does not support
- Note:
- This is to provide an intermidiate solution before such filter to be supported by titan natively
Create a helm template function which contains the envoy filter configuration
- The name of function needs to be globally unique within the entire the umbrella chart deployment
- You can use values to provide the configuration input, see the exmaple below for detail
Example
{{- define "envoy.filters.http.custom_response_handling_for_console_app" }}
{{- $config := .config | default dict }}
{{- $customFilterEnabled := ternary $config.enabled true (hasKey $config "enabled") }}
{{- if $customFilterEnabled }}
- name: custom-composite-filter
typed_config:
"@type": type.googleapis.com/envoy.extensions.common.matching.v3.ExtensionWithMatcher
extension_config:
name: composite
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.composite.v3.Composite
xds_matcher:
matcher_list:
matchers:
- predicate:
single_predicate:
input:
name: request-headers
typed_config:
"@type": type.googleapis.com/envoy.type.matcher.v3.HttpRequestHeaderMatchInput
header_name: :path
value_match:
prefix: "/oidc/redirect"
on_match:
action:
name: composite-action
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.composite.v3.ExecuteFilterAction
typed_config:
name: envoy.filters.http.custom_response
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.custom_response.v3.CustomResponse
custom_response_matcher:
matcher_list:
matchers:
# Redirect to different upstream if the status code is 504.
- predicate:
single_predicate:
input:
name: "504_response"
typed_config:
"@type": type.googleapis.com/envoy.type.matcher.v3.HttpResponseStatusCodeMatchInput
value_match:
exact: "504"
on_match:
action:
name: action
typed_config:
"@type": type.googleapis.com/envoy.extensions.http.custom_response.local_response_policy.v3.LocalResponsePolicy
status_code: {{ $config.redirectStatusCode | default "302" }}
response_headers_to_add:
- header:
key: "Location"
value: {{ $config.redirectLocation | default "/unKnowUri" | quote }}
{{- end }}
{{- end }}
titanSideCars:
customTpls:
envoy:
filters:
- name: envoy.filters.http.custom_response_handling_for_console_app
config:
redirectStatusCode: "302"
redirectLocation: ""/cc/loginError?loginError=4"