Geek Logbook

Tech sea log book

Set secrets in Databricks

If you add as plain text the user and password of your connections you are making a mistake that it’s easy to solve. In order to solve

  • You have to install the data bricks cli with pip:
pip install databricks-cli
  • You have to configure your CLI
databricks configure --token

Now you can use the CLI and it should be connected to your instances. So, now we can run the commands to set the keys.

  • Create a Secret Scope
databricks secrets create-scope --scope <scope-name>

For example, if I want to create a secret scope for my user i can create the following

databricks secrets create-scope --scope jinomichelaque

If you inside your scope want to put a key you have to run:

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

Following the example before if I want to put my snowflake user I should run

databricks secrets put --scope jinomichelaque --key snowflakeuser

After that you can add your user:

You have to do the same in order to add your password:

databricks secrets put --scope jinomichelaque --key snowflakepassword

After put your user and password you can see if you have added it properly with the following command:

databricks secrets list --scope jinomichelaque

And you can call the value for the key stores using

SNOWFLAKE_USER = dbutils.secrets.get("jinomichelaque", "snowflakeuser")
SNOWFLAKE_PASSWORD = dbutils.secrets.get("jinomichelaque", "snowflakepassword")

Sources:

Leave a Reply

Your email address will not be published. Required fields are marked *.