ductor icon indicating copy to clipboard operation
ductor copied to clipboard

Secrets from .env are passed in docker exec/run argv (visible via ps)

Open ryuhaneul opened this issue 4 months ago • 0 comments

What happened?

When the Docker sandbox is enabled (docker.enabled: true), values loaded from ~/.ductor/.env are passed to the container as -e KEY=VALUE, so they appear in the docker client's command line and are readable by any local user via ps or /proc/<pid>/cmdline.

  • ductor_bot/cli/base.py - the exec branch of docker_wrap() builds -e f"{key}={value}" for each merged env entry, so this happens on every CLI turn.
  • ductor_bot/infra/docker.py - _env_secret_flags() does the same for docker run at container start.

Non-Docker execution is unaffected: ductor_bot/cli/executor.py merges the values into the subprocess env= mapping, so they never reach argv.

redact_cmd_for_log() masks values in the logged command string only; the real argv is unchanged, so it does not cover this.

Approaches considered

Not proposing a specific PR - recording the options and their caveats so you can pick:

  1. -e KEY (name only), value supplied through the docker client's environment. Docker reads the value from the client env, so argv carries only names (works from API 1.25+). Caveat: .env accepts arbitrary keys and some names are meaningful to the docker CLI itself, so this needs an explicit policy for those before it is safe. It also requires threading a client environment from docker_wrap() through SubprocessSpec, the executors, the provider call sites and DockerManager._exec; mutating the process-global environment is not viable because concurrent turns would race.
  2. --env-file. Keeps values out of argv, but needs a filtered temporary file holding plaintext (lifetime and cleanup), and docker's env-file parsing differs from the current dotenv handling.
  3. Docker Engine API/SDK instead of the CLI. Env travels in the request body, so neither argv nor the client environment is involved - but it is a larger architectural change.
  4. Keep secrets out of .env entirely. Only ~/.ductor/.env is ever read, so a sibling file that ductor never loads is un-injected by construction, with a small loader so each tool reads just the keys it needs. This is what I settled on downstream; it needs no ductor change, but it is a convention and does not protect anyone who keeps secrets in .env.

Also worth noting: even with argv addressed, environment set at docker run is stored in the container configuration and readable via docker inspect.

Steps to Reproduce

  1. Put a secret in ~/.ductor/.env, e.g. EXAMPLE_TOKEN=<value>.
  2. Run with docker.enabled: true (Docker sandbox).
  3. Send any message so a CLI turn starts.
  4. On the host, while the turn runs: ps -eo args | grep 'docker exec'

The command line contains -e EXAMPLE_TOKEN=<value>.

Expected Behavior

Secret values should not appear in process arguments. Passing them over a channel that is not world-readable (for example the child process environment) would keep ps and /proc/<pid>/cmdline clean.

Operating System

Linux

Environment

Docker

Which LLM provider?

Not provider-specific

ductor version

0.20.1

/diagnose output


Relevant log output


LLM self-diagnosis (optional)

No response

Additional context

No response

Before submitting

  • [x] I have searched existing issues for duplicates.
  • [x] I am running the latest version.

ryuhaneul avatar Jul 24 '26 11:07 ryuhaneul