Call to return Secret from KeyVault via SecretClient using Managed Identity Credentials does not return from Java call
I am running Ubuntu on a Linux VM in the Azure cloud. This VM has the System Assigned Identity set to "on". My key vault has granted the role of "Key Vault Administrator" to my VM.
My Java code below is taken from the example at https://github.com/Azure/azure-sdk-for-java/wiki/Azure-Identity-Examples The output is shown below. I have debug set on for com.azure. When it creates the credential, I get one line of output from the Azure SDK code looking for environment variables.
LOGGER.debug("Retrieve Credentials from Azure");
KeyVaultSecret keyVaultSecret = null;
try {
String keyVaultURL = "https://" + uCCVMAttributesUpdate.getAzureKeyVault() +
AZURE_KEYVAULT_SUFFIX;
LOGGER.debug("keyVaultURL<" + keyVaultURL + ">");
SecretClient secretClient = new SecretClientBuilder()
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.vaultUrl( keyVaultURL )
.credential (new ManagedIdentityCredentialBuilder().build() )
.buildClient();
LOGGER.debug("SecretClient created");
keyVaultSecret = secretClient.getSecret(AZURE_SECRET_NAME);
LOGGER.debug("Secrets retrieved");
} catch (Exception e) {
LOGGER.error("Caught exception reading Azure secrets", e);
}
Output:
2021-03-22 15:21:48 - [pool-3-thread-1][DEBUG][com.impl.ServiceImpl] - Retrieve Credentials from Azure 2021-03-22 15:21:48 - [pool-3-thread-1][DEBUG][com.impl.ServiceImpl] - keyVaultURLhttps://KeyVaultName.vault.azure.net/ 2021-03-22 15:21:48 - [pool-3-thread-1][DEBUG][com.azure.core.util.logging.ClientLogger] - Azure Identity => Found the following environment variables:
Does anyone know what the issue could be, or what else I could do to get more debug?
I need to fingure out why the call is not returning, throwing an exception, or outputting more debug. Also, I do not understand when it is looking for environment variables since I am using the ManagedIdentityCredentialBuilder.
BTW, I got the same result using the DefaultAzureCredential which the following link explains will try to find a managed identity first then fallback on other methods which use environment variables: https://learn.microsoft.com/en-us/java/api/overview/azure/identity-readme?view=azure-java-stable
Thank you for any help.