Repository navigation
Description
Problem
The error trap that pyflow writes into every job script (Host.preamble_error_function in pyflow/host.py) ends with:
echo "The environment was:"
printenv | sortWhen a job fails, every exported variable is written to the job output. Job outputs are readable through the ecFlow server and log server, and are often copied or archived. Users commonly export credentials (API tokens, passwords, access keys) in their login environment, and batch systems pass that environment on to jobs. One failed job can therefore write those credentials, in clear, into files that other people can read. The ecFlow job password (ECF_PASS) is printed too.
This applies to every host class that uses the trap (for example SimpleSSHHost, SLURMHost, PBSHost and TroikaHost). It is present on develop and in release 3.7.0. Users cannot turn it off today.
Proposed solution
Add two options to Host.__init__, stored on the instance and read in preamble_error_function, the same way trap_signals is handled. Subclasses already forward **kwargs, so only Host and the host docstrings change.
environment_dump:"redacted"(proposed default),"full"(current behaviour) or"none"(no dump).redact_patterns: list of regular expressions matched, case-insensitively, against variable names. Suggested default:["TOKEN", "SECRET", "PASS", "KEY", "CREDENTIAL", "AUTH", "COOKIE"].
Generated trap for "redacted":
echo "The environment was (values of sensitive names redacted):"
printenv -0 | sort -z \
| sed -z -E 's/^([^=]*(TOKEN|SECRET|PASS|KEY|CREDENTIAL|AUTH|COOKIE)[^=]*)=.*/\1=<redacted>/I' \
| tr '\0' '\n'- NUL-separated records (
printenv -0,sed -z) redact a multi-line value completely, not only its first line. - Variable names stay visible, so the dump keeps its value for debugging.
- Matching too many names only hides a value; matching too few leaks one, so a broad default list is safer.
- This needs GNU
printenv,sortandsed(-z,/I). That holds on the usual Linux HPC targets; the requirement should be documented, and"none"remains available where it does not hold.
Tools that build on pyflow and pass host options through (for example pyflow-wellies) could then set this from configuration:
host:
environment_dump: redactedSuggested tests
- For each host class, generate a job and check that the dump lines match the chosen option.
- Run the generated
ERRORfunction in bash with fake variables such asX_TOKEN(one line and multi-line) andHARMLESS. Check that the fake secret values never appear and thatHARMLESSdoes. - Check that
"full"reproduces today's output and that"none"prints no environment.
Related
The job header turns on set -x, which prints expanded command lines. Scripts that handle secrets must turn tracing off themselves and must not pass a secret on a command line. A sentence about this in the documentation, next to the new option, would help users.
Workaround until a release
exit_hook runs inside ERROR before printenv. A suite-level hook can unset sensitive variables first. It must keep ECF_*, because ecflow_client --abort=trap runs after the hook and needs ECF_PASS:
for _v in $(compgen -e); do
case "${_v^^}" in
ECF_*) ;;
*TOKEN*|*SECRET*|*PASSW*|*KEY*|*CREDENTIAL*|*AUTH*|*COOKIE*) unset "$_v" ;;
esac
doneThis still prints ECF_PASS; only a change in pyflow can hide it.
Activity
colonesej commentedon Nov 12, 2026
FYI @corentincarton