-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Is it possible to use my developer credentials as Managed Identity locally in Visual Studio Code? #9002
Comments
DefaultAzureCredential is a ChainedTokenCredential that first looks for an EnvironmentCredential via env var settings, then Managed Identity, then SharedTokenCacheCredential (which only supports vs2019 sign-in today). See the docs here: https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python And let me know if you have any issues. |
@jongio hi, I would just like to mention that I'm facing the same issue. Although it's possible to create a Service Principal and set its details as environment variables to let the DefaultAzureCredential method see them, it introduces the inconvenience of having to create these Service Principals just for this, and having to deal with the corresponding secrets/certificates carefully. It would be really convenient to just authenticate using az, and then make DefaultAzureCredential leverage this (I know you could "steal" tokens using the az command, but at least there is only one thing to worry about :) ) As the OP mentioned, this seems to be a feature already present in C# SDK and Visual Studio, but not in Python SDK and VS Code. This seems to be a duplicate of issue #8566 and seemed to be about to be released but don't know what happened :( |
If all goes well this week, we'll have a preview out soon. I"ll flag this thread to post more info when we have it. |
A preview of DefaultAzureCredential with Az Cli credential support was released yesterday: https://pypi.org/project/azure-identity/1.4.0b1/ Please try it out and provide feedback. Thanks, Jon |
Does this work with Any ideas to get this working? It's quite a lot of overhead to push my function to Azure for every small change that I want to test. |
@davidobrien1985 - Azure.Identity support is coming to Management Plane soon. In the meantime, I created an adapter for DefaultAzureCredential called DefaultAzureMgmtCredential, which you can find here: https://github.com/jongio/azidext Please give it a try and let me know if you run into any issues. |
@jongio thanks (pinged you on Teams as well) @anthonychu actually helped me with this and I got it working following his example here: https://github.com/anthonychu/python-azure-resources-msi/blob/master/ListResourceGroups/__init__.py |
@jongio I've tried the preview of DefaultAzureCredential with Az Cli credential support, but DefaultAzureCredential doesn't seem to recognize my login, I'm currently logged in into the azure subscription as a contributor (the object storage service is within the same subscription). Here is the codesnippet I use:
Here is the error I get:
Before running the code, i've logged in with Thanks a lot! |
Hi @kevroes, thanks for the bug report. I've opened a new issue to track it and will fix it for the next release. |
In azure-identity 1.4.0b3, released today, |
Hi @chlowell I logged into VS Code via Azure Account plugin. No configuration/env var. this simple code below
But I got this weird error, it looks like my user name didn't pick up correctly, instead some Visual Studio Code.
I found in my VS code setting, there are two new lines.
I spent a lot of time, try to get above work but no luck. any help, thanks. Victor |
I have an Azure Function App which uses its Managed Identity to access Key Vault. It works on Azure.
When developing locally, is it possible to use my developer credentials as the Managed Identity in Visual Studio Code?
I know for C# and Visual Studio, there is an option: Azure Service Authentication -> Account Selection.
https://docs.microsoft.com/en-us/azure/key-vault/service-to-service-authentication#authenticating-to-azure-services
Sample code and exception:
credentials = DefaultAzureCredential()
key_vault_uri = "https://yihongkv.vault.azure.net/"
secret_client = SecretClient(
key_vault_uri, # Your KeyVault URL
credentials
)
secret = secret_client.get_secret("key2")
azure.core.exceptions.ClientAuthenticationError: No valid token received. EnvironmentCredential: Incomplete environment configuration.. ImdsCredential: IMDS endpoint unavailable. SharedTokenCacheCredential: No cached
token found for '[email protected]'
The text was updated successfully, but these errors were encountered: