Skip to content

epic: TLS-Aware AuthBridge — Token Exchange and Policy Enforcement for Encrypted Agent Traffic #1552

Closed
2 of 2 issues completed

Description

@mrsabath

Executive summary. AuthBridge's Envoy sidecar treats outbound TLS as opaque passthrough, so the majority of agent traffic — LLM APIs, GitHub, MCP tool servers, and agent-to-agent mTLS — bypasses token exchange and policy enforcement entirely. This epic closes that gap by treating "TLS-aware" as three distinct, individually-solvable problems: HTTP_PROXY CONNECT tunneling for external APIs (host-based policy and token exchange without MITM), SPIFFE SVIDs for agent-to-agent mTLS (identity issuance, not connection proxying), and AI-Gateway delegation for content inspection. The outcome is that encrypted agent traffic — including Claude Code and sandboxed agents using HTTP_PROXY — gets policy enforcement, token exchange, and audit without AuthBridge ever performing certificate interception.

Epic: TLS-Aware AuthBridge — Token Exchange and Policy Enforcement for Encrypted Agent Traffic

Problem

Today, AuthBridge's Envoy sidecar treats all outbound TLS connections as opaque passthrough — encrypted traffic bypasses ext_proc entirely, so no token exchange or policy enforcement occurs (kagenti-extensions#184). This was an early pragmatic choice, but it leaves a critical gap: the majority of agent-to-service communication (LLM APIs, GitHub, MCP tool servers) uses TLS, and agents that enable mTLS for agent-to-agent communication get no AuthBridge services at all.

The problem is often framed as unsolvable — "AuthBridge can't inspect TLS without MITM" — but this conflates three distinct scenarios that each have a clean solution:

Scenario Traffic Pattern Why It Seems Hard Actual Solution
Agent → external API (TLS) https://api.anthropic.com, https://api.github.com Proxy can't read encrypted body HTTP_PROXY CONNECT tunneling — proxy sees destination host, performs token exchange on the CONNECT request, tunnels encrypted bytes unchanged
Agent → agent (mTLS) SPIFFE SVID mutual TLS between pods Proxy can't intercept mutual auth Not a proxy problem — agents authenticate directly via SPIFFE SVIDs. AuthBridge issues the SVID, not the connection. Istio ambient mesh provides mTLS transparently.
Content inspection (guardrails) LLM request/response bodies Must read cleartext to apply guardrails AI Gateway layer (LiteLLM, Praxis) terminates TLS and inspects. AuthBridge delegates, doesn't MITM.

Scope

This epic covers:

  1. Token exchange on TLS connections in proxy-sidecar mode (CONNECT tunneling)
  2. SPIFFE SVID issuance and rotation for agent-to-agent mTLS
  3. Integration with AI Gateway for content inspection (delegation, not MITM)
  4. Claude Code / OpenShell compatibility (HTTP_PROXY support)

Out of scope: Envoy-sidecar mode TLS interception (covered by kagenti-extensions#330), Praxis evaluation (#1187), plugin pipeline architecture (#1458).


Architecture

Scenario 1: Agent → External API (TLS) via HTTP_PROXY CONNECT

The proxy-sidecar mode (#1428) already plans to use HTTP_PROXY env var injection. This epic extends it to handle TLS via standard CONNECT tunneling:

Agent (Claude Code, LangGraph, etc.)
    │
    │  HTTP CONNECT api.github.com:443
    │  (honors HTTP_PROXY/HTTPS_PROXY env var)
    ▼
┌──────────────────────────────────────┐
│  AuthBridge proxy-sidecar            │
│                                      │
│  1. Parse CONNECT target host:port   │
│  2. Match against access policy      │
│     (allow/deny by host)             │
│  3. Token exchange (RFC 8693)        │
│     → audience-scoped token for      │
│       api.github.com                 │
│  4. Inject Authorization header      │
│     into tunneled TLS handshake*     │
│  5. Establish tunnel, relay bytes    │
│                                      │
│  * Or: exchange token, pass to agent │
│    via response header on CONNECT    │
└──────────────────────────────────────┘
    │
    │  TLS to api.github.com:443
    ▼
  External API

Key insight: The CONNECT method gives the proxy the destination hostname before TLS is established. This is enough for:

  • Host-based access control (allow/deny per destination)
  • Token exchange (audience = destination host)
  • Audit logging (who connected where, when)

The proxy never sees the encrypted payload — no MITM, no certificate manipulation.

Claude Code compatibility: Claude Code honors HTTP_PROXY and HTTPS_PROXY environment variables. The webhook injects these env vars pointing to the AuthBridge proxy sidecar. This means Claude Code running in Kagenti sandboxes (including OpenShell) gets automatic token exchange on every outbound TLS connection — no configuration needed.

Token injection challenge: Standard CONNECT tunneling creates an opaque tunnel — the proxy can't inject headers into the inner HTTP request. Two approaches:

Approach Mechanism Trade-off
A: Token-in-tunnel Proxy performs TLS termination to upstream, re-encrypts to agent (dual-hop TLS) Full header injection but adds latency and complexity
B: Token-out-of-band Proxy exchanges token and passes it via CONNECT response headers; agent reads and attaches No MITM, but requires agent cooperation (SDK/wrapper)
C: Pre-flight exchange Agent calls proxy API to get scoped token before making direct TLS connection Clean separation, works with any agent, but two-step flow

Recommended: Approach C (pre-flight exchange) for proxy-sidecar mode. The proxy exposes a local endpoint (localhost:<port>/exchange?audience=api.github.com) that agents call to get a scoped token. Agents that honor HTTP_PROXY get automatic host-level policy enforcement + audit; token attachment is the agent's responsibility (or handled by a thin SDK wrapper).

For agents that cannot be modified (e.g., Claude Code making direct API calls), Approach A is available as opt-in (configured per destination in access policy).

Scenario 2: Agent → Agent (mTLS) via SPIFFE

Agent-to-agent mutual TLS is not a proxy problem. The agents authenticate directly using SPIFFE SVIDs:

Agent A (SPIFFE ID: spiffe://kagenti/ns/team1/sa/weather-agent)
    │
    │  mTLS using X.509 SVID
    │  (SPIRE Workload API → /run/spire/sockets/agent.sock)
    ▼
Agent B (SPIFFE ID: spiffe://kagenti/ns/team2/sa/research-agent)

AuthBridge's role is identity issuance, not connection proxying:

Responsibility Component How
Issue SPIFFE SVID to agent SPIRE Agent + spiffe-helper sidecar SPIRE attestation via K8s PSAT
Register agent identity Kagenti Operator Creates SPIRE registration entry on AgentCard creation
Validate peer identity Agent's TLS library Standard X.509 SVID verification
Authorize agent-to-agent call Istio AuthorizationPolicy or OPA Policy checks SPIFFE ID
Audit the connection Istio ambient mesh telemetry OTel spans with SPIFFE IDs

Istio ambient mesh handles mTLS transparently when both agents are in ambient mode — no code changes needed. For cross-cluster or mesh-free scenarios, agents use the SPIRE Workload API directly.

Scenario 3: Content Inspection via AI Gateway Delegation

When content inspection is needed (guardrails, PII detection, prompt injection defense), AuthBridge delegates to an AI Gateway rather than performing MITM:

Agent → AuthBridge proxy → AI Gateway (LiteLLM / Praxis)
                              │
                              ├─ TLS terminated here
                              ├─ Content inspection (guardrails)
                              ├─ Token attribution (cost tracking)
                              └─ Re-encrypted to upstream LLM

AuthBridge routes LLM-destined traffic to the gateway endpoint (configurable per destination). The gateway terminates TLS, applies inspection policies, and forwards to the upstream LLM. This is the same model as a corporate forward proxy — well-understood, no agent changes needed.

The plugin pipeline (#1458) enables AuthBridge to classify traffic (MCP, A2A, LLM) and route it to the appropriate handler.


Relationship to Existing Epics

Epic Relationship
#1428 Lean AuthBridge Default Prerequisite — proxy-sidecar mode with HTTP_PROXY injection is the foundation for CONNECT tunneling. Phase 1 item "Token exchange on TLS connections" (kagenti-extensions#184) is a direct sub-task of this epic.
#1429 Replace iptables Complementary — NetworkPolicy enforcement ensures agents can't bypass the proxy, closing the TLS bypass gap.
#1187 Modular AuthBridge Parent — this epic is a concrete workstream within the "environment-adaptive agent networking" goal.
#1458 Plugin Pipeline Consumer — the plugin pipeline provides traffic classification (MCP/A2A/LLM) needed for AI Gateway routing decisions.
#1461 OpenShell Sandbox Integration — OpenShell sandboxes use the supervisor's network namespace. Proxy-sidecar mode with HTTP_PROXY (not iptables) is the only viable AuthBridge integration path for supervised agents.
#820 Sandboxed Agent Runtime Enables — TLS-aware proxy mode enables AuthBridge for all sandboxed agents, including those using Claude Code with HTTP_PROXY.

Progress Tracker

Phase 1: CONNECT Tunneling in Proxy-Sidecar Mode

Token exchange and host-based policy on CONNECT requests. Resolves kagenti-extensions#184.

Item Status Reference
CONNECT method handler in proxy-sidecar listener NEW —
Host-based access policy on CONNECT target NEW —
Pre-flight token exchange endpoint (/exchange?audience=) NEW —
Dual-hop TLS for MITM-capable destinations (opt-in) NEW —
Claude Code HTTP_PROXY integration test NEW —
Update AuthBridge config schema for TLS policy NEW —

Phase 2: SPIFFE SVID for Agent-to-Agent mTLS

Ensure agents can authenticate to each other using SPIFFE SVIDs, with AuthBridge managing identity lifecycle.

Item Status Reference
Operator: auto-register SPIRE entry on AgentCard creation OPEN existing SPIRE integration
spiffe-helper in proxy-sidecar mode (no Envoy dependency) NEW —
E2E test: agent-to-agent mTLS with SPIFFE SVIDs NEW —
Cross-namespace agent mTLS with Istio AuthorizationPolicy NEW —

Phase 3: AI Gateway Delegation for Content Inspection

Route LLM traffic through AI Gateway for inspection without MITM.

Item Status Reference
Traffic classification in proxy mode (MCP/A2A/LLM/other) Tracked in #1458
Configurable gateway routing rules per destination NEW —
LiteLLM integration as AI Gateway endpoint EXISTING LiteLLM already deployed in Kagenti
E2E test: guardrails applied to LLM traffic via gateway NEW —

Phase 4: OpenShell + Supervised Agent Integration

AuthBridge proxy mode for supervised agents in network-namespaced sandboxes.

Item Status Reference
HTTP_PROXY injection for supervised agent pods NEW —
Socat bridge or supervisor --setup-only for proxy access Tracked in sandboxing-layers.md
E2E test: supervised agent with AuthBridge proxy + token exchange NEW —

Success Criteria

  • Token exchange works on outbound TLS connections in proxy-sidecar mode (CONNECT tunneling)
  • Host-based access control applies to CONNECT destinations (TLS traffic no longer bypasses policy)
  • Claude Code running in Kagenti sandbox gets automatic token exchange via HTTP_PROXY
  • Agent-to-agent mTLS uses SPIFFE SVIDs with Operator-managed identity lifecycle
  • LLM traffic routed through AI Gateway for content inspection without MITM at AuthBridge layer
  • Supervised agents (OpenShell) can use AuthBridge proxy mode via HTTP_PROXY env var

References

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    epic
    Identity
    on May 12, 2026
  2. moved this from New /:ToDo to Epics in Rossoctl Issue Prioritizationon May 21, 2026
  3. mrsabath commented on May 21, 2026

    @mrsabath
    MemberAuthor

    Related workstream: bridge-to-bridge mTLS

    Phase 2 of this epic ("SPIFFE SVID for Agent-to-Agent mTLS") overlaps with transport-layer mTLS between AuthBridge sidecars. That narrower workstream is now tracked separately so we don't duplicate implementation tracking:

    → #1636 — epic: Secure mTLS Communication Between Agents via AuthBridge

    Topic #1552 (this epic) #1636
    Token exchange on external TLS (CONNECT, pre-flight /exchange) Primary Out of scope
    AuthBridge forward → remote reverse mTLS (SPIRE SVIDs, mtlsMode) Mentioned in Phase 2 Primary (Phase 1 done: kagenti-extensions#424, kagenti-operator#369, kagenti#1627)
    MultiAgent topology SPIFFE allowlist — Phase 2
    AI Gateway / content inspection Phase 3 Out of scope

    Phase 2 items here that are specifically identity lifecycle (Operator SPIRE registration on AgentCard, cross-namespace Istio AuthorizationPolicy) remain in this epic; wire encryption between proxy-sidecar listeners should be tracked and closed under #1636.

  4. self-assigned this
    on Jun 2, 2026
  5. mrsabath commented on Jun 12, 2026

    @mrsabath
    MemberAuthor

    📊 Status sync — 2026-06-12 (automated rollup, please verify before acting)

    None of this epic's own tracker items are marked done; Phase 1 (CONNECT tunneling), the core deliverable, has not started. The only completed work is in the spun-off #1636 (Phase 1 mTLS): ext#424 MERGED, kagenti-operator#369 MERGED, kagenti#1627 MERGED.

    Per the author's pinned comment (2026-05-21), Phase 2 (agent-to-agent mTLS / wire encryption) was carved out into #1636 — but the Phase 2 tracker table in the body was not updated to reflect that split. Suggest trimming Phase 2 here to identity-lifecycle items only and pointing wire-encryption at #1636.

    🔗 Suggestions: ext#424 + kagenti-operator#369 (both MERGED) fulfil this epic's Phase 2 SPIFFE items but are currently attributed only to #1636. #1899 (mesh-wide 503 from expired SPIRE SVIDs) is a relevant operational SPIFFE issue.

  6. self-assigned this
    on Jun 23, 2026
  7. huang195 commented on Jun 23, 2026

    @huang195
    Member

    TLS bridge was added to authbridge - it generically terminates TLS connections whether or not client obeys HTTP_PROXY or not. We should close this epic.

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

Metadata

Metadata

Labels

Identityepic

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions