Azure / Azure/azure-cli

`az login` should not select the default subscription

Open
#27,915 4 comments 4 reactions 1 assignee Assigned to @jiasli View on GitHub
Account act-identity-squad Auto-Assign Azure CLI Team feature-request RBAC
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

Currently, `az login` chooses the first enabled subscription as the default subscription:

https://github.com/Azure/azure-cli/blob/e8efb791ea2f0ba5e4f172b26f75725fd8aa8079/src/azure-cli-core/azure/cli/core/_profile.py#L500-L502

The list and its item order returned by [Tenants - List](https://learn.microsoft.com/en-us/rest/api/resources/tenants/list) and [Subscriptions - List](https://learn.microsoft.com/en-us/rest/api/resources/subscriptions/list) can change, so the first/default subscription selected by `az login` can change. Without explicitly specifying the subscription, the user may accidentally perform operations on a wrong subscription. For example:

- Running `az group delete` on a wrong subscription can cause production environment destruction.
- Running `az role assignment create` can lead to permission leak.

**Proposal**

`az login` should not select the default subscription. In order to select the default subscription, one can

- Run `az account set`
- Run `az login` with `--subscription` (https://github.com/Azure/azure-cli/issues/14933)

See: IcM 418947258

_Originally posted by @jiasli in https://github.com/Azure/azure-cli/issues/14933#issuecomment-1752567021_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.