Search code examples
azureazure-functionsazure-keyvaultazure-synapse

Access key vault in azure synapse analytical pipeline notebook


I have a secret saved in the Azure key vault and want to access it in the Synapse analytical pipeline when I run the manual notebook it does not give an error and I get my secret in the output of the notebook. Still, when I run the notebook through a pipeline it gives an error, and an error message is attached below while I have already added the access policy in my Azure key vault and my email ID, as well as my workspace name. Error Details

I aim to get the key vault secret value in my notebook through the pipeline run not manually.

from notebookutils import mssparkutils
mssparkutils.credentials.getSecret('kv-dp-WorkspaceName','TestNoteBook')

The above two lines of code give me the secret value when I run the notebook manual.


Solution

  • To get secret by calling notebook in pipeline you need to spacify key vault liked service name in the code.

    • First crate linked service to particular Key vault below: enter image description here

    • In key vault assingn appropeiate permission to managed identitiy of service principal of syampse workspace: enter image description here

    • Then Run below code in synaps notebook

    from notebookutils import mssparkutils
    mssparkutils.credentials.getSecret('key vault name','secret name','linkedservice name')
    

    Notebook executed from pipeline successfully:

    enter image description here