An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
Our team wanted to connect to Kusto with Synapse Spark using certificate authentication. I created the following code snippet that shows how to get the cert from Key Vault, use it to get an access token, and then pass that token to the Spark Kusto Connector:
import base64
from azure.identity import CertificateCredential
# Get certificate data from Key Vault using the Synapse Linked Service
certificate_data = mssparkutils.credentials.getSecretWithLS("<your-akv-linked-service-name>", "<your-certificate-name-in-akv>")
# Decode the certificate data into bytes (as required by the azure.identity package)
pkcs12_bytes = base64.b64decode(certificate_data)
# Use the certificate bytes to get a credential
credential = CertificateCredential(tenant_id="<your-entra-tenant-id>", client_id="<your-client-id>", certificate_data=pkcs12_bytes, send_certificate_chain=True)
# Get a token for the credential (using Kusto as the scope)
access_token = credential.get_token("https://kusto.kusto.windows.net/.default")
# Use our token to authenticate to Kusto
df = spark.read \
.format("com.microsoft.kusto.spark.synapse.datasource") \
.option("accessToken", access_token.token) \
.option("kustoCluster", "https://<your-cluster-name>.kusto.windows.net") \
.option("kustoDatabase", "<your-database-name>") \
.option("kustoQuery", "<your-kql-query>") \
.load()
display(df)