Skip to content

Azure/login should logout the active account at the beginning - #376

Merged
Shiying Chen (MoChilia) merged 2 commits into
masterfrom
logout
Nov 27, 2023
Merged

Azure/login should logout the active account at the beginning#376
Shiying Chen (MoChilia) merged 2 commits into
masterfrom
logout

Conversation

@MoChilia

Copy link
Copy Markdown
Member

Azure CLI should run az logout to clear the active account at the beginning like what is done in Azure PowerShell:

let commands = 'Clear-AzContext -Scope Process; ';
commands += 'Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue; ';

Otherwise, when the user doesn't explicitly give the subscription-id or the given subscription-id is invaild, the post steps will continue using the user's active subscription which has set last time and not logged out.

The following test case will encounter this issue:

# SP1 is ignored and SP2 will be used for login, but it will fail since SP2 has no access to the given subscription
- name: Login with both creds and individual parameters
id: login_12
continue-on-error: true
uses: ./
with:
creds: ${{secrets.SP1}}
client-id: ${{ secrets.OIDC_SP2_CLIENT_ID }}
tenant-id: ${{ secrets.OIDC_SP2_TENANT_ID }}
subscription-id: ${{ secrets.OIDC_SP2_SUBSCRIPTION_ID }}
allow-no-subscriptions: true
enable-AzPSSession: true

Comment thread src/Cli/AzureCliLogin.ts
core.debug(`Azure CLI version used:\n${output}`);

try {
await this.executeAzCliCommand(["logout"], true, execOptions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps az account clear for a cleaner environment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose az logout is enough for signing out the current active subscription. And the following steps will use the subscription set in azure/login. There may be a situation that customer needs to switch the active subscription by manually running az account set.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In automation, az account clear may be a better choice for a cleaner environment. I will modify the code.

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.

3 participants