#!/usr/bin/env bash # NOT RUN against a real subscription. Names are examples. Gives an App Service app a system-assigned managed # identity, lets it call one Azure OpenAI resource with Entra ID, then turns key authentication off. set -euo pipefail RG=my-rg; APP=my-spring-ai-app; AOAI=my-openai-resource az webapp identity assign --resource-group "$RG" --name "$APP" PRINCIPAL_ID=$(az webapp identity show --resource-group "$RG" --name "$APP" --query principalId -o tsv) SCOPE=$(az cognitiveservices account show --resource-group "$RG" --name "$AOAI" --query id -o tsv) # The data-plane role. Owner and Contributor on the resource do not let a caller run inference with Entra ID. az role assignment create --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal \ --role "Cognitive Services OpenAI User" --scope "$SCOPE" # Entra ID authentication needs a custom subdomain on the resource (https://.openai.azure.com). # Then switch API keys off, so a leaked key stops being a way in: az resource update --ids "$SCOPE" --set properties.disableLocalAuth=true