-
Notifications
You must be signed in to change notification settings - Fork 126
Integrate token exchange middleware #2143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2143 +/- ##
==========================================
+ Coverage 48.82% 48.84% +0.02%
==========================================
Files 242 242
Lines 30714 30723 +9
==========================================
+ Hits 14996 15007 +11
+ Misses 14596 14588 -8
- Partials 1122 1128 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds OAuth 2.0 Token Exchange (RFC 8693) support to both 'thv proxy' and 'thv run' commands for secure downstream token swapping. Changes include: - New token exchange configuration flags in RemoteAuthFlags - Refactored secret resolution into reusable resolveSecretFromSources - Token exchange middleware registration in runner config builder - Conditional middleware application based on configuration When token exchange is configured via --token-exchange-url, the middleware exchanges the user's bearer token for a downstream token suitable for backend authentication. Fixes: #2066
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds OAuth 2.0 Token Exchange (RFC 8693) support to both 'thv proxy' and 'thv run' commands for secure downstream token swapping.
- New token exchange configuration flags added to RemoteAuthFlags for specifying exchange endpoints, credentials, and token parameters
- Refactored secret resolution into a reusable function that supports multiple sources (flags, files, environment variables)
- Token exchange middleware integrated into both proxy and runner configurations with conditional activation
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/runner/middleware.go | Registers token exchange middleware factory in supported middleware map |
pkg/runner/config_builder.go | Adds token exchange config parameter and conditional middleware creation |
pkg/api/v1/workload_service.go | Updates API service to pass nil token exchange config (not supported via API) |
docs/cli/thv_run.md | Documents new token exchange CLI flags for run command |
docs/cli/thv_proxy.md | Documents new token exchange CLI flags for proxy command |
cmd/thv/app/run_flags.go | Integrates token exchange config creation and passes to middleware builder |
cmd/thv/app/proxy.go | Refactors secret resolution and adds token exchange middleware selection logic |
cmd/thv/app/auth_flags.go | Defines token exchange flags structure and config building logic |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
func resolveClientSecret() (string, error) { | ||
// resolveSecretFromSources resolves a secret from multiple sources with priority ordering | ||
// Priority: 1. Direct value (flag), 2. File path, 3. Environment variable | ||
// Returns empty string if no source provides a value (not an error) |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function comment states it returns empty string when no source provides a value, but this behavior may not be clear to callers who expect secrets. Consider clarifying that callers should validate if an empty result is acceptable for their use case.
// Returns empty string if no source provides a value (not an error) | |
// Returns empty string if no source provides a value (not an error). | |
// Callers MUST validate whether an empty result is acceptable for their use case, | |
// especially when expecting secrets. An empty string means no secret was found. |
Copilot uses AI. Check for mistakes.
logger.Warnf("Failed to resolve token exchange client secret: %v", err) | ||
clientSecret = "" |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is logged as a warning but then silently ignored by setting clientSecret to empty string. This could lead to configuration issues being overlooked. Consider either propagating the error or making the warning more explicit about the fallback behavior.
logger.Warnf("Failed to resolve token exchange client secret: %v", err) | |
clientSecret = "" | |
logger.Errorf("Failed to resolve token exchange client secret: %v. Token exchange will be disabled.", err) | |
return nil |
Copilot uses AI. Check for mistakes.
@claude review this PR. When reviewing make sure to take existing patterns in the CLI and the rest of the project into account. |
Claude finished @jhrozek's task —— View job Code Review: PR #2143 - Integrate token exchange middlewareI've reviewed this PR against existing patterns in the codebase. Overall, the implementation is well-structured and follows established conventions. Here are my findings: ✅ Strengths
|
Adds OAuth 2.0 Token Exchange (RFC 8693) support to both 'thv proxy' and 'thv run' commands for secure downstream token swapping.
Changes include:
- New token exchange configuration flags in RemoteAuthFlags
- Refactored secret resolution into reusable resolveSecretFromSources
- Token exchange middleware registration in runner config builder
- Conditional middleware application based on configuration
When token exchange is configured via --token-exchange-url, the
middleware exchanges the user's bearer token for a downstream token
suitable for backend authentication.
Fixes: #2066