Cannot access secrets from notebook call by pipeline

Lotus88 176 Reputation points
2025-07-01T09:46:54.2833333+00:00

Hi,

I have grant secrets permission to my Synapse workspace and my microsoft entra ID.

I have notebooks that read the secrets created by me. I can run the notebook to access my secrets and it is working. However when I tried to run the notebook from pipeline, I keep getting errors and below is my notebook code. What could be the problem ?

from notebookutils import mssparkutils
tst_user_name = mssparkutils.credentials.getSecret('kv-002', 'secret-user')
An error occurred while calling z:mssparkutils.credentials.getSecret.\n: com.microsoft.azure.synapse.tokenlibrary.TokenServiceClientResponseStatusException: Token Service returned 'Client Error' (400), with message: {\"result\":\"DependencyError\",\"errorId\":\"BadRequest\",\"errorMessage\":\"[Code=CannotAcquireMSIForVault, Target=Vault, Message=Cannot acquire MSI token for a Vault audience.

User's image

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,385 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Venkat Reddy Navari 3,630 Reputation points Microsoft External Staff Moderator
    2025-07-01T15:59:46.74+00:00

    Hi Lotus88 This kind of issue usually shows up because notebooks run differently depending on how they’re triggered.

    When you run it manually, it uses your own Microsoft Entra ID (formerly Azure AD), which has access to the Key Vault.

    But when the notebook runs from a pipeline, it uses the Synapse workspace's managed identity, and that identity must have the right permissions and be able to acquire a token for the Key Vault. That’s likely where it’s failing.

    The error message about not being able to acquire MSI for a Vault usually points to one of these common causes:

    Things to Check

    Managed Identity: Ensure the system-assigned managed identity is turned on for your Synapse workspace (Azure Portal → Synapse → Identity → System-assigned = On).

    Vault Name in Code: Double-check the Key Vault name you're passing in the code. It should be the actual resource name not an alias or display name:

    
    mssparkutils.credentials.getSecret('kv-002', 'secret-user')
    

    Key Vault Networking: If you're using firewall rules or private endpoints, your Synapse workspace might not be able to reach the vault.

    As a quick test, set the Key Vault to "Allow access from all networks" to rule out network restrictions.


    I hope this information helps. Please do let us know if you have any further queries.

    Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.