Create secrets scopes and keys for databricks, and how to give scope access to someone else


In previous blogs, we have discussed about how to install the databricks command line tool (CLI),
and how to add authentication to the databricks website host.

Steps to install databricks command line for both linux and windows system can be found here:
https://www.datasciencebyexample.com/2022/10/11/2022-10-11-1/

Steps to add authentication to the databricks website host can be found here:
https://www.datasciencebyexample.com/2022/10/12/2022-10-12-1/

Now back to how to create secrets scopes and keys uisng databricks command line tool.
Go to your terminal where you have installed the CLT.

1. add scope in databricks

Step 1: Creating a New Scope
scope name that make sense to yourself, where token will live

databricks secrets create-scope --scope <scope-name>

Step 2: Pushing Token to Scope as the key for the scope

databricks secrets put --scope <scope-name> --key <key-name>

Step 3: Access token in Databricks Notebook

dbutils.secrets.get(scope=<scope-name>, key=<key-name>)

if you try to print out the key obtained by dbutils in the databricks notebook, it will be something that doesn’t make sense.
This is expected behavior to protect the key; Just define some variable to hold the key and use in later operations that will expect the key.

2. Managing Scope - Giving Scope Access to Someone Else

check what users have access to scope:

databricks secrets list-acls --scope <name-of-scope>

Now give access to other users:

databricks secrets put-acl --scope <name-of-scope> --principal <email-of-user>

Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC