Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Add decrypt and encrypt template functions #1521

Merged
merged 1 commit into from
Oct 11, 2021

Conversation

twpayne
Copy link
Owner

@twpayne twpayne commented Oct 11, 2021

cc @azmodude the decrypt function will help you only encrypt the sensitive parts of files.

I don't think the encrypt function will be used much, but it's there for completeness.

@twpayne twpayne force-pushed the encryption-template-funcs branch from e30e2e1 to 779ddd3 Compare October 11, 2021 18:22
@twpayne twpayne force-pushed the encryption-template-funcs branch from 779ddd3 to e6e591a Compare October 11, 2021 18:39
@twpayne twpayne merged commit 92ce33c into master Oct 11, 2021
@twpayne twpayne deleted the encryption-template-funcs branch October 11, 2021 19:33
@gorschu
Copy link

gorschu commented Oct 12, 2021

You, Sir, are an absolute legend! Thanks for this feature originating from a Tweet I did not even mention you properly in. :)

Did some tests just now, works beautifully by dropping encrypted include files in my source state, including and decrypting them via templates and ignoring them in my .chezmoiignore file at the same time to never leave source state.
This also opens up a lot of possibilities for me having an encrypted include to my .chezmoi.toml.tmpl and setting some private variables there to be later inserted into files.

Thanks again!

@twpayne
Copy link
Owner Author

twpayne commented Oct 12, 2021

Thanks for the kind words!

This also opens up a lot of possibilities for me having an encrypted include to my .chezmoi.toml.tmpl and setting some private variables there to be later inserted into files.

Note that there might be a chicken-and-egg problem here: when running chezmoi init on a new machine, encryption will not initially be configured. Encryption will only be available once the config file has been written and re-read by chezmoi.

@gorschu
Copy link

gorschu commented Oct 12, 2021

Most deserved!

Note that there might be a chicken-and-egg problem here: when running chezmoi init on a new machine, encryption will not initially be configured. Encryption will only be available once the config file has been written and re-read by chezmoi.

Yup, stumbled upon that issue. What I am doing for now is I am writing a very basic chezmoi.toml in my bootstrapping script that sets everything up (fetch GPG key, install op, install chezmoi, ...) initially to include my encryption method and key. The subsequent 'real' chezmoi init is then able to pick that minimal config up and replace it with the full decrypted version of the file. Works quite well for me.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants