mssparkutils getSecret doesn't work

Abinash Tumulu 56 Reputation points Microsoft Employee
2022-09-26T18:35:09.023+00:00

I'm facing issue while getting secrets using mssparkutils and also using tokenlibray. Can you please help here?

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("kv-name", "SPNSecret", "LSName")  
print(connection_string)  

Getting following error:

~/cluster-env/env/lib/python3.8/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)  
    324             value = OUTPUT_CONVERTER[type](answer[2:], gateway_client)  
    325             if answer[1] == REFERENCE_TYPE:  
--> 326                 raise Py4JJavaError(  
    327                     "An error occurred while calling {0}{1}{2}.\n".  
    328                     format(target_id, ".", name), value)  
  
Py4JJavaError: An error occurred while calling z:com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.getSecret.  
: java.lang.Exception: Access token couldn't be obtained {"result":"DependencyError","errorId":"BadRequest","errorMessage":"LSRServiceException is [{\"StatusCode\":400,\"ErrorResponse\":{\"code\":null,\"message\":null,\"target\":null},\"StackTrace\":\"   at Microsoft.Marlin.Common.ADF.Impl.LSRClient.CheckForFailures(HttpResponseMessage response, String responseContent) in C:\\\\source\\\\Common\\\\Microsoft.Marlin.Common.ADF\\\\Impl\\\\LSRClient.cs:line 355\\r\\n   at Microsoft.Marlin.Common.ADF.Impl.LSRClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken, String traceId) in C:\\\\source\\\\Common\\\\Microsoft.Marlin.Common.ADF\\\\Impl\\\\LSRClient.cs:line 372\\r\\n   at   

@PRADEEPCHEEKATLA-MSFT

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.
4,484 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Victor Seifert 151 Reputation points
    2022-09-28T05:39:24.49+00:00

    I got the exact same error all of a sudden this week.. this is NOT an issue of un-published LinkedServices.

    This seems a lot more like an error in a new update of the TokenLibrary. We randomly get these errors throughout all of our environments and Synapse workspaces.

    2 people found this answer helpful.
    0 comments No comments

  2. PRADEEPCHEEKATLA-MSFT 80,096 Reputation points Microsoft Employee
    2022-09-27T08:14:31.843+00:00

    Hello @Anonymous ,

    Thanks for the question and using MS Q&A platform.

    Can you please clarify if after creating the Linked Service, then selecting “OK”, have you also clicked on “Publish”?

    Note: Before using the Linked Service, you need to publish it.

    Resolution: You will be experience the above issue when you have not published the Azure Key Vault Linked Service.

    As per the repro - I got the same error message as shown above when I have not published the Azure Key Vault Linked Service.

    244990-image.png

    When I published the Azure Key Vault Linked Service - it started working as expected.

    245072-image.png

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is jhow you can be part of Q&A Volunteer Moderators
    0 comments No comments