At the start of the month I wrote a blog post about how to use 1Password for managing all of your secrets on the command line: How to use 1Password for Secrets in ~/.bashrc or ~/.zshrc. After 1 month of using this approach in the wild, I have a few updates.
My primary problem was that it was very annoying to authenticate every time I opened a new terminal session. But… liked the idea of using 1Password to store all of my secrets, and not copying and pasting secrets into my startup scripts.
After some experimentation, I found a compromise that works for me.
- In the previous version, the
op inject
command was run every time I opened a new terminal session, which required me to authenticate every session. - Now, the
op inject
command is only run when thezsh/secrets-out.zsh
file does not exist, or when thezsh/secrets-in.zsh
file has changed. Only in one of those two circumstances will I be prompted to authenticate.
This approach does introduce a new downside however. There is now a file on my disk "${DOTFILES_DIR}/zsh/secrets-out.zsh"
that stores secrets in plain text (similar to what I did before). But now that I am using 1Password to manage this file I do not need to manually update this file.
I also created an alias so I can manually update the secrets if I need to. For example if I were to change a password in 1Password.