Skip to content

Commit 27bd9b9

Browse files
committed
Support resource indicator in remote auth
Fix #1192
1 parent 8989d46 commit 27bd9b9

File tree

18 files changed

+59
-5
lines changed

18 files changed

+59
-5
lines changed

cmd/thv/app/auth_flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type RemoteAuthFlags struct {
7575
RemoteAuthIssuer string
7676
RemoteAuthAuthorizeURL string
7777
RemoteAuthTokenURL string
78+
RemoteAuthResource string
7879

7980
// Token Exchange Configuration
8081
TokenExchangeURL string
@@ -162,6 +163,8 @@ func AddRemoteAuthFlags(cmd *cobra.Command, config *RemoteAuthFlags) {
162163
"OAuth authorization endpoint URL (alternative to --remote-auth-issuer for non-OIDC OAuth)")
163164
cmd.Flags().StringVar(&config.RemoteAuthTokenURL, "remote-auth-token-url", "",
164165
"OAuth token endpoint URL (alternative to --remote-auth-issuer for non-OIDC OAuth)")
166+
cmd.Flags().StringVar(&config.RemoteAuthResource, "remote-auth-resource", "",
167+
"OAuth 2.0 resource indicator (RFC 8707)")
165168

166169
// Token Exchange flags
167170
cmd.Flags().StringVar(&config.TokenExchangeURL, "token-exchange-url", "",

cmd/thv/app/run_flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,11 @@ func getRemoteAuthFromRemoteServerMetadata(
677677
authCfg.CallbackPort = runner.DefaultCallbackPort
678678
}
679679

680-
// Issuer / URLs: CLI non-empty wins
680+
// Issuer / URLs / Resource: CLI non-empty wins
681681
authCfg.Issuer = firstNonEmpty(f.RemoteAuthIssuer, oc.Issuer)
682682
authCfg.AuthorizeURL = firstNonEmpty(f.RemoteAuthAuthorizeURL, oc.AuthorizeURL)
683683
authCfg.TokenURL = firstNonEmpty(f.RemoteAuthTokenURL, oc.TokenURL)
684+
authCfg.Resource = firstNonEmpty(f.RemoteAuthResource, oc.Resource)
684685

685686
// OAuthParams: REPLACE metadata when CLI provides any key/value.
686687
if len(runFlags.OAuthParams) > 0 {
@@ -725,6 +726,7 @@ func getRemoteAuthFromRunFlags(runFlags *RunFlags) (*remote.Config, error) {
725726
Issuer: runFlags.RemoteAuthFlags.RemoteAuthIssuer,
726727
AuthorizeURL: runFlags.RemoteAuthFlags.RemoteAuthAuthorizeURL,
727728
TokenURL: runFlags.RemoteAuthFlags.RemoteAuthTokenURL,
729+
Resource: runFlags.RemoteAuthFlags.RemoteAuthResource,
728730
OAuthParams: runFlags.OAuthParams,
729731
}, nil
730732
}

docs/cli/thv_proxy.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/cli/thv_run.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/docs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/v1/workload_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (s *WorkloadService) BuildFullRunConfig(ctx context.Context, req *createReq
160160
AuthorizeURL: remoteServerMetadata.OAuthConfig.AuthorizeURL,
161161
TokenURL: remoteServerMetadata.OAuthConfig.TokenURL,
162162
UsePKCE: remoteServerMetadata.OAuthConfig.UsePKCE,
163+
Resource: remoteServerMetadata.OAuthConfig.Resource,
163164
OAuthParams: remoteServerMetadata.OAuthConfig.OAuthParams,
164165
Headers: remoteServerMetadata.Headers,
165166
EnvVars: remoteServerMetadata.EnvVars,

pkg/api/v1/workload_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ type remoteOAuthConfig struct {
110110
CallbackPort int `json:"callback_port,omitempty"`
111111
// Whether to skip opening browser for OAuth flow (defaults to false)
112112
SkipBrowser bool `json:"skip_browser,omitempty"`
113+
// OAuth 2.0 resource indicator (RFC 8707)
114+
Resource string `json:"resource,omitempty"`
113115
}
114116

115117
// createRequest represents the request to create a new workload
@@ -222,6 +224,7 @@ func runConfigToCreateRequest(runConfig *runner.RunConfig) *createRequest {
222224
OAuthParams: runConfig.RemoteAuthConfig.OAuthParams,
223225
CallbackPort: runConfig.RemoteAuthConfig.CallbackPort,
224226
SkipBrowser: runConfig.RemoteAuthConfig.SkipBrowser,
227+
Resource: runConfig.RemoteAuthConfig.Resource,
225228
}
226229
headers = runConfig.RemoteAuthConfig.Headers
227230
}

pkg/auth/discovery/discovery.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ type OAuthFlowConfig struct {
374374
CallbackPort int
375375
Timeout time.Duration
376376
SkipBrowser bool
377+
Resource string // RFC 8707 resource indicator (optional)
377378
OAuthParams map[string]string
378379
}
379380

@@ -494,6 +495,7 @@ func createOAuthConfig(ctx context.Context, issuer string, config *OAuthFlowConf
494495
config.Scopes,
495496
true, // Enable PKCE by default for security
496497
config.CallbackPort,
498+
config.Resource,
497499
config.OAuthParams,
498500
)
499501
}
@@ -508,6 +510,7 @@ func createOAuthConfig(ctx context.Context, issuer string, config *OAuthFlowConf
508510
config.Scopes,
509511
true, // Enable PKCE by default for security
510512
config.CallbackPort,
513+
config.Resource,
511514
)
512515
}
513516

0 commit comments

Comments
 (0)