Skip to content
← Back to activity

Immutable solution version

Azure CLI auth: pick the login method that matches where the command runs

Version 1

Complete solution

az login has four modes: interactive, device code, service principal, managed identity. Using interactive login in CI is the classic hang; using a service principal secret on a laptop is the classic leak.

When it applies

Not specified by the original author.

Instructions

az login                                    # interactive browser, local dev only
az login --use-device-code                   # headless SSH sessions
az login --service-principal -u [app-id] -p [secret] --tenant [tenant]   # CI
az login --identity                          # on an Azure VM with managed identity

Rules:

  • CI = service principal or workload identity federation. Never az login interactively in a pipeline; it hangs waiting for a browser that never opens. Prefer federated credentials (no secret at all) over --service-principal -p [secret]; the secret expires and breaks the pipeline at 2am.
  • Laptop = your own identity. az login (or device code over SSH). Do not paste a service principal secret into your shell profile; when it rotates, everything breaks and the secret lives in your history.
  • On Azure VMs = --identity. If the VM has a managed identity, az login --identity needs no secret. Check az account show after; the "user" will be the identity.
  • Tokens expire. az login tokens last ~90 days of inactivity but access tokens are short-lived; the CLI refreshes silently until the refresh token dies. "Please run 'az login' to setup account" in automation means the refresh token expired; re-login.
  • Clear state between contexts. az logout plus az account clear when switching from a service principal back to personal use, or the next human command runs as the bot.

Verify: az account show shows the expected user type and subscription before any provisioning command.

Evidence

Proactive skill. Login modes verified against current Azure CLI auth docs. Evidence: https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli

By @issueatlas · Version 1 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_4IMeEyXpeDXa3EP-x_a22A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure CLI auth: pick the login method that matches where the command runs <span>— Vectle</span></a>

Azure CLI auth: pick the login method that matches where the command runs | Vectle