Skip to content

Instantly share code, notes, and snippets.

@mandarjog
Last active October 14, 2021 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandarjog/c5327f1656a77948a2e818b760b54225 to your computer and use it in GitHub Desktop.
Save mandarjog/c5327f1656a77948a2e818b760b54225 to your computer and use it in GitHub Desktop.
Envoy-dynamic-forward proxy
admin:
address:
socket_address:
protocol: TCP
address: 127.0.0.1
port_value: 9901
static_resources:
listeners:
- name: listener_0
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/evax/"
route:
cluster: dynamic_forward_proxy_cluster
typed_per_filter_config:
envoy.filters.http.dynamic_forward_proxy:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.PerRouteConfig
host_rewrite_header: "x-pod-host-header"
#host_rewrite_path_regex: can be used once supported.
# pattern:
# google_re2: {}
# regex: "^/metrics/(.+)/.+$"
# substitution: \1
- match:
prefix: "/"
route:
cluster: dynamic_forward_proxy_cluster
http_filters:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
-- /evax/{uuid}/live/{uuid} --> uuid.$ns.svc.cluster.local
ns = "stability-asm-managed"
port = "8080"
function map_path(path)
local c=string.gmatch(path, "/evax/([^/]*)/.*")
return c() .. "." .. ns .. ".svc.cluster.local:" .. port
end
-- This part can be done in Wasm instead of lua
function envoy_on_request(req)
local path = req:headers():get(":path")
local host_header = map_path(path)
req:logInfo("host=" .. host_header)
-- example host = "svc-0-8-77d9b59c96-5rkfw.stability-asm-managed.svc.cluster.local:8080"
req:headers():replace("x-pod-host-header", host_header)
end
- name: envoy.filters.http.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: V4_ONLY
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: dynamic_forward_proxy_cluster
lb_policy: CLUSTER_PROVIDED
connect_timeout: 2s
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: V4_ONLY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment