output "client_id" { description = "Give this to azure/login as client-id. A public identifier." value = azurerm_user_assigned_identity.deploy.client_id } output "principal_id" { description = "The identity's object ID, for role assignments made elsewhere." value = azurerm_user_assigned_identity.deploy.principal_id } output "verify" { description = "How to prove only the named subjects can sign in, and that it is recorded." value = <<-EOT Print the subject a real token carries, in a workflow step with id-token: write: curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | jq -r .value | python3 -c 'import base64,json,sys; p=sys.stdin.read().split(".")[1]; print(json.loads(base64.urlsafe_b64decode(p + "=" * (-len(p) % 4)))["sub"])' It must equal one of allowed_subjects, character for character. Run azure/login@v2 with client-id ${azurerm_user_assigned_identity.deploy.client_id} from an allowed branch or environment: az commands succeed. Run it from any other branch or environment: AADSTS70021, no matching federated identity record. ${var.sign_in_log_workspace_id != "" ? "In the workspace: AADManagedIdentitySignInLogs | union AADServicePrincipalSignInLogs | where ServicePrincipalId == \"${azurerm_user_assigned_identity.deploy.principal_id}\" | project TimeGenerated, FederatedCredentialId, ResultType, IPAddress" : "Set sign_in_log_workspace_id to keep the exchanges beyond the tenant's 7 or 30 days."} EOT }