Skip to content

docs(step-02): make Application Insights tracing keyless - #25

Merged
Pierre Malarme (pmalarme) merged 1 commit into
mainfrom
pmalarme-reimagined-lamp
Aug 13, 2026
Merged

docs(step-02): make Application Insights tracing keyless#25
Pierre Malarme (pmalarme) merged 1 commit into
mainfrom
pmalarme-reimagined-lamp

Conversation

@pmalarme

Copy link
Copy Markdown
Collaborator

Why

Step 2's optional tracing section told participants that connecting Application Insights means the project emits telemetry "using a connection string — not an identity — so emitting traces needs no role assignment."

That contradicts this repo's Zero Trust rule ("No passwords, no keys, no secrets"). Foundry does support Entra-authenticated trace ingestion, so the workshop should teach the keyless path like every other resource.

This also fixes a real failure Pierre Malarme (@pmalarme) hit on a deployed agent:

Forbidden ... Please make sure your Application Insights resource has enabled
entra Id authentication and has the correct `Monitoring Metrics Publisher` role assigned.
{"Code":"InvalidOperation","Message":"The Agent/SDK does not have permissions to send telemetry to this resource."}

What changed

Docs only — one file, .workshop/docs/steps/02-tools.md. No code, no manifest, resources: [] is untouched.

The section is renumbered 1–4 → 1–5:

  1. Connect Application Insights (keyless) — set Auth type = Project Managed Identity before finishing the wizard (it defaults to connection-string auth), plus the Edit authentication path to convert an existing key-based connection.
  2. Let both writing identities emit traces — hosted agents emit from two identities. The portal grants Monitoring Metrics Publisher to the project MI on create, but the agent's instance identity never gets it automatically — that's the The Agent/SDK does not have permissions error above. Local auth is disabled only after both grants land.
  3. Grant yourself Monitoring Reader (unchanged).
  4. Log Analytics Reader at both scopes for evaluations (unchanged).
  5. Generate traffic + a troubleshooting entry for the Forbidden case.

Security fix found in review

az role assignment create --scope "" does not fail — it silently falls back to subscription scope (_build_role_scope: falsy scope → scope = subscription_scope).

The first draft declared $APP_INSIGHTS in one fenced block and reused it in four others. A participant running any later block in a fresh shell would have granted Monitoring Metrics Publisher and Monitoring Reader subscription-wide — the opposite of least privilege. Every scope-taking block now fail-fast guards (${VAR:?...} / if (-not $env:VAR) { throw }), verified in real bash and PowerShell.

Also from review: portal step ordering, a resource-wide blast-radius warning + rollback for DisableLocalAuth, expanded required-permissions (connections/write — Foundry User alone can't create the connection), and a corrected reference description (the hosted-agent-permissions doc's observability section is about human viewing; it does not list "Log Analytics Data Reader for the project identity").

Validation

  • python .workshop/scripts/lint_steps.py0 failures (2 pre-existing unrelated warnings)
  • python -m pytest .workshop/scripts/tests154 passed
  • render_readme.py --step 2 inspected; guards and the #run-and-deploy-travelbuddy anchor render correctly
  • Guard syntax executed in real bash and PowerShell (unset → fails, set → passes through)
  • Verified against Microsoft Learn: trace-ingestion-entra-authentication, observability troubleshooting, hosted-agent-permissions
  • No .workshop/solutions/02-tools/ or .workshop/step_files/02/ update needed (portal/CLI setup only, no code)

Confirmed working end-to-end by Pierre Malarme (@pmalarme) on a live deployment.

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

The tracing section told participants that connecting Application Insights
means the project emits telemetry "using a connection string — not an
identity", contradicting the repo's keyless-auth-only rule. Foundry does
support Entra-authenticated ingestion, so use it.

- Connect with Auth type = Project Managed Identity (set before finishing
  the wizard, since it defaults to connection-string auth), plus the
  Edit authentication path for an existing key-based connection.
- Grant Monitoring Metrics Publisher to BOTH writing identities: the
  project MI and the agent's instance identity. The agent identity is
  never granted automatically and is what fails after azd deploy with
  "The Agent/SDK does not have permissions to send telemetry".
- Disable local auth only after both grants have landed, with a
  dedicated-resource warning (it is resource-wide) and a rollback.
- Guard every scope-taking command. `az role assignment create --scope ""`
  does not fail, it silently falls back to subscription scope, so a
  participant running a later block in a fresh shell would have granted
  these roles subscription-wide.
- Expand the required-permissions note, fix the renumbered cross-refs,
  and correct the hosted-agent-permissions reference description.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 754171bf-7b59-4870-b062-884cb7f4fd4b
@pmalarme
Pierre Malarme (pmalarme) merged commit 7279f65 into main Aug 13, 2026
9 checks passed
@pmalarme
Pierre Malarme (pmalarme) deleted the pmalarme-reimagined-lamp branch August 13, 2026 11:13
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