Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
I am now trying to get connection from function app to warehouse.
I can do it once and only once since the MI will be blocked by default after the successful connection.
It is said that there is no email address with the service principal I am using hence the token will expire after the 1st use. Any idea how to get it up and running?
Solved! Go to Solution.
MI works. I can close it now.
Hi @simontaylor,
Thank you for posting your query in Microsoft Fabric Community Forum. Also, thanks to @deborshi_nag , for those inputs on this thread.
Direct Managed Identity authentication from Azure services such as Functions or Container Apps to Fabric Warehouse/Lakehouse SQL endpoints is generally not supported currently and that the currently supported production approach is to authenticate using a Service Principal. They are also right that a more secure pattern is to avoid client secrets and instead use certificate-based authentication, with the certificate stored in Key Vault and accessed using the Function App’s Managed Identity.
SQL access tokens are not single-use; they are short-lived (typically about one hour) and must simply be requested again whenever a new connection is created. Token expiry is expected behavior and does not prevent repeated connections as long as the application refreshes the token.
Given the current platform capabilities, the practical solution is to use a Service Principal authenticated with a certificate (not a secret), store the certificate securely in Key Vault, allow the Function App’s Managed Identity to retrieve it and then obtain a fresh SQL access token for each connection attempt.
Hope the above provided information help you resolve the issue, if you have any further concerns or queries, please feel free to reach out to us.
Best Regards,
Community Support Team.
I can use MI to get it connected and then write query result to kusto with three consecutive successes now.
Will circle back once I get next one after some hours.
Great. Then can you please let me know how to create the cert in corp?
AME key vault cert or federated credentials?
no fed cred - not supported, only option to use AME.
AME can access corp fabric data warehouse?
not sure what you mean by corp fabric data warehouse, but for any Fabric Warehouse recommended secretless method today for secure app authentication is SPN + Certificate (e.g., AME cert).
My situation doesn't support SPN + cert. I am checking whether I can upload the cert file to deploy it to linux server.
If I can use the key in the pfx file anc then I think it should work to do auth.
Hello @simontaylor
I believe you are referring to Fabric User Defined Functions. These do indeed support Managed Identity or Service Principal, as outlined in the blog below.
Service principal and private library support for Fabric User data functions | Microsoft Fabric Blo…
By default, the use of Service Principals is restricted until access is granted at either the workspace or item level, and the relevant tenant setting is enabled to allow Service Principals to use Fabric APIs. If these steps are not completed, the initial attempt may succeed due to cached credentials, but subsequent attempts will fail.
To grant SPN access to the Fabric item, please refer to the following link:
Service Principals in Fabric Data Warehouse - Microsoft Fabric | Microsoft Learn
The tenant setting to enable can be found in:
Fabric Admin Portal > Tenant settings > Developer settings > “Service principals can use Fabric APIs”
Hello @simontaylor
Thanks for supplying the details. It seems you're using Python to access a SQL Endpoint. Unfortunately
import pyodbc
from typing import Callable
from azure.identity import DefaultAzureCredential, ClientSecretCredential
from azure.keyvault.secrets import SecretClient
KEYVAULT_URL = # e.g., "https://my-kv.vault.azure.net"
FABRIC_SERVER = # e.g., "xxxx.datawarehouse.fabric.microsoft.com"
FABRIC_DATABASE = # exact Warehouse/Lakehouse name
# Key Vault secret names (your choice)
TENANT_SECRET_NAME = "fabric-sp-tenant-id"
CLIENT_ID_SECRET_NAME = "fabric-sp-client-id"
CLIENT_SECRET_NAME = "fabric-sp-client-secret"
cred = DefaultAzureCredential() # picks MI in Azure, falls back to other dev creds locally
client = SecretClient(vault_url=KEYVAULT_URL, credential=cred)
tenant_id = with_retry(lambda: client.get_secret(TENANT_SECRET_NAME).value)
client_id = with_retry(lambda: client.get_secret(CLIENT_ID_SECRET_NAME).value)
client_secret = with_retry(lambda: client.get_secret(CLIENT_SECRET_NAME).value)
sp_cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
token = with_retry(lambda: sp_cred.get_token("https://database.windows.net/.default").token)
# ODBC connection string (no Authentication keyword; we'll pass token via attrs_before)
conn_str = (
"Driver={ODBC Driver 18 for SQL Server};"
f"Server={FABRIC_SERVER};"
f"Database={FABRIC_DATABASE};"
"Encrypt=Yes;TrustServerCertificate=No;Connection Timeout=30;"
)
# Convert token to the format expected by the SQL Server ODBC driver
token_bytes = token.encode("utf-16-le")
token_struct = struct.pack("<I", len(token_bytes)) + token_bytes
SQL_COPT_SS_ACCESS_TOKEN = 1256
# Connect with token
return pyodbc.connect(conn_str, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct}) Please ensure your MI has appropriate grants to read the SPN details from the KV.
Sorry. SPN + Secret is not my choice. I can't use it in that way.
Solved: Using Managed Identity for Fabric Lakehouse SQL An... - Microsoft Fabric Community
I think the solution of the above link may work for my case. But I am not sure if I need to use key vault cert or federated credentials to do auth.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 9 | |
| 4 | |
| 3 | |
| 3 |