'Create Kusto client using federated identity credential without using any app secret

I'm trying to connect to Azure Data Explorer (ADX/ Kusto) from Azure Kubernetes Service (AKS) pod.

# Sample code
from azure.kusto.data import KustoClient, KustoConnectionStringBuilder
KCSB_DATA = KustoConnectionStringBuilder.with_aad_application_key_authentication(KUSTO_DATA_URI, CLIENT_ID, CLIENT_SECRET, AUTHORITY_ID)
ingest_data = KustoClient(KCSB_DATA)

Is there any way to create Kusto client using AAD application Authentication by providing federated identity credential but without using any app secret(CLIENT_SECRET) in python?



Solution 1:[1]

In this scenario there are two ways you can do

Without CLIENT_SECRET

from azure.kusto.data import KustoClient, KustoConnectionStringBuilder
kcsb = KustoConnectionStringBuilder.with_az_cli_authentication(KUSTO_URI)
ingest_data = KustoClient(kcsb)

If you have not signed in with your AAD credentials it will Automatically prompt you to do so opening a web browser to sign in.

With CLIENT_SECRET

from azure.kusto.data.request import KustoClient, KustoConnectionStringBuilder
from azure.kusto.data.exceptions import KustoServiceError
from azure.kusto.data.helpers import dataframe_from_result_table

KUSTO_DATABASE = "XXXX"
CLUSTER = "https://mynode.myregion.kusto.windows.net"
CLIENT_ID = "XXXX"
CLIENT_SECRET = "XXXX"
AUTHORITY_ID = "<insert here your tenant id>"
KCSB_DATA = KustoConnectionStringBuilder.with_aad_application_key_authentication(CLUSTER, CLIENT_ID, CLIENT_SECRET, AUTHORITY_ID)
KUSTO_CLIENT = KustoClient(KCSB_DATA)
CREATE_TABLE_COMMAND = “ Follow below link”
RESPONSE = KUSTO_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_TABLE_COMMAND)
dataframe_from_result_table(RESPONSE.primary_results[0])

You can refer this link:

https://docs.microsoft.com/en-us/azure/data-explorer/python-ingest-data#add-import-statements-and-constants

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BhanunagasaiVamsi-MT