Skip to content
kjanatPublic

About

manage keys in env files

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

124 Commits

Folders and files

Repository files navigation

envctl

GitHub release OpenSSF Scorecard OpenSSF Best Practices

Edit one key in an env file without disturbing anything else, and keep secrets out of your terminal while you do it.

$ envctl set .env DATABASE_URL 'postgres://localhost/app'
$ envctl get DATABASE_URL
postgres://localhost/app
$ envctl --redact list --values
DATABASE_URL=<redacted>
DEBUG=true

Order, comments, and spacing survive every edit. Writes go through a temp file and a rename, so a crash never leaves half a file behind. A single C11 binary with no runtime dependencies.

Install

curl -fsSL https://raw.githubusercontent.com/kjanat/envctl/master/install.sh | sh

install.sh picks the release asset for your OS and architecture, checks it against SHA256SUMS, and installs to ~/.local/bin. Where no release binary exists, it builds that release from source with GNU make and a C11 compiler. Override with ENVCTL_INSTALL_DIR and ENVCTL_VERSION, set ENVCTL_FROM_SOURCE=1 to always build, or ENVCTL_ATTEST=1 to also verify the binary's build provenance with gh.

Release binaries

GitHub Releases carries linux-{amd64,arm64}, darwin-{amd64,arm64}, windows-{amd64,arm64}, and freebsd-amd64, with SHA256SUMS, an SPDX SBOM, and build provenance attestations.
The Linux binaries link musl statically, so they run on any distribution.

Download and verify a binary by hand
gh release download -R kjanat/envctl \
  --pattern envctl-linux-amd64 --output ~/.local/bin/envctl
chmod +x ~/.local/bin/envctl
gh attestation verify ~/.local/bin/envctl --repo kjanat/envctl

envctl.spdx.json is an SPDX 2.3 SBOM with every binary's checksums, attested for the same binaries:

gh attestation verify ~/.local/bin/envctl --repo kjanat/envctl \
  --predicate-type https://spdx.dev/Document/v2.3

Container image

ghcr.io/kjanat/envctl, also on Docker Hub as kjanat/envctl, runs envctl in Docker on linux/amd64 and linux/arm64, and ORAS pulls the binary for any platform from the same tag:

docker run --rm -i ghcr.io/kjanat/envctl redact --no-env <build.log
sudo oras pull -o / --platform darwin/arm64 ghcr.io/kjanat/envctl:0.8.1
Tags, writing files, installing without root, and attestations

The image is distroless with the static Linux build. Each release is tagged by its version, such as 0.8.1; the latest also moves 0.8, 0, and latest. It runs as a non-root user in /work, so mount the directory and pass your user ID for commands that write files:

docker run --rm -v "${PWD}:/work" --user "$(id -u):$(id -g)" \
  ghcr.io/kjanat/envctl set .env DEBUG 1

ORAS unpacks every platform's binary as an executable ./usr/local/bin/envctl (envctl.exe on Windows), which -o / puts in /usr/local/bin. ORAS has no other install location, so for ~/.local/bin pull to a temporary directory:

tmp="$(mktemp -d)"
oras pull -o "${tmp}" --platform darwin/arm64 ghcr.io/kjanat/envctl:0.8.1
install -m 0755 "${tmp}/usr/local/bin/envctl" ~/.local/bin/envctl && rm -rf "${tmp}"

Both registries serve the same index by the same digest. It has build provenance and an SBOM of the image and its Debian base packages as attestations on GitHub, not in the registry:

gh attestation verify oci://ghcr.io/kjanat/envctl:0.8.1 --repo kjanat/envctl

From source

With any C11 compiler:

git clone https://github.com/kjanat/envctl.git && cd envctl && make && make install

make install places the binary, the man page, and the bash, zsh, and fish completion scripts under PREFIX (~/.local by default). make test runs the suite.

GitHub Actions

The root setup action builds envctl from the source its uses: ref points to and puts it on GITHUB_PATH for later steps:

- uses: kjanat/envctl@<SHA>
- run: envctl --version
Building, downloading, inputs, and outputs

The runner already fetched the source to run the action, so building it needs only make and a C compiler, which GitHub's Linux, macOS, and Windows x64 runners have, and no network. Where the build fails, the action downloads the release that ref is tagged as instead, or the latest release.

Set with: { version: latest } or with: { version: v0.7.0 } to download a release instead of building. The action fetches the binary and the release's SHA256SUMS from the public release URLs and checks the binary against it before running it or changing GITHUB_PATH. It makes no GitHub API requests and needs neither a token nor the GitHub CLI.

The version, path, and sha256 outputs identify the installed executable, and source says whether it was built or downloaded. To also check the build provenance of a download, run gh attestation verify on the path output.

Commands

envctl set     [file] <KEY> [VALUE]   create or replace a key
envctl get     [file] <KEY>           print the active value
envctl disable [file] <KEY>           comment a key out, keep its value
envctl enable  [file] <KEY>           uncomment a key
envctl delete  [file] <KEY>           remove a key entirely
envctl list    [file]                 print active keys
envctl redact  [file]                 filter stdin to stdout, masking secrets
envctl env                            print the environment, always redacted
envctl completions <shell>            completion script for bash/zsh/fish/pwsh
envctl module pwsh                    PowerShell cmdlets wrapping the binary

./.env is assumed when you leave the file out. Without a command word, envctl <KEY> is a get and envctl <KEY> <VALUE> is a set. ls and rm are aliases for list and delete.

Secrets stay out of the way

Values that look like secrets are masked when a coding agent is driving your terminal, and whenever you ask with --redact:

$ envctl env
PATH=/usr/bin:/bin
API_TOKEN=<redacted>

Pipes stay raw, so TOKEN=$(envctl get TOKEN) keeps working. envctl redact runs the same masking over any text you pipe through it, which is how build logs and agent output stop leaking:

npm run build 2>&1 | envctl redact

This is presentation hygiene, not a security boundary. See SECURITY.md.

Documentation

Page Contents
Commands Every command and flag, file format, exit codes, guarantees
Redaction When masking is on, what counts as a secret, filter mode
Shell integration Completions for four shells, PowerShell cmdlets
Recipes Rotate a secret, mask CI output, compare two env files, and friends

man envctl carries the full reference offline, and envctl <cmd> --help prints one command with only the flags it accepts.

How it stays honest

src/cli.c holds one table of commands and flags. Parser validation, --help, the man page, the completion scripts, and the PowerShell module all come out of it, so a flag cannot exist without the documentation knowing about it. The man page is regenerated by make man, and make test fails when the checked-in copy no longer matches.

Development and release workflow: CONTRIBUTING.md.
Threat model and vulnerability reporting: SECURITY.md.

License

MIT

About

manage keys in env files

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages