Hello Tobias Quadfasel,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are trying to use a managed identity in a way that is not fully supported by MLflow's current authentication flow.
MLflow does not natively support managed identity authentication via .databrickscfg alone. The below steps align with best practice guidance and are secure, scalable, and recommended for production environments: https://learn.microsoft.com/en-us/azure/databricks/dev-tools/auth/azure-mi
- Install Required Libraries using bash command:
pip install azure-identity mlflow databricks-sdk - Manually acquire Azure AD token using Managed Identity using Python:
from azure.identity import ManagedIdentityCredential import requests # Get token for Databricks credential = ManagedIdentityCredential(client_id="<your-client-id>") token = credential.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default") # Use token in headers for Databricks REST API headers = { "Authorization": f"Bearer {token.token}" }- The resource ID
2ff814a6-3304-4ab8-85cb-cd0e6f879c1dis the Azure Databricks App ID
- The resource ID
- Then, use REST API to download Artifacts or Models, since MLflow may not support this token directly, use the REST API:
response = requests.get( "https://<your-databricks-instance>.azuredatabricks.net/api/2.0/mlflow/artifacts/download", headers=headers, params={"run_id": "<your-run-id>", "path": "<artifact-path>"} )
Alternatively, this step is a practical workaround, not officially documented as a supported method for managed identity with MLflow. If you want to try MLflow with token injection:
import mlflow
import os
os.environ["DATABRICKS_HOST"] = "https://<your-databricks-instance>.azuredatabricks.net"
os.environ["DATABRICKS_TOKEN"] = token.token # Inject token manually
mlflow.set_tracking_uri("databricks")
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.