---
title: Workspace secret scopes
description: Create and manage workspace secret scopes, store and read secrets, set scope permissions, and understand how secret values are redacted.
canonical_url: https://docs.databricks.com/gcp/en/security/secrets/workspace-secret-scopes
---

# Workspace secret scopes

A workspace secret scope is a named collection of secrets in one workspace. Secret scope permissions control who can read, write, and manage the secrets in it. Permissions apply to the whole scope, not to individual secrets, so a user who can read one secret in a scope can read all of them. To compare workspace secret scopes with Unity Catalog secrets, see [Choose where to store a secret](https://docs.databricks.com/gcp/en/security/secrets/index.md#choose-where-to-store-a-secret).

To use a workspace secret scope:

1. Create a secret scope.
2. Add secrets to the scope.
3. Grant permissions on the scope.
4. Reference the secrets in your code, or in a Spark configuration property or environment variable. See [Use a secret in a Spark configuration property or environment variable](https://docs.databricks.com/gcp/en/security/secrets/secrets-spark-conf-env-var.md).

> [!WARNING]
>
> Workspace admins, secret creators, and users who have been granted permission can access and read Databricks secrets. Although Databricks attempts to redact secret values in notebook outputs, it is not possible to fully prevent these users from viewing secret contents. Always assign secret access permissions carefully to protect sensitive information.

## <a id="scopes" />Manage secret scopes

Databricks recommends aligning secret scopes to roles or applications rather than individuals.

Secret scopes are stored in an encrypted database owned and managed by Databricks.

After creating a secret scope, you can assign permissions to grant users access to read, write, and manage secret scopes.

### <a id="databricks-backed" />Create a secret scope

Create a secret scope with the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/index.md) (version 0.205 and above), the Databricks workspace UI, or the [Secrets API](https://docs.databricks.com/api/workspace/secrets).

Secret scope names:

* Must be unique within a workspace.
* Must consist of alphanumeric characters, dashes, underscores, `@`, and periods, and cannot exceed 128 characters.
* Are case insensitive.

Secret scope names are considered non-sensitive and are readable by all users in the workspace.

#### Databricks CLI

To create a scope using the Databricks CLI:

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

By default, scopes are created with MANAGE permission for the user who created the scope. After you have created a Databricks-backed secret scope, you can add secrets to it.

#### Databricks

1. Go to `https://<databricks-instance>#secrets/createScope`. Replace `<databricks-instance>` with the [workspace URL](https://docs.databricks.com/gcp/en/workspace/workspace-details.md#workspace-url) of your Databricks deployment. This URL is case sensitive. For example, `scope` in `createScope` must use an uppercase `S`.

2. Enter the name of the secret scope. Secret scope names are case insensitive.

3. In **Manage Principal** select **Creator** or **All workspace users** to specify which users have the MANAGE permission on the secret scope.

   The MANAGE permission allows users to read, write, and grant permissions on the scope. Your account must have the [Premium plan](https://databricks.com/product/pricing/platform-addons) to choose **Creator**.

4. Click **Create**.

5. Use the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/index.md) `databricks secrets list-scopes` command to verify that the scope was created successfully.

### <a id="list-scopes" />List secret scopes

To list the existing scopes in a workspace using the CLI:

```bash
databricks secrets list-scopes
```

You can also list secret scopes using the [Secrets API](https://docs.databricks.com/api/workspace/secrets).

### <a id="delete-a-secret-scope" />Delete a secret scope

Deleting a secret scope deletes all secrets and ACLs applied to the scope. To delete a scope using the CLI, run the following:

```bash
databricks secrets delete-scope <scope-name>
```

You can also delete a secret scope using the [Secrets API](https://docs.databricks.com/api/workspace/secrets).

## <a id="secrets" />Manage secrets

A secret is a key-value pair that stores sensitive material using a key name that is unique within a secret scope.

### <a id="create-a-secret" />Create a secret

Create a secret with the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/index.md) (version 0.205 and above), the [Databricks SDK for Python](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace/secrets.html) in a notebook, or the [Secrets API](https://docs.databricks.com/api/workspace/secrets). Secret names are case insensitive.

#### Databricks CLI

When you create a secret in a Databricks-backed scope, you can specify the secret value in one of the following ways:

* Pass the value in the `string_value` field of a JSON request body with the `--json` flag.
* Specify the value as a string with the `--string-value` flag.
* Input the secret when prompted interactively (single-line secrets).
* Pass the secret using standard input (multi-line secrets).

For example:

```bash
databricks secrets put-secret --json '{
  "scope": "<scope-name>",
  "key": "<key-name>",
  "string_value": "<secret>"
}'
```

If you are creating a multi-line secret, you can pass the secret using standard input. For example:

```bash
(cat << EOF
this
is
a
multi
line
secret
EOF
) | databricks secrets put-secret <scope-name> <key-name>
```

#### Databricks SDK for Python

```python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

w.secrets.put_secret("<secret_scope>","<key-name>",string_value ="<secret>")
```

### <a id="read-a-secret" />Read a secret

Read a secret with the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/index.md) (version 0.205 and above), or in a notebook with [Secrets utility (dbutils.secrets)](https://docs.databricks.com/gcp/en/dev-tools/databricks-utils.md#dbutils-secrets).

#### Databricks CLI

To read the value of a secret using the Databricks CLI, you must decode the base64 encoded value. You can use `jq` to extract the value and `base64 --decode` to decode it:

```bash
databricks secrets get-secret <scope-name> <key-name> | jq -r .value | base64 --decode
```

#### Secrets utility (dbutils.secrets)

```python
password = dbutils.secrets.get(scope = "<scope-name>", key = "<key-name>")
```

### <a id="list-secrets" />List secrets

To list secrets in a given scope:

```bash
databricks secrets list-secrets <scope-name>
```

The response shows metadata about the secrets, such as their key names. To list this metadata in a notebook or job, use [Secrets utility (dbutils.secrets)](https://docs.databricks.com/gcp/en/dev-tools/databricks-utils.md#dbutils-secrets). For example:

```python
dbutils.secrets.list('my-scope')
```

### <a id="delete-a-secret" />Delete a secret

To delete a secret from a scope with the Databricks CLI:

```bash
databricks secrets delete-secret <scope-name> <key-name>
```

You can also use the [Secrets API](https://docs.databricks.com/api/workspace/secrets).

## <a id="permissions" />Manage secret scope permissions

By default, the user who creates a secret scope has the `MANAGE` permission on it, which lets them read secrets in the scope, write secrets to it, and manage its permissions.

Manage secret scope permissions with the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/index.md) (version 0.205 and above) or the [Secrets API](https://docs.databricks.com/api/workspace/secrets). For secret permission levels, see [Secret ACLs](https://docs.databricks.com/gcp/en/security/auth/access-control/index.md#secrets).

### <a id="grant-a-user-permissions-on-a-secret-scope" />Grant a user permissions on a secret scope

> [!NOTE]
>
> Granting permissions on a secret scope requires the [Premium plan](https://databricks.com/product/pricing/platform-addons).

To grant a user permissions on a secret scope using the Databricks CLI:

```bash
databricks secrets put-acl <scope-name> <principal> <permission>
```

Making a put request for a principal that already has an applied permission overwrites the existing permission level.

The `principal` field specifies an existing Databricks principal. A user is specified using their email address, a service principal using its `applicationId` value, and a group using its group name. For more information, see [Principal](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-principal.md).

For example, to let a group such as `datascience` read the secrets in a scope, grant it `READ`:

```bash
databricks secrets put-acl <scope-name> <group> READ
```

### <a id="view-secret-scope-permissions" />View secret scope permissions

To view all secret scope permissions for a given secret scope:

```bash
databricks secrets list-acls <scope-name>
```

To get the secret scope permissions applied to a principal for a given secret scope:

```bash
databricks secrets get-acl <scope-name> <principal>
```

If no ACL exists for the given principal and scope, this request fails.

### <a id="delete-a-secret-scope-permission" />Delete a secret scope permission

To delete a secret scope permission applied to a principal for a given secret scope:

```bash
databricks secrets delete-acl <scope-name> <principal>
```

## <a id="redaction" />Secret redaction

Storing credentials as Databricks secrets helps protect them when you run notebooks and jobs. However, you can still accidentally print a secret to standard output buffers or display the value during variable assignment.

To prevent this, Databricks attempts to redact secret values that are read using `dbutils.secrets.get()` and referenced in a Spark configuration property. When displayed, the secret values are replaced with `[REDACTED]`.

For example, if you set a variable to a secret value using `dbutils.secrets.get()` and then print that variable, that variable is replaced with `[REDACTED]`.

> [!WARNING]
>
> Redaction applies only to literal secret values. The secret redaction functionality does not prevent deliberate and arbitrary transformations of a secret literal. To control secrets, use [access control lists](https://docs.databricks.com/gcp/en/security/auth/access-control/index.md) to limit permissions to run commands. This prevents unauthorized access to shared notebook contexts.

### <a id="secret-redaction-in-sql" />Secret redaction in SQL

Databricks attempts to redact all SQL data query language (DQL) commands that invoke the secret function, including referenced views and user-defined functions. When the `secret` function is used, the output is replaced with `[REDACTED]` where possible. Like notebook redaction, this only applies to literal values, not to transformed or indirectly referenced secrets.

For SQL data manipulation language (DML) commands, Databricks allows secret lookups if the secret is considered safe. For example, a secret is safe when wrapped in a cryptographic function such as `sha()` or `aes_encrypt()`, which prevent raw values from being stored unencrypted.

### <a id="secret-validation-in-sql" />Secret validation in SQL

Databricks also applies validation to block SQL DML commands that could result in unencrypted secrets being saved to tables. The query analyzer attempts to identify and prevent these scenarios, which helps avoid accidental storage of sensitive information in plaintext.

## <a id="additional-resources" />Additional resources

| Resource                                                                                                                                                    | Description                                                                                     |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [Secret management](https://docs.databricks.com/gcp/en/security/secrets/index.md)                                                                           | Compare workspace secret scopes with Unity Catalog secrets, and see where you can use each one. |
| [Use a secret in a Spark configuration property or environment variable](https://docs.databricks.com/gcp/en/security/secrets/secrets-spark-conf-env-var.md) | Reference secrets in Spark configuration properties and environment variables.                  |
