Skip to content

Proposal: Replace per-pod sidecar with per-namespace gateway proxy using node-level traffic redirection #145

Closed

Description

@huang195

Summary

Explore replacing the current per-pod sidecar model for IBAC context collection with a per-namespace gateway proxy backed by a node-level iptables DaemonSet for transparent traffic redirection. This reduces operational overhead and resource consumption while preserving synchronous interception capabilities (e.g., human-in-the-loop approval).

Background

Currently, IBAC collects context (user queries, agent-to-agent, agent-to-tool, agent-to-LLM communications) by running a sidecar alongside each agent pod — similar to the Istio sidecar model. While effective, this approach has drawbacks:

  • High resource overhead: One proxy per pod
  • Operational complexity: Sidecar lifecycle tied to every workload
  • Intrusiveness: Mutating every pod spec

Alternatives Considered

Approach Language agnostic Sync capable Overhead
SDK / Library instrumentation No Yes None
Per-namespace gateway proxy Yes Yes Low (1 per namespace)
Ambient mesh (ztunnel + waypoint) Yes Yes Medium
eBPF + userspace daemon Yes Partial Low
Agent framework hooks No Yes None

SDK/library and framework hooks were ruled out because IBAC must support agents written in many languages and frameworks.

eBPF alone was ruled out because synchronous L7 interception (e.g., prompting for human input mid-request) requires punting to userspace anyway.

Per-namespace gateway proxy was selected as the best balance of transparency, sync capability, and operational simplicity.

Proposed Architecture

Overview

  ┌──────────────────────────────────────────────────────────────┐
  │  Namespace: agent-workspace                                  │
  │                                                              │
  │   caller ──X──► agent pod    agent pod ──X──► external       │
  │      │                          │                            │
  │      └──► gateway-proxy ──►  agent pod ──► gateway-proxy ──► external
  │                                                              │
  │   NetworkPolicy blocks direct paths (X)                      │
  │   Node-level iptables redirects traffic through gateway      │
  └──────────────────────────────────────────────────────────────┘

Components

1. Per-Namespace Gateway Proxy (Deployment)

A shared Envoy + ext-proc deployment per namespace (reusing existing AuthProxy stack):

  • Outbound listener (port 15001): Intercepts agent → LLM, agent → tool, agent → agent calls. Applies IBAC policy, supports synchronous human-in-the-loop approval.
  • Inbound listener (port 15006): Intercepts external → agent calls. Validates identity, collects context.

2. Node-Level Traffic Redirector (DaemonSet)

A DaemonSet with NET_ADMIN / NET_RAW capabilities that installs iptables rules in the host network namespace to transparently redirect traffic from agent pods to the gateway:

# Outbound: redirect agent pod traffic to gateway
iptables -t nat -A PREROUTING   -s <agent-pod-CIDR>   -j REDIRECT --to-port 15001

# Inbound: redirect traffic destined for agent pods to gateway
iptables -t nat -A PREROUTING   -d <agent-pod-IP>   -j DNAT --to-destination <gateway-pod-IP>:15006

The redirector should watch the Kubernetes API for agent pods (by label, e.g., kagenti.io/type: agent) and dynamically manage iptables rules as pods come and go.

Why node-level iptables over HTTP_PROXY env vars: Some agents use non-HTTP protocols (raw TCP, gRPC with custom dialers). HTTP_PROXY only covers HTTP/HTTPS. Node-level iptables is protocol-agnostic and fully transparent.

3. NetworkPolicy (Enforcement Guardrail)

NetworkPolicy ensures agent pods cannot bypass the gateway even if iptables rules are misconfigured:

  • Default deny all egress and ingress for agent pods
  • Allow egress only to the gateway proxy and kube-dns
  • Allow ingress only from the gateway proxy

This is defense-in-depth — the iptables DaemonSet handles redirection, NetworkPolicy prevents bypass.

Comparison to Current Sidecar Model

Aspect Sidecar (current) Gateway + DaemonSet (proposed)
Proxies per namespace 1 per pod (N) 1 gateway + 1 DaemonSet per node
Resource overhead High Low
Pod spec mutation Inject containers None (or minimal env vars)
Sync interception Yes Yes
Protocol support All (transparent) All (transparent via iptables)
Granularity Per-pod Per-namespace (pod identified by IP/SA)
Host privileges needed No Yes (DaemonSet needs NET_ADMIN)

Implementation Tasks

  • Design the gateway proxy Deployment (adapt existing Envoy + ext-proc for shared mode)
  • Implement the iptables redirector DaemonSet (watch agent pods, manage rules dynamically)
  • Define NetworkPolicy templates for agent namespaces
  • Update the mutating webhook to optionally skip sidecar injection when gateway mode is enabled
  • Handle gateway HA (multiple replicas, pod disruption budget)
  • Handle gateway → agent pod routing (preserve original destination via SO_ORIGINAL_DST or headers)
  • Integration testing with non-HTTP agent protocols
  • Document migration path from sidecar to gateway mode

Open Questions

  • Should gateway mode and sidecar mode coexist (feature flag), or is this a full replacement?
  • How to handle cross-namespace agent-to-agent communication (each namespace has its own gateway)?
  • Should the DaemonSet use iptables or nftables (for newer kernels)?
  • How to identify the original destination pod after redirection (Envoy SO_ORIGINAL_DST listener filter vs. protocol-level headers)?

Activity

  1. added
    enhancement
    on Feb 25, 2026
  2. changed the title [-]Replace per-pod sidecar with per-namespace gateway proxy using node-level traffic redirection[/-] [+]Proposal: Replace per-pod sidecar with per-namespace gateway proxy using node-level traffic redirection[/+] on Feb 25, 2026
  3. self-assigned this
    on Mar 22, 2026
  4. huang195 commented on Apr 14, 2026

    @huang195
    MemberAuthor

    Closing this issue in favor of: #279, where we unify different solution variants under the same common harness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions