Keyless Azure-to-Kong Auth via Google WIF: Token Flow, Pitfalls & When to Use It
This article details a keyless authentication flow from Azure services to Kong using Google Workload Identity Federation, explaining the three-token exchange, audience configuration, identity mapping differences across Azure VM, App Service, and AKS, explicit Python token exchange steps, Kong verification requirements, and when direct Entra trust is preferable.
Reading font

Three Distinct Tokens in the Exchange Chain
The flow moves along three tokens, each with a different audience and purpose:
Entra access token – obtained via Azure Managed Identity; its aud points to the Entra resource application you registered (e.g., api://<RESOURCE_APP_CLIENT_ID>). It is not a generic Kong URL.
Google STS federated access token – the Entra token is exchanged at Google STS; the request’s audience is the full WIF provider resource name (e.g., //iam.googleapis.com/projects/.../providers/azure-provider). This tells STS which trust configuration to use.
Google OIDC ID Token – the STS token calls generateIdToken with audience set to Kong’s expected identifier (e.g., https://kong.example.com). This final token is what Kong validates.
Google manages the signing private key; the workload only handles short-lived bearer tokens. Keyless eliminates long-lived private keys in the application, but leaked short-lived tokens remain usable until expiry.
Azure Side: Separate Two Application Identities
Distinguish the caller’s managed identity from the Entra resource application that receives the token. The resource app must be registered, have a service principal, and an Application ID URI (e.g., api://<RESOURCE_APP_CLIENT_ID>). If the resource app requires assigned permissions, grant them to the caller. api://AzureADTokenExchange appears in AKS Workload Identity federated credential configuration as the audience for Kubernetes Service Account token exchange. It is not the default audience for all managed identities and must not be copied into the Google provider configuration.
Three identity fields are easily confused:
Object ID / Principal ID – the managed identity’s service principal object identifier in the tenant.
Client ID – the application identifier; used to select a specific user-assigned managed identity.
sub – the subject claim in the current token. Google’s Azure VM documentation states the managed identity access token’s sub contains the Object ID, so google.subject=assertion.sub is not inherently wrong; the error is assuming Object ID and Client ID are interchangeable.
Before configuring, decode a real token locally and inspect iss, aud, sub, oid, ver. Decoding is for field inspection only—not signature verification—and never paste full tokens into public debuggers.
The example uses google.subject=assertion.oid to bind explicitly by Object ID, provided the token contains the expected oid. If retaining assertion.sub, the IAM principal’s last segment must match the actual sub value.
Concrete Configuration Example: Azure VM + Single Managed Identity + Entra v1 Token
Variables (replace placeholders):
PROJECT_ID="your-gcp-project"
PROJECT_NUMBER="123456789012"
TENANT_ID="your-entra-tenant-id"
MI_OBJECT_ID="your-managed-identity-object-id"
APP_ID_URI="api://your-resource-app-client-id"
AZURE_TOKEN_AUD="$APP_ID_URI"
SA_EMAIL="kong-client-sa@${PROJECT_ID}.iam.gserviceaccount.com"
PROVIDER="projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/azure-pool/providers/azure-provider"
KONG_AUDIENCE="https://kong.example.com"AZURE_TOKEN_AUDmust match the actual token’s aud. v1 tokens may use the resource URI or client ID; v2 tokens typically use the resource API’s client ID. Upgrading token versions requires re-checking audience, not just issuer.
Enable APIs, create workload identity pool and provider:
gcloud services enable iam.googleapis.com sts.googleapis.com iamcredentials.googleapis.com --project="$PROJECT_ID"
gcloud iam workload-identity-pools create azure-pool \
--project="$PROJECT_ID" --location=global \
--display-name="Azure Kong clients"
gcloud iam workload-identity-pools providers create-oidc azure-provider \
--project="$PROJECT_ID" --location=global \
--workload-identity-pool=azure-pool \
--issuer-uri="https://sts.windows.net/${TENANT_ID}/" \
--allowed-audiences="$AZURE_TOKEN_AUD" \
--attribute-mapping="google.subject=assertion.oid" \
--attribute-condition="assertion.tid == 'TENANT_ID' && assertion.oid == '{MI_OBJECT_ID}'"The issuer must match the token’s iss exactly, including trailing slash. v2 issuer is usually https://login.microsoftonline.com/<TENANT_ID>/v2.0. Do not use a tenant-agnostic issuer to widen trust.
Create dedicated service account and bind roles/iam.workloadIdentityUser (which includes iam.serviceAccounts.getOpenIdToken):
gcloud iam service-accounts create kong-client-sa --project="$PROJECT_ID"
gcloud iam service-accounts add-iam-policy-binding "$SA_EMAIL" \
--project="$PROJECT_ID" \
--role="roles/iam.workloadIdentityUser" \
--member="principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/azure-pool/subject/{MI_OBJECT_ID}"Do not grant project-level Owner or broad Token Creator roles to fix 403 errors. Verify which principal calls which API and that the binding targets the correct service account. Within the same pool, avoid mapping different providers to the same google.subject, which would cause them to share an IAM principal.
Explicit Token Exchange Walk-through (Python)
The following script runs on an Azure VM using IMDS. It performs the three exchanges step by step for clarity and debugging. Requires requests; variables sourced from environment.
import os
import requests
provider = os.environ["PROVIDER"]
sa_email = os.environ["SA_EMAIL"]
audience = os.environ["KONG_AUDIENCE"]
# Azure VM IMDS: select intended user-assigned identity if needed.
params = {
"api-version": "2018-02-01",
"resource": os.environ["APP_ID_URI"],
}
if os.environ.get("MI_CLIENT_ID"):
params["client_id"] = os.environ["MI_CLIENT_ID"]
metadata = requests.Session()
metadata.trust_env = False
response = metadata.get(
"http://169.254.169.254/metadata/identity/oauth2/token",
headers={"Metadata": "true"}, params=params, timeout=10,
)
response.raise_for_status()
azure_token = response.json()["access_token"]
response = requests.post(
"https://sts.googleapis.com/v1/token",
data={
"audience": f"//iam.googleapis.com/{provider}",
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
"scope": "https://www.googleapis.com/auth/cloud-platform",
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
"subject_token": azure_token,
}, timeout=20,
)
response.raise_for_status()
sts_token = response.json()["access_token"]
response = requests.post(
"https://iamcredentials.googleapis.com/v1/projects/-/"
f"serviceAccounts/{sa_email}:generateIdToken",
headers={"Authorization": f"Bearer {sts_token}"},
json={"audience": audience, "includeEmail": True},
timeout=20,
)
response.raise_for_status()
id_token = response.json()["token"]
response = requests.get(
os.environ["KONG_REQUEST_URL"],
headers={"Authorization": f"Bearer {id_token}"},
timeout=20,
)
response.raise_for_status()KONG_REQUEST_URLis the actual business endpoint (may include path); it need not equal KONG_AUDIENCE. Production code must cache tokens by expiry, refresh early with jitter, coalesce concurrent refreshes, handle timeouts/rate limits/retries per hop, and never log Authorization headers or token responses.
Credential Config File ≠ Fully Automatic SDK Behavior
On Azure VM, generate an external account config:
gcloud iam workload-identity-pools create-cred-config "$PROVIDER" \
--service-account="$SA_EMAIL" \
--azure --app-id-uri="$APP_ID_URI" \
--output-file=gcp-wif-config.jsonThe file describes credential source and exchange endpoints; it contains no private key. It can be managed as regular deployment config but must be protected from tampering because clients fetch credentials based on its URLs.
Setting GOOGLE_APPLICATION_CREDENTIALS lets supported clients load the config. However, “can obtain a Google access token” ≠ “every language’s ID Token helper automatically generates the target audience ID Token.” The latter depends on library, version, and call pattern—verify explicitly after the manual flow works.
The --azure flag produces IMDS-targeted config; it does not generalize to all Azure services:
Azure VM – uses IMDS; with multiple user-assigned identities, explicitly select one.
App Service – uses the service’s identity endpoint and headers ( IDENTITY_ENDPOINT, IDENTITY_HEADER) or Azure Identity SDK.
AKS – two paths: (a) projected Kubernetes Service Account token → Entra Workload Identity → Entra access token → Google WIF; (b) Google WIF directly trusts AKS OIDC issuer, skipping Entra. Option (b) requires new issuer, subject, audience config—cannot reuse VM config.
Kong’s Job: Verify Signature, Then Authorize
Google issues RS256-signed ID Tokens; Kong must fetch public keys from Google’s OIDC discovery/JWKS, select by kid, and handle caching/rotation.
Three mandatory checks (all must pass):
Allowed signing algorithm and valid signature (no algorithm confusion).
Exact iss, agreed aud, and time constraints ( exp, nbf).
Allowed service account sub and its permitted routes. generateIdToken produces a sub that is the service account’s unique numeric ID, not the Azure Object ID. Multiple Azure workloads sharing one Google service account appear as the same principal to Kong. Workloads needing distinct permissions or audit boundaries should use separate service accounts or maintain trusted identity linkage records.
Checking only iss=https://accounts.google.com and correct aud is insufficient—other Google principals can obtain tokens for the same audience. Authorization must narrow further.
Plugin choice matters: Kong’s OpenID Connect plugin (Enterprise only) supports discovery/JWKS; the standard JWT plugin validates against configured public keys and claims_to_verify only covers exp / nbf, not audience. Custom claim verification and principal allow-lists must be implemented in the chosen plugin or a trusted authorization layer.
Pre-production tests: valid identity succeeds; wrong audience fails; unauthorized service account fails; expired token fails; key rotation triggers re-fetch; request headers cannot forge upstream trusted identity.
When Is the Google Hop Worth It?
If Kong already uses Google service accounts as the unified machine identity, this bridge preserves the authorization model while keeping long-lived secrets out of Azure workloads. Cost: dependency on Azure, Google STS, and IAM Credentials availability during refresh, plus added configuration and troubleshooting complexity.
If callers are primarily on Azure and the gateway can validate Entra access tokens directly, register a resource application for the business API, have Kong validate tokens issued for that API, and authorize based on caller identity, app roles, or explicit rules. Do not reuse a Microsoft Graph token for a custom API.
Decision question: does the gateway need a unified Google service account identity, or just a trusted machine caller? The former fits WIF bridging; the latter often starts with direct Entra trust. Either way, remove long-lived private keys from applications, and configure identity mapping, audience validation, and route authorization precisely.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.