- Use
op runto pass environment variables from a 1Password Environment - Use
op runto load secrets into the environment. - Use
op readto read secrets. - Use
op injectto load secrets into a config file. - Use
op plugin runto load secrets using a shell plugin.
Requirements
Before you can use 1Password CLI to load secrets into your scripts, you’ll need to:- Sign up for 1Password.
- Install 1Password CLI.
- Store the secrets you need for your script in your 1Password account.
Use op run to pass environment variables from a 1Password Environment Beta
Beta featureTo use
op run with 1Password Environments, you’ll need to install the latest beta build of 1Password CLI, version 2.33.0-beta.02 or later.op run to pass environment variables stored in a 1Password Environment to an application or script at runtime.
1Password CLI runs the application or script in a subprocess with the environment variables stored in your 1Password Environment provisioned for the duration of the process.
Use op run to pass secrets using secret references
You can replace the plaintext secrets in your environemnt files with secret reference URIs that reference where your project secrets are stored in your 1Password account, then use op run to load the corresponding secrets from 1Password and pass them to your script as environment variables at runtime.
Learn more about loading secrets into the environment.
Use op read to read secrets
You can use op read with secret references directly in your script or with environment variables.
Directly in your script
With this method, secrets are only passed to the single command that includes the secret reference. For example, to replace your Docker username and password with secret references in a command to log in to Docker:yourscript.sh
With environment variables
You can also include a command to set environment variables toop read and secret references in your script.
For example, if you supply an AWS command in your script with secrets using the AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID environment variables, your script might look like this:
yourscript.sh
Use op inject to load secrets into a config file
If your script uses a configuration file, you can template the config file with secret references, then use op inject to pass the config file with the resolved secrets to your script at runtime.
This allows you to check config files into source control and keep them in sync throughout developer workstations, CI, and production servers. And you can include template variables within the secret references to load different sets of secrets for different environments.
Learn how to load secrets into config files.
Use op plugin run to load secrets using a shell plugin
If your script runs interactively and each person using the script authenticates with their own personal token, you can minimize the configuration required in advance of using the script with a 1Password Shell Plugin. Shell plugins prompt each user to select their credentials when the script is executed.
Each person using the script will be prompted to configure when their credentials should be used to authenticate. To make sure the credentials they selected will also be used for future invocations of the script, they can configure their credentials as a global or directory default.
To use a shell plugin to authenticate an individual command, wrap the command in op plugin run. For example, to use the AWS shell plugin to provide an AWS Access Key and Secret Key ID to the sts get-caller-identity command:
yourscript.sh
aws command in the script.
yourscript.sh