Repository navigation
🐛 Start gRPC listener before credential resolution - #323
Conversation
The authbridge binary blocked for up to 2 minutes at startup waiting for credential files written by client-registration. During this time, the ext_proc gRPC server was not running, causing Envoy to get Connection refused on every outbound request. - Move credential file resolution to a background goroutine that runs after the gRPC listener starts - Replace eager JWKS verifier with LazyJWKSVerifier that fetches keys on first Verify() call, with retry on failure - Use atomic.Pointer for identity and sync.RWMutex for exchanger auth to safely update credentials from the background goroutine - Export ResolveCredentialFiles and ResolveClientAuth for use by main Outbound passthrough traffic now works immediately on startup. Token exchange and inbound validation work once credentials and JWKS keys are available. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
cwiklik
left a comment
There was a problem hiding this comment.
Review Summary
Good fix for a real startup race. The architecture is sound: lazy JWKS verification, atomic.Pointer for identity (lock-free hot-path reads), RWMutex for exchanger auth (allows concurrent token exchanges), and credential resolution moved to a background goroutine.
Verified:
Audience: cfg.Identity.ClientID(main.go:309) matches the existing pattern inResolve()on main (// inbound audience defaults to client ID) — not a bug- All
a.identityread sites in auth.go properly migrated to.Load()— no missed call sites - Comment claim that goroutine has exclusive
cfg.Identitywrite access checks out
Suggestions (non-blocking)
1. Missing tests for validation/lazy.go — 51 lines of new concurrency-sensitive code (mutex, lazy init, retry-on-failure) with zero test coverage. Worth adding lazy_test.go covering:
- Verify() initializes only on first call
- Init failure is retried on next Verify (not cached)
- Concurrent Verify calls during init don't trigger multiple HTTP fetches (single-flight via mutex)
The existing jwks_test.go is a good template.
2. Silent failure mode in cmd/authbridge/main.go — if credential files never appear (e.g., client-registration sidecar crashed) or JWKS endpoint is permanently unreachable, the system runs in degraded state with only slog.Warn messages. Consider exposing a readiness signal (e.g., a flag flipped by UpdateIdentity and surfaced via a health endpoint) so Kubernetes can detect the degraded state instead of silently routing traffic to a non-functional authbridge.
Praise
- Retry-on-failure (vs
sync.Oncewhich would permanently cache the error) is the right call — temporarily unreachable JWKS shouldn't permanently break validation. Good comment explaining the choice. atomic.Pointer[IdentityConfig]for lock-free reads on the inbound hot path +sync.RWMutexfor exchanger auth — right concurrency primitives for each access pattern.
Areas reviewed: Go (auth, exchange, validation, config, main)
Commits: 1 commit, signed-off ✓, Assisted-By trailer ✓
CI: 18/18 passing ✓
LGTM.
Summary
Problem
The authbridge binary blocks for up to 2 minutes at startup waiting for /shared/client-id.txt and /shared/client-secret.txt (60s timeout each). These files are written by the client-registration sidecar, which may not be ready yet on a fresh cluster. During this wait, the ext_proc gRPC server on port 9090 is not running -- Envoy gets Connection refused on every outbound request.
This caused flaky E2E failures: test_agent_simple_query fails because the weather-service agent cannot reach weather-tool-mcp through Envoy.
Fix
Files changed
Test plan
Assisted-By: Claude (Anthropic AI) [email protected]