Fail unseal-key prompts on EOF - #819
Merged
Merged
Conversation
`read_line` reports EOF as `Ok(0)`, and the count was discarded, so an exhausted stdin was indistinguishable from a blank line. Answering the threshold and then pressing Ctrl-D left every remaining share as an empty string, which `save_unseal_keys` wrote over an existing key file before reporting success and exiting zero. Check the count and fail instead, reading through an injected `BufRead` so both branches are reachable from a test without touching process stdin. While here, attribute a threshold that does not parse to `error_invalid_unseal_threshold` rather than to a read failure, and take both prompt strings from i18n. They were hardcoded in English even though the declarations, accessors and Korean translations all existed already. Closes #818
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the third of the tree's interactive readers.
prompt_unseal_keys_interactivediscarded the byte countread_linereturns, so an exhausted stdin was indistinguishable from a blank line.The reachable path is a plain operator mistake: answer the threshold, paste fewer shares than that, press Ctrl-D. Every remaining read returned
Ok(0), the vector filled with empty strings, andsave_unseal_keystruncated an existingunseal-keys.txtto blank lines, printed "saved" and exited zero. Nothing surfaced untilread_unseal_keys_from_filefiltered the blanks and bailed withUnseal key file is empty— by which point OpenBao is sealed and the shares are off the host.Changes
read_lineand bail witherror_prompt_eof()at both prompts. A blank line the operator typed still behaves as it did.&mut dyn BufReadso both branches are testable without process stdin.prompt_unseal_keys_interactivekeeps its name, parameters andpub(crate)visibility, so both call sites are untouched.error_invalid_unseal_thresholdinstead oferror_prompt_read_failed, which was attached to a parse failure.BOOTROOT_LANG=korendered English here. The English strings are byte-identical, so default-locale output does not move.Test plan
cargo test— all pass. The eightbootroot_rotatefailures on my machine are the Docker daemon being absent (dial unix /var/run/docker.sock), unrelated to this change.cargo clippy --all-targets -- -D warningsandcargo fmt -- --check --config group_imports=StdExternalCrateare clean.BOOTROOT_LANG=ko bootroot openbao save-unseal-keys --secrets-dir <tempdir>renders the Korean prompts, and Ctrl-D exits nonzero without creating the file.Preflight E2E was not run: this touches no Docker lifecycle, no E2E script and no code path they exercise —
initprompts for unseal keys through its own reader, and the other caller of this one is guarded byis_terminal().Closes #818