Dev.to Security 🔐 Cybersecurity 👁 2 📖 7 min read

Unity Catalog Secrets vs Databricks Secret Scopes: Which Is More Secure?

When building ETL pipelines in Databricks, we frequently work with sensitive information such as database passwords, API keys, access tokens, and application credentials. But where should we store these credentials? Sh

Unity Catalog Secrets vs Databricks Secret Scopes: Which Is More Secure?

When building ETL pipelines in Databricks, we frequently work with sensitive information such as database passwords, API keys, access tokens, and application credentials.

But where should we store these credentials?

Should we use traditional Databricks Secret Scopes or move towards Unity Catalog Secrets?

Both approaches help protect sensitive information, but they have different access-control mechanisms, governance capabilities, and security models.

In this article, we will explore both approaches with practical Python examples, understand how to retrieve multiple secrets using a for loop, and compare which approach is more secure for production data engineering workloads.

1. Why Do We Need Secret Management?

Consider this example:

username = "admin"
password = "my_password123"
api_key = "123456789abcdef"

Storing credentials directly in notebooks is risky.

These credentials might accidentally become exposed through:

  • Notebook sharing
  • Git repositories
  • Logs and debugging statements
  • Shared development environments

Instead, we should store sensitive information securely and retrieve it only when required.

Databricks provides two approaches:

  1. Workspace Secret Scopes
  2. Unity Catalog Secrets

2. Databricks Workspace Secret Scopes

Databricks Secret Management allows us to store sensitive information using secret scopes.

A secret scope is a collection of key-value pairs.

For example:

prod_scope
    |
    |--- db_username
    |--- db_password
    |--- api_key
    |--- client_secret

Here:

  • prod_scope is the secret scope.
  • db_username is the secret key.
  • The actual username is the secret value.

Step 1: Create a secret scope

databricks secrets create-scope prod_scope

Step 2: Add secrets

databricks secrets put-secret prod_scope db_username

databricks secrets put-secret prod_scope db_password

databricks secrets put-secret prod_scope api_key

Step 3: Retrieve secrets using Python

We can use dbutils.secrets.get().

username = dbutils.secrets.get(
    scope="prod_scope",
    key="db_username"
)

password = dbutils.secrets.get(
    scope="prod_scope",
    key="db_password"
)

Now we can use these credentials in our ETL pipelines without hardcoding them.

Step 4: Retrieve multiple secrets using a for loop

What if our application requires multiple credentials?

We can first list the available secret metadata.

secret_list = dbutils.secrets.list("prod_scope")

for secret in secret_list:
    print(secret.key)

Example output:

db_username
db_password
api_key
client_secret

Now retrieve the values:

secrets_dict = {}

for secret in secret_list:

    secret_value = dbutils.secrets.get(
        scope="prod_scope",
        key=secret.key
    )

    secrets_dict[secret.key] = secret_value

Access individual values:

username = secrets_dict["db_username"]
password = secrets_dict["db_password"]
api_key = secrets_dict["api_key"]

Important: The list() operation returns secret metadata, not actual secret values. The get() operation requires appropriate READ permission.

Avoid printing secrets_dict, as it contains sensitive values.

Who can access Workspace Secrets?

Workspace Secret Scopes provide three main permission levels:

Permission Access
READ Read secrets in the scope
WRITE Add, update, and delete secrets
MANAGE Manage the scope and its permissions

The important limitation is that permissions are applied at the scope level.

For example:

prod_scope
    |
    |--- db_password
    |--- api_key
    |--- client_secret

If a developer receives READ permission on prod_scope, they can read all the secrets within that scope.

You cannot grant access to only db_password while restricting the other secrets within the same scope.

This is one of the major limitations of workspace secret scopes.

3. Unity Catalog Secrets

Unity Catalog Secrets provide another way to manage sensitive information.

Unlike workspace secret scopes, Unity Catalog Secrets are governed securable objects.

They follow a three-level namespace:

catalog.schema.secret

For example:

production.api_credentials.client_secret

Here:

  • production is the catalog.
  • api_credentials is the schema.
  • client_secret is the secret name.

The main advantage is centralized governance and more granular permissions.

Step 1: Create a catalog and schema

CREATE SCHEMA IF NOT EXISTS production.api_credentials;

Step 2: Create a Unity Catalog secret

Secrets can be created using Catalog Explorer or the Unity Catalog Secrets REST API.

An illustrative API request body:

{
    "catalog_name": "production",
    "schema_name": "api_credentials",
    "name": "client_secret",
    "value": "your_actual_secret_value"
}

Never hardcode the actual secret value into a notebook or Git repository.

Step 3: Grant permissions

Unity Catalog supports privileges such as:

  • USE CATALOG
  • USE SCHEMA
  • READ SECRET
  • WRITE SECRET
  • CREATE SECRET

For example:

GRANT USE CATALOG
ON CATALOG production
TO `data_engineers`;

GRANT USE SCHEMA
ON SCHEMA production.api_credentials
TO `data_engineers`;

GRANT READ SECRET
ON SECRET production.api_credentials.client_secret
TO `data_engineers`;

This allows authorized users to read the specified secret.

Step 4: Retrieve a secret using Python

client_secret = dbutils.secrets.get(
    catalog="production",
    schema="api_credentials",
    key="client_secret"
)

Notice the difference:

Workspace Secret Scope:

dbutils.secrets.get(
    scope="prod_scope",
    key="db_password"
)

Unity Catalog Secret:

dbutils.secrets.get(
    catalog="production",
    schema="api_credentials",
    key="client_secret"
)

The same utility is used, but the way we identify the secret changes.

Step 5: Retrieve multiple Unity Catalog Secrets using a for loop

First, list the available secret metadata:

secret_list = dbutils.secrets.list(
    catalog="production",
    schema="api_credentials"
)

for secret in secret_list:
    print(secret.key)

Example output:

client_secret
api_key
db_username
db_password

Now retrieve the values:

secrets_dict = {}

for secret in secret_list:

    secret_value = dbutils.secrets.get(
        catalog="production",
        schema="api_credentials",
        key=secret.key
    )

    secrets_dict[secret.key] = secret_value

Access the credentials:

client_secret = secrets_dict["client_secret"]
api_key = secrets_dict["api_key"]
username = secrets_dict["db_username"]
password = secrets_dict["db_password"]

Important: Unity Catalog can return metadata for secrets that the current user cannot read. Therefore, listing a secret does not automatically grant permission to retrieve its value.

For production applications, I recommend retrieving only the specific secrets required by the application rather than attempting to read every secret in a schema.

4. Who Can Read Secrets in Unity Catalog?

This is one of the most important differences between the two approaches.

Consider the following structure:

production
    |
    |--- api_credentials
           |
           |--- client_secret
           |--- api_key
           |--- db_password

Suppose we have three teams:

Team Required access
Data Engineering API key
Application Team Client secret
Database Team Database password

With workspace secret scopes, granting READ permission to the scope exposes all secrets within that scope to the authorized user.

With Unity Catalog, we can grant READ SECRET on individual secrets.

For example:

GRANT READ SECRET
ON SECRET production.api_credentials.api_key
TO `data_engineers`;
GRANT READ SECRET
ON SECRET production.api_credentials.client_secret
TO `application_team`;
GRANT READ SECRET
ON SECRET production.api_credentials.db_password
TO `database_team`;

Each team can receive access to only the credentials it needs.

The required parent privileges, including USE CATALOG and USE SCHEMA, must also be available.

How can we check permissions?

For Unity Catalog:

SHOW GRANTS ON SECRET
production.api_credentials.api_key;

For Workspace Secret Scopes:

databricks secrets list-acls prod_scope

This helps administrators review who has access to sensitive credentials.

5. Workspace Secret Scopes vs Unity Catalog Secrets

Let's compare both approaches.

Feature Workspace Secret Scopes Unity Catalog Secrets
Organization Scope and key Catalog, schema and secret
Availability Workspace-level Metastore-level governance
Access control Scope-level ACL Secret-level privileges
Individual secret permissions No Yes
Centralized governance Limited Yes
List secret metadata Yes Yes
Read secret values With READ permission With READ SECRET or ownership
Write permissions WRITE WRITE SECRET
Audit integration Workspace-level Unity Catalog audit integration
Fine-grained permissions No Yes

The biggest difference is the permission model.

Workspace Secret Scopes control access at the scope level, whereas Unity Catalog Secrets support more granular access control.

6. Which Is More Secure?

My recommendation is Unity Catalog Secrets for enterprise environments where centralized governance and granular access control are important.

Let's understand why.

Scenario 1: Workspace Secret Scope

Suppose you have five secrets in one production scope.

A developer needs access to only one API key.

However, granting READ permission on the scope gives that developer access to all five secrets.

This increases the risk of unnecessary credential exposure.

Scenario 2: Unity Catalog Secrets

Now consider the same scenario using Unity Catalog.

You can grant READ SECRET permission on only the API key.

The developer does not automatically receive permission to read the other secrets.

This follows the principle of least privilege.

Security comparison

Unity Catalog Secrets provide stronger access governance than workspace secret scopes.

However, neither approach makes secrets completely inaccessible to authorized users.

Once someone has permission to read a secret, they can retrieve its value through supported interfaces.

Secret redaction in notebook output is helpful, but it is not a complete security boundary.

7. Security Best Practices

Regardless of which approach you choose, follow these practices:

1. Never hardcode credentials

Avoid storing passwords and API keys directly in notebooks.

2. Follow the principle of least privilege

Grant access only to users, groups, and service principals that need it.

3. Separate secrets by application and environment

For example:

production
    |
    |--- orders_app
    |      |--- api_key
    |      |--- db_password
    |
    |--- customer_app
           |--- client_secret
           |--- api_token

4. Avoid retrieving every secret unnecessarily

Only retrieve the credentials required by your application.

5. Never print secret values

Avoid displaying sensitive credentials in notebook output.

6. Review access permissions regularly

Check which users and service principals can access production secrets.

7. Rotate credentials regularly

Establish an appropriate credential rotation strategy.

8. Avoid committing credentials to Git

Never push actual secret values into GitHub, GitLab, or other source control repositories.

Conclusion

Both Databricks Workspace Secret Scopes and Unity Catalog Secrets help protect sensitive information used in data engineering workloads.

However, their governance models are different.

Workspace Secret Scopes are simple to implement and useful for individual workspace requirements.

Unity Catalog Secrets provide centralized governance, metastore-level availability, and more granular permissions.

For modern enterprise Databricks implementations, I would recommend evaluating Unity Catalog Secrets first, especially when multiple teams need access to different credentials.

As data engineers, our responsibility is not limited to building efficient ETL pipelines. We must also ensure that the credentials used by those pipelines are properly protected.

Official Documentation

  1. Databricks Secret Management
  2. Unity Catalog Secrets
  3. Workspace Secret Scopes
  4. Databricks Utilities Reference
📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.