Skip to content

Commit 94b3e24

Browse files
Feat/observability (#40)
* (chore): added otel tracing to envoy proxy config * (chore): added otel tracing to envoy proxy config * (chore): fixed configuration to adhere to yaml spec * (chore): changed exporter endpoint to phoenix * (chore): changed exporter endpoint to phoenix v2 * (chore): changed exporter endpoint to phoenix v3 * chore(): added proper phoenix authentication to envoy * chore(): patched gateway to allow routes from all namespaces * chore(): changed api key * chore(): changed api key v2 * chore(): changed api key v3 * chore(): changed api key v4 * chore(): http redirect fix v1 * chore(): http redirect fix v2 * chore(): http redirect fix v3 * chore(): http redirect fix v4 * chore(): http redirect fix v5 * chore(): http redirect fix v6 * chore(): doc on http to https redirect * chore(): remove obsolete OpenTelemetry configuration from gatewayConfig * chore(): disable gatewayConfig and update OTEL environment variables * chore(): enable gatewayConfig for ai-gateway-tracing * chore(): update OTEL_EXPORTER_OTLP_ENDPOINT to use port 4318 * chore(): dynamicvally patched all available virtual hosts --------- Co-authored-by: Stephane Segning Lambou <stephane.segning-lambou@adorsys.com>
1 parent f426cd1 commit 94b3e24

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

charts/ai-gateway-core/templates/envoypatchpolicy-308.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ spec:
1111
name: {{ .Values.gateway.name }}
1212
type: JSONPatch
1313
jsonPatches:
14+
{{- range $index, $domain := .Values.tls.domains }}
1415
- type: "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
15-
name: "{{ .Values.namespace | default .Release.Namespace }}/{{ .Values.gateway.name }}/http"
16+
name: "{{ $.Values.namespace | default $.Release.Namespace }}/{{ $.Values.gateway.name }}/http"
1617
operation:
17-
# Patching indices 1 and 2 which correspond to our actual domains
18+
# Patching all virtual hosts defined in tls.domains
1819
# Index 0 is a wildcard host that doesn't have a redirect
1920
op: add
20-
path: /virtual_hosts/1/routes/0/redirect/response_code
21-
value: "PERMANENT_REDIRECT"
22-
- type: "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
23-
name: "{{ .Values.namespace | default .Release.Namespace }}/{{ .Values.gateway.name }}/http"
24-
operation:
25-
op: add
26-
path: /virtual_hosts/2/routes/0/redirect/response_code
21+
path: /virtual_hosts/{{ add $index 1 }}/routes/0/redirect/response_code
2722
value: "PERMANENT_REDIRECT"
23+
{{- end }}
2824
{{- end }}

charts/ai-gateway-core/values.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ gatewayConfig:
6363
kubernetes:
6464
env:
6565
- name: OTEL_EXPORTER_OTLP_ENDPOINT
66-
value: "http://phoenix-svc.converse-phoenix:6006"
66+
value: "http://converse-collector.converse-otel:4318"
6767
- name: OTEL_METRICS_EXPORTER
6868
value: "none"
69-
- name: OTEL_EXPORTER_OTLP_HEADERS
70-
value: "Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJBcGlLZXk6MTQifQ.a26PKaWL5J-xiJwFM8spE2bXR4V8auqAyWDOCTr04Z4"
7169

7270
envoyProxy:
7371
enabled: true
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# HTTP Redirection: Why 308 Matters for APIs
2+
3+
This document explains the technical details behind the HTTP redirection issue we fixed in the `ai-gateway-core` chart.
4+
5+
## 1. The Core Issue: 301 vs. 308
6+
7+
When a client (like `curl`) makes a request to `http://` and receives a redirect to `https://`, the status code tells the client exactly how to behave.
8+
9+
### HTTP 301 (Moved Permanently)
10+
* **Legacy Behavior**: Originally, the spec said the method should be preserved. In practice, however, most browsers and clients (including `curl`) **change the method to GET** and drop the request body when following a 301 redirect.
11+
* **The Symptom**: Your `POST` request became a `GET` request on the second leg, leading to "method not allowed" or missing body errors.
12+
13+
### HTTP 308 (Permanent Redirect)
14+
* **Modern Behavior**: This code was specifically created to solve the ambiguity of 301. It **requires** the client to preserve the original HTTP method and body.
15+
* **The Result**: A `POST` remains a `POST`. This is essential for REST APIs.
16+
17+
## 2. The Discovery
18+
We knew it was a redirection issue when your `curl -v` log showed:
19+
```text
20+
* Clear auth, redirects to port from 80 to 443
21+
* Switch from POST to GET
22+
```
23+
This "Switch from POST to GET" is the hallmark behavior of a client following a 301 redirect.
24+
25+
## 3. The Implementation (Envoy Gateway)
26+
27+
### The Constraint
28+
Envoy Gateway (EG) implements the Kubernetes Gateway API. While the spec allows `308`, the **Envoy Gateway controller (as of v1.7.0) only supports `301` and `302`** in its standard `RequestRedirect` filter.
29+
30+
### The Workaround: EnvoyPatchPolicy
31+
Since we couldn't set `308` in the `HTTPRoute`, we had to go "under the hood" of the Envoy configuration (xDS) using an `EnvoyPatchPolicy`.
32+
33+
1. **Inspection**: We used `kubectl port-forward` and a `config_dump` to see exactly how EG was configuring Envoy.
34+
2. **Mapping**: We found that the redirect routes were located in specific `virtual_hosts` indices (1 and 2).
35+
3. **Patching**: We applied a JSON Patch to override the generated Envoy configuration:
36+
```yaml
37+
operation:
38+
op: add
39+
path: /virtual_hosts/1/routes/0/redirect/response_code
40+
value: "PERMANENT_REDIRECT" # This is Envoy's internal name for 308
41+
```
42+
43+
## 4. The `curl` Security Behavior
44+
45+
Even with a 308, you noticed that the `Authorization` header was initially missing in the second request.
46+
47+
### Why `curl` drops headers
48+
By default, `curl` is highly protective of your credentials. When it follows a redirect that changes the **origin** (even just a protocol change from `http` to `https`), it strips sensitive headers like `Authorization` to prevent them from being sent to a potentially malicious redirected destination.
49+
50+
### The Fix: `--location-trusted`
51+
The `--location-trusted` flag tells `curl` that you trust the redirected destination and want it to reuse the original credentials and headers.
52+
53+
## Summary Checklist for API Redirects
54+
1. **Use 308**: Always use 308 for internal HTTP -> HTTPS redirects in APIs.
55+
2. **Avoid 80**: Ideally, API clients should talk directly to 443 (HTTPS) to avoid the redirect trip entirely.
56+
3. **HSTS**: Consider enabling strict-transport-security (HSTS) headers so the client's OS remembers to use HTTPS automatically for future requests.

0 commit comments

Comments
 (0)