Skip to content

Azure: a refused select leaves az's default where it was - #110

Open
odgrim wants to merge 1 commit into
mainfrom
track-a/azure-select-rollback
Open

odgrim wants to merge 1 commit into
mainfrom
track-a/azure-select-rollback

Conversation

@odgrim

@odgrim odgrim commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Change

A select refused by a missing role leaves az's default where it was. Before this, the session kept its old choice and env gave the old subscription's IDs, but a bare az in AZURE_CONFIG_DIR used the refused account.

commit now checks the required roles first, with the role query naming its account (az role assignment list ... --subscription <account>). Only once the roles hold does it make that account the default.

Decisions

  • --subscription on the role query, not a rollback of the default. The bad state never arises, so no second az account set can fail and leave it behind. Az::role_names takes the account as Option<&SubscriptionId>. With none (the signed-in tenant with no account), az asks through its default, as before.
  • The fake now refuses a role query whose account is in another tenant than the scope's subscription, as Azure refuses a token from the wrong issuer. Without that, the fake could not tell which account a query went through.

Gaps

  • Untested:
    • passing the chosen subscription, not the account, to the role check. A tenant-level select in a second tenant would then query through the stale default. The fake checks the issuer only for /subscriptions/ scopes, so no test has that shape;
    • an az account set failing in select. Only the signInTo tests set set_error.

Evidence

  • a_refused_select_leaves_the_choice_and_az_default_as_they_were failed before the fix: left: Some("aaaaaaaa-0000-4000-8000-000000000001") right: Some("aaaaaaaa-0000-4000-8000-000000000002") (az's default had moved to Prod).
  • Hand mutants:
    • the old order, default first (180 passed, 1 failed): the test above;
    • the role query without its account (177 passed, 4 failed): a_tenant_level_choice_holds_no_subscription_role, detect_reports_a_login_that_lacks_a_required_role, detect_passes_over_a_failed_source_and_a_missing_role, each_service_principal_a_source_holds_is_tried_in_turn.
  • mise run check at 828e23a: 503 tests run: 503 passed, 0 skipped, lint clean, semver no publishable crates.
  • azure-cli 2.93.0, the version mise.toml pins:
    • role/_client_factory.py:13 takes the subscription from --scope only by re.match('/subscriptions/(?P<subscription>[^/]*)/', scope), which /subscriptions/<id> doesn't match;
    • core/commands/arm.py:430 adds --subscription to every command;
    • core/commands/__init__.py:663 puts it in cli_ctx.data['subscription_id'];
    • core/commands/client_factory.py:69-70 gives that to the client.
  • Audit dependencies is red, as on main, until the pin-project-lite 0.2.19 lock update.
  • Rebased for the stack, 36cd0ad to cb7cb06: the PR's diff has the same git patch-id --stable (405256d321bd) and the same changed lines, tree unchanged.

select made the new account az's default before checking the required
roles, so a select the roles refused kept the old choice while a bare
az used the refused account. The role query now names its account with
--subscription, and the default moves only once the roles hold.

az's role client takes the subscription from --scope only when a slash
follows it, so without --subscription it asks through the default.
@odgrim
odgrim force-pushed the track-a/azure-select-rollback branch from 36cd0ad to cb7cb06 Compare December 6, 2026 16:03
@odgrim
odgrim changed the base branch from track-a/azure-release-gaps to main December 6, 2026 16:04
@odgrim
odgrim added this pull request to stack #118 December 6, 2026 16:04
@odgrim
odgrim marked this pull request as ready for review December 6, 2026 16:14

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