Skip to content

Commit 4452a12

Browse files
authored
feat(gateway): migrate Istio edge config to a gateway-guardrails Helm chart (rate limits + CORS lockdown) (#218)
* feat(gateway): migrate Istio edge config to a gateway-guardrails Helm chart The public chatbot edge (Gateway, TLS, CORS, rate limits, mesh AuthorizationPolicies) was defined as raw kubectl_manifest YAML heredocs inside Terraform. That is unreviewable, has no schema validation, and had already drifted from the live cluster. Introduces docs-agent-mcp/charts/gateway-guardrails as the single source of truth for the edge: - Gateway + Let's Encrypt TLS (cert-manager), HTTP -> HTTPS redirect. - VirtualService with CORS locked to the published widget origin (was a wildcard regex) and a 30s route timeout so a hung LLM call cannot pin a worker. - Global rate limit: 60 req/min token bucket, scoped to the :443 listener only. The ingress pod is shared with knative-ingress-gateway and knative-local-gateway (the agent -> LLM path), so port scoping keeps the cap off the internal listeners. - Per-IP rate limit (Envoy ratelimit service + Redis) included but disabled: the ingress runs externalTrafficPolicy: Cluster, so client IPs are SNAT'd and a per-IP descriptor would act as a single shared bucket. Enabling it needs real client IPs at the gateway first. - The 8 RAG-stack AuthorizationPolicies, migrated verbatim. Terraform now installs the chart via a single helm_release (gateway_guardrails.tf); istio_policies.tf and kagent_ingress.tf are removed, along with the YAML string-interpolation used to build the CORS list. All knobs live in values.yaml (domain, origins, rate limits, timeouts, toggles). Validated: helm lint, helm template (default and per-IP variants), terraform validate, and kubectl apply --dry-run=server of the full rendered chart. MIGRATION NOTE: on an already-provisioned cluster, terraform state rm the old kubectl_manifest resources and let Helm adopt the live objects (annotate with meta.helm.sh/release-name), or accept a destroy/recreate of the edge config. Signed-off-by: Rohit Kumar <rr7433446@gmail.com> * feat(pipelines): emit structured JSON from download_github_issues Keep human-readable markdown in content for RAG embedding text, and add machine-readable fields (title, repo, issue_number, body, comments) so chunk_and_embed_issues no longer depends on regex-parsing MD. Downstream prefers structured fields and falls back to the legacy markdown parser only for older artifacts. Signed-off-by: Rohit Kumar <rr7433446@gmail.com> Co-authored-by: Rohit Kumar <kmr-rohit@users.noreply.github.com> --------- Signed-off-by: Rohit Kumar <rr7433446@gmail.com> Co-authored-by: Rohit Kumar <kmr-rohit@users.noreply.github.com>
1 parent b93d054 commit 4452a12

24 files changed

Lines changed: 1740 additions & 483 deletions

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,13 @@ We use Terraform for declarative, reproducible cluster infrastructure on OKE.
734734
* **`kubeflow_pipelines.tf`**: Deploys Kubeflow Pipelines (Standalone) into the `kubeflow` namespace without Istio sidecars (to prevent routing conflicts), persisting `fsGroup` patches for SeaweedFS.
735735
* **`milvus.tf`**: Uses the Milvus Operator to deploy a lightweight Milvus Standalone instance strictly scheduled on CPU nodes, reserving GPU nodes purely for LLM inference.
736736
* **`kagent.tf`**: Installs official `kagent-crds` and the `kagent` controller via OCI Helm charts, with bundled agents cleanly disabled.
737-
* **`istio_policies.tf`**: Implements zero-trust networking, explicitly allowing internal cluster traffic where needed (e.g., KFP Pipeline to Milvus, Kagent to Milvus).
737+
* **`gateway_guardrails.tf`**: Installs the local `charts/gateway-guardrails` Helm chart — the single source of truth for the public edge: Istio Gateway + TLS, CORS-locked VirtualService, rate limits, and the zero-trust AuthorizationPolicies that explicitly allow internal cluster traffic where needed (e.g., KFP Pipeline to Milvus, Kagent to Milvus). Replaces the former inline `istio_policies.tf` / `kagent_ingress.tf`.
738+
739+
### Gateway Guardrails Helm Chart (`docs-agent-mcp/charts/gateway-guardrails/`)
740+
Guardrails protecting the publicly shared chatbot, all tunable via `values.yaml`:
741+
* **Rate limiting**: 60 req/min global token bucket on the chatbot HTTPS listener (EnvoyFilter), plus an optional per-client-IP layer (Envoy ratelimit service + Redis, off until the ingress preserves client IPs).
742+
* **CORS lockdown**: only the published widget origin may embed the chatbot; a 30s route timeout caps hung LLM calls.
743+
* **Mesh policies**: the RAG-stack AuthorizationPolicies (Milvus, LLM, MCP, embeddings), previously raw YAML heredocs inside Terraform.
738744

739745
### Pipeline Optimizations (`docs-agent-mcp/pipelines/`)
740746
The ingestion pipeline was rewritten to maximize efficiency and avoid Kubernetes ephemeral storage eviction:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v2
2+
name: gateway-guardrails
3+
description: >-
4+
Public gateway guardrails for the Kubeflow docs-agent chatbot: Istio
5+
Gateway + TLS, CORS-locked VirtualService, global and per-IP rate limits,
6+
and the mesh AuthorizationPolicies for the RAG stack. Replaces the raw
7+
kubectl_manifest heredocs previously embedded in terraform
8+
(istio_policies.tf, kagent_ingress.tf) and the standalone manifests
9+
under manifests/istio*.
10+
type: application
11+
version: 0.1.0
12+
appVersion: "0.1.0"
13+
keywords:
14+
- istio
15+
- rate-limit
16+
- kubeflow
17+
- docs-agent
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# gateway-guardrails
2+
3+
Helm chart for the public gateway of the Kubeflow docs-agent chatbot.
4+
This chart is the **single source of truth** for the Istio edge config —
5+
it replaces the raw `kubectl_manifest` heredocs that previously lived in
6+
`terraform/istio_policies.tf` and `terraform/kagent_ingress.tf`, and the
7+
standalone YAML under `manifests/istio*`.
8+
9+
## What it manages
10+
11+
| Layer | Resources | Toggle |
12+
|---|---|---|
13+
| TLS | ClusterIssuer (Let's Encrypt) + Certificate | `gateway.tls.acme.enabled` |
14+
| Routing | Gateway + VirtualService (CORS lockdown, 30s timeout) | `gateway.enabled` |
15+
| Rate limit L1 | `a2a-global-ratelimit` EnvoyFilter — 60 req/min token bucket on the :443 listener | `rateLimit.global.enabled` |
16+
| Rate limit L2 | Envoy ratelimit service + Redis + EnvoyFilter — 10 req/min per client IP | `rateLimit.perIP.enabled` (off: needs real client IPs, see below) |
17+
| Mesh policies | 8 AuthorizationPolicies for the RAG stack (Milvus, LLM, MCP, embeddings) | `meshPolicies.enabled` |
18+
19+
## Why
20+
21+
The chatbot is backed by a single GPU-served LLM. Without limits, one script can
22+
exhaust GPU capacity (cost + DoS), and wide-open CORS let any origin embed it.
23+
These guardrails cap request volume and lock down who may call the endpoint —
24+
all at the Istio ingress, with no application changes.
25+
26+
## Install / upgrade
27+
28+
```bash
29+
helm upgrade --install gateway-guardrails . -n docs-agent \
30+
--set domain=agent.example.com \
31+
--set gateway.tls.acme.email=you@example.com
32+
```
33+
34+
Tuning examples:
35+
36+
```bash
37+
--set rateLimit.global.requestsPerMinute=120
38+
--set routing.cors.allowOrigins[0].exact=https://your-widget.example.app
39+
```
40+
41+
## Per-IP rate limit prerequisite
42+
43+
`rateLimit.perIP` ships **disabled**: the ingress Service runs
44+
`externalTrafficPolicy: Cluster`, so client IPs are SNAT'd to node IPs and a
45+
per-IP descriptor would act as one shared bucket — effectively a second, tighter
46+
global limit rather than per-client fairness. Before enabling, either set
47+
`externalTrafficPolicy: Local` on the ingress Service (and verify the LB health
48+
checks) or trust XFF via `meshConfig.numTrustedProxies`.
49+
50+
## Verifying
51+
52+
```bash
53+
# Rate limit: expect a mix of 200/429 past the per-minute cap
54+
seq 1 100 | xargs -P 25 -I{} curl -s -o /dev/null -w "%{http_code}\n" \
55+
-X POST https://$DOMAIN/api/a2a/docs-agent/kubeflow-docs-agent \
56+
-H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":"t","method":"x"}' | sort | uniq -c
57+
58+
# CORS: the allowed origin gets an allow-origin header; others do not
59+
curl -s -o /dev/null -D - -X OPTIONS https://$DOMAIN/api/a2a/docs-agent/kubeflow-docs-agent \
60+
-H "Origin: https://your-widget.example.app" -H "Access-Control-Request-Method: POST" \
61+
| grep -i access-control-allow-origin
62+
```
63+
64+
## Note on the shared ingress gateway
65+
66+
`knative-ingress-gateway` and `knative-local-gateway` also select
67+
`istio: ingressgateway` (the agent → LLM path rides knative-local on the same
68+
pod). The rate-limit EnvoyFilter is therefore scoped to the `:443` listener so
69+
it never applies to the knative / internal LLM listeners.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{/* Common labels stamped on every chart-managed resource. */}}
2+
{{- define "gateway-guardrails.labels" -}}
3+
app.kubernetes.io/part-of: docs-agent
4+
app.kubernetes.io/managed-by: {{ .Release.Service }}
5+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
6+
{{- end }}
7+
8+
{{/* Shared CORS policy — identical on every VirtualService route. */}}
9+
{{- define "gateway-guardrails.corsPolicy" -}}
10+
corsPolicy:
11+
allowOrigins:
12+
{{ toYaml .Values.routing.cors.allowOrigins | indent 4 }}
13+
allowMethods:
14+
{{ toYaml .Values.routing.cors.allowMethods | indent 4 }}
15+
allowHeaders:
16+
{{ toYaml .Values.routing.cors.allowHeaders | indent 4 }}
17+
maxAge: {{ .Values.routing.cors.maxAge | quote }}
18+
{{- end }}
19+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.gateway.enabled }}
2+
apiVersion: networking.istio.io/v1alpha3
3+
kind: Gateway
4+
metadata:
5+
name: kagent-gateway
6+
namespace: {{ .Values.namespaces.istioSystem }}
7+
labels:
8+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
9+
spec:
10+
selector:
11+
{{- toYaml .Values.gateway.selector | nindent 4 }}
12+
servers:
13+
- port:
14+
number: 80
15+
name: http
16+
protocol: HTTP
17+
hosts:
18+
- {{ .Values.domain | quote }}
19+
tls:
20+
httpsRedirect: {{ .Values.gateway.tls.enabled }}
21+
{{- if .Values.gateway.tls.enabled }}
22+
- port:
23+
number: 443
24+
name: https
25+
protocol: HTTPS
26+
hosts:
27+
- {{ .Values.domain | quote }}
28+
tls:
29+
mode: SIMPLE
30+
credentialName: {{ .Values.gateway.tls.credentialName }}
31+
{{- end }}
32+
{{- end }}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{{- if .Values.meshPolicies.enabled }}
2+
# =============================================================================
3+
# RAG-stack AuthorizationPolicies (migrated from terraform istio_policies.tf).
4+
# Default mesh policy is deny-all where sidecars are present; these explicitly
5+
# allow the traffic flows the stack needs.
6+
# =============================================================================
7+
8+
# --- Milvus internal traffic (ml-infra) ---
9+
apiVersion: security.istio.io/v1beta1
10+
kind: AuthorizationPolicy
11+
metadata:
12+
name: allow-milvus-standalone
13+
namespace: {{ .Values.namespaces.mlInfra }}
14+
labels:
15+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
16+
spec:
17+
selector:
18+
matchLabels:
19+
app.kubernetes.io/name: milvus
20+
component: standalone
21+
action: ALLOW
22+
rules:
23+
- to:
24+
- operation:
25+
ports: ["19530", "9091"]
26+
---
27+
apiVersion: security.istio.io/v1beta1
28+
kind: AuthorizationPolicy
29+
metadata:
30+
name: allow-milvus-etcd
31+
namespace: {{ .Values.namespaces.mlInfra }}
32+
labels:
33+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
34+
spec:
35+
selector:
36+
matchLabels:
37+
app.kubernetes.io/name: etcd
38+
action: ALLOW
39+
rules:
40+
- to:
41+
- operation:
42+
ports: ["2379", "2380"]
43+
---
44+
apiVersion: security.istio.io/v1beta1
45+
kind: AuthorizationPolicy
46+
metadata:
47+
name: allow-milvus-minio
48+
namespace: {{ .Values.namespaces.mlInfra }}
49+
labels:
50+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
51+
spec:
52+
selector:
53+
matchLabels:
54+
app: minio
55+
action: ALLOW
56+
rules:
57+
- to:
58+
- operation:
59+
ports: ["9000", "9001"]
60+
---
61+
# --- Cross-namespace traffic ---
62+
# docs-agent/mcp-server -> ml-infra/milvus (vector DB queries)
63+
apiVersion: security.istio.io/v1beta1
64+
kind: AuthorizationPolicy
65+
metadata:
66+
name: allow-mcp-to-milvus
67+
namespace: {{ .Values.namespaces.mlInfra }}
68+
labels:
69+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
70+
spec:
71+
selector:
72+
matchLabels:
73+
app.kubernetes.io/name: milvus
74+
component: standalone
75+
action: ALLOW
76+
rules:
77+
- from:
78+
- source:
79+
namespaces: ["{{ .Values.namespaces.docsAgent }}"]
80+
to:
81+
- operation:
82+
ports: ["19530"]
83+
---
84+
# docs-agent/kagent -> ml-infra/qwen-llm (LLM inference)
85+
apiVersion: security.istio.io/v1beta1
86+
kind: AuthorizationPolicy
87+
metadata:
88+
name: allow-kagent-to-llm
89+
namespace: {{ .Values.namespaces.mlInfra }}
90+
labels:
91+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
92+
spec:
93+
selector:
94+
matchLabels:
95+
serving.kserve.io/inferenceservice: qwen-llm
96+
action: ALLOW
97+
rules:
98+
- from:
99+
- source:
100+
namespaces: ["{{ .Values.namespaces.docsAgent }}", "{{ .Values.namespaces.istioSystem }}"]
101+
to:
102+
- operation:
103+
ports: ["8080", "8012"]
104+
---
105+
# docs-agent/kagent -> docs-agent/mcp-server (MCP tool calls)
106+
apiVersion: security.istio.io/v1beta1
107+
kind: AuthorizationPolicy
108+
metadata:
109+
name: allow-kagent-to-mcp
110+
namespace: {{ .Values.namespaces.docsAgent }}
111+
labels:
112+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
113+
spec:
114+
selector:
115+
matchLabels:
116+
app: mcp-kubeflow-docs
117+
action: ALLOW
118+
rules:
119+
- from:
120+
- source:
121+
namespaces: ["{{ .Values.namespaces.docsAgent }}"]
122+
to:
123+
- operation:
124+
ports: ["8000"]
125+
---
126+
# KFP pipeline pods (kubeflow ns) -> ml-infra/milvus (RAG ingestion)
127+
apiVersion: security.istio.io/v1beta1
128+
kind: AuthorizationPolicy
129+
metadata:
130+
name: allow-kubeflow-to-milvus
131+
namespace: {{ .Values.namespaces.mlInfra }}
132+
labels:
133+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
134+
spec:
135+
selector:
136+
matchLabels:
137+
app.kubernetes.io/name: milvus
138+
component: standalone
139+
action: ALLOW
140+
rules:
141+
- from:
142+
- source:
143+
namespaces: ["{{ .Values.namespaces.kubeflow }}"]
144+
to:
145+
- operation:
146+
ports: ["19530"]
147+
---
148+
# docs-agent/mcp-server -> ml-infra/embeddings-service (query-time embeddings)
149+
apiVersion: security.istio.io/v1beta1
150+
kind: AuthorizationPolicy
151+
metadata:
152+
name: allow-mcp-to-embeddings
153+
namespace: {{ .Values.namespaces.mlInfra }}
154+
labels:
155+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
156+
spec:
157+
selector:
158+
matchLabels:
159+
serving.kserve.io/inferenceservice: embeddings-service
160+
action: ALLOW
161+
rules:
162+
- from:
163+
- source:
164+
namespaces: ["{{ .Values.namespaces.docsAgent }}", "{{ .Values.namespaces.istioSystem }}"]
165+
to:
166+
- operation:
167+
ports: ["8080", "80", "8012"]
168+
---
169+
# kubeflow/pipeline pods -> ml-infra/embeddings-service (index-time embeddings)
170+
apiVersion: security.istio.io/v1beta1
171+
kind: AuthorizationPolicy
172+
metadata:
173+
name: allow-kubeflow-to-embeddings
174+
namespace: {{ .Values.namespaces.mlInfra }}
175+
labels:
176+
{{- include "gateway-guardrails.labels" . | nindent 4 }}
177+
spec:
178+
selector:
179+
matchLabels:
180+
serving.kserve.io/inferenceservice: embeddings-service
181+
action: ALLOW
182+
rules:
183+
- from:
184+
- source:
185+
namespaces: ["{{ .Values.namespaces.kubeflow }}", "{{ .Values.namespaces.istioSystem }}"]
186+
to:
187+
- operation:
188+
ports: ["8080", "80", "8012"]
189+
{{- end }}

0 commit comments

Comments
 (0)