Skip to content

Docker stdio servers: env values (incl. resolved secrets) are passed as -e KEY=VALUE argv and visible in ps #1809

Closed

Description

@AlexMKX

Summary

For stdio upstreams launched with docker run (and for Docker-isolated servers), every entry of the server's env map is turned into a -e KEY=VALUE command-line argument of the docker process. Secrets put into env — including ones written as ${keyring:…}, ${env:…} or ${file:…} references — therefore end up in the process table and are readable by any local user via ps aux / pgrep -af / /proc/<pid>/cmdline.

Version: v0.72.0 (also current main).

Where

  • internal/upstream/core/connection_docker.go — injectEnvVarsIntoDockerArgs:
    for key, value := range envVars {
        newArgs = append(newArgs, "-e", fmt.Sprintf("%s=%s", key, value))
    }
  • internal/upstream/core/isolation.go (Docker isolation path) — same pattern for serverConfig.Env.
  • internal/upstream/core/client.go — ExpandStructSecretsCollectErrors resolves secret references on a copy of the server config before the args are built, so the keyring/file references protect the config file but not argv.

PR #1181 / #1749 mask these values in mcpproxy's own logs, but the real process argv is unchanged.

Reproduce

{
  "name": "grafana",
  "command": "docker",
  "args": ["run", "--rm", "-i", "-e", "GRAFANA_SERVICE_ACCOUNT_TOKEN", "grafana/mcp-grafana", "-t", "stdio"],
  "env": { "GRAFANA_SERVICE_ACCOUNT_TOKEN": "${keyring:grafana_token}" }
}
$ pgrep -af 'docker run'
... docker run --cidfile /tmp/mcpproxy-cid-….txt -e GRAFANA_SERVICE_ACCOUNT_TOKEN=glsa_<real token> --rm -i ...

Note that the user deliberately wrote -e GRAFANA_SERVICE_ACCOUNT_TOKEN without a value; mcpproxy still prepends the KEY=VALUE form.

Expected

Secret values never appear in any process's argv.

Suggested fix

Docker already supports this natively: -e KEY (no =) makes the docker CLI take the value from its own environment. connection_stdio.go already merges c.config.Env into the child process environment (envVars), so injectEnvVarsIntoDockerArgs (and the isolation builder) could emit just -e KEY and leave the value in cmd.Env. The value then stays in /proc/<pid>/environ, which is readable only by the process owner and root.

An alternative is writing a 0600 temp --env-file, but -e KEY + cmd.Env needs no file lifecycle.

Docs

docs/features/keyring-integration.md says ${file:} keeps a secret out of docker inspect and /proc/<pid>/environ. For docker servers it does end up in argv, which is the more widely readable surface. It would help to state that explicitly until this is fixed.

Current workaround

Keep secrets out of env entirely for docker servers and pass "--env-file", "/etc/mcpproxy/secrets/<server>.env" (mode 0640 root:mcpproxy) in args.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions