cairnd hash-password: Enter should end input, hide what is typed, and document a kubectl-safe command #893

Closed
opened 2026-10-13 19:46:48 +00:00 by Cordy · 2 comments
Owner

Found on 2026-10-13 while setting up the files-bao break-glass account with kubectl exec -i … hash-password.

What happened

  • The prompt says "Reading password from stdin (end with Enter / EOF)...", but Enter does not end the input. The command reads until EOF (io.ReadAll), so it hangs until you press Ctrl-D.
  • Without a TTY (kubectl exec -i with no -t, which is the documented form), the typed password is echoed on screen.
  • While it waits, the long-lived kubectl exec websocket can time out over a VPN ("Websocket Ping failed … i/o timeout"), and the Ctrl-D then lands on a dead connection.

Fix

  1. Read one line. Stop at the first \n and trim CR/LF, so Enter ends the input as the prompt says. Piped input that has no trailing newline still works (EOF ends it too). Keep the 1024-byte limit.
  2. Hide typing on a terminal. When stdin is a TTY, turn echo off (golang.org/x/term ReadPassword, which we may already vendor) and ask for the password twice. When stdin is not a TTY, read silently and print no prompt to stdout, so pipes stay clean (prompt to stderr only).
  3. Docs (local-accounts.md "Per platform"): lead with the robust form, where the password never reaches the screen or the shell history and the exec ends at once:
    read -rs "PW?New emergency password: "; echo        # zsh; bash: read -rsp "…" PW
    printf '%s' "$PW" | kubectl exec -n <ns> -i deploy/<name> -- /ko-app/cairnd hash-password
    unset PW
    
    Also a -it variant for interactive use.
  4. Tests: one line ends the input; CRLF is handled; there is no echo when on a TTY (helper seam); piped input without a newline works; empty input is refused.
Found on 2026-10-13 while setting up the files-bao break-glass account with `kubectl exec -i … hash-password`. ## What happened - The prompt says "Reading password from stdin (end with Enter / EOF)...", but Enter does **not** end the input. The command reads until EOF (`io.ReadAll`), so it hangs until you press Ctrl-D. - Without a TTY (`kubectl exec -i` with no `-t`, which is the documented form), the typed password is **echoed on screen**. - While it waits, the long-lived `kubectl exec` websocket can time out over a VPN ("Websocket Ping failed … i/o timeout"), and the Ctrl-D then lands on a dead connection. ## Fix 1. **Read one line.** Stop at the first `\n` and trim CR/LF, so Enter ends the input as the prompt says. Piped input that has no trailing newline still works (EOF ends it too). Keep the 1024-byte limit. 2. **Hide typing on a terminal.** When stdin is a TTY, turn echo off (`golang.org/x/term` ReadPassword, which we may already vendor) and ask for the password twice. When stdin is not a TTY, read silently and print no prompt to stdout, so pipes stay clean (prompt to stderr only). 3. **Docs** (local-accounts.md "Per platform"): lead with the robust form, where the password never reaches the screen or the shell history and the exec ends at once: ``` read -rs "PW?New emergency password: "; echo # zsh; bash: read -rsp "…" PW printf '%s' "$PW" | kubectl exec -n <ns> -i deploy/<name> -- /ko-app/cairnd hash-password unset PW ``` Also a `-it` variant for interactive use. 4. **Tests:** one line ends the input; CRLF is handled; there is no echo when on a TTY (helper seam); piped input without a newline works; empty input is refused.
Author
Owner

Shipped in v0.6.338 (PR #894). It is live on both dogfoods.

  • Input: it reads one line, so Enter ends it. CRLF is trimmed. Piped input without a newline works. Empty input is refused, and so is input over 1024 bytes (before, it was silently cut).
  • On a TTY: echo is turned off with x/sys/unix termios (linux build tag; no new dependency). It prompts "New password" and "Repeat password", and refuses a mismatch. Echo is restored on every path, including Ctrl-C (exit 130).
  • Without a TTY: one stderr notice. stdout carries only the hash.
  • Docs: local-accounts.md now leads with the piped form, which keeps the password off the screen and out of the shell history:
    read -rs "PW?New emergency password: "; echo
    printf '%s' "$PW" | kubectl exec -n <ns> -i deploy/<name> -- /ko-app/cairnd hash-password
    unset PW
    
    • The kubectl exec, kubectl run and Docker commands now use -it.
    • README.md and example.config.json no longer suggest echo -n 'password' |.

The TTY path has been compiled and unit-tested through a fake terminal, but not yet run on a real pty. Still open: Nikola runs kubectl exec -n cairn -it deploy/cairn-openbao -- /ko-app/cairnd hash-password once, enters any test text twice, and checks it isn't echoed. No need to use the hash.

**Shipped in v0.6.338** (PR #894). It is live on both dogfoods. - **Input:** it reads one line, so Enter ends it. CRLF is trimmed. Piped input without a newline works. Empty input is refused, and so is input over 1024 bytes (before, it was silently cut). - **On a TTY:** echo is turned off with x/sys/unix termios (linux build tag; no new dependency). It prompts "New password" and "Repeat password", and refuses a mismatch. Echo is restored on every path, including Ctrl-C (exit 130). - **Without a TTY:** one stderr notice. stdout carries only the hash. - **Docs:** local-accounts.md now leads with the piped form, which keeps the password off the screen and out of the shell history: ``` read -rs "PW?New emergency password: "; echo printf '%s' "$PW" | kubectl exec -n <ns> -i deploy/<name> -- /ko-app/cairnd hash-password unset PW ``` - The `kubectl exec`, `kubectl run` and Docker commands now use `-it`. - README.md and example.config.json no longer suggest `echo -n 'password' |`. The TTY path has been compiled and unit-tested through a fake terminal, but not yet run on a real pty. Still open: Nikola runs `kubectl exec -n cairn -it deploy/cairn-openbao -- /ko-app/cairnd hash-password` once, enters any test text twice, and checks it isn't echoed. No need to use the hash.
Author
Owner

Live check (Nikola, files-bao, v0.6.338): passed. kubectl exec -n cairn -it deploy/cairn-openbao -- /ko-app/cairnd hash-password showed "New password:" and "Repeat password:" with nothing echoed, and Enter ended each entry without needing Ctrl-D. Closing.

**Live check (Nikola, files-bao, v0.6.338): passed.** `kubectl exec -n cairn -it deploy/cairn-openbao -- /ko-app/cairnd hash-password` showed "New password:" and "Repeat password:" with nothing echoed, and Enter ended each entry without needing Ctrl-D. Closing.
Cordy closed this issue 2026-10-13 21:04:22 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#893
No description provided.