if we select "Allow public access from specific virtual networks and IP addresses" in Networking blade of keyvault. For Databricks notebooks we can fetch secrets by using secret scope, How do we do like that in synapse notebooks. Please help me with the appropriate solution.
There are two ways ,You can retrieve secret keys values in azure synapse.
This is my Keyvault secret value:
Note: Make sure to check whether access policies permission given or not.
Approach 1:
Go to azure Synapse studio and follow this sample code.
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("dem123","testSecret","AzureKeyVault1")
print(connection_string)
Approach 2:
As per the Ms_doc try this code:
mssparkutils.credentials.getSecret('key_vault_name','secret_name')
Or
mssparkutils.credentials.getSecret('key_vault_name','secret_name','linked_service')
For more information refer this SO thread