05efd5cc8dae6773608cbca6955785342a9daeb6
Envoy Gateway Configuration
This document explains how the Envoy unified ingress gateway is configured and how to modify it.
Files
- deploy/k8s/envoy/envoy.yaml: ConfigMap + Deployment + Service for Envoy
Current Behavior
- Envoy listens on port 8080 in the Pod and exposes port 80 via a ClusterIP Service.
- Route
/api/userstouser-api-svc:8888. - Route
/api/emailtoemail-api-svc:8888. - Route
/healthzreturns200 okdirectly from gateway. - Unknown routes return
404from gateway.
Routing
In envoy.yaml, routes are defined under:
static_resources -> listeners -> http_connection_manager -> route_config -> virtual_hosts
The current routing rules are:
prefix: /api/users->cluster: user_api_clusterprefix: /api/email->cluster: email_api_clusterpath: /healthz-> direct response200prefix: /-> direct response404
To add a new HTTP service, add a new route above the default route and define a new cluster.
Example: route /api/order to order-api-svc:8899
- Add a route match:
- match: prefix: "/api/order" route: cluster: order_api_cluster
- Add a cluster:
- name: order_api_cluster connect_timeout: 2s type: STRICT_DNS lb_policy: ROUND_ROBIN load_assignment: cluster_name: order_api_cluster endpoints: - lb_endpoints: - endpoint: address: socket_address: address: order-api-svc.juwan.svc.cluster.local port_value: 8899
CSRF Protection (Double Cookie)
Envoy uses a Lua filter for double-cookie CSRF validation:
- Safe methods (GET/HEAD/OPTIONS):
- If missing, Envoy auto-issues two cookies:
csrf_tokencsrf_guard
- If missing, Envoy auto-issues two cookies:
- Unsafe methods (POST/PUT/PATCH/DELETE, etc):
- Requires BOTH headers:
X-CSRF-TokenX-CSRF-Guard
- Requires BOTH cookies:
csrf_tokencsrf_guard
- Header values must exactly match cookie values, otherwise Envoy returns
403.
- Requires BOTH headers:
If you want different cookie or header names, update these constants in Lua:
TOKEN_COOKIEGUARD_COOKIETOKEN_HEADERGUARD_HEADER
To relax or tighten rules, edit the functions:
- is_safe(method)
- envoy_on_request(request_handle)
Cookie Attributes
Current Set-Cookie:
csrf_token=<value>; Path=/; SameSite=Strictcsrf_guard=<value>; Path=/; SameSite=Strict
Deployment
Apply or update:
kubectl apply -f deploy/k8s/envoy/envoy.yaml
Common Changes
- Change listening port:
- Update listener port_value and Service targetPort/port.
- Change service namespace:
- Update cluster DNS addresses (e.g.
service.ns.svc.cluster.local).
- Update cluster DNS addresses (e.g.
- Add more services:
- Add route + add cluster, as shown above.
- Update CSRF policy:
- Edit Lua validation logic in
envoy.filters.http.lua.
- Edit Lua validation logic in
Description
Languages
Go
81.3%
Python
14.2%
Shell
2.9%
JavaScript
0.8%
PLpgSQL
0.5%
Other
0.2%