-
Notifications
You must be signed in to change notification settings - Fork 951
[azidentity] Allow Identity Binding mode to be set via configuration options #25664
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
Open
clnv
wants to merge
8
commits into
Azure:main
Choose a base branch
from
clnv:custom-proxy-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a4a4307
Allow passing token proxy options from options
clnv 8dd1286
Add optional GetFederatedToken
clnv cd5a6e3
Add missing doc
clnv 5a14d1b
Update sdk/azidentity/workload_identity.go
clnv 05ed0ce
Update sdk/azidentity/workload_identity.go
clnv 9f4d273
Fix typo
clnv 06c9eb3
Refactor options
clnv b3ac336
Remove go.work.sum
clnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= | ||
| github.com/keybase/dbus v0.0.0-20220506165403-5aa21ea2c23a/go.mod h1:YPNKjjE7Ubp9dTbnWvsP3HT+hYnY6TfXzubYTBeUxc8= | ||
| github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= | ||
| github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= | ||
| golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ= | ||
| golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | ||
| golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw= | ||
| golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw= |
121 changes: 121 additions & 0 deletions
121
sdk/azidentity/internal/customtokenproxy/configuration.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package customtokenproxy | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "net/url" | ||
| "os" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/azidentity/internal/exported" | ||
| ) | ||
|
|
||
| const ( | ||
| EnvAzureKubernetesCAData = "AZURE_KUBERNETES_CA_DATA" | ||
| EnvAzureKubernetesCAFile = "AZURE_KUBERNETES_CA_FILE" | ||
| EnvAzureKubernetesSNIName = "AZURE_KUBERNETES_SNI_NAME" | ||
| EnvAzureKubernetesTokenProxy = "AZURE_KUBERNETES_TOKEN_PROXY" | ||
| ) | ||
|
|
||
| func readOptionsFromEnv() *exported.CustomTokenProxyOptions { | ||
| return &exported.CustomTokenProxyOptions{ | ||
| TokenProxy: os.Getenv(EnvAzureKubernetesTokenProxy), | ||
| SNIName: os.Getenv(EnvAzureKubernetesSNIName), | ||
| CAFile: os.Getenv(EnvAzureKubernetesCAFile), | ||
| CAData: os.Getenv(EnvAzureKubernetesCAData), | ||
| } | ||
| } | ||
|
|
||
| func backfillOptionsFromEnv(opts *exported.CustomTokenProxyOptions) { | ||
| if opts.CAData != "" || opts.CAFile != "" || opts.SNIName != "" || opts.TokenProxy != "" { | ||
| return | ||
| } | ||
|
|
||
| // only backfill if all fields are empty | ||
| *opts = *readOptionsFromEnv() | ||
| } | ||
|
|
||
| func parseTokenProxyURL(endpoint string) (*url.URL, error) { | ||
| tokenProxy, err := url.Parse(endpoint) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse custom token proxy URL %q: %s", endpoint, err) | ||
| } | ||
| if tokenProxy.Scheme != "https" { | ||
| return nil, fmt.Errorf("custom token endpoint must use https scheme, got %q", tokenProxy.Scheme) | ||
| } | ||
| if tokenProxy.User != nil { | ||
| return nil, fmt.Errorf("custom token endpoint URL %q must not contain user info", tokenProxy) | ||
| } | ||
| if tokenProxy.RawQuery != "" { | ||
| return nil, fmt.Errorf("custom token endpoint URL %q must not contain a query", tokenProxy) | ||
| } | ||
| if tokenProxy.EscapedFragment() != "" { | ||
| return nil, fmt.Errorf("custom token endpoint URL %q must not contain a fragment", tokenProxy) | ||
| } | ||
| if tokenProxy.EscapedPath() == "" { | ||
| // if the path is empty, set it to "/" to avoid stripping the path from req.URL | ||
| tokenProxy.Path = "/" | ||
| } | ||
| return tokenProxy, nil | ||
| } | ||
|
|
||
| var ( | ||
| errCustomEndpointSetWithoutTokenProxy = errors.New( | ||
| "AZURE_KUBERNETES_TOKEN_PROXY is not set but other custom endpoint-related settings are present", | ||
| ) | ||
| errCustomEndpointMultipleCASourcesSet = errors.New( | ||
| "only one of AzureKubernetesCAFile or AzureKubernetesCAData can be specified", | ||
| ) | ||
| ) | ||
|
|
||
| func noopConfigure(*policy.ClientOptions) { | ||
| // no-op | ||
| } | ||
|
|
||
| // GetClientOptionsConfigurer returns a function that configures the client options to use the custom token proxy. | ||
| func GetClientOptionsConfigurer(opts *exported.CustomTokenProxyOptions) (func(*policy.ClientOptions), error) { | ||
| if opts == nil { | ||
| return noopConfigure, nil | ||
| } | ||
|
|
||
| backfillOptionsFromEnv(opts) | ||
|
|
||
| if opts.TokenProxy == "" { | ||
| // custom token proxy is not set, while other Kubernetes-related environment variables are present, | ||
| // this is likely a configuration issue so erroring out to avoid misconfiguration | ||
| if opts.SNIName != "" || opts.CAFile != "" || opts.CAData != "" { | ||
| return nil, errCustomEndpointSetWithoutTokenProxy | ||
| } | ||
|
|
||
| return noopConfigure, nil | ||
| } | ||
|
|
||
| tokenProxy, err := parseTokenProxyURL(opts.TokenProxy) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // CAFile and CAData are mutually exclusive, at most one can be set. | ||
| // If none of CAFile or CAData are set, the default system CA pool will be used. | ||
| if opts.CAFile != "" && opts.CAData != "" { | ||
| return nil, errCustomEndpointMultipleCASourcesSet | ||
| } | ||
|
|
||
| // preload the transport | ||
| t := &transport{ | ||
| caFile: opts.CAFile, | ||
| caData: []byte(opts.CAData), | ||
| sniName: opts.SNIName, | ||
| tokenProxy: tokenProxy, | ||
| } | ||
| if _, err := t.getTokenTransporter(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return func(clientOptions *policy.ClientOptions) { | ||
| clientOptions.Transport = t | ||
| }, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.