This troubleshooting guide covers failure investigation techniques, common errors for the credential types in the Azure Identity Java client library, and mitigation steps to resolve these errors.
- Handle Azure Identity Exceptions
- Find Relevant Information in Exception Messages
- Enable and Configure Logging
- Troubleshoot DefaultAzureCredential Authentication Issues
- Troubleshoot EnvironmentCredential Authentication Issues
- Troubleshoot ClientSecretCredential Authentication Issues
- Troubleshoot ClientCertificateCredential Authentication Issues
- Troubleshoot UsernamePasswordCredential Authentication Issues
- Troubleshoot ManagedIdentityCredential Authentication Issues
- Troubleshoot VisualStudioCodeCredential Authentication Issues
- Troubleshoot AzureCliCredential Authentication Issues
- Troubleshoot AzurePowerShellCredential Authentication Issues
- Get Additional Help
Exceptions arising from authentication errors can be raised on any service client method that makes a request to the service. This is because the token is requested from the credential on the first call to the service and on any subsequent requests to the service that need to refresh the token.
To distinguish these failures from failures in the service client, Azure Identity classes raise the ClientAuthenticationException
with details describing the source of the error in the exception message and possibly the error message. Depending on the application, these errors may or may not be recoverable.
// Create a secret client using the DefaultAzureCredential
SecretClient client = new SecretClientBuilder()
.vaultUrl("https://myvault.vault.azure.net/")
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
try {
KeyVaultSecret secret = client.geSecret("secret1");
} catch (ClientAuthenticationException e) {
//Handle Exception
e.printStackTrace();
}
The CredentialUnavailableExcpetion
is a special exception type derived from ClientAuthenticationException
. This exception type is used to indicate that the credential can’t authenticate in the current environment, due to lack of required configuration or setup. This exception is also used as a signal to chained credential types, such as DefaultAzureCredential
and ChainedTokenCredential
, that the chained credential should continue to try other credential types later in the chain.
Calls to service clients resulting in HttpResponseException
with a StatusCode
of 401 or 403 often indicate the caller doesn't have sufficient permissions for the specified API. Check the service documentation to determine which RBAC roles are needed for the specific request, and ensure the authenticated user or service principal have been granted the appropriate roles on the resource.
ClientAuthenticationException
is thrown when unexpected errors occurred while a credential is authenticating. This can include errors received from requests to the AAD STS and often contains information helpful to diagnosis. Consider the following ClientAuthenticationException
message.
This error contains several pieces of information:
-
Failing Credential Type: The type of credential that failed to authenticate. This can be helpful when diagnosing issues with chained credential types such as
DefaultAzureCredential
orChainedTokenCredential
. -
STS Error Code and Message: The error code and message returned from the Azure AD STS. This can give insight into the specific reason the request failed. For instance, in this specific case because the provided client secret is incorrect. More information on STS error codes can be found here.
-
Correlation ID and Timestamp: The correlation ID and call Timestamp used to identify the request in server-side logs. This information can be useful to support engineers when diagnosing unexpected STS failures.
Azure SDK for Java offers a consistent logging story to help aid in troubleshooting application errors and expedite their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help locate the root issue. View the logging wiki for guidance about enabling logging.
CAUTION: Requests and responses in the Azure Identity library contain sensitive information. Precaution must be taken to protect logs when customizing the output to avoid compromising account security.
Error | Description | Mitigation |
---|---|---|
CredentialUnavailableException raised with message. "DefaultAzureCredential failed to retrieve a token from the included credentials." |
All credentials in the DefaultAzureCredential chain failed to retrieve a token, each throwing a CredentialUnavailableException |
|
HttpResponseException raised from the client with a status code of 401 or 403 |
Authentication succeeded but the authorizing Azure service responded with a 401 (Authenticate), or 403 (Forbidden) status code. This can often be caused by the DefaultAzureCredential authenticating an account other than the intended or that the intended account does not have the correct permissions or roles assigned. |
|
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
Environment variables aren't fully configured. | A valid combination of environment variables wasn't set. | Ensure the appropriate environment variables are set prior to application startup for the intended authentication method.
|
ClientAuthenticationException
Error Code | Issue | Mitigation |
---|---|---|
AADSTS7000215 | An invalid client secret was provided. | Ensure the clientSecret provided when constructing the credential is valid. If unsure, create a new client secret using the Azure portal. Details on creating a new client secret can be found here. |
AADSTS7000222 | An expired client secret was provided. | Create a new client secret using the Azure portal. Details on creating a new client secret can be found here. |
AADSTS700016 | The specified application wasn't found in the specified tenant. | Ensure the specified clientId and tenantId are correct for your application registration. For multi-tenant apps, ensure the application has been added to the desired tenant by a tenant admin. To add a new application in the desired tenant, follow the instructions here. |
ClientAuthenticationException
Error Code | Description | Mitigation |
---|---|---|
AADSTS700027 | Client assertion contains an invalid signature. | Ensure the specified certificate has been uploaded to the AAD application registration. Instructions for uploading certificates to the application registration can be found here. |
AADSTS700016 | The specified application wasn’t found in the specified tenant. | Ensure the specified clientId and tenantId are correct for your application registration. For multi-tenant apps, ensure the application has been added to the desired tenant by a tenant admin. To add a new application in the desired tenant, follow the instructions here. |
ClientAuthenticationException
Error Code | Issue | Mitigation |
---|---|---|
AADSTS50126 | The provided username or password is invalid | Ensure the username and password provided when constructing the credential are valid. |
The ManagedIdentityCredential
is designed to work on a variety of Azure hosts that provide managed identity. Configuring the managed identity and troubleshooting failures varies from hosts. The below table lists the Azure hosts that can be assigned a managed identity, and are supported by the ManagedIdentityCredential
.
Host Environment | ||
---|---|---|
Azure Virtual Machines and Scale Sets | Configuration | Troubleshooting |
Azure App Service and Azure Functions | Configuration | Troubleshooting |
Azure Kubernetes Service | Configuration | Troubleshooting |
Azure Arc | Configuration | |
Azure Service Fabric | Configuration |
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
The requested identity hasn’t been assigned to this resource. | The IMDS endpoint responded with a status code of 400, indicating the requested identity isn’t assigned to the VM. | If using a user assigned identity, ensure the specified clientId is correct.If using a system assigned identity, make sure it has been enabled properly. Instructions to enable the system assigned identity on an Azure VM can be found here. |
The request failed due to a gateway error. | The request to the IMDS endpoint failed due to a gateway error, 502 or 504 status code. | Calls via proxy or gateway aren’t supported by IMDS. Disable proxies or gateways running on the VM for calls to the IMDS endpoint http://169.254.169.254/ |
No response received from the managed identity endpoint. | No response was received for the request to IMDS or the request timed out. | |
Multiple attempts failed to obtain a token from the managed identity endpoint. | Retries to retrieve a token from the IMDS endpoint have been exhausted. |
|
If you have access to the VM, you can verify the manged identity endpoint is available via the command line using curl.
curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://management.core.windows.net&api-version=2018-02-01' -H "Metadata: true"
Note that output of this command will contain a valid access token, and SHOULD NOT BE SHARED to avoid compromising account security.
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
ManagedIdentityCredential authentication unavailable. | The environment variables configured by the App Services host weren’t present. |
If you have access to SSH into the App Service, you can verify managed identity is available in the environment. First ensure the environment variables MSI_ENDPOINT
and MSI_SECRET
have been set in the environment. Then you can verify the managed identity endpoint is available using curl.
curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://management.core.windows.net&api-version=2018-02-01' -H "Metadata: true"
Note that the output of this command will contain a valid access token, and SHOULD NOT BE SHARED to avoid compromising account security.
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
No Managed Identity endpoint found | The application attempted to authenticate before an identity was assigned to its pod | Verify the pod is labeled correctly. This also occurs when a correctly labeled pod authenticates before the identity is ready. To prevent initialization races, configure NMI to set the Retry-After header in its responses (see Pod Identity documentation). |
It's a known issue that
VisualStudioCodeCredential
doesn't work with Azure Account extension versions newer than 0.9.11. A long-term fix to this problem is in progress. In the meantime, consider authenticating via the Azure CLI.
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
Failed To Read VS Code CredentialsORAuthenticate via Azure Tools plugin in VS Code | No Azure account information was found in the VS Code configuration. |
|
MSAL Interaction Required Exception | The VisualStudioCodeCredential was able to read the cached credentials from the cache but the cached token is likely expired. |
Log into the Azure Account extension via View > Command Palette to execute the Azure: Sign In command in the VS Code IDE. |
ADFS tenant not supported | ADFS tenants are not currently supported by Visual Studio Azure Service Authentication . |
Use credentials from a supported cloud when authenticating with Visual Studio. The supported clouds are:
|
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
Azure CLI not installed | The Azure CLI isn’t installed or couldn’t be found. |
|
Please run 'az login' to set up account | No account is currently logged into the Azure CLI, or the login has expired. |
You can manually verify that the Azure CLI is properly authenticated, and can obtain tokens. First use the account
command to verify the account which is currently logged in to the Azure CLI.
az account show
Once you've verified the Azure CLI is using correct account, you can validate that it’s able to obtain tokens for this account.
az account get-access-token --output json --resource https://management.core.windows.net
Note that output of this command will contain a valid access token, and SHOULD NOT BE SHARED to avoid compromising account security.
CredentialUnavailableException
Error Message | Description | Mitigation |
---|---|---|
PowerShell isn’t installed. | No local installation of PowerShell was found. | Ensure that PowerShell is properly installed on the machine. Instructions for installing PowerShell can be found here. |
Az.Account module >= 2.2.0 isn’t installed. | The Az.Account module needed for authentication in Azure PowerShell isn’t installed. | Install the latest Az.Account module. Installation instructions can be found here. |
Please run 'Connect-AzAccount' to set up account. | No account is currently logged into Azure PowerShell. |
You can manually verify that Azure PowerShell is properly authenticated, and can obtain tokens. First use the Get-AzContext
command to verify the account which is currently logged in to the Azure CLI.
PS C:\> Get-AzContext
Name Account SubscriptionName Environment TenantId
---- ------- ---------------- ----------- --------
Subscription1 (xxxxxxxx-xxxx-xxxx-xxx... test@outlook.com Subscription1 AzureCloud xxxxxxxx-x...
Once you've verified Azure PowerShell is using correct account, you can validate that it’s able to obtain tokens for this account.
Get-AzAccessToken -ResourceUrl "https://management.core.windows.net"
Note that output of this command will contain a valid access token, and SHOULD NOT BE SHARED to avoid compromising account security.
ClientAuthenticationException
Error Message | Description | Mitigation |
---|---|---|
The current credential is not configured to acquire tokens for tenant | The application must configure the credential to allow acquiring tokens from the requested tenant. | Add the requested tenant ID it to the additionallyAllowedTenants on the credential builder, or add "*" to additionallyAllowedTenants to allow acquiring tokens for any tenant.This exception was added as part of functional a breaking change to multi tenant authentication in version 1.6.0 . Users experiencing this error after upgrading can find details on the change and migration in BREAKING_CHANGES.md |
Additional information on ways to reach out for support can be found in the SUPPORT.md at the root of the repo.