Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; the earlier path-expansion issue is fixed.
|
env_from accepts "sops:<path>" to load variables from a SOPS-encrypted .yaml, .yml, .json or .env file, decrypted with the sops CLI from the project packages, runx or the host PATH. - Values are injected verbatim and devbox.json env can reference them. - Decryption runs once per command; failures warn and empty the declared variables instead of keeping the host values. - Secrets are never written to the devbox shell rc file: they reach the shell through its process env and are re-exported by reference.
Fish runs config.fish and the shellrc even when not interactive, so it always gets the secrets by reference. The sops lookup now starts with the profile and runx directories, as with OmitNixEnv the computed PATH already contains the host PATH.
6e28547 to
b9cbaac
Compare
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Instead of SOPS-specific support, could env_from accept exec: that prints a flat JSON object? sops becomes exec:sops decrypt --output-type json secrets.enc.yaml, and the process env, prompt handling, per-command cache and shell rc protections you built all still apply, without depending on one tool. e.g. {
"packages": ["sops@latest"],
"env": { "SOPS_AGE_KEY_FILE": "$PWD/.age/key.txt" },
"env_from": "exec:sops decrypt --output-type json secrets.enc.yaml"
}This would allow fetching secrets from any secret manager (later on we can figure out caching, perf etc). It would also allow combining non-secret env file and secrets. thoughts? |
Good idea, that's more flexible than a SOPS-only solution. I'll rework this branch to support exec:. |
env_from now accepts an "exec:<command>" source that prints a flat JSON object, as suggested in review, so any secret manager can be used. sops becomes "exec:sops decrypt --output-type json <file>". env_from also accepts an array of .env files and exec: commands, merged in order. Values from commands keep the secret handling: they are never written to disk and are passed to devbox shell by reference.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Done in 3ab2fbd: One trade-off: on failure we can't unset the keys anymore (we no longer know them), so the source is skipped with a warning and the other sources still apply. |
Summary
Adds two ways to load environment variables in
env_from, as suggested in review:exec:<command>runs a command that prints a flat JSON object. Any secret manager works, e.g.exec:sops decrypt --output-type json secrets.enc.yaml,exec:op ..., orexec:vault kv get -format=json ... | jq .data.data.env_fromaccepts a list of.envfiles andexec:commands, merged in order.devbox.jsonenvstill overrides everything. Existing string values keep working.{ "packages": ["sops@latest"], "env": { "SOPS_AGE_KEY_FILE": "$PWD/.age/key.txt" }, "env_from": [".env", "exec:sops decrypt --output-type json secrets.enc.yaml"] }How commands run:
sh -cin the project directory. It gets the project environment, including earlierenv_fromsources anddevbox.jsonenv.--pure).PATH, and invalid names or values are skipped with a warning. Values are not$-expanded, butdevbox.jsonenvcan reference them.Values from commands are treated as secrets:
devbox shellgets them through the process environment, and the generated shellrc only holds references (export K="${__DEVBOX_SECRET_K}"; unset ...).devbox.jsonvariables that reference a secret are treated as secrets too.How was it tested?
envfrom_exec: mock command, pipe, failure,.env+exec:array;envfrom_sops_age: real age-encrypted yaml and dotenv files decrypted withexec:sops.envfromandenvfrom_jetify_cloudtestscripts pass unchanged.devbox run lint: 0 issues.Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.