Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
SravyaNeela
Microsoft Employee
Microsoft Employee

Connect to Azure Data Explorer (kusto) to read data from fabric notebook

I have data source Azure Data Explorer kusto cluster and I need to connect to it in fabric notebook to read data by authenticating using workspace identity  or SPN

How to authenticate using SPN when notebook is running under different identity

How to authenticate using workspace identity

1 ACCEPTED SOLUTION
SravyaNeela
Microsoft Employee
Microsoft Employee

I had this code worked 

def getKustoData(kusto_query : str😞
    # Service Principal credentials
    spn_client_id = "client_id"
    spn_client_secret = mssparkutils.credentials.getSecret("keyvault_url", "screate_name")
    tenant_id = "tenant_id"
    # Define the Kusto cluster and database
    kusto_database = "database"
   
    # Read data from Kusto
    kusto_df = spark.read \
        .format("com.microsoft.kusto.spark.synapse.datasource") \
        .option("kustoCluster", kusto_cluster) \
        .option("kustoDatabase", kusto_database) \
        .option("kustoQuery", kusto_query) \
        .option("kustoAadAppId", spn_client_id) \
        .option("kustoAadAppSecret", spn_client_secret) \
        .option("kustoAuthorityId", tenant_id) \
        .load()
    return kusto_df


View solution in original post

7 REPLIES 7
SravyaNeela
Microsoft Employee
Microsoft Employee

I had this code worked 

def getKustoData(kusto_query : str😞
    # Service Principal credentials
    spn_client_id = "client_id"
    spn_client_secret = mssparkutils.credentials.getSecret("keyvault_url", "screate_name")
    tenant_id = "tenant_id"
    # Define the Kusto cluster and database
    kusto_database = "database"
   
    # Read data from Kusto
    kusto_df = spark.read \
        .format("com.microsoft.kusto.spark.synapse.datasource") \
        .option("kustoCluster", kusto_cluster) \
        .option("kustoDatabase", kusto_database) \
        .option("kustoQuery", kusto_query) \
        .option("kustoAadAppId", spn_client_id) \
        .option("kustoAadAppSecret", spn_client_secret) \
        .option("kustoAuthorityId", tenant_id) \
        .load()
    return kusto_df


Hi @SravyaNeela,
Thanks for sharing your working solution! please consider marking your reply as the Accepted Solution this helps highlight the resolution and can assist other community members who face similar challenges.

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @SravyaNeela,

 

We haven’t heard back from you regarding your issue. If it has been resolved, please mark the helpful response as the solution and give a ‘Kudos’ to assist others. If you still need support, let us know.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @SravyaNeela,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @SravyaNeela,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @SravyaNeela,

Thank you for reaching out to the Microsoft Fabric Forum Community. 

Additionally, to the @burakkaragoz, helpful response, I found the following links useful and relevant to your issue they provide practical examples and documentation for connecting Fabric notebooks to Azure Data Explorer (Kusto) using both Service Principal and Managed Identity: 

Querying KQL Database in Fabric Notebook Using Python SDK 

Use Fabric notebooks with data from a KQL database - Microsoft Fabric | Microsoft Learn 

 

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

 

Thank you. 

burakkaragoz
Community Champion
Community Champion

Hi @SravyaNeela ,

 

Great question — integrating Azure Data Explorer (Kusto) with Microsoft Fabric Notebooks using secure authentication methods like Service Principal (SPN) or Workspace Managed Identity is a powerful pattern for enterprise-grade data access.

🔐 1. Authenticating with Service Principal (SPN)

To authenticate using a Service Principal from a Fabric notebook:

from azure.kusto.data import KustoConnectionStringBuilder
from azure.kusto.data.helpers import dataframe_from_result_table
from azure.kusto.data import KustoClient

cluster = "https://<your-cluster>.kusto.windows.net"
client_id = "<your-app-id>"
client_secret = "<your-app-secret>"
tenant_id = "<your-tenant-id>"

kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(
    cluster, client_id, client_secret, tenant_id
)

client = KustoClient(kcsb)
query = "YourKustoDatabase | take 10"
response = client.execute("<YourKustoDatabase>", query)
df = dataframe_from_result_table(response.primary_results[0])

⚠️ Ensure the SPN has Data Reader permissions on the Kusto database and is registered in Azure AD.


🧭 2. Authenticating with Workspace Managed Identity

If your Fabric workspace is configured with a Managed Identity, and your Kusto cluster supports Azure AD-based access, you can authenticate using:

from azure.identity import DefaultAzureCredential
from azure.kusto.data import KustoClient, KustoConnectionStringBuilder

cluster = "https://<your-cluster>.kusto.windows.net"
credential = DefaultAzureCredential()

kcsb = KustoConnectionStringBuilder.with_aad_device_authentication(cluster)
client = KustoClient(kcsb)

Note: As of now, DefaultAzureCredential may not fully support Fabric’s managed identity context. If that’s the case, you may need to use Azure CLI login or interactive browser auth as a fallback during development.


Recommendations

  • Use SPN for production pipelines where automation and security isolation are critical.
  • Use Workspace Identity if your Fabric environment supports it and you want to centralize identity management.
  • Always validate that the identity (SPN or MI) has the necessary RBAC roles on the Kusto cluster.

Let me know if you’d like help setting up the Azure AD app registration or assigning permissions in Kusto!

Helpful resources

Announcements
May FBC25 Carousel

Fabric Monthly Update - May 2025

Check out the May 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.