Skip to content

Use Entra ID and asset-scoped runtime roles - #41

Open
Paul Yuknewicz (paulyuk) wants to merge 1 commit into
mainfrom
paulyuk-python-entra-authentication
Open

Paul Yuknewicz (paulyuk) wants to merge 1 commit into
mainfrom
paulyuk-python-entra-authentication

Conversation

@paulyuk

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: af5c1cfc41f90840f8e315d60fdd23c88ca16840

Dimension Assessment Rationale
Change confidence 9/10 ↑ Local workflow checks, container smoke, and authentication regressions passed.
↑ Fresh azd deployment completed; hosted model and GitHub tools succeeded; delegated calls returned 200 on the granted alias and 403 on an ungranted alias.
↓ PowerShell hooks were exercised locally, but a full Windows deployment was not run.

Problem

The sample creates an AI Gateway runtime key, retrieves it during provisioning, and documents key-based access. That bypasses the intended Entra runtime authorization boundary and leaves users managing an unnecessary credential.

Solution

Use Microsoft Entra ID throughout, with no gateway runtime key resource, secret retrieval, API-key headers, or key fallback.

  • Grant AI Gateway Models User to the local developer and the deployed agent's actual instance identity, only on the primary model alias. Resolve the hosted instance identity in matching Bash and PowerShell postdeploy hooks.
  • Grant AI Gateway Tools User to the Foundry project identity only on the GitHub tool server. Keep the separate upstream GitHub credential and managed-identity Foundry connection.
  • Request https://ai.gateway.azure.com/.default for hosted calls. Local Python calls explicitly request the delegated https://ai.gateway.azure.com/Data.All scope through Azure CLI, with bounded execution and in-memory token caching and refresh.
  • Use the Standard gateway SKU accepted by the resource provider. Keep lifecycle cleanup guards consistent and use supported gpt-5-mini deployment defaults.
  • Update setup, deployment, authorization, troubleshooting, and cleanup documentation. Show uv first and pip as the alternative.
  • Resolve dependencies through the Microsoft package mirror, including container builds. Lockfile package versions and artifact hashes are unchanged.

No disableLocalAuth template property is added because the current resource API does not expose it. The sample creates no runtime keys and supplies no key authentication path.

Deploy and call

gh auth status --hostname github.com
az login
azd auth login
azd up
uv sync
azd ai agent invoke "Create a concise daily repo digest for microsoft/agent-framework."

Call the granted gateway alias directly:

GATEWAY_ENDPOINT="$(azd env get-value AZURE_AI_GATEWAY_ENDPOINT)"
TOKEN="$(az account get-access-token \
  --scope https://ai.gateway.azure.com/Data.All --query accessToken -o tsv)"
curl --fail-with-body --silent --show-error \
  "${GATEWAY_ENDPOINT%/}/default/models/openai/v1/chat/completions" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"model":"gpt-latest","messages":[{"role":"user","content":"Reply with ok."}],"max_completion_tokens":128}'
unset TOKEN

Do not print or persist tokens or enable shell tracing. The README includes equivalent PowerShell commands and local agent instructions.

Validation

Ran the applicable repository workflow steps locally: Bicep builds, lifecycle and model-registration tests, Python unit tests, Docker build, and container smoke. Also ran Bicep lint, Bash syntax checks, PowerShell parsing, and execution tests for both script implementations.

A fresh azd up --no-prompt completed in temporary resource groups. The final hosted invocation returned HTTP 200 with a completed response, no failed response, and all three expected GitHub function calls. A delegated local call returned 200 on gpt-latest; the same caller received 403 on the ungranted gpt-mini-latest.

Deleted the temporary resource groups, scoped role assignments, generated Entra identities and blueprint, and deployment records. Purged the temporary Foundry accounts and verified absence. No existing gateway was modified.

Full end-to-end Windows deployment remains untested.

Remove gateway runtime keys and use refreshed Entra tokens. Scope model access to the developer and actual hosted instance identity, and tool access to the project connection. Preserve Bash and PowerShell parity and validate the supported gateway SKU and model defaults.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant