Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

MoChilia
Copy link
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

@MoChilia MoChilia merged commit 40935f9 into master Nov 27, 2023
24 checks passed
@MoChilia MoChilia deleted the logout branch November 27, 2023 09:21
@@ -34,6 +34,13 @@ export class AzureCliLogin {
await this.executeAzCliCommand(["--version"], true, execOptions);
core.debug(`Azure CLI version used:\n${output}`);

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

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
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
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