Repository navigation
Conversation
Support kagenti.io/outbound-ports-exclude and kagenti.io/inbound-ports-exclude pod annotations for per-workload iptables port exclusion, removing the need for manual AIB sidecars. Co-Authored-By: Claude Opus 4.6 <[email protected]>
INBOUND_PORTS_EXCLUDE only added rules to PROXY_INBOUND (PREROUTING chain). With Istio ambient mesh, ztunnel delivers inbound traffic via the OUTPUT chain, bypassing PREROUTING entirely. This caused Envoy to intercept and reject WebSocket upgrades with 403 upgrade_failed. Add RETURN rules for excluded inbound ports before the ztunnel mark-based catch-all redirect in PROXY_OUTPUT, so ports like 8443 (oauth-proxy) bypass Envoy even when ambient mesh is active. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Temporary override so the webhook injects the custom proxy-init image with the ztunnel inbound port exclusion fix. Co-Authored-By: Claude Opus 4.6 <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Code Review: Annotation-Based Port Exclusion
Good approach overall — the annotation threading, iptables rule placement for Istio ambient, and 8080 guarantee are all correct. A few issues need addressing before merge.
Blockers
-
Personal image in
defaults.go:quay.io/sallyom/proxy-init:latestmust be reverted toghcr.io/kagenti/kagenti-extensions/proxy-init:latest. This is a development artifact from local testing. -
DCO sign-off missing on all 3 commits. CI fails. Fix with:
git rebase --signoff main
Should Fix
-
No input validation on annotation values. Malformed annotation strings (non-numeric values, extra spaces like
"443, 4317", empty segments like"443,,4317") are passed directly through toinit-iptables.shas--dportarguments. Invalid ports will cause iptables to fail, which blocks pod startup entirely.Suggestion: Add a
parsePortList()helper incontainer_builder.gothat:- Trims whitespace from each entry
- Removes empty entries
- Validates each token is a numeric port in range 1-65535
- Deduplicates (removes user-supplied
8080if already in mandatory list)
-
Comment inconsistency in
init-iptables.sh: After inserting the new INBOUND_PORTS_EXCLUDE loop, the comment on what was "Rule 1" (now "Rule 2") and "Rule 3" still references "After rule 1" — should update to match the new numbering.
Minor
-
Duplicate
8080risk: If a user specifieskagenti.io/outbound-ports-exclude: "8080,443", the result isOUTBOUND_PORTS_EXCLUDE="8080,8080,443". Benign but inelegant — the validation helper above would fix this. -
Test coverage gaps: No tests for malformed input, boundary port values (0, 65535, 65536), or duplicate port handling. Consider adding at least one negative test case.
-
InjectInitContainerspath doesn't support annotations — passes empty strings. If this path is reachable, callers can't use port exclusion. Document this limitation or thread annotations through.
What's Good
- Port 8080 is always guaranteed (prepended, not user-replaceable)
- Nil annotation map safety is correct and tested
- Iptables rule placement for ambient mesh (PROXY_OUTPUT chain) is the right fix — clear comments explain why PREROUTING alone isn't sufficient
- Annotation constants follow
kagenti.io/naming convention - Tests are well-structured
Related
This PR addresses issue #235 (feat: Make OUTBOUND_PORTS_EXCLUDE configurable via annotation or ConfigMap). The issue also proposes ConfigMap and Helm values support (options 2 and 3), which could be follow-up PRs.
Areas reviewed: Go (webhook, container builder), Shell (init-iptables.sh), Tests, Security
Commits: 3, signed-off: no (DCO failing)
CI status: DCO check failing
|
Hi @sallyom — thank you so much for this excellent work! The annotation-based port exclusion design, the Istio ambient mesh fix in Since this PR was opened, the outbound port exclusion portion landed separately in #240 (which addressed part of the same problem space). That created merge conflicts here, and because the codebase had evolved significantly (e.g., #242 changed the SecurityContext model), rebasing this branch cleanly wasn't feasible. To move things forward, I created #248 which builds on top of
You are listed as co-author on the commit so the contribution is properly attributed to you. I also incorporated the review feedback (input validation, test coverage for edge cases) so it should be ready for a clean merge. Thanks again for the great contribution, Sally! 🙏 |
Add agent/uc/policy_check/check.py::check_policy_conflicts(policy_text, service_id) -> ConflictReport: a sequential, read-only survey that runs every focal entity of the target service through the diagnostic graph to completion (the first conflict never aborts), accumulates all conflicts + unevaluated entries, and derives status via ConflictReport.from_survey with the zero-evaluated guard. service_type is derived read-only from the IdP catalog (focus.type of the service resolved by id) -- Provision is never run, so the survey never mutates IdP state. The resolver's HTTPException(502/404) pre-survey boundary is preserved on both the type lookup and resolve_focal_entities. Fan-out mirrors builder.py exactly (scope-focal over own_scopes; role-focal over flatten_role(own_role) x other_scopes for AGENT). A found conflict returns a report, never raises. Refs #158. Part of #154. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[email protected]>
Summary
kagenti.io/outbound-ports-excludeandkagenti.io/inbound-ports-excludepod template annotations for per-workload iptables port exclusioninit-iptables.shto also exclude inbound ports from ztunnel delivery inPROXY_OUTPUTchain (required for Istio ambient mesh)Problem
The webhook's
BuildProxyInitContainer()hardcodesOUTBOUND_PORTS_EXCLUDE="8080"and sets noINBOUND_PORTS_EXCLUDE. On OpenShift with oauth-proxy, port 443 must be excluded outbound (K8s API token review)and ports like 8443 must be excluded inbound (direct UI access bypassing Envoy). Without these exclusions:
upgrade_failedon WebSocket connectionsAdditionally,
INBOUND_PORTS_EXCLUDEonly added rules to thePROXY_INBOUNDchain (PREROUTING). With Istio ambient mesh active (istio.io/dataplane-mode: ambient), ztunnel delivers inbound traffic via theOUTPUT chain, bypassing PREROUTING entirely — so inbound port exclusions had no effect.
Changes
Webhook (annotation-based port exclusion)
pod_mutator.go: AddOutboundPortsExcludeAnnotationandInboundPortsExcludeAnnotationconstants.InjectAuthBridgenow accepts and reads pod annotations.container_builder.go:BuildProxyInitContaineracceptsoutboundExclude, inboundExclude stringparams. Annotation values are appended to the default"8080"outbound exclusion.INBOUND_PORTS_EXCLUDEenv var is only set when provided.
authbridge_webhook.go: Extract annotations from pod template for all resource types and pass toInjectAuthBridge.proxy-init (Istio ambient mesh fix)
init-iptables.sh: AddRETURNrules for excluded inbound ports inPROXY_OUTPUTbefore the ztunnel mark-based catch-all redirect. This ensures port exclusions work regardless of whether traffic arrivesvia PREROUTING (non-ambient) or OUTPUT (ambient mesh via ztunnel).
Usage
Add annotations to pod template:
Annotation values are appended to the default outbound exclusion (8080). Without annotations, behavior is unchanged.
Draft note
Commit ef4d86c (chore: Point proxy-init default to quay.io/sallyom/proxy-init:latest) is a temporary override for testing. It will be dropped before merge.