Skip to content
agentgateway has joined the Agentic AI FoundationLearn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Azure

Page as Markdown

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.

  • implicit detects the credential from the environment, through the full DefaultAzureCredential chain. Use this form in production when the host supplies the identity, such as a virtual machine with a managed identity.
  • developerImplicit uses the Azure CLI login only. Use this form on a workstation, where it fails fast instead of trying the production sources first.
  • explicitConfig names 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: {}
Review the following table to understand this configuration.
FieldDescription
azure.implicitSet to {} to detect the credential from the environment with the full chain.
azure.developerImplicitSet to {} to use the Azure CLI login only.
azure.explicitConfig.clientSecretService principal credentials. Requires tenant_id, client_id, and client_secret, all in snake_case.
azure.explicitConfig.managedIdentityManaged identity of the Azure host. Set to {} for the system-assigned identity, or set userAssignedIdentity to select a user-assigned one.
azure.explicitConfig.managedIdentity.userAssignedIdentityIdentifier of a user-assigned managed identity. Set exactly one of clientId, objectId, or resourceId.
azure.explicitConfig.workloadIdentitySet 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 BackendAuthCompat

How 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.

  1. Environment credential. A service principal, used when AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET are all set.
  2. Workload identity credential. A federated token, used when AZURE_FEDERATED_TOKEN_FILE, AZURE_TENANT_ID, and AZURE_CLIENT_ID are set.
  3. 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.
  4. 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:80 and 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 when IDENTITY_ENDPOINT or MSI_ENDPOINT is 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 az or azd when it needs a token. It does not open an interactive flow, and it does not run az login or azd auth login for you. Mounting a credential directory such as ~/.azure into 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
SymptomCause
data did not match any variant of untagged enum BackendAuthCompatA 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.
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.