Skip to content

feat(authproxy): use CLIENT_ID for per-agent inbound audience validation - #282

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:use-client-id-for-audience-validation
Apr 8, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:use-client-id-for-audience-validation

Conversation

@huang195

@huang195 huang195 commented Apr 8, 2026

Copy link
Copy Markdown
Member

Summary

Replace the EXPECTED_AUDIENCE env var with the agent's CLIENT_ID (from /shared/client-id.txt) for inbound JWT audience validation. This makes audience validation per-agent by construction.

Problem

EXPECTED_AUDIENCE was either:

  • Not set (most demos) — no audience check, tokens interchangeable across agents
  • Set at namespace level — same value for all agents, tokens still interchangeable

A token intended for one agent could be used on any other agent in the same namespace.

Solution

Use CLIENT_ID from /shared/client-id.txt as the expected audience. This file is written by the operator (PR #247) or client-registration sidecar and contains the agent's unique Keycloak client ID:

  • SPIRE: spiffe://trust-domain/ns/namespace/sa/service-account
  • Non-SPIRE: namespace/workload-name

The audience scope created during client registration ensures platform tokens (kagenti UI) include this value in their aud claim.

Changes

  • go-processor/main.go: Use config.ClientID instead of EXPECTED_AUDIENCE env var
  • Demo configmaps: Remove EXPECTED_AUDIENCE references
  • Demo docs: Update to reflect automatic audience validation

Impact on existing demos

All demos verified — no breakage:

  • Weather Agent: tokens use agent's own client → correct aud
  • GitHub Issue: tokens use agent's own client → correct aud
  • Webhook: tokens use agent's own client → correct aud
  • Single-Target: tokens use agent's own client → correct aud
  • Multi-Target: inbound not tested in script; outbound unaffected

Test plan

  • Webhook demo: inbound validation rejects tokens without agent's client ID in aud
  • Weather agent demo: UI chat works (platform token has audience scope)
  • GitHub issue demo: Alice/Bob flows work with per-agent audience check
  • Tokens from admin-cli (without audience scope) are correctly rejected

Generated with Claude Code

@huang195
huang195 force-pushed the use-client-id-for-audience-validation branch 2 times, most recently from 9a080c3 to c6d7443 Compare April 8, 2026 14:31
…e EXPECTED_AUDIENCE

Replace the EXPECTED_AUDIENCE env var with the agent's CLIENT_ID
(from /shared/client-id.txt) for inbound JWT audience validation.
This makes audience validation per-agent by construction — the
operator or client-registration writes the agent's Keycloak client
ID to this file, so each agent validates against its own identity.

Previously, EXPECTED_AUDIENCE was:
- Not set (most demos) → no audience check, tokens interchangeable
- Set at namespace level → same value for all agents in namespace

Now, audience validation is automatic and per-agent. A token intended
for one agent cannot be used on another agent in the same namespace.

Works for both SPIRE and non-SPIRE paths:
- SPIRE: CLIENT_ID = spiffe://trust-domain/ns/namespace/sa/sa-name
- Non-SPIRE: CLIENT_ID = namespace/workload-name

Updated demo configmaps and docs to remove EXPECTED_AUDIENCE references.

Signed-off-by: Hai Huang <[email protected]>

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

Review Summary

This PR replaces the optional, manually-configured EXPECTED_AUDIENCE env var with automatic per-agent audience validation using the agent's CLIENT_ID (from /shared/client-id.txt). The change is clean and comprehensive — all code paths (resolved/legacy, envoy-proxy/authbridge), tests, docs, and demo configmaps are updated consistently. This is a meaningful security improvement that prevents token replay across agents in the same namespace.

Areas reviewed: Go, Helm/K8s YAML, Docs, Security
Commits: 1 commit, signed-off ✓
CI status: All passing (including Kind E2E)

Highlights:

  • Dual-mode parity verified: both resolved and legacy paths consistently remove EXPECTED_AUDIENCE injection
  • All 7 doc/CLAUDE.md files updated consistently
  • Test cleanup is correct: removed TestBuildEnvoyProxyContainer_HasExpectedAudienceFromConfigMap and updated TestBuildAuthBridgeContainer_AllEnvVars required env list

// Use CLIENT_ID (from /shared/client-id.txt) as the expected audience.
// This is per-agent by construction — the operator or client-registration
// writes the agent's Keycloak client ID to this file.
expectedAudience = config.ClientID

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 approach — sourcing audience from config.ClientID makes audience validation automatic and per-agent by construction. No more manual EXPECTED_AUDIENCE configuration to forget.

},
},
},
// Audience validation uses CLIENT_ID from /shared/client-id.txt (per-agent).

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.

👍 Good dual-mode parity — both resolved and legacy paths consistently remove EXPECTED_AUDIENCE injection, replaced by a clear comment pointing to the CLIENT_ID mechanism.

@huang195
huang195 merged commit 8716f7e into rossoctl:main Apr 8, 2026
18 checks passed
@huang195
huang195 deleted the use-client-id-for-audience-validation branch April 8, 2026 23:43
@grs

grs commented Apr 9, 2026

Copy link
Copy Markdown

Does this work with the client registration in the controller which configures the Keycloak clients' audience mappers: https://github.com/kagenti/kagenti-operator/blob/main/kagenti-operator/internal/keycloak/audience.go#L51

@grs

grs commented Apr 9, 2026

Copy link
Copy Markdown

Does this require configuring target audience rules to map from the service names to the client ids? (Or how will the token be requested with the correct scope?)

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.

3 participants