Skip to main content

AWS Secrets Manager secrets in Unity Catalog

Beta

This feature is in Beta.

Back a Unity Catalog schema with AWS Secrets Manager to use your AWS secrets in notebooks, jobs, and UDFs without copying them. The values stay in AWS, and Unity Catalog privileges control who can read or use each secret.

To compare external secrets with Databricks-managed secrets and workspace secret scopes, see Choose where to store a secret.

How external secrets work​

A schema is backed by one connection to your cloud secret manager. Two independent controls decide who can use a secret. The service credential's permissions in your secret manager decide which secrets Unity Catalog can import and read, and Unity Catalog privileges decide which principals can use them.

The service credential's IAM role and each connection's tag filter decide which AWS secrets each schema imports. UC privileges decide who can use them.

After you back a schema, external secrets behave as follows:

  • Each read fetches the current value: A value you rotate in your secret manager takes effect on the next read, with no change in Databricks. Code that already holds a value keeps it until it reads the secret again. Retrieved values may be cached on the compute that requested them, as with other secrets.
  • Manage secrets in your secret manager: Create, update, rotate, and delete secrets there. They are read-only in Unity Catalog. When you permanently delete a secret in your secret manager, Databricks removes the Unity Catalog secret, including its permissions and tags.
  • Listing imports new secrets: Listing the schema starts an asynchronous import. A secret added to or removed from your secret manager appears in Unity Catalog after a later list, which can take a few minutes for large stores. You can read a secret by name before it appears in a list.
  • Audit logs record both sides: Unity Catalog audit logs record the Databricks principal that read a secret. Cloud-side logs attribute access to the service credential.

Requirements​

  • Meet the requirements for Unity Catalog secrets.
  • The external secrets Beta must be enabled for your workspace. See Manage Databricks previews.
  • You need a Unity Catalog service credential and a Unity Catalog connection that uses it to authenticate to your secret manager. See Create service credentials and Create a connection.
  • To back the schema, you need USE CATALOG on the catalog, ownership of the schema or MANAGE on it, and USE CONNECTION on the connection. The schema must not contain any Databricks-managed secrets, so delete any before you back it.

Set up external secrets​

Create a service credential​

The connection authenticates to your secret manager with a Unity Catalog service credential.

  1. Create a service credential and its identity and access management (IAM) role, including the trust policy, as described in Create service credentials.

  2. Attach a permission policy that lets the role list and read your secrets. Replace <AWS-ACCOUNT-ID> and <AWS-IAM-ROLE-NAME> with your account ID and role name.

    To let the role read only secrets with a specific tag, use the following policy. secretsmanager:ListSecrets does not support resource-level permissions, so it applies to all secrets. The tag condition limits which values the role can read:

    JSON
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Sid": "ListSecrets",
    "Effect": "Allow",
    "Action": ["secretsmanager:ListSecrets"],
    "Resource": "*"
    },
    {
    "Sid": "ReadTaggedSecrets",
    "Effect": "Allow",
    "Action": ["secretsmanager:DescribeSecret", "secretsmanager:GetSecretValue"],
    "Resource": "*",
    "Condition": {
    "StringEquals": { "secretsmanager:ResourceTag/app": "orders" }
    }
    },
    {
    "Sid": "SelfAssume",
    "Effect": "Allow",
    "Action": ["sts:AssumeRole"],
    "Resource": ["arn:aws:iam::<AWS-ACCOUNT-ID>:role/<AWS-IAM-ROLE-NAME>"]
    }
    ]
    }

    To let the role read every secret in the account and region, remove the Condition block.

Create a connection​

Create a Unity Catalog connection that uses the service credential and points to your secret manager. You need CREATE CONNECTION on the metastore.

  1. In Catalog Explorer, click the + menu and select Create a connection.
  2. Enter a Connection name and select the AWS Secrets Manager connection type.
  3. Select the service credential, and set the AWS region. The secrets must be in this region.
  4. Optionally, add the tag_key and tag_value options. See Filter imported secrets by tag.
  5. Click Create.

To limit the schema to tagged secrets, add tag_key and, optionally, tag_value to the connection's options, for example "tag_key": "app", "tag_value": "orders". Only secrets with a matching tag are imported and readable:

  • If you set tag_key without tag_value, Unity Catalog imports every secret that has the tag key, whatever its value.
  • Matching is case-sensitive and exact.
  • A secret outside the filter is treated as not found, even when you read it by name.

Use the same tag in the IAM policy condition, so that the role can read exactly the secrets the filter imports. If the role can list a secret but can't read it, Unity Catalog imports the secret, but reads fail.

Back a schema with the connection​

  1. In Catalog Explorer, go to the schema.
  2. In the schema's details, find the external secrets manager setting and click Enable. Enable stays unavailable until the schema has no secrets.
  3. Select the connection you created, then confirm.

To point the schema at a different connection, click Edit. To return the schema to Databricks-managed storage, edit the schema and disable external secrets. Either change removes the previously imported secrets from the schema, including their permissions and tags.

Verify the setup​

To confirm that Unity Catalog can list and read your secrets, run the following in a notebook:

Python
# List the secrets in the schema. This also starts an import of new secrets.
dbutils.secrets.list(catalog="main", schema="orders_app")

# Read one secret by name
dbutils.secrets.get(catalog="main", schema="orders_app", key="example_secret")

If the list is empty, run it again after a few minutes. If a read fails, see Troubleshooting.

Secret names in Unity Catalog​

Unity Catalog imports an external secret only if its name meets these rules:

  • Names longer than 255 characters are not imported.
  • Names are case-insensitive. If two secrets differ only by case, Unity Catalog keeps the first one imported and ignores the rest.
  • . becomes : and / becomes |. Databricks recommends avoiding these characters in external secret names.

To read a secret before it appears in a list, use its name with these substitutions.

For example, to read an AWS secret named myOrg/mySecret.v3, run the following:

Python
dbutils.secrets.get(catalog="main", schema="orders_app", key="myOrg|mySecret:v3")

Troubleshooting​

  • A secret is listed, but reading it fails: The role can list the secret but can't read its value. Add secretsmanager:GetSecretValue and secretsmanager:DescribeSecret for that secret to the role's policy, and check that its IAM tag condition matches the connection's tag filter.
  • A secret is not found when you read it by name: The secret is outside the connection's tag filter, or its name needs the naming substitutions.
  • A new secret doesn't appear: List the schema, wait a few minutes, and list it again. Check the naming restrictions and the schema quota.
  • Some secrets never appear: A schema holds up to 1,000 secrets. When your secret manager has more, Unity Catalog imports the oldest first by creation date and skips the rest. Expose only the secrets you need in each schema. See Group secrets by who needs them.

Limitations​

In addition to the limitations that apply to all Unity Catalog secrets, externally backed secrets have the following limitations:

  • Cross-cloud access is not supported: Back schemas with the secret manager native to the workspace's cloud.
  • Read latency and cost: Every read fetches the value from the external secret manager, which adds latency and can incur cloud provider costs.
note

If the external secret manager that backs a schema is in a different region from the metastore or workspace that reads it, secret values and their metadata cross regions. Databricks does not guarantee in-region processing of external secrets.

External secret names and values can contain personal data. You are responsible for keeping personal data out of them unless your use case requires it.

Additional resources​