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")
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")
I found a solution to get the secret without the key vault name. There is an API called
Token.getSecretWithLS("AzureKeyVaultLink", "MyConnectionString"));
which will get the secret from the KV.
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.
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)
Reference:
https://dzone.com/articles/securely-access-azure-sql-database-from-azure-syna
Below code can be used for getting keyvault url associated with the linked service.
import sys
my_linked_service_name = "LS_Keyvault"
spark_session = SparkSession.builder.getOrCreate()
token_library = spark_session._jvm.com.microsoft.azure.synapse.tokenlibrary.TokenLibrary
keyvaultUrl = token_library.getFullConnectionStringAsMap(my_linked_service_name).get("url")