🔐Interact with secrets

Managing your secrets with ZenML.

How to create a secret

To create a secret with a name <SECRET_NAME> and a key-value pair, you can run the following CLI command:

zenml secret create <SECRET_NAME> \

--<KEY_1>=<VALUE_1> \

--<KEY_2>=<VALUE_2>

# Another option is to use the '--values' option and provide key-value pairs in either JSON or YAML format.

zenml secret create <SECRET_NAME> \

--values='{"key1":"value2","key2":"value2"}'

Alternatively, you can create the secret in an interactive session (in which ZenML will query you for the secret keys and values) by passing the --interactive/-i parameter:

zenml secret create <SECRET_NAME> -i

For secret values that are too big to pass as a command line argument, or have special characters, you can also use the special @ syntax to indicate to ZenML that the value needs to be read from a file:

zenml secret create <SECRET_NAME> \

--key=@path/to/file.txt \

...

# Alternatively, you can utilize the '--values' option by specifying a file path containing key-value pairs in either JSON or YAML format.

zenml secret create <SECRET_NAME> \

--values=@path/to/file.txt

The CLI also includes commands that can be used to list, update and delete secrets. A full guide on using the CLI to create, access, update and delete secrets is available here.

Interactively register missing secrets for your stack

If you're using components with secret references in your stack, you need to make sure that all the referenced secrets exist. To make this process easier, you can use the following CLI command to interactively register all secrets for a stack:

zenml stack register-secrets [<STACK_NAME>]

The ZenML client API offers a programmatic interface to create, e.g.:

from zenml.client import Client

client = Client()

client.create_secret(

name="my_secret",

values={

"username": "admin",

"password": "abc123"