Skip to content

feat: Add kagenti.io/outbound-ports-exclude annotation for proxy-init - #240

Merged
mrsabath merged 2 commits into
rossoctl:mainfrom
mrsabath:feat/outbound-ports-exclude-annotation
Mar 16, 2026
Merged

mrsabath merged 2 commits into
rossoctl:mainfrom
mrsabath:feat/outbound-ports-exclude-annotation

Conversation

@mrsabath

Copy link
Copy Markdown
Member

Summary

  • Add kagenti.io/outbound-ports-exclude pod annotation for per-workload outbound port exclusion
  • Webhook reads the annotation and appends user-supplied ports to the mandatory 8080 in OUTBOUND_PORTS_EXCLUDE
  • Input validation: rejects non-numeric, out-of-range, empty tokens; deduplicates 8080; trims whitespace
  • No changes to init-iptables.sh — it already supports comma-separated OUTBOUND_PORTS_EXCLUDE

Problem

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 manual fix-iptables init container patch documented in the demo guides.

Usage

Add the annotation to the pod template:

metadata:
  annotations:
    kagenti.io/outbound-ports-exclude: "11434"

The webhook produces OUTBOUND_PORTS_EXCLUDE="8080,11434" on the proxy-init container. Port 8080 is always included regardless of annotation value.

Changes

File Change
container_builder.go BuildProxyInitContainer accepts outboundPortsExclude param; buildOutboundExcludeValue validates and merges ports
pod_mutator.go InjectAuthBridge accepts annotations map; reads kagenti.io/outbound-ports-exclude
authbridge_webhook.go Passes pod.Annotations to InjectAuthBridge
container_builder_test.go 9 tests for buildOutboundExcludeValue (empty, single, multi, dedup, whitespace, invalid, boundary) + 2 integration tests
pod_mutator_test.go 2 tests: annotation flows through to proxy-init env; nil annotations safe

Relationship 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

  • Unit tests pass (go test ./internal/...)
  • Deploy webhook with this change, create agent with kagenti.io/outbound-ports-exclude: "11434" annotation
  • Verify proxy-init container has OUTBOUND_PORTS_EXCLUDE=8080,11434
  • Verify Ollama connectivity from agent pod without manual iptables workaround

Closes #235 (partial: annotation-based exclusion only)

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 pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@mrsabath
mrsabath merged commit 1a644f3 into rossoctl:main Mar 16, 2026
18 checks passed
@mrsabath
mrsabath deleted the feat/outbound-ports-exclude-annotation branch March 16, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Make OUTBOUND_PORTS_EXCLUDE configurable via annotation or ConfigMap

2 participants