Take the passwords out of a .env file
A .env file is convenient, but it's also the file most likely to leak a password: copied to a ticket, pushed by mistake, or shared with a new teammate. With Devolutions CLI, the file keeps its shape and its variable names, but each secret becomes a devo:// reference. The file is then safe to commit, and the values reach your app only when it starts.
Replace the values with references
Open your
.envfile.For each secret, find its reference. See Find the reference to a secret.
Replace the value with the reference. Leave the other values as they are.
# Database
DB_HOST=db.internal.example
DB_USER=devo://ws/<workspace-id>/vault/<vault-id>/entry/<entry-id>/field/username
DB_PASSWORD=devo://ws/<workspace-id>/vault/<vault-id>/entry/<entry-id>/field/password
# A reference can also sit inside a longer value
DATABASE_URL="postgres://app:{{ devo://ws/<workspace-id>/vault/<vault-id>/entry/<entry-id>/field/password }}@db.internal.example/app"Run your app with the file
devo secret run --env-file .env -- npm startDevolutions CLI reads the file, resolves every reference it contains, and starts your app with all the variables of the file in its environment: the resolved secrets and the plain values. Resolved values are hidden in what the app prints, as with any devo secret run. See Run a command with its secrets.
You can combine --env-file with --env-ref. If a variable of the file has the same name as a variable of your shell that already holds a reference, the file wins. The variable of your shell is still resolved first, though: if its reference is broken, the launch fails anyway. Unset it or fix it.
How Devolutions CLI reads the file
KEY=value
One variable per line. Spaces around the name and the value are removed.
Empty lines and lines that start with #
Ignored.
KEY="value" or KEY='value'
One pair of matching quotes around the whole value is removed.
A reference inside a value
Replaced by the secret. Wrap it in {{ }} when other text touches it, so Devolutions CLI knows where it ends.
$NAME, ${NAME}, or ${NAME:-default} inside a reference
Replaced by the value of an environment variable, for example to pick the workspace ID per environment. Without a default, the variable must be set and not empty.
A few things that work in some .env loaders don't work here:
Variable names use letters, digits, and underscores only, and can't start with a digit. A line that starts with
exportis refused.A
#after a value isn't a comment: it becomes part of the value.A value can't span several lines.
The same variable name can't appear twice, or in both the file and
--env-ref.
What to commit
A .env file with references only
Yes. A reference contains names or IDs, never a value. Without access to the vault, it opens nothing.
A file produced by devo secret inject
No. It contains the values in plain text. Add it to .gitignore.
A .env file that still holds a password
No. Replace the value with a reference first.
If it doesn't work
"Environment file lines must use KEY=value syntax.": a line has no
=, or starts with one. Fix that line, or turn it into a comment with#.A reference doesn't resolve: see A secret reference doesn't resolve.
Your tool only reads a configuration file, not environment variables: see Fill a configuration file from a template.
Next
Last updated
Was this helpful?