1Password Usage#
This document outlines how the 1Password CLI is integrated with chezmoi for managing secrets and sensitive configuration data in this dotfiles setup.
Overview#
1Password is the primary secrets manager for this dotfiles configuration. chezmoi is configured to use the 1Password CLI (op) to fetch secrets, which are then injected into configuration files via templates.
Prerequisites#
- 1Password Account: You need an active 1Password account.
- 1Password CLI Installed: The
chezmoiquick start process (see mainREADME.md) handles the installation of theopCLI tool. - Initial Sign-in: As detailed in the main
README.md, after the initialchezmoi apply, you must sign in to the 1Password CLI:
You may need to runeval $(op signin)chezmoi applyagain after this initial sign-in if some secrets were not provisioned.
Storing and Referencing Secrets with Chezmoi#
chezmoi utilizes its template functions to interact with the op CLI. Secrets are stored in your 1Password vaults, and chezmoi templates reference them, typically using the onepassword template function or by directly calling op.
General Approach#
- Store Secret in 1Password: Add your secret (e.g., API key, token, password) to your 1Password vault.
- Use clear, consistent item names.
- For multi-field items, note the field names you want to retrieve.
- Reference in Chezmoi Template: In your
chezmoitemplate file (e.g.,private_dot_config/some_app/config.toml.tmpl), use achezmoitemplate function to fetch the secret.
Example: Storing an API Key#
- In 1Password:
- Create a "Login" or "API Credential" item named, for example,
My App API Key. - Store the API key in the
passwordfield or a custom field.
- Create a "Login" or "API Credential" item named, for example,
- In
chezmoitemplate:
(Note: The exact# Example: .config/my_app/credentials.tmpl # api_key = "{{ (onepasswordRead "op://Personal/My App API Key/password").stdout }}"onepasswordReadsyntax or alternativeopcalls might vary based on your specificchezmoihelper functions or direct CLI usage in templates.)
Storing GPG Git Signing Key ID#
To securely store and retrieve your GPG key ID for Git commit signing:
- In 1Password:
- Create a "Secure Note" or "Login" item, perhaps named
Git ConfigurationorMy GPG Key. - Add a custom field (e.g., named
git_signingkey_id) and paste your GPG key ID into its value.
- Create a "Secure Note" or "Login" item, perhaps named
- In
chezmoitemplate (e.g.,dot_gitconfig.tmpl):
(Adjust the item name and path as per your 1Password setup.)# Example for .gitconfig.tmpl [user] name = {{ .name | quote }} email = {{ .email | quote }} # signingkey = "{{ (onepasswordRead "op://Personal/Git Configuration/git_signingkey_id").stdout }}"
Common chezmoi Template Functions for 1Password#
(This section can be expanded with specific examples of onepassword functions or custom op CLI wrappers you use in your templates.)
onepassword "item_name"onepasswordDetails "item_name"onepasswordRead "op_item_path"(e.g.,op://Vault/ItemName/fieldname)
Refer to your chezmoi configuration and the official chezmoi documentation for the exact functions and syntax available and preferred in your setup.
Troubleshooting#
- Authentication Issues: Ensure
eval $(op signin)has been run and your session is active. - Item Paths: Double-check the 1Password item names, vault names, and field names used in your templates. The
op item get "Item Name" --fields label="Field Name"command can be useful for verifying. - Chezmoi Apply: Remember to run
chezmoi applyto propagate changes after updating templates or 1Password items.