Call an Azure Functions API from a Pod
Authenticate an AKS workload to an HTTP-triggered Function with Microsoft Entra ID and authorize the caller as an API client.
Learning status: Not practiced
The moving parts
An AKS pod can call an HTTP-triggered Azure Function as an application client. Use Workload ID to obtain an Entra token, then configure the Function API to authenticate that token and authorize the caller. A function key and a Kubernetes RoleBinding are not substitutes for this API identity flow.
Configure the API and caller
- Configure an Entra application to represent the Function API. Expose an application permission or app role for the operation the workload needs.
- Configure Microsoft Entra authentication for the Function App and require authentication. Ensure the API accepts the configured token audience.
- Assign the API permission or app role to the workload's managed identity or service principal, and grant tenant consent where required.
- In the Function code, enforce the app role or other authorization rule for protected operations. Authentication proves who called; the API still decides what the caller may do.
The Function's trigger authorization level is distinct from Entra authentication. Avoid adding a function key as an unnecessary second credential when the API is protected by Entra; configure the trigger and platform authentication consistently.
Request an API token
With a supported Azure Identity SDK, request a token for the API's application ID URI and call the endpoint with a bearer token. For example:
import { DefaultAzureCredential } from "@azure/identity";
const credential = new DefaultAzureCredential();
const token = await credential.getToken(
"api://<function-api-client-id>/.default",
);
if (!token) {
throw new Error("Could not obtain an access token for the Function API");
}
const response = await fetch(functionUrl, {
headers: { Authorization: `Bearer ${token.token}` },
});
if (!response.ok) {
throw new Error(`Function request failed: ${response.status}`);
}
The /.default scope requests the API permissions already assigned to the calling identity. Use the exact API identifier and permission design configured for your application; a token for Storage or another service cannot be reused for this API.
If the Function uses a private endpoint or restricted access, separately configure routing, name resolution, and network rules so the pod can reach it.
Sources: Configure Microsoft Entra authentication for App Service, App Service authentication and authorization, AKS Workload ID overview.
Connects to