Skip to content

feat: Add inbound port exclusion annotation and Istio ambient mesh fix - #248

Merged
mrsabath merged 2 commits into
rossoctl:mainfrom
mrsabath:feat/inbound-ports-exclude-ambient-mesh
Mar 17, 2026
Merged

mrsabath merged 2 commits into
rossoctl:mainfrom
mrsabath:feat/inbound-ports-exclude-ambient-mesh

Conversation

@mrsabath

Copy link
Copy Markdown
Member

Summary

  • Add kagenti.io/inbound-ports-exclude pod annotation for per-workload inbound port exclusion
  • Fix init-iptables.sh for Istio ambient mesh: inbound port exclusions now work in PROXY_OUTPUT chain (not just PREROUTING)
  • Add input validation, deduplication, and range checking for inbound port values (matching the existing outbound validation from feat: Add kagenti.io/outbound-ports-exclude annotation for proxy-init #240)

Problem

PR #240 added kagenti.io/outbound-ports-exclude but 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), so INBOUND_PORTS_EXCLUDE rules in PROXY_INBOUND have no effect -- ports must also be excluded in PROXY_OUTPUT.

Changes

Webhook

  • pod_mutator.go: Add InboundPortsExcludeAnnotation constant. Read both annotations and pass to BuildProxyInitContainer.
  • container_builder.go: BuildProxyInitContainer now accepts inboundPortsExclude parameter. INBOUND_PORTS_EXCLUDE env var is only set when provided. New buildPortExcludeValue() validates, deduplicates, and range-checks inbound ports.
  • Tests added for all new behavior (9 table-driven validation tests + 4 integration tests).

proxy-init (Istio ambient mesh fix)

  • init-iptables.sh: Add RETURN rules for excluded inbound ports in PROXY_OUTPUT before the ztunnel catch-all redirect (Rule 1). Renumber subsequent rules.

Usage

metadata:
  annotations:
    kagenti.io/outbound-ports-exclude: "443,4317"
    kagenti.io/inbound-ports-exclude: "8443,18789"

Without the inbound annotation, behavior is unchanged (no INBOUND_PORTS_EXCLUDE env 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:

  • Input validation on annotation values (range, dedup, whitespace)
  • No personal image references
  • DCO sign-off
  • Comprehensive test coverage

Supersedes #158.

Test plan

  • go test ./... passes (unit + integration)
  • Deploy on OpenShift with ambient mesh, verify inbound port exclusion works
  • Verify outbound port exclusion still works (regression check)

@mrsabath
mrsabath force-pushed the feat/inbound-ports-exclude-ambient-mesh branch from 4e709e6 to a0b4f68 Compare March 17, 2026 02:02
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]>

@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.

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
}

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.

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)

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.

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]>
@mrsabath
mrsabath merged commit feea30d into rossoctl:main Mar 17, 2026
18 checks passed
@mrsabath
mrsabath deleted the feat/inbound-ports-exclude-ambient-mesh branch March 17, 2026 21:32
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.

2 participants