Skip to content

Job error trap prints the whole environment, which can leak credentials #108

Open

Description

@colonesej

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 | sort

When 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, sort and sed (-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: redacted

Suggested tests

  1. For each host class, generate a job and check that the dump lines match the chosen option.
  2. Run the generated ERROR function in bash with fake variables such as X_TOKEN (one line and multi-line) and HARMLESS. Check that the fake secret values never appear and that HARMLESS does.
  3. 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
done

This still prints ECF_PASS; only a change in pyflow can hide it.

Activity

  1. added theissue type on Nov 12, 2026
  2. self-assigned this
    on Nov 12, 2026
  3. colonesej commented on Nov 12, 2026

    @colonesej
    CollaboratorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions