An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
SocketTimeoutException when trying to extract service tags via proxy server using AzureResourceManger Java SDK
I'm using the Azure Resource-Manager Java SDK to extract all service tags from a specific subscription in our cloud environment.
I'm facing a problem when trying to do so via porxy server. The invocation of the following statement, causes a SocketTimeoutException while trying to access login.microsoftonline.com:
azureResourceManager.networks().manager().serviceClient().getServiceTags().listWithResponse(region, Context.NONE);
The AzureResourceManager is created with the following configurations:
ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
HttpClient httpClient = new OkHttpAsyncHttpClientBuilder()
.proxy(proxyOptions)
.build();
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
ClientSecretCredential credentials = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecretKey)
.tenantId(tenant)
.build();
AzureResourceManager azureResourceManager = AzureResourceManager
.configure()
.withLogLevel(HttpLogDetailLevel.BASIC)
.withHttpClient(httpClient)
.authenticate(credentials, profile)
.withSubscription(subId);
I verified access from my machine (CentOS-7) to the login.microsoftonline.com url via proxy, by adding the HTTP_PROXY to my enc and using 'curl -vk login.microsoftonline.com'.
Still when running my Java application and executing 'tcpdump -i em1 -n dst host login.microsoftonline.com' from terminal, I can clearly see that traffic is not going through the proxy and tries to directly access the microsoft URL.
The error Im getting is:
2023-09-06 07:51:40,198 ERROR {ForkJoinPool.commonPool-worker-19} [com.microsoft.aad.msal4j.ConfidentialClientApplication] (AuthenticationResultSupplier.java:155) [][Correlation ID: 6da13044-e4ab-44bf-8c22-493745e72047] Execution of class com.microsoft.aad.msal4j.AcquireTokenSilentSupplier failed.
com.microsoft.aad.msal4j.MsalClientException: java.io.UncheckedIOException: java.net.SocketTimeoutException: connect timed out
at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequest(HttpHelper.java:56) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.executeRequest(AadInstanceDiscoveryProvider.java:286) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.sendInstanceDiscoveryRequest(AadInstanceDiscoveryProvider.java:237) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.doInstanceDiscoveryAndCache(AadInstanceDiscoveryProvider.java:347) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AadInstanceDiscoveryProvider.getMetadataEntry(AadInstanceDiscoveryProvider.java:90) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AuthenticationResultSupplier.getAuthorityWithPrefNetworkHost(AuthenticationResultSupplier.java:39) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AcquireTokenSilentSupplier.execute(AcquireTokenSilentSupplier.java:23) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:69) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:18) ~[msal4j-1.13.8.jar!/:1.13.8]
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) ~[?:1.8.0_382]
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596) ~[?:1.8.0_382]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[?:1.8.0_382]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[?:1.8.0_382]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[?:1.8.0_382]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175) ~[?:1.8.0_382]
Caused by: java.io.UncheckedIOException: java.net.SocketTimeoutException: connect timed out
at com.azure.core.http.okhttp.OkHttpAsyncHttpClient.sendSync(OkHttpAsyncHttpClient.java:118) ~[azure-core-http-okhttp-1.11.10.jar!/:1.11.10]
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:38) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.HttpLoggingPolicy.processSync(HttpLoggingPolicy.java:142) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:41) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.implementation.http.policy.InstrumentationPolicy.processSync(InstrumentationPolicy.java:75) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:41) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:164) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:176) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:176) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:176) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.RetryPolicy.processSync(RetryPolicy.java:114) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:41) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.HttpPipelineSyncPolicy.processSync(HttpPipelineSyncPolicy.java:42) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.policy.UserAgentPolicy.processSync(UserAgentPolicy.java:153) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:41) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.core.http.HttpPipeline.sendSync(HttpPipeline.java:131) ~[azure-core-1.40.0.jar!/:1.40.0]
at com.azure.identity.implementation.HttpPipelineAdapter.send(HttpPipelineAdapter.java:67) ~[azure-identity-1.9.0.jar!/:1.9.0]
at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequestWithRetries(HttpHelper.java:99) ~[msal4j-1.13.8.jar!/:1.13.8]
at com.microsoft.aad.msal4j.HttpHelper.executeHttpRequest(HttpHelper.java:52) ~[msal4j-1.13.8.jar!/:1.13.8]
... 14 more
Note that the com.microsoft.azure.management.Azure SDK is working fine via proxy from the same application.
Is something missing in configuration/code?
Any feedback will be appreciated.