skip to Main Content

What is the best way to perform unattended az login in a "single-tenant/multiple-subscription" environment?

In this example. I’ll use --device-code login method.


$ az login --use-device-code

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code L96AYFHBU to authenticate.

Retrieving tenants and subscriptions for the selection...

[Tenant and subscription selection]

No     Subscription name    Subscription ID     Tenant
-----  -------------------  ------------------  --------------
[1] *  #sub-name-1#         #sub-id-1#          #tenant#
[2]    #sub-name-2#         #sub-id-2#          #tenant#

The default is marked with an *; the default tenant is '#tenant#' and subscription is '#sub-name-1#' (#sub-id-1#).

Select a subscription and tenant (Type a number or Enter for no changes): <enter>

Tenant: #tenant#
Subscription: #sub-name-1# (#sub-id-1#)

[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236

If you encounter any problem, please open an issue at https://aka.ms/azclibug

[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.

To avoid confirm request, I tried az account set --subscription #sub-name-1# but this change only subscription default and confirmation prompt still remains.

I do not know is there is some azure config set available

Anyway, the only workaround I found is this one:


az login --use-device-code <<< "n"


references:

2

Answers


  1. To avoid confirm request, I tried az account set –subscription #sub-name-1# but this change only subscription default and confirmation prompt still remains.

    You can run the following command to disable confirmation prompts:

    az config set core.disable_confirm_prompt=true
    

    As an alternative, set the AZURE_CORE_DISABLE_CONFIRM_PROMPT environment variable or use a CLI configuration file.

    For more details refer to CLI configuration values and environment variables.

    Login or Signup to reply.
  2. I had a similar issue when running the Azure CLI az login command remotely.

    It would automatically ask for a device login but then afterwards, it would still pause and ask which subscription I’d like to login with.

    As I can’t interact with it, it would just get stuck here with no way to proceed.

    To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code MYCODE to authenticate.
    
    Retrieving tenants and subscriptions for the selection...
    
    [Tenant and subscription selection]
    
    No     Subscription name           Subscription ID                       Tenant
    -----  --------------------------  ------------------------------------  --------------
    [1] *  Microsoft Partner Network   123*********************************  tenant
    [2]    MSID_DEVX_RED_PPE           456*********************************  Microsoft
    [3]    MSIT-DSR_DLP_Sentinel-PROD  789*********************************  Microsoft
    [4]    StoreCore-PST-PIFD          011*********************************  Microsoft
    
    The default is marked with an *; the default tenant is 'tenant' and subscription is 'Microsoft Partner Network' (123*********************************).
    
    Select a subscription and tenant (Type a number or Enter for no changes): 
    

    This prompt would appear even if I use az login --use-device-code which you might assume would force it to non-interactive.

    To resolve this I used the linux yes command.

    yes | az login
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search