Getting env files onto the host
secrets-tool hostenv builds a small script from secrets.enc that writes the env files on the Docker host. For each file you say which values go in and what they are called there.
secrets-tool hostenv --target /opt/app/api.env --map DB_PW=SPRING_DATASOURCE_PASSWORD --map JWT_SECRET --target /opt/app/db.env --map DB_PW=POSTGRES_PASSWORD --host root@server
--map SOURCE=TARGET takes the value SOURCE from secrets.enc and writes it as TARGET=… into the file; --map JWT_SECRET keeps the name. --stage prod or --file choose the file as with any command.
What you see
The console shows the script only masked and commented out, e.g. <DB_PW: set, 24 chars> or <DB_PW: NOT SET>. This view cannot be run. No value appears, not even in error messages. If a value is missing or empty, the command stops and writes nothing.
The runnable copy is in your TEMP folder and readable only by you: on Windows without inherited permissions and with exactly one rule, elsewhere with mode 600. Below it are the three commands you paste one after the other:
scp 'C:\Users\…\Temp\app-hostenv.sh' root@server:app-hostenv.sh ssh root@server 'bash ~/app-hostenv.sh; rc=$?; shred -u ~/app-hostenv.sh 2>/dev/null || rm -f ~/app-hostenv.sh; exit $rc' Remove-Item -LiteralPath 'C:\Users\…\Temp\app-hostenv.sh'
The script lands in the target user's home, not in /tmp, and is deleted after the run. On the host it writes each file with umask 077 and printf. printf is built into bash, so the values are in no process list. Each file is first created next to its place and then moved there, with mode 600. Missing folders are created.
Run it right away: --ssh
With --ssh root@server instead of --host, the CLI runs the script itself. It only goes over ssh's standard input, in no command line and in no file. If it fails on the host, hostenv also ends with exit code 1.
Check in the one-liner: --guard
So that a deployment never starts with old values, put the check in front of docker run. Use the same --target and --map as when writing:
$guard = secrets-tool hostenv --guard --target /opt/app/api.env --map DB_PW=SPRING_DATASOURCE_PASSWORD --map JWT_SECRET --hint 'on the PC: deploy.ps1 -EnvFile' Write-Output "$guard && docker pull … && docker run -d --env-file /opt/app/api.env …"
If the file on the host is missing, unreadable or no longer matches secrets.enc (for example after rotating a key), the line stops with a clear message and status 1, before any container is stopped. It relies on a SHA-256 checksum over the sorted lines of the file. That is the same as LC_ALL=C sort FILE | sha256sum on the host. --hash prints just that checksum.
Checksums only for long random values. If a file holds only a single short or simple password, the checksum could be reversed by trying. For such files --hash refuses, and --guard only checks that the file exists and is not empty. Files with a long random value (such as JWT_SECRET) get the full check.
Limit: docker inspect
hostenv keeps the values out of one-liners, the screen buffer, the clipboard, shell history and the process list. It does not protect the running container: Docker copies the contents of --env-file into the container configuration, and docker inspect and docker exec … env show the values to anyone allowed to use Docker on the host. More under Use in deployments.
Exit codes
0: written or printed. 1: value missing, file or ssh failed. 2: wrong invocation.