Repository navigation
feat(authproxy): use CLIENT_ID for per-agent inbound audience validation - #282
Conversation
9a080c3 to
c6d7443
Compare
…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 <huang195@gmail.com>
c6d7443 to
61ca04c
Compare
mrsabath
left a comment
There was a problem hiding this comment.
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_AUDIENCEinjection - All 7 doc/CLAUDE.md files updated consistently
- Test cleanup is correct: removed
TestBuildEnvoyProxyContainer_HasExpectedAudienceFromConfigMapand updatedTestBuildAuthBridgeContainer_AllEnvVarsrequired 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 |
There was a problem hiding this comment.
👍 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). |
There was a problem hiding this comment.
👍 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.
|
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 |
|
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?) |
Summary
Replace the
EXPECTED_AUDIENCEenv var with the agent'sCLIENT_ID(from/shared/client-id.txt) for inbound JWT audience validation. This makes audience validation per-agent by construction.Problem
EXPECTED_AUDIENCEwas either:A token intended for one agent could be used on any other agent in the same namespace.
Solution
Use
CLIENT_IDfrom/shared/client-id.txtas 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:spiffe://trust-domain/ns/namespace/sa/service-accountnamespace/workload-nameThe audience scope created during client registration ensures platform tokens (kagenti UI) include this value in their
audclaim.Changes
config.ClientIDinstead ofEXPECTED_AUDIENCEenv varEXPECTED_AUDIENCEreferencesImpact on existing demos
All demos verified — no breakage:
Test plan
Generated with Claude Code