azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

CLI authentication

Open kevjumba opened this issue 3 years ago • 5 comments

  • Package Name: azure-cli
  • Package Version: 2.39.0
  • Operating System: M1 Monterey
  • Python Version: 3.10.3

Describe the bug I can't authenticate to azure or get the azure credentials. I've logged in through vs code and az login through the cli. I can see my resources under the Azure pulldown in vscode but when I run code, I get

VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code.
	AzureCliCredential: Azure CLI not found on path
	AzurePowerShellCredential: PowerShell is not installed

I'm just running this code:

from azure.identity import VisualStudioCodeCredential
from azure.mgmt.resource.resources import ResourceManagementClient

credential = VisualStudioCodeCredential()
client = ResourceManagementClient(
    credential=credential,
    subscription_id="YOUR_SUBSCRIPTION_ID"
)

To Reproduce Steps to reproduce the behavior: 1.

Expected behavior This isn't supposed to happen.

Screenshots Azure vscode screenshot verifying that I'm logged in: Uploading Screen Shot 2022-08-09 at 5.34.19 PM.png…

Additional context Add any other context about the problem here.

kevjumba avatar Aug 10 '22 00:08 kevjumba

Thanks for reaching out.

It's a known issue that VisualStudioCodeCredential doesn't work with Azure Account extension versions newer than 0.9.11. A long-term fix to this problem is in progress. In the meantime, consider authenticating via the Azure CLI.

For more details, you can refer https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md#troubleshoot-visualstudiocodecredential-authentication-issues.

xiangyan99 avatar Aug 10 '22 15:08 xiangyan99

Hi @kevjumba. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Aug 10 '22 15:08 ghost

@xiangyan99 Hello, I've actually tried logging in with the azure cli. I get output when i run az login with a json dump of the correct credentials. However when I run curl 'http://169.254.169.254/metadata/identity/oauth2/token?resource=https://management.core.windows.net&api-version=2018-02-01' -H "Metadata: true" I get operation timed out and I still get the error above when I try to connect using the azure sdk. Also none of the environment variables are set for some reason..

Do you know of any additional configuration I have to do here?

kevjumba avatar Aug 10 '22 17:08 kevjumba

From your code shared above,

credential = VisualStudioCodeCredential()

It looks to me you only tried the VSCode credential.

Have you tried

credential = AzureCliCredential()

?

xiangyan99 avatar Aug 10 '22 17:08 xiangyan99

I fixed the issue. You have to do this https://stackoverflow.com/questions/43983718/set-global-path-environment-variable-in-vs-code to update the vscode path.

I was running jupyter notebooks inside of the vscode cli and that was not using the same $PATH variable as the vscode terminal.

kevjumba avatar Aug 10 '22 17:08 kevjumba

Hi @kevjumba, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.

ghost avatar Aug 17 '22 22:08 ghost