Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Itsgoodas
New Member

Writing / updating secrets to azure key vault from fabric

Anyone else having this issue or potential work arounds to write/overwrite secrets from fabric notebook to azure key vault?


It seems that the below code works when I use PyTridentTokenLibrary and mssparkutils it works successfuly but only on getting a token.

 

`import requests`
`from azure.keyvault.secrets import SecretClient`
`from trident_token_library_wrapper import PyTridentTokenLibrary as tl`
`from azure.identity import DefaultAzureCredential`


`akvName = 'azurekeyvault-name'`


`kv_access_token = mssparkutils.credentials.getToken("keyvault")`

`refresh_token = tl.get_secret_with_token("https://keyvault","secret_name",kv_access_token)`

`refresh_token = tl.get_secret_with_token("https://keyvault","secret_name",kv_access_token)`

 

but when setting or putting a secret it returns an error:

 

`mssparkutils.credentials.putSecret(akvName, secret_name, secret_value)`


**Error:**


> Py4JJavaError: An error occurred while calling z:mssparkutils.credentials.putSecret. : java.util.NoSuchElementException: spark.arcadia.session.token at org.apache.spark.SparkConf.$anonfun$get$1(SparkConf.scala:266) at scala.Option.getOrElse(Option.scala:189) at org.apache.spark.SparkConf.get(SparkConf.scala:266) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.$anonfun$getAccessTokenInternal$3(TokenLibrary.scala:271) at scala.util.Try$.apply(Try.scala:213) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.getAccessTokenInternal(TokenLibrary.scala:270) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.$anonfun$getAccessTokenInternal$4(TokenLibrary.scala:303) at scala.util.Try$.apply(Try.scala:213) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.getAccessTokenInternal(TokenLibrary.scala:291) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.getAccessTokenAsync(TokenLibrary.scala:216) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary.putAkvSecret(TokenLibrary.scala:815) at com.microsoft.azure.synapse.tokenlibrary.TokenLibrary$.putSecret(TokenLibrary.scala:1386) at mssparkutils.credentials$.putSecret(credentials.scala:138) at mssparkutils.credentials.putSecret(credentials.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) at py4j.Gateway.invoke(Gateway.java:282) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.GatewayConnection.run(GatewayConnection.java:238) at java.lang.Thread.run(Thread.java:750)

​

3 REPLIES 3
v-nikhilan-msft
Community Support
Community Support

Hi @Itsgoodas ,

Thankyou for using Microsoft Fabric Community and thanks for posting your question here.

I would be taking this forward to our internal team to understand if there is any deployment responsible for this error you are experiencing. However, meanwhile, I want you to make sure the following permissions are all set at your end. Kindly make sure :

  • The Synapse notebook managed service identity has been granted Secrets permission to the Azure Key Vault. Check Enable Azure RBAC permissions on Key Vault for more details on how to do that.
  • Active directory user id has blob contributor role in the storage account.

Looking forward to your response. Thanks.

Hi @Itsgoodas ,

We haven’t heard from you on the last response and was just checking back to see if you can provide the details asked above. Please let us know if you have any further queries.

Hi @Itsgoodas ,
Just following up to check whether you can provide the details asked in the above comment. Do let us know if you have any further queries.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.