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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/azure-login-negative.yml
Expand Up @@ -347,11 +347,6 @@ jobs:
script: |
core.setFailed('Last action should fail but not. Please check it.')

# logout first to avoid the conflict with SP1
- name: Azure CLI logout
run: |
az logout

# 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
Expand Down
7 changes: 7 additions & 0 deletions src/Cli/AzureCliLogin.ts
Expand Up @@ -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.

}
catch (error) {
core.debug(`Ignore logout error: "${error}"`);
}

this.setAzurestackEnvIfNecessary();

await this.executeAzCliCommand(["cloud", "set", "-n", this.loginConfig.environment], false);
Expand Down