s528060
s528060

Reputation: 83

KustoConnectionStringBuilder.with_aad_application_certificate_authentication in Synapse notebook

I am trying to use app with certificate for authentication in KustoConnectionStringBuilder, the certificate is saved in a KeyVault, as I found from the examples in github is required to download the PEM file as shown in the code below:

filename = "path to a PEM certificate"
with open(filename, "r") as pem_file:
    PEM = pem_file.read()

thumbprint = "certificate's thumbprint"
kcsb = KustoConnectionStringBuilder.with_aad_application_certificate_authentication(cluster, client_id, PEM, thumbprint, authority_id)

Could someone point me in how to properly retrieve the certificate from the KeyVault in Synapse, I tried using DefaultAzureCredentials and looks is not supported in Synapse, is there any way to retrieve the cer file using linked service of the KeyVault?

Upvotes: 0

Views: 316

Answers (1)

Bhavani
Bhavani

Reputation: 5317

DefaultAzureCredentials and looks are not supported in Synapse. Is there any way to retrieve the .cer file using a linked service of the KeyVault?

You can follow the procedure below to retrieve a certificate from the key vault:

  1. Create a service principal, create a secret, save TenantId, ClientId, and Secret values. Add the Key Vault Administrator role in the key vault to the service principal by selecting IAM and clicking on Add and select Add role assignment.

enter image description here

  1. Select the Key Vault Administrator role and go to the next step. Select the user or group option and click on the select member option. Select the SPN and click on the Review + Assign option.

enter image description here

  1. Use the code below to get the details of the certificate in a Synapse notebook:
from azure.identity import ClientSecretCredential
from azure.keyvault.certificates import CertificateClient

credential = ClientSecretCredential("<tenant_id>", "<client_id>", "<client_secret>")
certificate_client = CertificateClient(vault_url="https://<keyVaultName>.vault.azure.net/", credential=credential)
certificate = certificate_client.get_certificate("<certificateName>")

print(certificate.name)
print(certificate.properties.version)
print(certificate.policy.issuer_name)

This will retrieve the details successfully, as shown below:

enter image description here

For more information, you can refer to this.

Upvotes: 0

Related Questions