Skip to main content

Module secret_env

Module secret_env 

Source
Expand description

Taking a secret out of the process environment for good.

The launcher hands srv and the host AGENTMUX_AUTH_KEY and AGENTMUX_HOST_REG_SECRET in their environment. std::env::remove_var drops the variable from the process’s own view (and from the environment of any process it starts afterwards), but on Unix the strings stay where the kernel put them at exec, and /proc/<pid>/environ (Linux) and ps eww / KERN_PROCARGS2 (macOS) read exactly that block, for any process of the same user. Wiping overwrites the value in place before removing it.

On Windows SetEnvironmentVariable rewrites the process’s live environment block, which is what another process reads, so removing the variable there is enough.

The two startup secrets are moved out of the environment as the first thing srv and the host do (stash_startup_secrets), before they start anything, so no process they spawn inherits them; the code that needs a value takes it from the stash with take.

Constants§

STARTUP_SECRETS
What the launcher hands srv and the host in their environment.

Functions§

discard_startup_secrets
Wipes STARTUP_SECRETS from the environment for good, keeping no copy. For a process that mints its own secrets and never needs the ones it was started with (the launcher): a pane or shell that holds an instance’s key must not pass it on through /proc/<pid>/environ.
is_set
Whether name has a non-empty value, stashed or still in the environment.
stash
Moves each named variable that is set and not empty into the stash.
stash_startup_secrets
Moves STARTUP_SECRETS out of the environment into the stash (wiped from the environment block in place on Unix). Call it first thing in main.
stashed
The stashed secrets as variables, for a process that re-executes itself and needs them again in its new environment.
take
The value of name: the stashed one, else (a process that never stashed, a test) the environment’s, wiped from there as it is read. None when unset.