Repository navigation
feat: Add inbound port exclusion annotation and Istio ambient mesh fix - #248
Conversation
4e709e6 to
a0b4f68
Compare
Add kagenti.io/inbound-ports-exclude pod annotation for per-workload inbound port exclusion from iptables interception. This complements the existing kagenti.io/outbound-ports-exclude annotation (#240). Fix init-iptables.sh for Istio ambient mesh: when ambient mesh is active, ztunnel delivers inbound traffic via the OUTPUT chain (not PREROUTING), so INBOUND_PORTS_EXCLUDE rules in PROXY_INBOUND had no effect. Add RETURN rules for excluded inbound ports in PROXY_OUTPUT before the ztunnel catch-all redirect. Both annotations validate port values (range 1-65535, dedup, trim whitespace) and log warnings for invalid entries. Based on sallyom work in #158. Resolves all review comments. Co-authored-by: Sally O'Malley <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
a0b4f68 to
b3ef820
Compare
pdettori
left a comment
There was a problem hiding this comment.
Clean, well-structured PR. The iptables rule placement is correct (RETURN before ztunnel catch-all DNAT in PROXY_OUTPUT), validation mirrors existing outbound logic, and test coverage is thorough. The PR description and inline comments explaining the ambient mesh behavior are excellent.
Two minor suggestions below — neither blocks merge.
| t.Errorf("OUTBOUND_PORTS_EXCLUDE = %q, want %q", env.Value, "8080") | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
suggestion: TestBuildProxyInitContainer_DefaultExclude and TestBuildProxyInitContainer_WithAnnotationPorts lost the assertion that OUTBOUND_PORTS_EXCLUDE is present. The original tests had t.Error("proxy-init container missing OUTBOUND_PORTS_EXCLUDE env var") at the bottom — now if the env var is missing entirely, these tests pass silently.
Consider adding a foundOutbound bool like TestBuildProxyInitContainer_WithBothExcludes does. Not blocking since other tests cover presence.
| if tok == "" { | ||
| continue | ||
| } | ||
| p, err := strconv.Atoi(tok) |
There was a problem hiding this comment.
nit: buildPortExcludeValue and buildOutboundExcludeValue share ~90% identical validation logic (parse, trim, range-check 1-65535, dedup). Could extract a shared helper and have buildOutboundExcludeValue prepend the mandatory 8080. Not blocking — the duplication is small and both are internal.
- Add foundOutbound assertion to DefaultExclude and WithAnnotationPorts tests so missing OUTBOUND_PORTS_EXCLUDE env var is caught - Extract validateAndDeduplicatePorts() shared helper to eliminate duplicate validation logic between buildOutboundExcludeValue and buildPortExcludeValue Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
Summary
kagenti.io/inbound-ports-excludepod annotation for per-workload inbound port exclusioninit-iptables.shfor Istio ambient mesh: inbound port exclusions now work in PROXY_OUTPUT chain (not just PREROUTING)Problem
PR #240 added
kagenti.io/outbound-ports-excludebut only for outbound ports. On OpenShift with oauth-proxy, inbound ports like 8443 must also be excluded from Envoy interception. Additionally, with Istio ambient mesh active, ztunnel delivers inbound traffic via the OUTPUT chain (not PREROUTING), soINBOUND_PORTS_EXCLUDErules inPROXY_INBOUNDhave no effect -- ports must also be excluded inPROXY_OUTPUT.Changes
Webhook
pod_mutator.go: AddInboundPortsExcludeAnnotationconstant. Read both annotations and pass toBuildProxyInitContainer.container_builder.go:BuildProxyInitContainernow acceptsinboundPortsExcludeparameter.INBOUND_PORTS_EXCLUDEenv var is only set when provided. NewbuildPortExcludeValue()validates, deduplicates, and range-checks inbound ports.proxy-init (Istio ambient mesh fix)
init-iptables.sh: AddRETURNrules for excluded inbound ports inPROXY_OUTPUTbefore the ztunnel catch-all redirect (Rule 1). Renumber subsequent rules.Usage
Without the inbound annotation, behavior is unchanged (no
INBOUND_PORTS_EXCLUDEenv var is set).Relationship to #158
This PR is based on @sallyom's work in #158 but built cleanly on top of #240 (which already merged outbound port exclusion with validation). All review comments from #158 are resolved:
Supersedes #158.
Test plan
go test ./...passes (unit + integration)