Closed vanlanchoy closed 5 months ago
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi, @vanlanchoy. It appears you are using a fairly old version of azure-identity
. Is it possible for you to upgrade to the latest with pip install -U azure-identity
and then retry?
Also, what Azure hosting environment/service are you running this code on? ManagedIdentityCredential
only works in certain Azure hosts with Managed Identity enabled.
Hi @vanlanchoy. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Hi @pvaneck , I've tried upgraded my Azure.Identity module to 1.16.0 msal-1.28.0, and I'm running my code in Azure Synapse Workspace and still getting the same error. Does the module currently supporting UAMI/SAMI?
Based on the docs here: https://learn.microsoft.com/azure/synapse-analytics/synapse-service-identity#user-assigned-managed-identity, "User-assigned Managed Identity is not currently supported in Synapse notebooks and Spark job definitions.". I'm not sure why this is the case, but this is the likely cause of the UAMI Credential being unable to work. Try using system-assigned MI, and see if you encounter the same problem.
I am seeing the same error for SAMI scenario as well.
Hmm, @xiangyan99 do you know if Managed Identity authentication is supported through our SDKs in Synapse Notebooks? I feel like it might not be as it doesn't seem like the IMDS endpoint is accessible from within the notebook/Spark pool, and we don't do any specific checks for Synapse specific environment variable within ManagedIdentityCredential...
You'd probably have to use service principals (ClientSecretCredential/EnvironmentCredential), or perhaps some of the msspark util functions listed here: https://learn.microsoft.com/azure/synapse-analytics/spark/microsoft-spark-utilities?pivots=programming-language-python
No. Azure identity library does not work in Synapse workspace.
In order to use managed identity in Synapse workspace, you need to use mssparkutils.
For more information: https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary?pivots=programming-language-python
Hi @vanlanchoy. 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.
Hi @vanlanchoy, 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.
Hi $abhbhatt, only the original author of the issue can ask that it be unresolved. Please open a new issue with your scenario and details if you would like to discuss this topic with the team.
No. Azure identity library does not work in Synapse workspace.
In order to use managed identity in Synapse workspace, you need to use mssparkutils.
For more information: https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary?pivots=programming-language-python
Hey @xiangyan99 I'm trying to also use managed identity to connect to a service from a workspace (to Azure Open AI in my case). I don't understand how using mssparkutils can help with that. Is there any way to get the workspace or any managed identity from the notebook code in Synapse?
@xiangyan99 , I cannot use SPN due to security issues. I have to switch to MI. After switching to system assigned MI and following the steps mentioned at https://learn.microsoft.com/en-us/azure/machine-learning/how-to-authenticate-batch-endpoint?view=azureml-api-2&tabs=sdk#running-jobs-using-a-managed-identity, I am still facing the ImdsCredential.get_token failed
Hi $aayushsin, only the original author of the issue can ask that it be unresolved. Please open a new issue with your scenario and details if you would like to discuss this topic with the team.
No. Azure identity library does not work in Synapse workspace. In order to use managed identity in Synapse workspace, you need to use mssparkutils. For more information: https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary?pivots=programming-language-python
Hey @xiangyan99 I'm trying to also use managed identity to connect to a service from a workspace (to Azure Open AI in my case). I don't understand how using mssparkutils can help with that. Is there any way to get the workspace or any managed identity from the notebook code in Synapse?
In my case I am trying to connect to an Azure ML workspace
I managed to get it working by creating a linkedservice to Azure ML workspace from Synapse after making sure that the Synapse's Managed Identity has at least a role of a Data Scientist (it can be perhaps "Reader" in your case?) to the Azure ML workspace.
I used the following code with mssparkutils library:
from notebookutils import mssparkutils
aml_token = mssparkutils.credentials.getConnectionStringOrCreds("ls_azureml")
where "ls_azureml" is the linkedservice name.
I also had to use a class to get the credential working through an access token from the linkedservice (thanks chatGPT):
# Assuming aml_token contains the access token
class AmlTokenCredential(TokenCredential):
def __init__(self, token):
self.token = token
def get_token(self, *scopes, **kwargs):
# Wrap the token in an AccessToken object with a valid expiry date
return AccessToken(self.token, expires_on=int(time.time()) + 3600)
# Use the aml_token retrieved earlier
aml_token = mssparkutils.credentials.getConnectionStringOrCreds("ls_azureml")
# Create an instance of AmlTokenCredential with the token
credential = AmlTokenCredential(aml_token)
You can then use credential variable in MLClient class (my specific case) to connect to the ML Workspace.
Hope this helps!
Describe the bug ImdsCredential.get_token failed: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint.
To Reproduce Steps to reproduce the behavior:
Expected behavior a token string returned by the service endpoint.
Screenshots
Additional context