How can we find existing secret scopes in databricks workspace. And which keyvault is referred by specific SecretScope in Azure Databricks?
4 Answers
This command lists available scopes on databricks:
dbutils.secrets.listScopes()

- 553
- 5
- 12
-
1So this was my intent to post this questions, as I was wondering if there's way to do it via Notebook itself. thanks! – tikiabbas Dec 29 '22 at 17:17
-
This answer does not include showing the keyvault that is backed by the scope. – Siete Mar 13 '23 at 15:27
If you want a quick idea of which keyvault a secret scope refers to, the number of vaults is relatively small, you have list access through Azure portal and the keys between the vaults differ, you can try the following:
First list the scopes using:
dbutils.secrets.listScopes()
(Thanks to Matkurek)
And then list the secret names within specific scopes using:
dbutils.secrets.list("SCOPE_NAME")
This might help you pin down which vault the scope points to.
It seams that the only alternative is the CLI option described by Alex Ott

- 328
- 3
- 14
You can do this with either:
- Databricks Secrets REST API - the list secret scopes API will give that information
- Databricks CLI - the
databricks secrets list-scopes
command will show your KeyVault URL

- 80,552
- 8
- 87
- 132
You can try this snippet here in Python:
import pandas
import json
import requests
# COMMAND ----------
# MAGIC %md ### define variables
# COMMAND ----------
pat = 'EnterPATHere' # paste PAT. Get it from settings > user settings
workspaceURL = 'EnterWorkspaceURLHere' # paste the workspace url in the format of 'https://adb-1234567.89.azuredatabricks.net' Note, the URL must not end with '/'
# COMMAND ----------
# MAGIC %md ### list secret scopes
# COMMAND ----------
response = requests.get(workspaceURL + '/api/2.0/secrets/scopes/list',\
headers = {'Authorization' : 'Bearer '+ pat,\
'Content-Type': 'application/json'})
pandas.json_normalize(json.loads(response.content), record_path = 'scopes')
I have happened to have written a blog post about this where a full Python script is provided to manage secret scopes in Azure Databricks.

- 51
- 2