Requirements
Before you can use 1Password to secure your config files, you’ll need to:- Sign up for 1Password.
- Install 1Password CLI.
- Store the secrets you want to provision in your 1Password account.
Step 1: Get secret references
You can get secret references in several ways:- With the 1Password desktop app: Copy secret references from the app.
- With 1Password for VSCode: Insert secret references from 1Password as you edit code.
- With 1Password CLI: Get secret references for one or multiple fields with
op item get. - Use the secret reference syntax rules to write secret references manually.
Step 2: Use secret references in your config file
Replace the plaintext secrets in your config file with the appropriate secret references, following the template syntax. For example, if you start with a config file that looks like this:config.yml
username and password secrets on the mysql item in the prod vault, you would end up with this templated config file:
config.yml.tpl
Step 2: Inject the secrets
To load secrets from the config file and provision them at runtime, useop inject to inject the secrets directly into your production environment. For example:
config.yml, you’ll see the secret references replaced with the plaintext secrets they reference.
The config file template is stored together with the code in source control, so that every developer can see the structure of the file.
Make sure to delete the resolved config file when you no longer need it.
Step 3: Differentiate between environments
We highly recommend you organize your 1Password items in the same way across all of your environments. For example:app/dev/db/password and app/prod/db/password.
If you do this, you can use variables in your template file to switch to a different set of secrets. You can have variables for your environment, stage, region, or anything else. For example:
config.yml.tpl
APP_ENV variable when you inject into the template, using the Template Syntax:
- Bash, Zsh, sh, fish
- PowerShell
Optional: Use op inject in production
Now that the application works with the right configuration locally, you can use 1Password CLI to provision secrets in production environments.
To do this, you’ll first need to:
- Install 1Password CLI 2 in your production environment.
- Set up a Secrets Automation workflow.
- Deploy 1Password Connect Server and make it accessible to your production environment.
OP_CONNECT_HOST and OP_CONNECT_TOKEN environment variables to your Connect instance’s credentials in your production environment.
You can now move your secrets to config files and have them readily accessible with op inject.
The following commands can be used with a Connect server:
op runop injectop readop item get