-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Changes to add proxy url in WIC #46972
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
Changes from 2 commits
e4ea2d5
da9e1d2
4cc6934
32ae943
f3be809
d15d8ce
a793987
f0d0b27
51b44c2
8f80a14
045894d
0793e0b
079701f
476fc56
2d594a9
388e64d
16b05b4
dafdc57
cc92d35
8efbfc2
05d1519
263a2fc
553673c
03db57b
e8831ab
625a975
a902dcf
66fdb6d
1725960
f3ef65d
9b86363
b9a9305
25e06a5
ae038cb
0f93a2c
979bebe
2a11c6e
4272c25
ee88ee0
3c5a1f4
f2895ac
0086bcb
b948dfb
3d5e17a
f0e26f2
e57e945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,276 @@ | ||||||||||||||||||||||||
| package com.azure.identity.implementation; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import com.azure.core.http.HttpClient; | ||||||||||||||||||||||||
| import com.azure.core.http.HttpPipelineCallContext; | ||||||||||||||||||||||||
| import com.azure.core.http.HttpPipelineNextPolicy; | ||||||||||||||||||||||||
| import com.azure.core.http.HttpPipelineNextSyncPolicy; | ||||||||||||||||||||||||
| import com.azure.core.http.HttpRequest; | ||||||||||||||||||||||||
| import com.azure.core.http.HttpResponse; | ||||||||||||||||||||||||
| import com.azure.core.http.policy.HttpPipelinePolicy; | ||||||||||||||||||||||||
| import com.azure.core.util.Configuration; | ||||||||||||||||||||||||
| import com.azure.core.util.CoreUtils; | ||||||||||||||||||||||||
| import com.azure.core.util.logging.ClientLogger; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import java.io.InputStream; | ||||||||||||||||||||||||
| import java.io.ByteArrayInputStream; | ||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||
| import java.net.URI; | ||||||||||||||||||||||||
| import java.net.URISyntaxException; | ||||||||||||||||||||||||
| import java.nio.file.Files; | ||||||||||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||||||||||
| import java.nio.file.Paths; | ||||||||||||||||||||||||
| import java.security.KeyStore; | ||||||||||||||||||||||||
| import java.security.cert.CertificateFactory; | ||||||||||||||||||||||||
| import java.security.cert.X509Certificate; | ||||||||||||||||||||||||
| import java.util.Arrays; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import javax.net.ssl.SSLContext; | ||||||||||||||||||||||||
| import javax.net.ssl.TrustManagerFactory; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import reactor.core.publisher.Mono; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public class WorkloadIdentityTokenProxyPolicy implements HttpPipelinePolicy { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private static final ClientLogger LOGGER = new ClientLogger(WorkloadIdentityCustomProxyConfiguration.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 byte[] caData; | ||||||||||||||||||||||||
| private String caFile; | ||||||||||||||||||||||||
| private String sniName; | ||||||||||||||||||||||||
| private URI tokenProxyUri; | ||||||||||||||||||||||||
| private HttpClient httpClient; | ||||||||||||||||||||||||
| private SSLContext sslContext; | ||||||||||||||||||||||||
| private byte[] lastCaBytes; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| WorkloadIdentityTokenProxyPolicy(IdentityClientOptions identityClientOptions) { | ||||||||||||||||||||||||
| Configuration configuration = identityClientOptions.getConfiguration() == null | ||||||||||||||||||||||||
| ? Configuration.getGlobalConfiguration() | ||||||||||||||||||||||||
| : identityClientOptions.getConfiguration(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| String tokenProxyUrl = configuration.get(AZURE_KUBERNETES_TOKEN_PROXY); | ||||||||||||||||||||||||
| String sniName = configuration.get(AZURE_KUBERNETES_SNI_NAME); | ||||||||||||||||||||||||
| String caFile = configuration.get(AZURE_KUBERNETES_CA_FILE); | ||||||||||||||||||||||||
| String caData = configuration.get(AZURE_KUBERNETES_CA_DATA); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (CoreUtils.isNullOrEmpty(tokenProxyUrl)) { | ||||||||||||||||||||||||
| if (!CoreUtils.isNullOrEmpty(sniName) | ||||||||||||||||||||||||
| || !CoreUtils.isNullOrEmpty(caFile) | ||||||||||||||||||||||||
| || !CoreUtils.isNullOrEmpty(caData)) { | ||||||||||||||||||||||||
| throw LOGGER.logExceptionAsError(new IllegalStateException( | ||||||||||||||||||||||||
| "AZURE_KUBERNETES_TOKEN_PROXY is not set but other custom endpoint-related environment variables are present")); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| this.tokenProxyUri = null; | ||||||||||||||||||||||||
| this.caFile = null; | ||||||||||||||||||||||||
| this.caData = null; | ||||||||||||||||||||||||
| this.sniName = null; | ||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!CoreUtils.isNullOrEmpty(caFile) && !CoreUtils.isNullOrEmpty(caData)) { | ||||||||||||||||||||||||
| throw LOGGER.logExceptionAsError(new IllegalStateException( | ||||||||||||||||||||||||
| "Only one of AZURE_KUBERNETES_CA_FILE or AZURE_KUBERNETES_CA_DATA can be set.")); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| this.tokenProxyUri = parseAndValidateProxyUrl(tokenProxyUrl); | ||||||||||||||||||||||||
| this.sniName = sniName; | ||||||||||||||||||||||||
| this.caFile = caFile; | ||||||||||||||||||||||||
| this.caData = CoreUtils.isNullOrEmpty(caData) ? null : caData.getBytes(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||||||||||||||||||||||||
| //HttpClient client = createHttpClient(); | ||||||||||||||||||||||||
| HttpRequest request = context.getHttpRequest(); | ||||||||||||||||||||||||
| HttpRequest proxyRequest = rewriteTokenRequestForProxy(request); | ||||||||||||||||||||||||
| context.setHttpRequest(proxyRequest); | ||||||||||||||||||||||||
| return next.process(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| public HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) { | ||||||||||||||||||||||||
| HttpRequest request = context.getHttpRequest(); | ||||||||||||||||||||||||
| HttpRequest proxyRequest = rewriteTokenRequestForProxy(request); | ||||||||||||||||||||||||
| context.setHttpRequest(proxyRequest); | ||||||||||||||||||||||||
| return next.processSync(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private HttpRequest rewriteTokenRequestForProxy(HttpRequest request) { | ||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| URI originalUri = request.getUrl().toURI(); | ||||||||||||||||||||||||
| String originalPath = originalUri.getRawPath(); | ||||||||||||||||||||||||
| String originalQuery = originalUri.getRawQuery(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| String tokenProxyBase = tokenProxyUri.toString(); | ||||||||||||||||||||||||
| if(!tokenProxyBase.endsWith("/")) tokenProxyBase += "/"; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if(!tokenProxyBase.endsWith("/")) tokenProxyBase += "/"; | |
| if (!tokenProxyBase.endsWith("/")) tokenProxyBase += "/"; |
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.
Commented-out code should be removed before merging. This appears to be unused development code that clutters the implementation.
| // private HttpClient createHttpClient() { | |
| // if((caData == null || caData.length == 0) && (caFile == null || caFile.isEmpty())) { | |
| // if(httpClient == null) { | |
| // // httpClient = | |
| // } | |
| // } | |
| // if(caFile == null || caFile.isEmpty()) { | |
| // // httpClient = | |
| // } | |
| // throw new UnsupportedOperationException("Unimplemented method 'createHttpClient'"); | |
| // } |
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.
Grammar error in comment. Should be 'If no CA override provided, use default' or 'If no CA override is provided, use default'.
| // If no CA override provide, use default | |
| // If no CA override provided, use default |
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.
Missing space after 'if' keyword. Should follow Java coding conventions with proper spacing.
| if(!Files.exists(path)) { | |
| if (!Files.exists(path)) { |
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.
Missing space after 'if' keyword. Should follow Java coding conventions with proper spacing.
| if(currentContent.length == 0) { | |
| if (currentContent.length == 0) { |
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.
Missing space after 'if' keyword. Should follow Java coding conventions with proper spacing.
Uh oh!
There was an error while loading. Please reload this page.