Do not pass the mnemonic environment variables on to ssh and sftp #16

Closed
opened 2026-09-21 09:17:56 +02:00 by clawbot · 1 comment
Collaborator

keyfunc ssh to and keyfunc ssh install start the system ssh and sftp with the tool's whole environment. When the mnemonic came from KEYFUNC_MNEMONIC, the child process holds the mnemonic in its environment for as long as it runs (readable in /proc/<pid>/environ by the same user, and forwardable to the host by a SendEnv line in the user's ssh config). ssh to exists so the private key never leaves the tool; the mnemonic must not leave it either.

Implementation

  • In internal/cli/ssh/to.go (connect) and internal/cli/ssh/install.go (session), set the child's Env to the tool's environment with KEYFUNC_MNEMONIC and KEYFUNC_MNEMONIC_COMMAND removed. Use the constants mnemonic.Variable and mnemonic.CommandVariable; one small shared helper in the ssh cli package, no new package.
  • The mnemonic command itself (internal/mnemonic) keeps the full environment.
  • README, "Giving it the mnemonic": one sentence saying the two variables are not passed on to ssh or sftp.

Definition of done

  • A test with a fake ssh and a fake sftp on PATH that record their environment shows neither variable reaches them, for both ssh to and ssh install, while another variable set in the test does.
  • README sentence added and true of the code.
  • make check green. Branch cut from next, PR base next.

Model: fable-5-1

`keyfunc ssh to` and `keyfunc ssh install` start the system `ssh` and `sftp` with the tool's whole environment. When the mnemonic came from `KEYFUNC_MNEMONIC`, the child process holds the mnemonic in its environment for as long as it runs (readable in `/proc/<pid>/environ` by the same user, and forwardable to the host by a `SendEnv` line in the user's ssh config). `ssh to` exists so the private key never leaves the tool; the mnemonic must not leave it either. ## Implementation - In `internal/cli/ssh/to.go` (`connect`) and `internal/cli/ssh/install.go` (`session`), set the child's `Env` to the tool's environment with `KEYFUNC_MNEMONIC` and `KEYFUNC_MNEMONIC_COMMAND` removed. Use the constants `mnemonic.Variable` and `mnemonic.CommandVariable`; one small shared helper in the `ssh` cli package, no new package. - The mnemonic command itself (`internal/mnemonic`) keeps the full environment. - README, "Giving it the mnemonic": one sentence saying the two variables are not passed on to `ssh` or `sftp`. ## Definition of done - A test with a fake `ssh` and a fake `sftp` on `PATH` that record their environment shows neither variable reaches them, for both `ssh to` and `ssh install`, while another variable set in the test does. - README sentence added and true of the code. - `make check` green. Branch cut from `next`, PR base `next`. Model: fable-5-1
clawbot self-assigned this 2026-09-21 09:17:56 +02:00
Author
Collaborator

PR: #29

ssh to (connect) and ssh install (session) now start the system ssh
and sftp with the tool's environment stripped of KEYFUNC_MNEMONIC and
KEYFUNC_MNEMONIC_COMMAND, through one shared helper in the ssh cli
package. The mnemonic command still runs with the full environment. The
CLI stand-in ssh and sftp now record their environment, and two tests
drive ssh install and ssh to and show neither variable reaches them
while another one set alongside them does. README gained one sentence.

Model: opus-4-8

PR: https://git.eeqj.de/sneak/keyfunc/pulls/29 `ssh to` (connect) and `ssh install` (session) now start the system `ssh` and `sftp` with the tool's environment stripped of `KEYFUNC_MNEMONIC` and `KEYFUNC_MNEMONIC_COMMAND`, through one shared helper in the ssh cli package. The mnemonic command still runs with the full environment. The CLI stand-in `ssh` and `sftp` now record their environment, and two tests drive `ssh install` and `ssh to` and show neither variable reaches them while another one set alongside them does. README gained one sentence. Model: opus-4-8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/keyfunc#16