Repository navigation
feat: Add kagenti.io/outbound-ports-exclude annotation for proxy-init - #240
Conversation
Support per-workload outbound port exclusion via pod annotation. The webhook reads kagenti.io/outbound-ports-exclude from the pod template and appends the user-supplied ports to the mandatory 8080 exclusion in the proxy-init OUTBOUND_PORTS_EXCLUDE env var. This eliminates the manual fix-iptables init container workaround needed when agents use Ollama (port 11434) or other services on ports that would otherwise be intercepted by Envoy. Input validation: - Non-numeric, out-of-range (0, >65535), and empty tokens are dropped - Duplicate 8080 is deduplicated - Whitespace around tokens is trimmed Closes #235 (partial: annotation-based exclusion only) Signed-off-by: Mariusz Sabath <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Review Summary
Clean, focused PR that adds per-workload outbound port exclusion via the kagenti.io/outbound-ports-exclude annotation. The three-layer propagation (webhook → mutator → builder) is well-structured, port 8080 is guaranteed in all code paths, nil annotation handling is safe in Go, and the test coverage for buildOutboundExcludeValue is thorough (7 unit test cases covering empty, valid, invalid, dedup, boundary, and whitespace inputs).
Areas reviewed: Go code, tests, security
Commits: 1 commit, DCO signed-off ✓
CI status: all 17 checks passing ✓
One test gap noted (inline comment on pod_mutator_test.go). The silent-drop behavior for invalid ports could be improved with better observability (see inline comment on container_builder.go).
Overall: solid, well-scoped extraction from #158 that addresses the immediate Ollama blocker (#235).
…olved value - Upgrade invalid port log from Info to V(0) WARNING so typos are visible in production logs (admission.Response.Warnings for kubectl feedback is a good follow-up) - Add missing t.Fatal in TestInjectAuthBridge_NilAnnotations so the test actually fails if proxy-init or OUTBOUND_PORTS_EXCLUDE is absent - Log the resolved excludeValue after validation instead of the raw annotation, so operators see what was actually applied Signed-off-by: Mariusz Sabath <[email protected]>
Summary
kagenti.io/outbound-ports-excludepod annotation for per-workload outbound port exclusion8080inOUTBOUND_PORTS_EXCLUDE8080; trims whitespaceinit-iptables.sh— it already supports comma-separatedOUTBOUND_PORTS_EXCLUDEProblem
The webhook hardcodes
OUTBOUND_PORTS_EXCLUDE="8080"in the proxy-init container. When agents use Ollama (port 11434) or other services on non-excluded ports, Envoy intercepts the traffic and corrupts streaming LLM responses. The current workaround is a manualfix-iptablesinit container patch documented in the demo guides.Usage
Add the annotation to the pod template:
The webhook produces
OUTBOUND_PORTS_EXCLUDE="8080,11434"on the proxy-init container. Port 8080 is always included regardless of annotation value.Changes
container_builder.goBuildProxyInitContaineracceptsoutboundPortsExcludeparam;buildOutboundExcludeValuevalidates and merges portspod_mutator.goInjectAuthBridgeacceptsannotationsmap; readskagenti.io/outbound-ports-excludeauthbridge_webhook.gopod.AnnotationstoInjectAuthBridgecontainer_builder_test.gobuildOutboundExcludeValue(empty, single, multi, dedup, whitespace, invalid, boundary) + 2 integration testspod_mutator_test.goRelationship to #158
This PR extracts the outbound port exclusion subset from PR #158 (which also adds inbound port exclusion and Istio ambient mesh fixes). This focused PR addresses the immediate blocker for the Ollama-based demos (#235).
Test plan
go test ./internal/...)kagenti.io/outbound-ports-exclude: "11434"annotationOUTBOUND_PORTS_EXCLUDE=8080,11434Closes #235 (partial: annotation-based exclusion only)