Secrets and Environment
Status: 🟢 Implemented —
.kargo.envloading,${env:…}interpolation, andkargo envall work.
Builds need secrets: registry credentials, signing passwords, CI tokens. They must
not be committed. Kargo gives them one home — .kargo.env — and one way to
reference them — ${env:VAR}.
The distinction that matters
| Build secrets | Build configuration | |
|---|---|---|
| Examples | Nexus password, GPG passphrase, CI token | API URL, feature flag, analytics key |
| Needed by | The build itself | The shipped application |
| Lives in | .kargo.env (gitignored) | [build-config] or flavors |
| Ends up in the binary | No | Yes |
Getting this backwards is the common mistake. A registry password in
[build-config] is committed and compiled into your artifact. An API URL in
.kargo.env is missing on every machine that did not set it up by hand.
Ask: does the build need it, or does the app need it?
.kargo.env
A shell-style KEY=value file beside Kargo.toml:
# Private repository auth
NEXUS_USERNAME=deploy
NEXUS_PASSWORD=s3cret-token
MAVEN_TOKEN=abc123
# Signing
KEYSTORE_PASSWORD=changeit
GPG_PASSPHRASE=hunter2
# Machine-specific paths
ANDROID_SDK=/Users/jane/Library/Android/sdk
JAVA_HOME=/usr/lib/jvm/java-25-openjdk
kargo new and kargo init create the file and add it to .gitignore. Check
that it stayed there before your first commit.
Referencing values
Anywhere in Kargo.toml:
[repositories]
internal = { url = "https://nexus.example.com/maven", username = "${env:NEXUS_USERNAME}", password = "${env:NEXUS_PASSWORD}" }
[signing]
gpg-key = "${env:GPG_KEY}"
gpg-password = "${env:GPG_PASSPHRASE}"
[toolchain]
jdk = "${env:JAVA_HOME}"
Interpolation runs when the manifest is read, before TOML parsing, so it works in any string value — a URL, a path, a version — not just credentials.
Resolution order
Later wins:
~/.kargo/config.toml— global defaults<project>/.kargo.env— this project on this machine- The process environment
So CI can override a developer's local value by exporting it, with no file to edit:
NEXUS_PASSWORD="$CI_NEXUS_TOKEN" kargo publish
An unresolved ${env:VAR} fails the command and names the variable. It does not
silently become an empty string — which is how a build quietly publishes to the
wrong place.
Inspecting
kargo env
NEXUS_USERNAME deploy
NEXUS_PASSWORD ****
MAVEN_TOKEN ****
ANDROID_SDK /Users/jane/Library/Android/sdk
Values that look like secrets are masked. To see them:
kargo env --reveal
--reveal is deliberately explicit, because the common use of kargo env is
pasting output into a bug report.
In CI
Do not write .kargo.env in CI. Export secrets from your platform's secret store
and let the process environment supply them:
- name: Publish
env:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: kargo publish
Secrets from a manager
For values you would rather not have on disk at all, fetch them with a command:
[flavors.tier.paid.signing]
keystore = "release.keystore"
key-alias = "paid-release"
store-password-cmd = "op read 'op://Dev/Keystore/password'"
# ~/.kargo/config.toml
[credentials.my-nexus]
username = "deploy"
token-cmd = "secret-tool lookup service nexus"
The command runs at build time and its stdout is the value. Nothing is stored, and
any manager with a CLI works — 1Password, pass, secret-tool, Vault.
Rules Kargo enforces
kargo newandkargo initgitignore.kargo.env.- An unresolved
${env:…}is an error, not an empty string. kargo publishrefuses to run with unresolved placeholders in the manifest, so a missing credential cannot become a literal${env:NEXUS_PASSWORD}in a published POM.kargo envmasks by default.kargo lintwarns on values that look like hardcoded secrets inKargo.toml. ⚪ Planned.
If a secret gets committed
Rotate it. Removing the file in a later commit does not help — the value is in the repository's history and in every clone. Treat a committed secret as a leaked secret and replace it at the source.
Next
- Publishing — where credentials get used
- Continuous Integration
- Environment Variables — what Kargo exports to builds