-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable Custom Proxy in WorkloadIdentityCredential #47041
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
anannya03
wants to merge
10
commits into
Azure:main
Choose a base branch
from
anannya03:add_fic_bypass_fic_limit
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b7ca0dc
changes to add proxy in wic
anannya03 b162676
integration with wicbuilder and wic
anannya03 8502259
review comments
anannya03 7a521b5
added wic testcases and some review comments
anannya03 f6ba982
Merge branch 'main' into add_fic_bypass_fic_limit
anannya03 0a32cb0
Merge branch 'add_fic_bypass_fic_limit' of https://github.com/anannya…
anannya03 0c69110
unit test
anannya03 89396ed
live testing based updates
anannya03 702cc3f
spotless, spotbugs, checkstyle and local server test
anannya03 7092460
Merge branch 'main' into add_fic_bypass_fic_limit
anannya03 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
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
112 changes: 112 additions & 0 deletions
112
...ava/com/azure/identity/implementation/customtokenproxy/CustomTokenProxyConfiguration.java
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,112 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.identity.implementation.customtokenproxy; | ||
|
|
||
| import com.azure.core.util.logging.ClientLogger; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| import com.azure.core.util.Configuration; | ||
| import com.azure.core.util.CoreUtils; | ||
|
|
||
| public final class CustomTokenProxyConfiguration { | ||
|
|
||
| private static final ClientLogger LOGGER = new ClientLogger(CustomTokenProxyConfiguration.class); | ||
|
|
||
| public static final String AZURE_KUBERNETES_TOKEN_PROXY = "AZURE_KUBERNETES_TOKEN_PROXY"; | ||
| public static final String AZURE_KUBERNETES_CA_FILE = "AZURE_KUBERNETES_CA_FILE"; | ||
| public static final String AZURE_KUBERNETES_CA_DATA = "AZURE_KUBERNETES_CA_DATA"; | ||
| public static final String AZURE_KUBERNETES_SNI_NAME = "AZURE_KUBERNETES_SNI_NAME"; | ||
|
|
||
| private CustomTokenProxyConfiguration() { | ||
| } | ||
|
|
||
| public static boolean isConfigured(Configuration configuration) { | ||
| String tokenProxyUrl = configuration.get(AZURE_KUBERNETES_TOKEN_PROXY); | ||
| return !CoreUtils.isNullOrEmpty(tokenProxyUrl); | ||
| } | ||
|
|
||
| public static ProxyConfig parseAndValidate(Configuration configuration) { | ||
| String tokenProxyUrl = configuration.get(AZURE_KUBERNETES_TOKEN_PROXY); | ||
| String caFile = configuration.get(AZURE_KUBERNETES_CA_FILE); | ||
| String caData = configuration.get(AZURE_KUBERNETES_CA_DATA); | ||
| String sniName = configuration.get(AZURE_KUBERNETES_SNI_NAME); | ||
|
|
||
| if (CoreUtils.isNullOrEmpty(tokenProxyUrl)) { | ||
| if (!CoreUtils.isNullOrEmpty(sniName) | ||
| || !CoreUtils.isNullOrEmpty(caFile) | ||
| || !CoreUtils.isNullOrEmpty(caData)) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException( | ||
| "AZURE_KUBERNETES_TOKEN_PROXY is not set but other custom endpoint-related environment variables are present")); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| if (!CoreUtils.isNullOrEmpty(caFile) && !CoreUtils.isNullOrEmpty(caData)) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException( | ||
| "Only one of AZURE_KUBERNETES_CA_FILE or AZURE_KUBERNETES_CA_DATA can be set.")); | ||
| } | ||
|
|
||
| URL proxyUrl = validateProxyUrl(tokenProxyUrl); | ||
|
|
||
| byte[] caCertBytes = null; | ||
| if (!CoreUtils.isNullOrEmpty(caData)) { | ||
| try { | ||
| caCertBytes = caData.getBytes(StandardCharsets.UTF_8); | ||
| } catch (Exception e) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException( | ||
| "Failed to decode CA certificate data from AZURE_KUBERNETES_CA_DATA", e)); | ||
| } | ||
| } | ||
|
|
||
| ProxyConfig config = new ProxyConfig(proxyUrl, sniName, caFile, caCertBytes); | ||
| return config; | ||
| } | ||
|
|
||
| private static URL validateProxyUrl(String endpoint) { | ||
| if (CoreUtils.isNullOrEmpty(endpoint)) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException("Proxy endpoint cannot be null or empty")); | ||
| } | ||
|
|
||
| try { | ||
| URI tokenProxy = new URI(endpoint); | ||
|
|
||
| if (!"https".equals(tokenProxy.getScheme())) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException( | ||
| "Custom token endpoint must use https scheme, got: " + tokenProxy.getScheme())); | ||
| } | ||
|
|
||
| if (tokenProxy.getRawUserInfo() != null) { | ||
| throw LOGGER.logExceptionAsError( | ||
| new IllegalArgumentException("Custom token endpoint URL must not contain user info: " + endpoint)); | ||
| } | ||
|
|
||
| if (tokenProxy.getRawQuery() != null) { | ||
| throw LOGGER.logExceptionAsError( | ||
| new IllegalArgumentException("Custom token endpoint URL must not contain a query: " + endpoint)); | ||
| } | ||
|
|
||
| if (tokenProxy.getRawFragment() != null) { | ||
| throw LOGGER.logExceptionAsError( | ||
| new IllegalArgumentException("Custom token endpoint URL must not contain a fragment: " + endpoint)); | ||
| } | ||
|
|
||
| if (tokenProxy.getRawPath() == null || tokenProxy.getRawPath().isEmpty()) { | ||
| tokenProxy = new URI(tokenProxy.getScheme(), null, tokenProxy.getHost(), tokenProxy.getPort(), "/", | ||
| null, null); | ||
| } | ||
|
|
||
| return tokenProxy.toURL(); | ||
|
|
||
| } catch (URISyntaxException | IllegalArgumentException e) { | ||
| throw LOGGER.logExceptionAsError(new IllegalArgumentException("Failed to normalize proxy URL path", e)); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Unexpected error while validating proxy URL: " + endpoint, e); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.