For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Azure
Authenticate to an Azure service from the gateway with a Microsoft Entra ID token.
Verified Code examples on this page have been automatically tested and verified.Attaches to:
About
The azure backend authentication method gets a Microsoft Entra ID token and writes it to the Authorization header of every request that agentgateway forwards to the backend. Agentgateway requests the token for the Azure Cognitive Services scope, or for the Azure AI scope when the backend is an Azure AI Foundry endpoint, and it caches the credential after the first successful use.
The method has three forms.
implicitdetects the credential from the environment, through the fullDefaultAzureCredentialchain. Use this form in production when the host supplies the identity, such as a virtual machine with a managed identity.developerImplicituses the Azure CLI login only. Use this form on a workstation, where it fails fast instead of trying the production sources first.explicitConfignames one credential source: a service principal, a managed identity, or a workload identity.
Note
This page covers azure as a general backend authentication method, which works for any Azure service. To route requests to Azure OpenAI or Azure AI Foundry as an LLM provider, see Azure, which covers the same authentication methods alongside the provider settings.
Configuration examples
Each example shows the backendAuth policy only. Attach it to a backend under backends[].policies, or to a route under routes[].policies.
Detect the credential from the environment. Agentgateway tries each source of the DefaultAzureCredential chain in order.
backendAuth:
azure:
implicit: {}| Field | Description |
|---|---|
azure.implicit | Set to {} to detect the credential from the environment with the full chain. |
azure.developerImplicit | Set to {} to use the Azure CLI login only. |
azure.explicitConfig.clientSecret | Service principal credentials. Requires tenant_id, client_id, and client_secret, all in snake_case. |
azure.explicitConfig.managedIdentity | Managed identity of the Azure host. Set to {} for the system-assigned identity, or set userAssignedIdentity to select a user-assigned one. |
azure.explicitConfig.managedIdentity.userAssignedIdentity | Identifier of a user-assigned managed identity. Set exactly one of clientId, objectId, or resourceId. |
azure.explicitConfig.workloadIdentity | Set to {} to use the projected federated token. |
Warning
The three fields under clientSecret are tenant_id, client_id, and client_secret, in snake_case. Every field around them is camelCase, so this is easy to get wrong. The camelCase spelling is not accepted, and agentgateway rejects the configuration when it loads rather than falling back to another credential source.
Error: routes[0]: data did not match any variant of untagged enum BackendAuthCompatHow agentgateway resolves an implicit credential
With implicit, agentgateway tries the following credential sources in order and stops at the first one that returns a token. The chain matches the DefaultAzureCredential chain of the Azure SDK.
- Environment credential. A service principal, used when
AZURE_TENANT_ID,AZURE_CLIENT_ID, andAZURE_CLIENT_SECRETare all set. - Workload identity credential. A federated token, used when
AZURE_FEDERATED_TOKEN_FILE,AZURE_TENANT_ID, andAZURE_CLIENT_IDare set. - Managed identity credential. The identity of the Azure host, read from the instance metadata service. A user-assigned identity is selected with
AZURE_CLIENT_ID. - Developer tools credential. The cached login of the Azure CLI (
az login) or the Azure Developer CLI (azd auth login).
Agentgateway caches the source that first returns a token and uses it for every later request. Each azure policy keeps its own cache, so two backends that name different service principals do not share a credential.
Two behaviors of this chain are worth knowing.
- The managed identity step is guarded by a probe. Before it tries the instance metadata service, agentgateway opens a TCP connection to
169.254.169.254:80and waits one second. If the connection does not succeed, agentgateway skips the step. Without the probe, the Azure SDK retries for about 99 seconds on a host that is not an Azure virtual machine, which would stall every request on the route. Agentgateway skips the probe whenIDENTITY_ENDPOINTorMSI_ENDPOINTis set, because the SDK then uses that endpoint instead of the metadata service. - The developer tools step needs a command that agentgateway does not bundle. Agentgateway calls
azorazdwhen it needs a token. It does not open an interactive flow, and it does not runaz loginorazd auth loginfor you. Mounting a credential directory such as~/.azureinto a container makes a cached login available, but it does not install the command. In a container, use a service principal, a managed identity, or a workload identity instead.
Tip
To find out which source agentgateway used, run the binary with RUST_LOG=trace and look for DefaultAzureCredential in the output. Agentgateway records the name of the source that provided the token, and the construction error of every source that failed.
Troubleshoot
A request that agentgateway cannot authenticate returns a 500.
backend authentication failed: the credential provider was not enabled| Symptom | Cause |
|---|---|
data did not match any variant of untagged enum BackendAuthCompat | A field name is wrong. Check the clientSecret fields for camelCase, and check that userAssignedIdentity sets exactly one identifier. |
Every request returns a 500, and the log shows that each credential source failed to construct. | Agentgateway has no identity. Set an explicit credential source, or supply the environment variables that one of the implicit sources needs. |
| Requests hang for roughly a second before they fail. | The managed identity probe is timing out. Agentgateway is not on an Azure host, so the step is skipped after the one-second probe. Use an explicit credential source to skip it. |
| The Azure CLI source never runs in a container. | The image does not contain az or azd. Use a service principal, a managed identity, or a workload identity. |
| The first request on a route takes several seconds. | Agentgateway is resolving the credential for the first time. The result is cached, so later requests do not pay this cost. |