Code Monkey home page Code Monkey logo

Comments (7)

twpayne avatar twpayne commented on July 21, 2024

I would like to have a template option where I can call SOPS, and it's correspondent key to get the value, something like {{ sops "apis.openai" }} and return the value from the YAML, or JSON.

Are you sure that this is possible with SOPS? I haven't used SOPS, but from looking at its README.md, it looks like SOPS can only handle whole files and cannot decrypt individual secrets.

Specifically, if you have {{ sops "apis.openai" }} in your template, what command should chezmoi run to get the secret?

from chezmoi.

mhalano avatar mhalano commented on July 21, 2024

You're right. SOPS decrypt all the file. Maybe we could have a secretYAML, similar to secretJSON, that could parse the value?
If this isn't possible, we can still have a .sops file that runs sops -d <filename>.

from chezmoi.

twpayne avatar twpayne commented on July 21, 2024

There's already a fromYaml template function so you can set the secret.command chezmoi configuration variable to sops and then do something like:

{{ (secret "-d" "my-sops-file.yaml" | fromYaml).apis.openai }}

from chezmoi.

mhalano avatar mhalano commented on July 21, 2024

Understood. Nice to know. Maybe then we could just implement the support for .sops files?

from chezmoi.

twpayne avatar twpayne commented on July 21, 2024

Understood. Nice to know. Maybe then we could just implement the support for .sops files?

That would require re-implementing sops, so no.

Given that you can use the above example in your templates, or call the sops binary from a run_ script, I'll close this issue as not planned.

from chezmoi.

luismanson avatar luismanson commented on July 21, 2024

Hi, i just got here looking to do the same, Im looking to use encrypted variable stored in my dotfiles.

For what I've been reading, there is no direct support for this however looking at this issue I've comeup with a small change to what you proposed:
{{- $secret_vars:= (joinPath .chezmoi.sourceDir ".chezmoi_vars.yaml.age" | include | decrypt |fromYaml) -}}

my idea is to be able to use (for example) "{{ .secret_vars.mypassword }}" in a template.

is this ok?
I've also noticed I need to place this snippet on top of every template, can this be done globally and define these vars upon chezmoi execution ?

thanks!

from chezmoi.

twpayne avatar twpayne commented on July 21, 2024

is this ok?

Yes-ish. It works, but you're effectively writing your own password manager at this point, one that stores all your secrets in an encrypted YAML file.

I've also noticed I need to place this snippet on top of every template, can this be done globally and define these vars upon chezmoi execution ?

No, this cannot be done globally (unless you want to store your secrets unencrypted in your chezmoi config file).

from chezmoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.