Skip to content

Commit

Permalink
Improve error messages in Workload Identity Credential. (#41849)
Browse files Browse the repository at this point in the history
* update code

* update TSG + fix checkstyle
  • Loading branch information
g2vinay authored and billwert committed Sep 13, 2024
1 parent c12182e commit 97e1665
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 4 additions & 3 deletions sdk/identity/azure-identity/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ Get-AzAccessToken -ResourceUrl "https://management.core.windows.net"

## Troubleshoot `WorkloadIdentityCredential` authentication issues

| Error |Description| Mitigation |
|---|---|---|
|`CredentialUnavailableException` raised with message. "WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured."|The `WorkloadIdentityCredential` requires `clientId`, `tenantId` and `tokenFilePath` to authenticate with Microsoft Entra ID.| <ul><li>If using `DefaultAzureCredential` then:</li><ul><li>Ensure client ID is specified via `workloadIdentityClientId` setter or `AZURE_CLIENT_ID` env variable.</li><li>Ensure tenant ID is specified via `AZURE_TENANT_ID` env variable.</li><li>Ensure token file path is specified via `AZURE_FEDERATED_TOKEN_FILE` env variable.</li><li>Ensure authority host is specified via `AZURE_AUTHORITY_HOST` env variable.</ul><li>If using `WorkloadIdentityCredential` then:</li><ul><li>Ensure tenant ID is specified via `tenantId` setter on credential builder or `AZURE_TENANT_ID` env variable.</li><li>Ensure client ID is specified via `clientId` setter on the credential builder or `AZURE_CLIENT_ID` env variable.</li><li>Ensure token file path is specified via `tokenFilePath` setter on the credential builder or `AZURE_FEDERATED_TOKEN_FILE` environment variable. </li></ul></li><li>Consult the [product troubleshooting guide](https://azure.github.io/azure-workload-identity/docs/troubleshooting.html) for other issues.</li></ul>
| Error | Description | Mitigation |
|---|-------------------------------------------------------------------------------------------------------------------------------|---|
|`CredentialUnavailableException` raised with message. "WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured."| The `WorkloadIdentityCredential` requires `clientId`, `tenantId` and `tokenFilePath` to authenticate with Microsoft Entra ID. | <ul><li>If using `DefaultAzureCredential` then:</li><ul><li>Ensure client ID is specified via `workloadIdentityClientId` setter or `AZURE_CLIENT_ID` env variable.</li><li>Ensure tenant ID is specified via `AZURE_TENANT_ID` env variable.</li><li>Ensure token file path is specified via `AZURE_FEDERATED_TOKEN_FILE` env variable.</li><li>Ensure authority host is specified via `AZURE_AUTHORITY_HOST` env variable.</ul><li>If using `WorkloadIdentityCredential` then:</li><ul><li>Ensure tenant ID is specified via `tenantId` setter on credential builder or `AZURE_TENANT_ID` env variable.</li><li>Ensure client ID is specified via `clientId` setter on the credential builder or `AZURE_CLIENT_ID` env variable.</li><li>Ensure token file path is specified via `tokenFilePath` setter on the credential builder or `AZURE_FEDERATED_TOKEN_FILE` environment variable. </li></ul></li><li>Consult the [product troubleshooting guide](https://azure.github.io/azure-workload-identity/docs/troubleshooting.html) for other issues.</li></ul>
|`CredentialUnavailableException` raised with message. "WorkloadIdentityCredential authentication unavailable. The request to the authority host was invalid."| The configured properties for workload identity are invalid. | Ensure the properties for workload identity are correctly configured on the credential builder and right permissions are assigned to the workload identity.

## Troubleshoot `IntelliJCredential` authentication issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public Mono<AccessToken> authenticateWithWorkloadIdentityConfidentialClient(Toke
.resolveTenantId(tenantId, request, options));
return confidentialClient.acquireToken(builder.build());
}
)).onErrorMap(t -> new CredentialUnavailableException("Managed Identity authentication is not available.", t))
)).onErrorMap(t -> new CredentialUnavailableException("Workload Identity authentication is not available.", t))
.map(MsalToken::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,40 @@ AccessToken authenticateWithExchangeTokenHelper(TokenRequestContext request, Str

return SERIALIZER_ADAPTER.deserialize(connection.getInputStream(), MSIToken.class,
SerializerEncoding.JSON);
} catch (IOException exception) {
if (connection == null) {
throw LOGGER.logExceptionAsError(new RuntimeException(
"Could not connect to the authority host: " + url + ".", exception));
}
int responseCode;
try {
responseCode = connection.getResponseCode();
} catch (Exception e) {
throw LoggingUtil.logCredentialUnavailableException(LOGGER, options,
new CredentialUnavailableException(
"WorkloadIdentityCredential authentication unavailable. "
+ "Connection to the authority host cannot be established, "
+ e.getMessage() + ".", e));
}
if (responseCode == 400) {
throw LoggingUtil.logCredentialUnavailableException(LOGGER, options,
new CredentialUnavailableException(
"WorkloadIdentityCredential authentication unavailable. "
+ "The request to the authority host was invalid. "
+ "Additional details: " + exception.getMessage() + ".", exception));
}

throw LOGGER.logExceptionAsError(new RuntimeException(
"Couldn't acquire access token from Workload Identity.", exception));
} finally {
if (connection != null) {
connection.disconnect();
}
}
}



String getSafeWorkingDirectory() {
if (isWindowsPlatform()) {
String windowsSystemRoot = System.getenv("SystemRoot");
Expand Down

0 comments on commit 97e1665

Please sign in to comment.