Skip to content

Make labs 00-15 Entra-first with alias-scoped runtime roles - #77

Open
Paul Yuknewicz (paulyuk) wants to merge 6 commits into
paulyuk-disabled-built-in-key-docsfrom
paulyuk-lab-catalog-identity-migration
Open

Paul Yuknewicz (paulyuk) wants to merge 6 commits into
paulyuk-disabled-built-in-key-docsfrom
paulyuk-lab-catalog-identity-migration

Conversation

@paulyuk

@paulyuk Paul Yuknewicz (paulyuk) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 3c33b3536ab0144841b9a49c19dc4e1634b4a7a1

Dimension Assessment Rationale
Change confidence 8/10 ↑ Lab 06 deployed live with Bicep: Entra call 200, an unauthorized alias 403, no credential 401, token limit 429.
↑ Lab 06 Terraform passed apply, a no-change plan, an Entra call returning 200, and destroy.
↑ Bicep builds, Terraform fmt and validate, Bash and PowerShell parsing, notebook compile, plugin check and focused helper tests all pass locally.
↑ The delegated token helper was checked live and returned the gateway audience.
↑ Lab 28 troubleshooting now checks x-ms-model-router-mode for the objective, matching live labs 16-33 tests where every objective chose gpt-5-mini.
↓ No live auto-alias gateway was available here, so the header contract rests on those tests and the product docs.
↓ Labs other than 06 had static checks only, with no live deployment.
↓ The strict labs check shows 20 step-reference warnings until the labs 16-33 headings land.
↓ Portal steps were not checked in a browser.

Stacked on #75. Review and merge #75 first.

Problem

Labs 00-15 taught runtime API keys as the normal way to call AI Gateway, and several Bicep, Terraform and notebook paths created keys on their own. New gateways disable key-based access, so those paths stop working, and they teach the wrong default.

What changes

Labs 00-15 call the gateway with Microsoft Entra tokens and least-privilege runtime roles:

  • AI Gateway Models User (a6b68e3d-a1f0-4c60-8678-237c050cf4ea) on each alias the lab calls, never workspace-wide by default.
  • AI Gateway Tools User (dce03f8d-857f-4e40-a90d-67770fa6ecd2) on each MCP tool server the lab calls.
  • Portal, Azure CLI, REST, Bicep, Terraform, azd, SDK samples, notebooks, and the Bash and PowerShell helpers all follow the same flow. Every lab shows an allowed call and a denied call.
  • publish-model.bicep and the shared modules create no runtime key unless a dedicated key lab sets createApiKey. role-assignment.bicep now defaults to alias scope.
  • The key-based budget and telemetry comparisons from labs 07 and 14 move to lab 10, the dedicated key lab. A gateway Owner must enable key-based access before running it.
  • labs/shared/utils.py adds runtime_token() and runtime_token_provider(). They call az account get-access-token --scope https://ai.gateway.azure.com/Data.All directly and refresh the token before it expires. AzureCliCredential turns that scope into --resource, which requests the wrong token. Lab.runtime_token uses the helper.
  • TROUBLESHOOTING, AUTHORING, SETUP, RELEASE-NOTES and the labs skill now describe the Entra flow. Lab 28 names gpt-6-sol as the Model Router selector, because gpt-6.1-sol is rejected. Lab 28 troubleshooting checks the objective with x-ms-model-router-mode, because the served model doesn't show which objective applied.

Common case

Bash:

alias_id="$gateway_id/workspaces/default/aliases/gpt-5-mini"
az role assignment create --assignee "$(az ad signed-in-user show --query id -o tsv)" \
  --role a6b68e3d-a1f0-4c60-8678-237c050cf4ea --scope "$alias_id"
token=$(az account get-access-token --scope https://ai.gateway.azure.com/Data.All --query accessToken -o tsv)
curl -s "$gateway_url/default/models/openai/v1/chat/completions" \
  -H "Authorization: Bearer $token" -H "Content-Type: application/json" \
  -d '{"model":"gpt-5-mini","messages":[{"role":"user","content":"Hello"}]}'

PowerShell:

$aliasId = "$gatewayId/workspaces/default/aliases/gpt-5-mini"
az role assignment create --assignee (az ad signed-in-user show --query id -o tsv) `
  --role a6b68e3d-a1f0-4c60-8678-237c050cf4ea --scope $aliasId
$token = az account get-access-token --scope https://ai.gateway.azure.com/Data.All --query accessToken -o tsv
Invoke-RestMethod "$gatewayUrl/default/models/openai/v1/chat/completions" -Method Post `
  -Headers @{ Authorization = "Bearer $token" } -ContentType application/json `
  -Body '{"model":"gpt-5-mini","messages":[{"role":"user","content":"Hello"}]}'

SDKs and managed identities use DefaultAzureCredential with https://ai.gateway.azure.com/.default.

Verification

  • Lab 06 Bicep deployed into a temporary resource group. Results: Entra call 200, an alias without a grant 403, no credential 401, and a burst hit 429 Token limit is exceeded.
  • Lab 06 Terraform: apply, a no-change plan, an Entra call returning 200, then destroy.
  • Bicep builds, Terraform fmt and validate, Bash and PowerShell parsing, notebook JSON and code compile, the plugin check, and the helper tests for labs 02, 04, 10, 11, 14, 15, 20 and shared all pass.
  • All verification resources, role assignments and soft-deleted Foundry accounts were deleted.

Not converted

  • Labs 16-33 are converted in a separate PR. Until those headings land, npm run check reports 20 troubleshooting step-reference warnings for labs 18, 22, 26, 27 and 28. They come from lab steps that PR renames.
  • The lab 00 and 01 video narration predates the Entra flow and needs to be re-recorded.
  • The lab 04 notebook's 403 check needs a second identity, passed in AI_GATEWAY_UNAUTHORIZED_TOKEN.
  • disableLocalAuth isn't in the AI Gateway API or the az aigateway CLI yet. The templates don't set it, and key enablement is written as a gateway Owner prerequisite.

Notebooks call AI Gateway with the signed-in identity instead of a runtime key.
Lab.runtime_token() returns a cached, refreshed delegated token for
https://ai.gateway.azure.com/Data.All. Lab.authorize(alias=...) or
Lab.authorize(server=...) grants AI Gateway Models User on one alias or
AI Gateway Tools User on one MCP server when the assignment is missing.
mcp_session and mcp_request accept a token provider so long sessions refresh.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Lab 02 publishes a Foundry model and calls it with Microsoft Entra ID and an
alias-scoped AI Gateway Models User grant in every track: portal, CLI, curl
scripts, Python, TypeScript, .NET, Bicep, Terraform, and the notebook.

publish-model.bicep takes createApiKey, default false, and returns an empty
apiKeyName unless a dedicated key exercise passes true. The Terraform track
has the matching create_api_key variable with a moved block for existing
state. Lab 18 imports this module and no longer gets a runtime key.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Labs 18-31 now acquire a runtime token instead of creating a key, read their
outputs without a key, and drop the API-key client qualifiers from lab 26 and
lab 31 steps. Update the shared troubleshooting step references to match.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Labs 00-15 now call AI Gateway with Microsoft Entra tokens and AI Gateway
Models User on each called alias (Tools User on each MCP server). Bicep,
Terraform, azd, CLI and REST tracks, SDK samples, notebooks and Bash and
PowerShell helpers create no runtime keys. Key and per-key budget and
telemetry comparisons move to lab 10, the dedicated key lab.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
AzureCliCredential turns the Data.All scope into
`az account get-access-token --resource`, which returns the wrong token.
runtime_token() and runtime_token_provider() in labs/shared/utils.py call
`az account get-access-token --scope` directly, cache the token and refresh
it 5 minutes before expiry, with no Lab, gateway discovery or ARM access.
Lab.runtime_token delegates to them.

TROUBLESHOOTING gets the labs 03-15 Entra rows, a note on the --resource
behavior, and lab 28's move from GPT-5.5 to gpt-6-sol, including the
Model Router selector error for gpt-6.1-sol.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Live tests chose gpt-5-mini for every prompt under Balanced, Cost and
Quality, so the served model doesn't show which objective applied. The
lab 28 rows and the labs skill now point to x-ms-model-router-mode for
the objective, and to auto_model_selection.models to reach gpt-6-sol.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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