'How to get the KeyVault name in the notebook from the keyvault link in Synapse?

How to get the KeyVault name in the notebook from the keyvault link in Synapse?

I need the KeyVault name to pass to the TokenLibrary.

TokenLibrary.getSecret(keyVaultName,"MyConnectionString", "AzureKeyVaultLink")



Solution 1:[1]

Please make sure to enable managed service identity and add keyvault secrets and also add linked service to azure synapse

Go Azure key Vault in my case keyvam is KeyVault name.

Ref

Syntax:

connection_string = TokenLibrary.getSecret("mykeyvault", "ConnectionString")

you can use linked service as shown in the below reference.

connection_string = TokenLibrary.getSecret("mykeyvault", "ConnectionString", "AzureKeyVaultLinkedServiceName")

Sample example:

import sys
from pyspark.sql import SparkSession
sc = SparkSession.builder.getOrCreate()
token_library = sc._jvm.com.microsoft.azure.synapse.tokenlibrary.TokenLibrary
connection_string = token_library.getSecret('keyvam','vamsi')
print(connection_string)

Ref2

Reference:

https://docs.microsoft.com/en-us/answers/questions/445496/access-secret-from-vault-using-synapse-pyspark-not.html

https://docs.microsoft.com/en-us/answers/questions/445496/access-secret-from-vault-using-synapse-pyspark-not.html

https://docs.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary?pivots=programming-language-python&WT.mc_id=data-34417-abhishgu#getsecret

https://dzone.com/articles/securely-access-azure-sql-database-from-azure-syna

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