From e5a236de571bd43847a2b20e849ed5560fa2748c Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:00:04 +0800 Subject: [PATCH 1/6] ask before trusting a new host key, refuse one with no terminal --- CHANGELOG.md | 12 + CLAUDE.md | 11 +- SECURITY.md | 18 +- USAGE.md | 34 ++- docs/commands/baryovm.md | 2 +- docs/commands/baryovm_cloud.md | 2 +- docs/commands/baryovm_cloud_firebase.md | 2 +- docs/commands/baryovm_cloud_gcloud.md | 2 +- docs/commands/baryovm_cloud_wrangler.md | 2 +- docs/commands/baryovm_deploy.md | 2 +- docs/commands/baryovm_doctor.md | 2 +- docs/commands/baryovm_gh.md | 2 +- docs/commands/baryovm_git.md | 2 +- docs/commands/baryovm_guard.md | 2 +- docs/commands/baryovm_guard_check.md | 2 +- .../baryovm_guard_check_commit-msg.md | 2 +- .../baryovm_guard_check_pre-commit.md | 2 +- docs/commands/baryovm_guard_check_pre-push.md | 2 +- docs/commands/baryovm_guard_install-hooks.md | 2 +- docs/commands/baryovm_project.md | 2 +- docs/commands/baryovm_project_export.md | 2 +- docs/commands/baryovm_project_release.md | 2 +- docs/commands/baryovm_prove.md | 2 +- docs/commands/baryovm_publish.md | 2 +- docs/commands/baryovm_publish_npm.md | 2 +- docs/commands/baryovm_publish_nuget.md | 2 +- docs/commands/baryovm_repo.md | 2 +- docs/commands/baryovm_repo_init.md | 2 +- docs/commands/baryovm_repo_move.md | 2 +- docs/commands/baryovm_repo_verify.md | 2 +- docs/commands/baryovm_scan.md | 2 +- docs/commands/baryovm_ship.md | 2 +- docs/commands/baryovm_site.md | 2 +- docs/commands/baryovm_site_add.md | 2 +- docs/commands/baryovm_site_deploy.md | 2 +- docs/commands/baryovm_stack.md | 2 +- docs/commands/baryovm_stack_add.md | 2 +- docs/commands/baryovm_stack_backup.md | 2 +- docs/commands/baryovm_stack_backups.md | 2 +- docs/commands/baryovm_stack_deploy.md | 2 +- docs/commands/baryovm_stack_discover.md | 2 +- docs/commands/baryovm_stack_env.md | 2 +- docs/commands/baryovm_stack_env_list.md | 2 +- docs/commands/baryovm_stack_env_set.md | 2 +- docs/commands/baryovm_stack_env_unset.md | 2 +- docs/commands/baryovm_stack_list.md | 2 +- docs/commands/baryovm_stack_logs.md | 2 +- docs/commands/baryovm_stack_ps.md | 2 +- docs/commands/baryovm_stack_publish.md | 2 +- docs/commands/baryovm_stack_pull.md | 2 +- docs/commands/baryovm_stack_release.md | 2 +- docs/commands/baryovm_stack_remove.md | 2 +- docs/commands/baryovm_stack_restore.md | 2 +- docs/commands/baryovm_stack_rollback.md | 2 +- docs/commands/baryovm_stack_set-backup.md | 2 +- docs/commands/baryovm_stack_set-managed.md | 2 +- docs/commands/baryovm_stack_set-publish.md | 2 +- docs/commands/baryovm_stack_set-update.md | 2 +- docs/commands/baryovm_stack_set-verify.md | 2 +- docs/commands/baryovm_stack_tls.md | 2 +- docs/commands/baryovm_stack_update.md | 2 +- docs/commands/baryovm_status.md | 2 +- docs/commands/baryovm_up.md | 2 +- docs/commands/baryovm_version.md | 2 +- docs/commands/baryovm_vm.md | 4 +- docs/commands/baryovm_vm_add.md | 2 +- docs/commands/baryovm_vm_bootstrap.md | 2 +- docs/commands/baryovm_vm_exec.md | 2 +- docs/commands/baryovm_vm_forget-key.md | 4 +- docs/commands/baryovm_vm_harden.md | 2 +- docs/commands/baryovm_vm_health.md | 2 +- docs/commands/baryovm_vm_list.md | 2 +- docs/commands/baryovm_vm_patch.md | 2 +- docs/commands/baryovm_vm_ping.md | 2 +- docs/commands/baryovm_vm_provision.md | 2 +- docs/commands/baryovm_vm_prune.md | 2 +- docs/commands/baryovm_vm_remote.md | 2 +- docs/commands/baryovm_vm_remote_install.md | 2 +- docs/commands/baryovm_vm_remote_set.md | 2 +- docs/commands/baryovm_vm_remove.md | 2 +- docs/commands/baryovm_vm_runner.md | 2 +- docs/commands/baryovm_vm_runner_remove.md | 2 +- docs/commands/baryovm_vm_threats.md | 2 +- internal/cli/project.go | 7 +- internal/cli/root.go | 26 +- internal/cli/vm.go | 6 +- internal/hostkeys/hostkeys.go | 109 +++++-- internal/hostkeys/hostkeys_test.go | 101 ++++++- internal/sshx/askhostkey_test.go | 275 ++++++++++++++++++ internal/sshx/sshx.go | 131 ++++++++- internal/ui/ui.go | 19 ++ 91 files changed, 770 insertions(+), 141 deletions(-) create mode 100644 internal/sshx/askhostkey_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5e6d3..a2bc176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,18 @@ previously accepted is called out here rather than left to be discovered. server block in a shape the step does not edit is reported, and a rejected jail, a rolled-back drop or a failed reload ends the run with an error. +### Changed + +- **A new VM host key is now asked about on a terminal, and refused when there is no terminal.** + On a terminal you see the host and the offered fingerprint and answer `Trust this host key? + [y/N]`; only `y` or `yes` records it. With no terminal (a pipe, CI) or with `-o json`, an + unknown host is refused, as `--strict-host-keys` always did. This refuses something the last + release accepted: a CI job that relied on learning a fresh VM must now pin the key in + `known_hosts` first, or set `BARYOVM_STRICT_HOST_KEYS=0`. To get the old learn-on-first-use + behaviour everywhere, set `BARYOVM_STRICT_HOST_KEYS=0` or pass `--strict-host-keys=false` (the + flag wins over the environment). Known keys and changed keys behave as before, and time spent at + the prompt does not count against the 30 second handshake deadline. + ### Fixed - **A silent SSH host no longer hangs the CLI.** The handshake has its own 30 second deadline (the diff --git a/CLAUDE.md b/CLAUDE.md index ce3041a..6e30a91 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -103,8 +103,15 @@ every interpolated value with `sshx.Quote`**. This is the injection boundary and it is covered by tests in `internal/sshx/sshx_test.go`. A remote command built with `fmt.Sprintf` and a bare `%s` is a bug even when the value looks safe. -Host identity is verified in `internal/hostkeys`: trust on first use against -`$BARYOVM_HOME/known_hosts`, then refuse on change. The user's own +Host identity is verified in `internal/hostkeys`: ask on first use against +`$BARYOVM_HOME/known_hosts`, then refuse on change. An unknown host is a +`hostkeys.Mode`: Ask on a terminal (not JSON), Refuse with no terminal or under +`--strict-host-keys`, Learn under `--strict-host-keys=false` or +`BARYOVM_STRICT_HOST_KEYS=0`. The mode is resolved in `sshx.HostKeyMode`; the +cli layer sets `sshx.SetInteractive` and `sshx.ConfirmHostKey` (the prompt, +which pauses the spinner), because engine packages never print. The prompt +time is kept out of the SSH handshake deadline, and `project release` forces +Refuse for its run. The user's own `~/.ssh/known_hosts` is read as a second source, since a key they checked by hand is better than one offered to us now. There is deliberately no flag that skips the check for every host, because the moment one exists it ends up in a diff --git a/SECURITY.md b/SECURITY.md index 7f34f79..d4e7d78 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -24,19 +24,23 @@ down. material**. - **Host identity**. Before running anything on a VM, BaryoVM checks the host's SSH key against `~/.baryovm/known_hosts` (override with `BARYOVM_HOME`), - written **owner-only (`0600`)**. The first connection to a machine records the - key and prints its fingerprint; every later connection must match. A key that + written **owner-only (`0600`)**. The first connection to a machine shows the + fingerprint and asks `Trust this host key? [y/N]` on a terminal, and records + the key only on a yes. With no terminal, or with `-o json`, an unknown host is + refused. Every later connection must match. A key that has **changed** stops the command and prints both fingerprints, because a rebuilt VM and someone else answering on that address look identical from here. `baryovm vm forget-key ` drops one recorded key so the - next connection learns the new one. There is no flag that disables the check - for every host. Your own `~/.ssh/known_hosts` is read as an additional source, + next connection asks about the new one. There is no flag that disables the + check for every host; `BARYOVM_STRICT_HOST_KEYS=0` (or `--strict-host-keys=false`) + goes back to learning an unknown host without asking. Your own `~/.ssh/known_hosts` is read as an additional source, never written. - **Host identity in CI**. Trust on first use assumes there is a first use. A runner with no memory between runs would learn a key every run, which is not - verification. Set `BARYOVM_STRICT_HOST_KEYS=1` (or `--strict-host-keys`) and - BaryoVM refuses an unknown host instead of learning it, so the job fails - rather than trusting whatever answered. Record the key first, ideally from a + verification. A runner has no terminal, so BaryoVM refuses an unknown host by + default and the job fails rather than trusting whatever answered. Setting + `BARYOVM_STRICT_HOST_KEYS=1` (or `--strict-host-keys`) says so explicitly, and + also refuses on a terminal instead of asking. Record the key first, ideally from a committed file or a secret rather than an `ssh-keyscan` at deploy time. - **App secrets**. BaryoVM never reads or copies your apps' secrets. Backups may copy a stack's config file (e.g. `.env`) into the remote backup directory diff --git a/USAGE.md b/USAGE.md index ab132db..c6e9b33 100644 --- a/USAGE.md +++ b/USAGE.md @@ -50,9 +50,21 @@ baryovm vm forget-key oracle # drop its recorded SSH host key ### Host keys -The first connection to a machine records its SSH host key in -`~/.baryovm/known_hosts` and prints the fingerprint. Every connection after that -must match, and one that does not stops the command: +The first connection to a machine asks about its SSH host key, like OpenSSH. On +a terminal you see the host and the fingerprint it offered, and a prompt: + +```text +! 203.0.113.10:22 has no recorded host key + offered: SHA256:9KpQ... + verify it: ssh-keyscan -p 22 -t ecdsa,ed25519 203.0.113.10 | ssh-keygen -lf - +Trust this host key? [y/N] +``` + +Only `y` or `yes` trusts it and records it in `~/.baryovm/known_hosts`. Anything +else, including an empty answer, refuses and records nothing. With no terminal +(a pipe, CI) or with `-o json`, nobody can be asked, so an unknown host is +refused. Every connection after the first must match the recorded key, and one +that does not stops the command: ```text host key for 203.0.113.10:22 changed @@ -63,8 +75,12 @@ host key for 203.0.113.10:22 changed A rebuilt VM is the ordinary reason, and so is someone answering on that address who should not be. BaryoVM cannot tell them apart, so it stops. If you rebuilt the machine, `baryovm vm forget-key ` drops the old key and the -next connection learns the new one. There is no flag that turns the check off -for every host. +next connection asks about the new one. There is no flag that turns the check +off for every host. + +To get the old behaviour back, where an unknown host is learned on first use +without asking, set `BARYOVM_STRICT_HOST_KEYS=0` (or pass +`--strict-host-keys=false`). ### Host keys in CI @@ -73,7 +89,9 @@ between runs, so every run is the first one, and learning a key on each run means trusting whatever answers on that address, every time, with a key that can dump your database. -Strict mode refuses to learn. An unknown host is an error: +A CI job has no terminal, so an unknown host is refused by default. Setting +strict mode says so explicitly, and also refuses on a terminal instead of +asking: ```sh export BARYOVM_STRICT_HOST_KEYS=1 # or --strict-host-keys @@ -99,6 +117,8 @@ at deploy time trusts whatever answers; a committed file does not. The flag beats the environment, so `--strict-host-keys=false` is how a human turns it off for one command on a machine where the workflow sets it globally. +A job that used to rely on learning a fresh VM must now pin the key as above, or +set `BARYOVM_STRICT_HOST_KEYS=0` to keep learning. ### Keys held by ssh-agent @@ -1176,7 +1196,7 @@ What the file may and may not hold: partial. Each stack goes through the same code as `stack release` (backup first, sync, build, compose up, verify), so a safeguard added to one is in the other. -It never trusts a host on first use. Each VM needs a pinned `hostKey`, or the run needs +It never trusts a host on first use, and never asks about one. Each VM needs a pinned `hostKey`, or the run needs `--strict-host-keys` (or `BARYOVM_STRICT_HOST_KEYS=1`) with the key already in known_hosts. A pinned key is held for that run only and never written to disk, so a committed file cannot change what the machine trusts. If `$BARYOVM_HOME/known_hosts` or `~/.ssh/known_hosts` already holds a different key diff --git a/docs/commands/baryovm.md b/docs/commands/baryovm.md index 47f2fed..ea64619 100644 --- a/docs/commands/baryovm.md +++ b/docs/commands/baryovm.md @@ -12,7 +12,7 @@ CLI-first: the MAUI app and MCP server drive this same CLI (with -o json). ``` -h, --help help for baryovm -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud.md b/docs/commands/baryovm_cloud.md index 6837b59..66fe07f 100644 --- a/docs/commands/baryovm_cloud.md +++ b/docs/commands/baryovm_cloud.md @@ -16,7 +16,7 @@ baryovm cloud [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_firebase.md b/docs/commands/baryovm_cloud_firebase.md index 94cc182..c71517a 100644 --- a/docs/commands/baryovm_cloud_firebase.md +++ b/docs/commands/baryovm_cloud_firebase.md @@ -51,7 +51,7 @@ baryovm cloud firebase [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_gcloud.md b/docs/commands/baryovm_cloud_gcloud.md index 2dbd719..5c7d697 100644 --- a/docs/commands/baryovm_cloud_gcloud.md +++ b/docs/commands/baryovm_cloud_gcloud.md @@ -40,7 +40,7 @@ baryovm cloud gcloud [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_wrangler.md b/docs/commands/baryovm_cloud_wrangler.md index d27504c..e7a929a 100644 --- a/docs/commands/baryovm_cloud_wrangler.md +++ b/docs/commands/baryovm_cloud_wrangler.md @@ -42,7 +42,7 @@ baryovm cloud wrangler [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_deploy.md b/docs/commands/baryovm_deploy.md index c8dd961..8fdd8a7 100644 --- a/docs/commands/baryovm_deploy.md +++ b/docs/commands/baryovm_deploy.md @@ -33,7 +33,7 @@ baryovm deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_doctor.md b/docs/commands/baryovm_doctor.md index 3d5ef5d..821be92 100644 --- a/docs/commands/baryovm_doctor.md +++ b/docs/commands/baryovm_doctor.md @@ -23,7 +23,7 @@ baryovm doctor [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_gh.md b/docs/commands/baryovm_gh.md index a8f80ea..ec16365 100644 --- a/docs/commands/baryovm_gh.md +++ b/docs/commands/baryovm_gh.md @@ -42,7 +42,7 @@ baryovm gh [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_git.md b/docs/commands/baryovm_git.md index 33e0a4b..d138de9 100644 --- a/docs/commands/baryovm_git.md +++ b/docs/commands/baryovm_git.md @@ -59,7 +59,7 @@ baryovm git [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard.md b/docs/commands/baryovm_guard.md index 2765f12..a74e263 100644 --- a/docs/commands/baryovm_guard.md +++ b/docs/commands/baryovm_guard.md @@ -16,7 +16,7 @@ baryovm guard [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check.md b/docs/commands/baryovm_guard_check.md index 6385aca..e54217b 100644 --- a/docs/commands/baryovm_guard_check.md +++ b/docs/commands/baryovm_guard_check.md @@ -16,7 +16,7 @@ baryovm guard check [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_commit-msg.md b/docs/commands/baryovm_guard_check_commit-msg.md index aed3da1..d3d4c57 100644 --- a/docs/commands/baryovm_guard_check_commit-msg.md +++ b/docs/commands/baryovm_guard_check_commit-msg.md @@ -16,7 +16,7 @@ baryovm guard check commit-msg [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_pre-commit.md b/docs/commands/baryovm_guard_check_pre-commit.md index aae37cd..e98e1a4 100644 --- a/docs/commands/baryovm_guard_check_pre-commit.md +++ b/docs/commands/baryovm_guard_check_pre-commit.md @@ -16,7 +16,7 @@ baryovm guard check pre-commit [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_pre-push.md b/docs/commands/baryovm_guard_check_pre-push.md index 934b0ba..a53bdab 100644 --- a/docs/commands/baryovm_guard_check_pre-push.md +++ b/docs/commands/baryovm_guard_check_pre-push.md @@ -16,7 +16,7 @@ baryovm guard check pre-push [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_install-hooks.md b/docs/commands/baryovm_guard_install-hooks.md index 512cab9..31de903 100644 --- a/docs/commands/baryovm_guard_install-hooks.md +++ b/docs/commands/baryovm_guard_install-hooks.md @@ -24,7 +24,7 @@ baryovm guard install-hooks [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project.md b/docs/commands/baryovm_project.md index b2752e1..3bc6f27 100644 --- a/docs/commands/baryovm_project.md +++ b/docs/commands/baryovm_project.md @@ -16,7 +16,7 @@ baryovm project [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project_export.md b/docs/commands/baryovm_project_export.md index 7c50bb9..ed6b507 100644 --- a/docs/commands/baryovm_project_export.md +++ b/docs/commands/baryovm_project_export.md @@ -33,7 +33,7 @@ baryovm project export [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project_release.md b/docs/commands/baryovm_project_release.md index a77a2ea..2fab735 100644 --- a/docs/commands/baryovm_project_release.md +++ b/docs/commands/baryovm_project_release.md @@ -35,7 +35,7 @@ baryovm project release [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_prove.md b/docs/commands/baryovm_prove.md index 8c64fb4..d460654 100644 --- a/docs/commands/baryovm_prove.md +++ b/docs/commands/baryovm_prove.md @@ -33,7 +33,7 @@ baryovm prove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish.md b/docs/commands/baryovm_publish.md index f2c811d..0e126ad 100644 --- a/docs/commands/baryovm_publish.md +++ b/docs/commands/baryovm_publish.md @@ -16,7 +16,7 @@ baryovm publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish_npm.md b/docs/commands/baryovm_publish_npm.md index d1c3e28..e1b77d6 100644 --- a/docs/commands/baryovm_publish_npm.md +++ b/docs/commands/baryovm_publish_npm.md @@ -49,7 +49,7 @@ baryovm publish npm [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish_nuget.md b/docs/commands/baryovm_publish_nuget.md index ed3e2df..b380459 100644 --- a/docs/commands/baryovm_publish_nuget.md +++ b/docs/commands/baryovm_publish_nuget.md @@ -46,7 +46,7 @@ baryovm publish nuget [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo.md b/docs/commands/baryovm_repo.md index 358eace..83ebe88 100644 --- a/docs/commands/baryovm_repo.md +++ b/docs/commands/baryovm_repo.md @@ -16,7 +16,7 @@ baryovm repo [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_init.md b/docs/commands/baryovm_repo_init.md index cc93350..f1aa58f 100644 --- a/docs/commands/baryovm_repo_init.md +++ b/docs/commands/baryovm_repo_init.md @@ -70,7 +70,7 @@ baryovm repo init [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_move.md b/docs/commands/baryovm_repo_move.md index 918318f..173cf0a 100644 --- a/docs/commands/baryovm_repo_move.md +++ b/docs/commands/baryovm_repo_move.md @@ -65,7 +65,7 @@ baryovm repo move [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_verify.md b/docs/commands/baryovm_repo_verify.md index 7312f05..f7ec64d 100644 --- a/docs/commands/baryovm_repo_verify.md +++ b/docs/commands/baryovm_repo_verify.md @@ -46,7 +46,7 @@ baryovm repo verify [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_scan.md b/docs/commands/baryovm_scan.md index d02f3ca..cd7e0b6 100644 --- a/docs/commands/baryovm_scan.md +++ b/docs/commands/baryovm_scan.md @@ -35,7 +35,7 @@ baryovm scan --url [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_ship.md b/docs/commands/baryovm_ship.md index 647c767..bcd2fae 100644 --- a/docs/commands/baryovm_ship.md +++ b/docs/commands/baryovm_ship.md @@ -43,7 +43,7 @@ baryovm ship [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site.md b/docs/commands/baryovm_site.md index 181b126..42527c4 100644 --- a/docs/commands/baryovm_site.md +++ b/docs/commands/baryovm_site.md @@ -16,7 +16,7 @@ baryovm site [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site_add.md b/docs/commands/baryovm_site_add.md index 8ef4c44..f94c061 100644 --- a/docs/commands/baryovm_site_add.md +++ b/docs/commands/baryovm_site_add.md @@ -48,7 +48,7 @@ baryovm site add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site_deploy.md b/docs/commands/baryovm_site_deploy.md index f4be56f..9eaf60e 100644 --- a/docs/commands/baryovm_site_deploy.md +++ b/docs/commands/baryovm_site_deploy.md @@ -32,7 +32,7 @@ baryovm site deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack.md b/docs/commands/baryovm_stack.md index 36f0bf3..f8bfe9f 100644 --- a/docs/commands/baryovm_stack.md +++ b/docs/commands/baryovm_stack.md @@ -16,7 +16,7 @@ baryovm stack [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_add.md b/docs/commands/baryovm_stack_add.md index 7b4386c..e0d1c3d 100644 --- a/docs/commands/baryovm_stack_add.md +++ b/docs/commands/baryovm_stack_add.md @@ -30,7 +30,7 @@ baryovm stack add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_backup.md b/docs/commands/baryovm_stack_backup.md index ccbef7a..77fe0d3 100644 --- a/docs/commands/baryovm_stack_backup.md +++ b/docs/commands/baryovm_stack_backup.md @@ -18,7 +18,7 @@ baryovm stack backup [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_backups.md b/docs/commands/baryovm_stack_backups.md index a9150c9..12e3b90 100644 --- a/docs/commands/baryovm_stack_backups.md +++ b/docs/commands/baryovm_stack_backups.md @@ -16,7 +16,7 @@ baryovm stack backups [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_deploy.md b/docs/commands/baryovm_stack_deploy.md index 4dcd5d7..489a7ef 100644 --- a/docs/commands/baryovm_stack_deploy.md +++ b/docs/commands/baryovm_stack_deploy.md @@ -29,7 +29,7 @@ baryovm stack deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_discover.md b/docs/commands/baryovm_stack_discover.md index 593688b..5685f0b 100644 --- a/docs/commands/baryovm_stack_discover.md +++ b/docs/commands/baryovm_stack_discover.md @@ -40,7 +40,7 @@ baryovm stack discover [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env.md b/docs/commands/baryovm_stack_env.md index f14d5b2..652ef3e 100644 --- a/docs/commands/baryovm_stack_env.md +++ b/docs/commands/baryovm_stack_env.md @@ -27,7 +27,7 @@ baryovm stack env [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_list.md b/docs/commands/baryovm_stack_env_list.md index b1672cb..2854d2a 100644 --- a/docs/commands/baryovm_stack_env_list.md +++ b/docs/commands/baryovm_stack_env_list.md @@ -16,7 +16,7 @@ baryovm stack env list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_set.md b/docs/commands/baryovm_stack_env_set.md index 5721459..242fa42 100644 --- a/docs/commands/baryovm_stack_env_set.md +++ b/docs/commands/baryovm_stack_env_set.md @@ -17,7 +17,7 @@ baryovm stack env set [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_unset.md b/docs/commands/baryovm_stack_env_unset.md index ee19225..f07c81a 100644 --- a/docs/commands/baryovm_stack_env_unset.md +++ b/docs/commands/baryovm_stack_env_unset.md @@ -17,7 +17,7 @@ baryovm stack env unset [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_list.md b/docs/commands/baryovm_stack_list.md index 7923539..d511196 100644 --- a/docs/commands/baryovm_stack_list.md +++ b/docs/commands/baryovm_stack_list.md @@ -16,7 +16,7 @@ baryovm stack list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_logs.md b/docs/commands/baryovm_stack_logs.md index 9af66f3..442de6c 100644 --- a/docs/commands/baryovm_stack_logs.md +++ b/docs/commands/baryovm_stack_logs.md @@ -18,7 +18,7 @@ baryovm stack logs [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_ps.md b/docs/commands/baryovm_stack_ps.md index 07c838a..9e84058 100644 --- a/docs/commands/baryovm_stack_ps.md +++ b/docs/commands/baryovm_stack_ps.md @@ -16,7 +16,7 @@ baryovm stack ps [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_publish.md b/docs/commands/baryovm_stack_publish.md index 29b30d1..989d64a 100644 --- a/docs/commands/baryovm_stack_publish.md +++ b/docs/commands/baryovm_stack_publish.md @@ -35,7 +35,7 @@ baryovm stack publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_pull.md b/docs/commands/baryovm_stack_pull.md index 789747e..39460ad 100644 --- a/docs/commands/baryovm_stack_pull.md +++ b/docs/commands/baryovm_stack_pull.md @@ -17,7 +17,7 @@ baryovm stack pull [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_release.md b/docs/commands/baryovm_stack_release.md index 0b40527..dcbb747 100644 --- a/docs/commands/baryovm_stack_release.md +++ b/docs/commands/baryovm_stack_release.md @@ -32,7 +32,7 @@ baryovm stack release [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_remove.md b/docs/commands/baryovm_stack_remove.md index c1de57c..883624d 100644 --- a/docs/commands/baryovm_stack_remove.md +++ b/docs/commands/baryovm_stack_remove.md @@ -16,7 +16,7 @@ baryovm stack remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_restore.md b/docs/commands/baryovm_stack_restore.md index e76b48d..2f21d3c 100644 --- a/docs/commands/baryovm_stack_restore.md +++ b/docs/commands/baryovm_stack_restore.md @@ -28,7 +28,7 @@ baryovm stack restore [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_rollback.md b/docs/commands/baryovm_stack_rollback.md index eb3b750..a43d31c 100644 --- a/docs/commands/baryovm_stack_rollback.md +++ b/docs/commands/baryovm_stack_rollback.md @@ -30,7 +30,7 @@ baryovm stack rollback [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-backup.md b/docs/commands/baryovm_stack_set-backup.md index 6486586..0d6a8f4 100644 --- a/docs/commands/baryovm_stack_set-backup.md +++ b/docs/commands/baryovm_stack_set-backup.md @@ -40,7 +40,7 @@ baryovm stack set-backup [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-managed.md b/docs/commands/baryovm_stack_set-managed.md index e7ae4bb..881d043 100644 --- a/docs/commands/baryovm_stack_set-managed.md +++ b/docs/commands/baryovm_stack_set-managed.md @@ -42,7 +42,7 @@ baryovm stack set-managed [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-publish.md b/docs/commands/baryovm_stack_set-publish.md index 7ed9de8..06d545a 100644 --- a/docs/commands/baryovm_stack_set-publish.md +++ b/docs/commands/baryovm_stack_set-publish.md @@ -30,7 +30,7 @@ baryovm stack set-publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-update.md b/docs/commands/baryovm_stack_set-update.md index 9195bd7..f18c7ba 100644 --- a/docs/commands/baryovm_stack_set-update.md +++ b/docs/commands/baryovm_stack_set-update.md @@ -28,7 +28,7 @@ baryovm stack set-update [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-verify.md b/docs/commands/baryovm_stack_set-verify.md index a02f62e..203f7c8 100644 --- a/docs/commands/baryovm_stack_set-verify.md +++ b/docs/commands/baryovm_stack_set-verify.md @@ -35,7 +35,7 @@ baryovm stack set-verify [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_tls.md b/docs/commands/baryovm_stack_tls.md index f9010f4..9d7f9fb 100644 --- a/docs/commands/baryovm_stack_tls.md +++ b/docs/commands/baryovm_stack_tls.md @@ -33,7 +33,7 @@ baryovm stack tls [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_update.md b/docs/commands/baryovm_stack_update.md index 648189b..9905b9a 100644 --- a/docs/commands/baryovm_stack_update.md +++ b/docs/commands/baryovm_stack_update.md @@ -52,7 +52,7 @@ baryovm stack update [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_status.md b/docs/commands/baryovm_status.md index 3ed5daa..bd73d6c 100644 --- a/docs/commands/baryovm_status.md +++ b/docs/commands/baryovm_status.md @@ -45,7 +45,7 @@ baryovm status [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_up.md b/docs/commands/baryovm_up.md index 30019c4..85ce510 100644 --- a/docs/commands/baryovm_up.md +++ b/docs/commands/baryovm_up.md @@ -46,7 +46,7 @@ baryovm up [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_version.md b/docs/commands/baryovm_version.md index cb19538..7eb843a 100644 --- a/docs/commands/baryovm_version.md +++ b/docs/commands/baryovm_version.md @@ -16,7 +16,7 @@ baryovm version [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm.md b/docs/commands/baryovm_vm.md index 08612de..a4e874b 100644 --- a/docs/commands/baryovm_vm.md +++ b/docs/commands/baryovm_vm.md @@ -16,7 +16,7 @@ baryovm vm [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO @@ -25,7 +25,7 @@ baryovm vm [flags] * [baryovm vm add](baryovm_vm_add.md) - Register an existing VM by host + SSH key * [baryovm vm bootstrap](baryovm_vm_bootstrap.md) - Install the container runtime (docker or podman) on a VM (idempotent) * [baryovm vm exec](baryovm_vm_exec.md) - Run a command on a registered VM over SSH -* [baryovm vm forget-key](baryovm_vm_forget-key.md) - Forget a VM's recorded SSH host key, so the next connection learns it again +* [baryovm vm forget-key](baryovm_vm_forget-key.md) - Forget a VM's recorded SSH host key, so the next connection asks about it again * [baryovm vm harden](baryovm_vm_harden.md) - Apply the SSH hardening policy to a VM * [baryovm vm health](baryovm_vm_health.md) - Ask a VM the questions an owner should ask monthly (read only) * [baryovm vm list](baryovm_vm_list.md) - List registered VMs diff --git a/docs/commands/baryovm_vm_add.md b/docs/commands/baryovm_vm_add.md index c10d144..778c3d2 100644 --- a/docs/commands/baryovm_vm_add.md +++ b/docs/commands/baryovm_vm_add.md @@ -32,7 +32,7 @@ baryovm vm add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_bootstrap.md b/docs/commands/baryovm_vm_bootstrap.md index aa1aa9a..b7c73a8 100644 --- a/docs/commands/baryovm_vm_bootstrap.md +++ b/docs/commands/baryovm_vm_bootstrap.md @@ -18,7 +18,7 @@ baryovm vm bootstrap [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_exec.md b/docs/commands/baryovm_vm_exec.md index 8fdb113..d42909d 100644 --- a/docs/commands/baryovm_vm_exec.md +++ b/docs/commands/baryovm_vm_exec.md @@ -40,7 +40,7 @@ baryovm vm exec -- ... [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_forget-key.md b/docs/commands/baryovm_vm_forget-key.md index b91cba1..d52cffa 100644 --- a/docs/commands/baryovm_vm_forget-key.md +++ b/docs/commands/baryovm_vm_forget-key.md @@ -1,6 +1,6 @@ ## baryovm vm forget-key -Forget a VM's recorded SSH host key, so the next connection learns it again +Forget a VM's recorded SSH host key, so the next connection asks about it again ``` baryovm vm forget-key [flags] @@ -16,7 +16,7 @@ baryovm vm forget-key [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_harden.md b/docs/commands/baryovm_vm_harden.md index b23bd3e..6a06aed 100644 --- a/docs/commands/baryovm_vm_harden.md +++ b/docs/commands/baryovm_vm_harden.md @@ -58,7 +58,7 @@ baryovm vm harden [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_health.md b/docs/commands/baryovm_vm_health.md index 4cbf253..0c0a323 100644 --- a/docs/commands/baryovm_vm_health.md +++ b/docs/commands/baryovm_vm_health.md @@ -35,7 +35,7 @@ baryovm vm health [name] [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_list.md b/docs/commands/baryovm_vm_list.md index b34e072..4c0a330 100644 --- a/docs/commands/baryovm_vm_list.md +++ b/docs/commands/baryovm_vm_list.md @@ -16,7 +16,7 @@ baryovm vm list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_patch.md b/docs/commands/baryovm_vm_patch.md index b2f3d80..34f1d00 100644 --- a/docs/commands/baryovm_vm_patch.md +++ b/docs/commands/baryovm_vm_patch.md @@ -33,7 +33,7 @@ baryovm vm patch [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_ping.md b/docs/commands/baryovm_vm_ping.md index 7b9f8f4..af1367b 100644 --- a/docs/commands/baryovm_vm_ping.md +++ b/docs/commands/baryovm_vm_ping.md @@ -16,7 +16,7 @@ baryovm vm ping [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_provision.md b/docs/commands/baryovm_vm_provision.md index 65fe6e2..074d0d2 100644 --- a/docs/commands/baryovm_vm_provision.md +++ b/docs/commands/baryovm_vm_provision.md @@ -26,7 +26,7 @@ baryovm vm provision [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_prune.md b/docs/commands/baryovm_vm_prune.md index da21750..da4552c 100644 --- a/docs/commands/baryovm_vm_prune.md +++ b/docs/commands/baryovm_vm_prune.md @@ -38,7 +38,7 @@ baryovm vm prune [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote.md b/docs/commands/baryovm_vm_remote.md index 7d8b844..b389b85 100644 --- a/docs/commands/baryovm_vm_remote.md +++ b/docs/commands/baryovm_vm_remote.md @@ -24,7 +24,7 @@ baryovm vm remote [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote_install.md b/docs/commands/baryovm_vm_remote_install.md index 3073099..47c3d2c 100644 --- a/docs/commands/baryovm_vm_remote_install.md +++ b/docs/commands/baryovm_vm_remote_install.md @@ -28,7 +28,7 @@ baryovm vm remote install [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote_set.md b/docs/commands/baryovm_vm_remote_set.md index 21285ed..2c8c2f4 100644 --- a/docs/commands/baryovm_vm_remote_set.md +++ b/docs/commands/baryovm_vm_remote_set.md @@ -16,7 +16,7 @@ baryovm vm remote set [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remove.md b/docs/commands/baryovm_vm_remove.md index 65852de..b6f1aef 100644 --- a/docs/commands/baryovm_vm_remove.md +++ b/docs/commands/baryovm_vm_remove.md @@ -16,7 +16,7 @@ baryovm vm remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_runner.md b/docs/commands/baryovm_vm_runner.md index f17d477..e2b7360 100644 --- a/docs/commands/baryovm_vm_runner.md +++ b/docs/commands/baryovm_vm_runner.md @@ -38,7 +38,7 @@ baryovm vm runner [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_runner_remove.md b/docs/commands/baryovm_vm_runner_remove.md index 0561dde..05f790e 100644 --- a/docs/commands/baryovm_vm_runner_remove.md +++ b/docs/commands/baryovm_vm_runner_remove.md @@ -25,7 +25,7 @@ baryovm vm runner remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_threats.md b/docs/commands/baryovm_vm_threats.md index 06bcaa8..249093a 100644 --- a/docs/commands/baryovm_vm_threats.md +++ b/docs/commands/baryovm_vm_threats.md @@ -25,7 +25,7 @@ baryovm vm threats [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) ``` ### SEE ALSO diff --git a/internal/cli/project.go b/internal/cli/project.go index 7fb765a..f7159cd 100644 --- a/internal/cli/project.go +++ b/internal/cli/project.go @@ -95,6 +95,11 @@ func newProjectReleaseCmd() *cobra.Command { used[store.FindStack(n).VM] = true } // Pins live for this run only: a committed file must not change what this machine trusts. + // Whatever the default would do for an ordinary command, a release never asks about a host + // and never learns one: the unpinned check below needs the explicit request, and every + // unknown host is refused at connect. + requested := sshx.StrictHostKeysRequested() + defer sshx.ForceRefuse()() hk := hostkeys.New(baryovmHome()) hostkeys.ResetSessionPins() defer hostkeys.ResetSessionPins() @@ -104,7 +109,7 @@ func newProjectReleaseCmd() *cobra.Command { continue } if vm.HostKey == "" { - if !sshx.StrictHostKeys() { + if !requested { return fail(fmt.Errorf("vms[%d].hostKey: vm %q has no pinned host key, and a project release never trusts a host on first use: add its public key to the file (`ssh-keyscan -t ed25519 %s`, check the fingerprint) or pass --strict-host-keys with the key already in known_hosts", i, vm.Name, vm.Host)) } continue diff --git a/internal/cli/root.go b/internal/cli/root.go index 06bd49a..af1d294 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -7,11 +7,13 @@ package cli import ( + "bufio" "bytes" "errors" "fmt" "os" "strings" + "sync" "github.com/BaryoDev/BaryoVM/internal/fleet" "github.com/BaryoDev/BaryoVM/internal/hostkeys" @@ -42,12 +44,14 @@ func newRoot() *cobra.Command { if cmd.Flags().Changed("strict-host-keys") { sshx.SetStrictHostKeys(strictHostKeys) } + // A person can be asked about an unknown host only on a terminal and not in JSON mode. + sshx.SetInteractive(ui.IsTTY() && !ui.JSON()) }, } jsonHelp(root) root.PersistentFlags().StringVarP(&outputFormat, "output", "o", "human", "output format: human | json") root.PersistentFlags().BoolVar(&strictHostKeys, "strict-host-keys", false, - "refuse an unknown host instead of learning its key (also BARYOVM_STRICT_HOST_KEYS=1)") + "always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0)") root.AddCommand(newVersionCmd(), newVMCmd(), newDeployCmd(), newDoctorCmd(), newUpCmd(), newStackCmd(), newProjectCmd(), newScanCmd(), newGitCmd(), newGhCmd(), newPublishCmd(), newCloudCmd(), newGuardCmd(), newSiteCmd(), newRemoteGroupCmd(), newRepoCmd(), newStatusCmd(), newShipCmd(), newProveCmd()) rejectUnknownSubcommands(root) return root @@ -197,6 +201,7 @@ func Execute() { sshx.OnLearnHostKey = func(host, fingerprint string) { learned = append(learned, host+" "+fingerprint) } + sshx.ConfirmHostKey = confirmHostKey defer func() { for _, l := range learned { host, fp, _ := strings.Cut(l, " ") @@ -210,6 +215,25 @@ func Execute() { } } +// hostKeyPromptMu keeps two prompts apart when a fleet command dials several VMs at once. +var hostKeyPromptMu sync.Mutex + +// confirmHostKey asks the person whether to trust an unknown host's key. Only y or yes trusts; an +// empty answer, EOF or a read error does not. The spinner is paused around it, because the dial +// usually runs inside ui.Step and the spinner would erase the prompt. +func confirmHostKey(host, fingerprint string) bool { + hostKeyPromptMu.Lock() + defer hostKeyPromptMu.Unlock() + var ok bool + ui.Pause(func() { + ui.Warnf("%s has no recorded host key", host) + ui.Detail("offered", fingerprint) + ui.Detail("verify it", hostkeys.Keyscan(host)+" | ssh-keygen -lf -") + ok = askYesNo(bufio.NewReader(os.Stdin), "Trust this host key? [y/N] ") + }) + return ok +} + // run is Execute without the process exit: the command, then the error report, then the exit code. // Tests drive this, so they go through the same path a user does. func run(root *cobra.Command, args []string) int { diff --git a/internal/cli/vm.go b/internal/cli/vm.go index 5d29815..6c67bb5 100644 --- a/internal/cli/vm.go +++ b/internal/cli/vm.go @@ -284,7 +284,7 @@ func requireVM(name string) (fleet.VM, error) { return *vm, nil } -// newVMForgetKeyCmd drops a recorded host key so the next connection learns the new one. +// newVMForgetKeyCmd drops a recorded host key so the next connection asks about the new one. // // This exists because refusing a changed key is only useful if there is a stated way through it. A // rebuilt VM presents a new key legitimately, and without this command the operator's options are @@ -293,7 +293,7 @@ func requireVM(name string) (fleet.VM, error) { func newVMForgetKeyCmd() *cobra.Command { return &cobra.Command{ Use: "forget-key ", - Short: "Forget a VM's recorded SSH host key, so the next connection learns it again", + Short: "Forget a VM's recorded SSH host key, so the next connection asks about it again", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { target := args[0] @@ -321,7 +321,7 @@ func newVMForgetKeyCmd() *cobra.Command { ui.Emit(ui.Result{ OK: true, Action: "vm forget-key", - Message: fmt.Sprintf("forgot %d host key(s) for %s, the next connection will learn the new one", n, target), + Message: fmt.Sprintf("forgot %d host key(s) for %s, the next connection will ask about the new one", n, target), }) return nil }, diff --git a/internal/hostkeys/hostkeys.go b/internal/hostkeys/hostkeys.go index 98c2077..2aafb97 100644 --- a/internal/hostkeys/hostkeys.go +++ b/internal/hostkeys/hostkeys.go @@ -10,10 +10,12 @@ // about to do next, which includes pg_dump output streamed over the session and the contents of a // stack's config file. // -// Trust on first use, then refuse on change: +// Ask on first use, then refuse on change: // -// - Unknown host: record the key, print the fingerprint, continue. This is the fresh VM case and -// it is the one time a key can be learned without a second channel to check it against. +// - Unknown host: what happens is the Store's Mode. Ask hands the fingerprint to a confirm hook +// (the cli layer prompts a person) and records the key only on a yes. Refuse is an error, for CI +// and anything else with nobody to ask. Learn records it and carries on, which is how releases +// before this one behaved and is still available for someone who wants it. // - Known host, same key: continue silently. // - Known host, different key: refuse, print both fingerprints, and name the one command that // accepts the new key for that host. There is deliberately no flag that turns the check off @@ -67,29 +69,58 @@ func (e *ErrChanged) Error() string { e.Host, e.Stored, e.Offered, e.Host) } -// ErrUnknownHost is returned in strict mode for a host with no recorded key. It carries the offered -// fingerprint so an operator can pin it after checking it, rather than having to go and fetch it. +// ErrUnknownHost is returned for a host with no recorded key that was not trusted: refused outright +// (strict, or no terminal to ask on) or declined when asked. It carries the offered fingerprint so an +// operator can pin it after checking it, rather than having to go and fetch it. type ErrUnknownHost struct { Host string Offered string Store string + // Declined is set when a person was asked and did not say yes. Unset means nobody was asked. + Declined bool } func (e *ErrUnknownHost) Error() string { + if e.Declined { + return fmt.Sprintf( + "host key for %s not trusted.\n"+ + " offered %s\n"+ + "\n"+ + "Nothing was recorded. To trust it later, check that fingerprint against the machine and\n"+ + "record it:\n"+ + "\n"+ + " %s >> %s\n", + e.Host, e.Offered, Keyscan(e.Host), e.Store) + } return fmt.Sprintf( - "no recorded host key for %s, and strict host key checking is on.\n"+ + "no recorded host key for %s, and there is nobody to ask (strict host key checking, or no terminal).\n"+ " offered %s\n"+ "\n"+ - "Strict mode refuses to learn a key, because there is nobody here to check it. A runner\n"+ - "with no memory between runs would otherwise trust whatever answers on this address,\n"+ - "every run.\n"+ + "An unknown host is refused here, because nobody can check its key. A runner with no memory\n"+ + "between runs would otherwise trust whatever answers on this address, every run.\n"+ "\n"+ "Check that fingerprint against the machine, then record it before this runs:\n"+ "\n"+ - " %s >> %s\n", + " %s >> %s\n"+ + "\n"+ + "To learn an unknown host's key on first use instead, as releases before this one did, set\n"+ + "BARYOVM_STRICT_HOST_KEYS=0 (or pass --strict-host-keys=false).\n", e.Host, e.Offered, Keyscan(e.Host), e.Store) } +// Mode is what a Store does with a host that has no recorded key anywhere. +type Mode int + +const ( + // Learn records the key and carries on (trust on first use). It is the zero value because that is + // what a Store did before modes existed; the cli layer picks the real default. + Learn Mode = iota + // Refuse returns ErrUnknownHost without asking. + Refuse + // Ask calls the Store's confirm hook. No hook, or an answer other than yes, refuses. + Ask +) + // Keyscan is the ssh-keyscan command that fetches a host's ecdsa and ed25519 keys. ssh-keyscan // takes the port as -p and cannot resolve host:port. func Keyscan(hostport string) string { @@ -105,14 +136,16 @@ type Store struct { path string // BaryoVM's own known_hosts, written here extraPath string // the user's ~/.ssh/known_hosts, read but never written - // strict refuses to learn. An unknown host is an error rather than a key recorded on faith. - // - // Trust on first use assumes there is a first use: one moment where a key is learned and every - // connection after it is checked. A CI runner has no memory between runs, so every run is the - // first one, and TOFU degrades to accepting whatever answers on the recorded address, every - // time, with a key that can dump the production database. Strict mode is how CI says "I already - // know this key, and if you do not, stop". - strict bool + // mode decides an unknown host. Trust on first use assumes there is a first use: one moment where + // a key is learned and every connection after it is checked. A CI runner has no memory between + // runs, so every run is the first one, and TOFU degrades to accepting whatever answers on the + // recorded address, every time, with a key that can dump the production database. Refuse is how + // CI says "I already know this key, and if you do not, stop". + mode Mode + + // confirm is asked in Ask mode. It must not be called with the store locked by the caller, and it + // may block for as long as a person takes to read a fingerprint. + confirm func(host, fingerprint string) bool } // New returns the store rooted at dir, which is BaryoVM's home. @@ -125,16 +158,34 @@ func New(dir string) *Store { } // Strict makes an unknown host an error rather than something to learn. Set it wherever there is no -// human to check a fingerprint and no memory between runs. +// human to check a fingerprint and no memory between runs. Strict(false) is Mode(Learn). func (s *Store) Strict(on bool) *Store { - s.strict = on + if on { + s.mode = Refuse + } else { + s.mode = Learn + } + return s +} + +// Mode sets what happens to an unknown host. +func (s *Store) Mode(m Mode) *Store { + s.mode = m return s } -// Callback returns an ssh.HostKeyCallback implementing trust on first use. +// Confirm sets the hook Ask mode calls with the host and the offered fingerprint. Only a true answer +// trusts the key. The hostkeys package never prints or reads input, so whoever sets this does that. +func (s *Store) Confirm(fn func(host, fingerprint string) bool) *Store { + s.confirm = fn + return s +} + +// Callback returns an ssh.HostKeyCallback implementing the Store's mode for unknown hosts. // -// learned is called with the fingerprint when a key is recorded for the first time, so the caller -// can tell the operator what it just trusted. It is not called when the key was already known. +// learned is called with the fingerprint when a key is recorded for the first time in Learn mode, so +// the caller can tell the operator what it just trusted. It is not called when the key was already +// known, nor in Ask mode, where the person has just seen the fingerprint. func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCallback { return func(hostname string, remote net.Addr, key ssh.PublicKey) error { offered := ssh.FingerprintSHA256(key) @@ -194,8 +245,18 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall } // Unknown everywhere: the fresh VM case. - if s.strict { + switch s.mode { + case Refuse: return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path} + case Ask: + // A missing hook means nobody can be asked, which is a refusal, never a yes. + if s.confirm == nil { + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path} + } + if !s.confirm(hostname, offered) { + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Declined: true} + } + return s.add(hostname, key) } // Learn it. if err := s.add(hostname, key); err != nil { diff --git a/internal/hostkeys/hostkeys_test.go b/internal/hostkeys/hostkeys_test.go index e8993ff..9b56a91 100644 --- a/internal/hostkeys/hostkeys_test.go +++ b/internal/hostkeys/hostkeys_test.go @@ -279,7 +279,7 @@ func TestStrictStillReportsAChangedKeyAsChanged(t *testing.T) { if err := s.Callback(nil)("192.0.2.10:22", addr(t), first); err != nil { t.Fatalf("first: %v", err) } - s.strict = true + s.Strict(true) err := s.Callback(nil)("192.0.2.10:22", addr(t), second) var ce *ErrChanged if !errors.As(err, &ce) { @@ -324,3 +324,102 @@ func TestKnownHostsForReturnsOnlyTheRecordedKeyOfThatHost(t *testing.T) { t.Errorf("an unknown host must give no keys, got %q", none) } } + +func TestAskTrustsAndRecordsOnYes(t *testing.T) { + var gotHost, gotFP string + s := newStore(t).Mode(Ask).Confirm(func(host, fp string) bool { + gotHost, gotFP = host, fp + return true + }) + key := newKey(t) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), key); err != nil { + t.Fatalf("a yes must trust the key: %v", err) + } + if gotHost != "192.0.2.10:22" || gotFP != ssh.FingerprintSHA256(key) { + t.Errorf("confirm saw %q %q, want the host and the offered fingerprint", gotHost, gotFP) + } + if b, _ := os.ReadFile(s.Path()); !strings.Contains(string(b), "192.0.2.10") { + t.Error("a yes must record the key") + } + // Recorded, so the next connection is a known host and is not asked again. + again := newStore(t).Mode(Ask).Confirm(func(string, string) bool { t.Error("asked about a known host"); return false }) + again.path = s.Path() + if err := again.Callback(nil)("192.0.2.10:22", addr(t), key); err != nil { + t.Fatalf("known key after a yes: %v", err) + } +} + +func TestAskRefusesAndWritesNothingOnNo(t *testing.T) { + s := newStore(t).Mode(Ask).Confirm(func(string, string) bool { return false }) + err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)) + var ue *ErrUnknownHost + if !errors.As(err, &ue) || !ue.Declined { + t.Fatalf("want a declined ErrUnknownHost, got %T: %v", err, err) + } + if !strings.Contains(err.Error(), "not trusted") { + t.Errorf("a declined key must say it was not trusted: %v", err) + } + if _, err := os.Stat(s.Path()); err == nil { + t.Fatal("a no must not write a known_hosts entry") + } +} + +func TestAskWithNoConfirmHookRefuses(t *testing.T) { + s := newStore(t).Mode(Ask) + err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)) + var ue *ErrUnknownHost + if !errors.As(err, &ue) || ue.Declined { + t.Fatalf("want ErrUnknownHost with nobody asked, got %T: %v", err, err) + } + if _, err := os.Stat(s.Path()); err == nil { + t.Fatal("nothing may be written when nobody was asked") + } +} + +func TestLearnModeStillLearnsWithoutAsking(t *testing.T) { + s := newStore(t).Mode(Learn).Confirm(func(string, string) bool { t.Error("learn mode must not ask"); return false }) + var learned string + if err := s.Callback(func(_, fp string) { learned = fp })("192.0.2.10:22", addr(t), newKey(t)); err != nil { + t.Fatalf("learn: %v", err) + } + if learned == "" { + t.Error("the learned hook must be called in Learn mode") + } + if _, err := os.Stat(s.Path()); err != nil { + t.Error("Learn must record the key") + } +} + +func TestAskDoesNotCallTheLearnedHook(t *testing.T) { + s := newStore(t).Mode(Ask).Confirm(func(string, string) bool { return true }) + if err := s.Callback(func(_, _ string) { t.Error("the person just saw the fingerprint; learned must not repeat it") })("192.0.2.10:22", addr(t), newKey(t)); err != nil { + t.Fatal(err) + } +} + +// A changed key is refused in every mode, and Ask must not even prompt for it. +func TestAChangedKeyIsRefusedInEveryMode(t *testing.T) { + for _, m := range []Mode{Learn, Refuse, Ask} { + s := newStore(t) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)); err != nil { + t.Fatalf("first: %v", err) + } + s.Mode(m).Confirm(func(string, string) bool { t.Error("a changed key must not be asked about"); return true }) + var ce *ErrChanged + if err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)); !errors.As(err, &ce) { + t.Errorf("mode %v: want ErrChanged, got %T: %v", m, err, err) + } + } +} + +func TestUnknownHostMessageNamesTheWayBackToLearning(t *testing.T) { + msg := (&ErrUnknownHost{Host: "192.0.2.10:22", Offered: "SHA256:x", Store: "/k"}).Error() + for _, want := range []string{"BARYOVM_STRICT_HOST_KEYS=0", "ssh-keyscan", "/k"} { + if !strings.Contains(msg, want) { + t.Errorf("message must mention %q: %s", want, msg) + } + } + if strings.Contains(msg, "strict host key checking is on") { + t.Error("the message must be right for the no-terminal default too") + } +} diff --git a/internal/sshx/askhostkey_test.go b/internal/sshx/askhostkey_test.go new file mode 100644 index 0000000..671b587 --- /dev/null +++ b/internal/sshx/askhostkey_test.go @@ -0,0 +1,275 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +package sshx + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/pem" + "errors" + "net" + "os" + "path/filepath" + "sync/atomic" + "testing" + "time" + + "golang.org/x/crypto/ssh" + + "github.com/BaryoDev/BaryoVM/internal/hostkeys" +) + +// setHostKeyState sets the process-wide inputs of the mode rule and puts them back afterwards. +func setHostKeyState(t *testing.T, override *bool, canAsk bool, confirm func(host, fp string) bool) { + t.Helper() + oldOverride, oldInteractive, oldConfirm := strictOverride, interactive, ConfirmHostKey + t.Cleanup(func() { strictOverride, interactive, ConfirmHostKey = oldOverride, oldInteractive, oldConfirm }) + strictOverride, interactive, ConfirmHostKey = override, canAsk, confirm +} + +func boolPtr(b bool) *bool { return &b } + +func TestHostKeyModeResolution(t *testing.T) { + yes := func(string, string) bool { return true } + cases := []struct { + name string + override *bool + env string + canAsk bool + confirm func(string, string) bool + want hostkeys.Mode + }{ + {"default on a terminal asks", nil, "", true, yes, hostkeys.Ask}, + {"default with no terminal or JSON refuses", nil, "", false, yes, hostkeys.Refuse}, + {"default on a terminal with nothing to ask with refuses", nil, "", true, nil, hostkeys.Refuse}, + {"env strict refuses on a terminal", nil, "1", true, yes, hostkeys.Refuse}, + {"env true refuses", nil, "true", true, yes, hostkeys.Refuse}, + {"env 0 learns on a terminal", nil, "0", true, yes, hostkeys.Learn}, + {"env off learns with no terminal", nil, "off", false, yes, hostkeys.Learn}, + {"env no learns", nil, "no", false, nil, hostkeys.Learn}, + {"env false learns", nil, "false", false, nil, hostkeys.Learn}, + {"env gibberish is the default", nil, "maybe", true, yes, hostkeys.Ask}, + {"flag strict beats env 0", boolPtr(true), "0", true, yes, hostkeys.Refuse}, + {"flag false beats env 1", boolPtr(false), "1", false, yes, hostkeys.Learn}, + {"flag false on a terminal learns, it does not ask", boolPtr(false), "", true, yes, hostkeys.Learn}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", c.env) + setHostKeyState(t, c.override, c.canAsk, c.confirm) + if got := HostKeyMode(); got != c.want { + t.Errorf("HostKeyMode() = %v, want %v", got, c.want) + } + if got, want := StrictHostKeys(), c.want == hostkeys.Refuse; got != want { + t.Errorf("StrictHostKeys() = %v, want %v", got, want) + } + }) + } +} + +func TestStrictHostKeysRequestedIsOnlyAnExplicitRequest(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + setHostKeyState(t, nil, false, nil) + if StrictHostKeysRequested() { + t.Error("the no-terminal default refuses but was not requested; a project release must still want a pin") + } + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "1") + if !StrictHostKeysRequested() { + t.Error("BARYOVM_STRICT_HOST_KEYS=1 is an explicit request") + } + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + if StrictHostKeysRequested() { + t.Error("BARYOVM_STRICT_HOST_KEYS=0 is not a strict request") + } +} + +func TestForceRefuseBeatsEveryOtherSettingAndRestores(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + setHostKeyState(t, boolPtr(false), true, func(string, string) bool { return true }) + restore := ForceRefuse() + if got := HostKeyMode(); got != hostkeys.Refuse { + t.Errorf("under ForceRefuse HostKeyMode() = %v, want Refuse", got) + } + restore() + if got := HostKeyMode(); got != hostkeys.Learn { + t.Errorf("after restore HostKeyMode() = %v, want Learn", got) + } +} + +// dialUnknownHost dials a server whose key BaryoVM has never seen, with an empty home, and returns +// the home so a test can look at what was recorded. +func dialUnknownHost(t *testing.T, host string, port int) (string, error) { + t.Helper() + home := t.TempDir() + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_HOME", home) + _, priv, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + t.Fatalf("generate login key: %v", err) + } + block, err := ssh.MarshalPrivateKey(priv, "") + if err != nil { + t.Fatalf("marshal login key: %v", err) + } + keyPath := filepath.Join(t.TempDir(), "id") + if err := os.WriteFile(keyPath, pem.EncodeToMemory(block), 0o600); err != nil { + t.Fatalf("write login key: %v", err) + } + c, err := Dial(Target{Host: host, Port: port, User: "u", KeyPath: keyPath}) + if err == nil { + c.c.Close() + } + return home, err +} + +func recorded(home string) string { + b, _ := os.ReadFile(filepath.Join(home, "known_hosts")) + return string(b) +} + +func TestDialAsksAboutAnUnknownHostAndRecordsTheKeyOnYes(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + signer := ed25519Signer(t) + host, port := serveHostKeys(t, signer) + var asked atomic.Int32 + var gotFP string + setHostKeyState(t, nil, true, func(_, fp string) bool { + asked.Add(1) + gotFP = fp + return true + }) + home, err := dialUnknownHost(t, host, port) + if err != nil { + t.Fatalf("a yes must let the dial through: %v", err) + } + if asked.Load() != 1 { + t.Errorf("asked %d times, want once", asked.Load()) + } + if gotFP != ssh.FingerprintSHA256(signer.PublicKey()) { + t.Errorf("the prompt was shown %q, not the offered fingerprint", gotFP) + } + if recorded(home) == "" { + t.Error("a yes must record the key") + } +} + +func TestDialRefusesAndRecordsNothingWhenTheAnswerIsNo(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port := serveHostKeys(t, ed25519Signer(t)) + setHostKeyState(t, nil, true, func(string, string) bool { return false }) + home, err := dialUnknownHost(t, host, port) + var unknown *hostkeys.ErrUnknownHost + if !errors.As(err, &unknown) || !unknown.Declined { + t.Fatalf("want a declined ErrUnknownHost, got %v", err) + } + if recorded(home) != "" { + t.Error("a no must not record the key") + } +} + +func TestDialRefusesAnUnknownHostWithNoTerminal(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port := serveHostKeys(t, ed25519Signer(t)) + var asked atomic.Int32 + setHostKeyState(t, nil, false, func(string, string) bool { asked.Add(1); return true }) + home, err := dialUnknownHost(t, host, port) + var unknown *hostkeys.ErrUnknownHost + if !errors.As(err, &unknown) || unknown.Declined { + t.Fatalf("want ErrUnknownHost that nobody was asked about, got %v", err) + } + if asked.Load() != 0 { + t.Error("with no terminal nobody may be asked") + } + if recorded(home) != "" { + t.Error("a refused host must not be recorded") + } +} + +func TestDialLearnsSilentlyWhenStrictIsSwitchedOff(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + host, port := serveHostKeys(t, ed25519Signer(t)) + var asked atomic.Int32 + setHostKeyState(t, nil, true, func(string, string) bool { asked.Add(1); return false }) + home, err := dialUnknownHost(t, host, port) + if err != nil { + t.Fatalf("BARYOVM_STRICT_HOST_KEYS=0 must learn on first use: %v", err) + } + if asked.Load() != 0 { + t.Error("learning must not prompt") + } + if recorded(home) == "" { + t.Error("learning must record the key") + } +} + +func TestDialStrictRefusesEvenWhenAPersonCouldBeAsked(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port := serveHostKeys(t, ed25519Signer(t)) + var asked atomic.Int32 + setHostKeyState(t, boolPtr(true), true, func(string, string) bool { asked.Add(1); return true }) + _, err := dialUnknownHost(t, host, port) + var unknown *hostkeys.ErrUnknownHost + if !errors.As(err, &unknown) || asked.Load() != 0 { + t.Fatalf("strict must refuse without asking, got %v (asked %d)", err, asked.Load()) + } +} + +// A person reading a fingerprint can take longer than the handshake deadline. The time spent in the +// prompt must not count against it. +func TestPromptTimeIsNotCountedAgainstTheHandshakeDeadline(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port := serveHostKeys(t, ed25519Signer(t)) + setHostKeyState(t, nil, true, func(string, string) bool { + time.Sleep(900 * time.Millisecond) + return true + }) + old := handshakeTimeout + handshakeTimeout = 300 * time.Millisecond + defer func() { handshakeTimeout = old }() + + if _, err := dialUnknownHost(t, host, port); err != nil { + t.Fatalf("a prompt longer than the handshake deadline must not fail the dial: %v", err) + } +} + +// The deadline still bounds a host that stalls after the prompt is answered. +func TestHandshakeDeadlineIsRearmedAfterThePrompt(t *testing.T) { + g := &handshakeGuard{} + srv, cli := netPipe(t) + defer srv.Close() + defer cli.Close() + _ = cli.SetDeadline(time.Now().Add(time.Hour)) + g.set(cli, 100*time.Millisecond) + g.pause(func() { time.Sleep(200 * time.Millisecond) }) + res := make(chan error, 1) + go func() { + _, err := cli.Read(make([]byte, 1)) + res <- err + }() + select { + case err := <-res: + if err == nil { + t.Fatal("read should time out, nothing was written") + } + case <-time.After(2 * time.Second): + t.Fatal("deadline not re-armed to the handshake window after the prompt") + } +} + +func netPipe(t *testing.T) (net.Conn, net.Conn) { + t.Helper() + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + acc := make(chan net.Conn, 1) + go func() { c, _ := ln.Accept(); acc <- c }() + cli, err := net.Dial("tcp", ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + return <-acc, cli +} diff --git a/internal/sshx/sshx.go b/internal/sshx/sshx.go index c555e5f..1387729 100644 --- a/internal/sshx/sshx.go +++ b/internal/sshx/sshx.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "strings" + "sync" "time" "golang.org/x/crypto/ssh" @@ -35,35 +36,92 @@ func home() string { return filepath.Join(h, ".baryovm") } -// StrictHostKeys reports whether an unknown host should be refused rather than learned. -// -// Read from the environment rather than passed down, because it has to reach a dial from every -// command without threading a parameter through six engine packages that have no business knowing -// about it. BARYOVM_STRICT_HOST_KEYS=1 is the form a CI job sets once for the whole workflow. -// // strictOverride is what the --strict-host-keys flag sets, so the flag wins over the environment. var strictOverride *bool +// interactive is set by the cli layer when a person can be asked: stdin and stderr are terminals and +// output is not JSON. sshx cannot look, because the terminal and the output mode live in ui and the +// dependency direction in CLAUDE.md runs one way. Unset means nobody can be asked. +var interactive bool + // SetStrictHostKeys is how the cli layer applies its flag. func SetStrictHostKeys(on bool) { strictOverride = &on } -// StrictHostKeys resolves the flag, then the environment. -func StrictHostKeys() bool { +// SetInteractive tells sshx whether a person can be asked about an unknown host key. +func SetInteractive(on bool) { interactive = on } + +// ForceRefuse makes every unknown host a refusal until the returned function is called, whatever the +// flag, the environment or the terminal say. A release uses it so that no host is ever trusted on +// first use during one, by prompt or otherwise. +func ForceRefuse() (restore func()) { + prev := strictOverride + on := true + strictOverride = &on + return func() { strictOverride = prev } +} + +// strictSetting reports an explicit choice: 1 strict (refuse), 0 learn on first use, -1 nothing set. +// The flag wins over the environment. BARYOVM_STRICT_HOST_KEYS is what a CI job sets once for the +// whole workflow, read here rather than passed down because it has to reach a dial from every +// command without threading a parameter through six engine packages. +func strictSetting() int { if strictOverride != nil { - return *strictOverride + if *strictOverride { + return 1 + } + return 0 } - switch os.Getenv("BARYOVM_STRICT_HOST_KEYS") { + switch strings.ToLower(os.Getenv("BARYOVM_STRICT_HOST_KEYS")) { case "1", "true", "yes", "on": - return true + return 1 + case "0", "false", "no", "off": + return 0 } - return false + return -1 } +// resolveMode is the rule for an unknown host. An explicit strict setting refuses, an explicit +// non-strict one learns on first use, and with nothing set a person is asked when there is one (and +// something to ask them with) and the host is refused when there is not. +func resolveMode(setting int, canAsk bool) hostkeys.Mode { + switch setting { + case 1: + return hostkeys.Refuse + case 0: + return hostkeys.Learn + } + if canAsk { + return hostkeys.Ask + } + return hostkeys.Refuse +} + +// HostKeyMode resolves the flag, then the environment, then whether a person can be asked. +func HostKeyMode() hostkeys.Mode { + return resolveMode(strictSetting(), interactive && ConfirmHostKey != nil) +} + +// StrictHostKeys reports whether an unknown host will be refused without asking. With nothing set +// that is true when there is no terminal, so it is not the same as "strict was requested"; see +// StrictHostKeysRequested. +func StrictHostKeys() bool { return HostKeyMode() == hostkeys.Refuse } + +// StrictHostKeysRequested reports whether the flag or BARYOVM_STRICT_HOST_KEYS asked for strict +// checking. A project release needs this, not the default: it must have a pin or an explicit strict +// request before it connects. +func StrictHostKeysRequested() bool { return strictSetting() == 1 } + // OnLearnHostKey is called the first time a host key is recorded, so the operator sees the // fingerprint they are now trusting. The cli layer sets it; sshx does not print (see CLAUDE.md on // the dependency direction), so a nil hook means the learning is silent. var OnLearnHostKey func(host, fingerprint string) +// ConfirmHostKey asks whether to trust an unknown host's key, and returns true only for a yes. The +// cli layer sets it and does the prompting; sshx never prints or reads input. It may block for as +// long as a person takes, and Dial keeps that time out of the handshake deadline. A nil hook means an +// unknown host cannot be asked about and is refused. +var ConfirmHostKey func(host, fingerprint string) bool + func learned(host, fingerprint string) { if OnLearnHostKey != nil { OnLearnHostKey(host, fingerprint) @@ -92,7 +150,16 @@ func Dial(t Target) (*Client, error) { } defer closeAgent() // signing happens during the handshake, so the agent is done once Dial returns addr := net.JoinHostPort(t.Host, fmt.Sprintf("%d", t.Port)) - store := hostkeys.New(home()).Strict(StrictHostKeys()) + guard := &handshakeGuard{} + store := hostkeys.New(home()).Mode(HostKeyMode()) + if confirm := ConfirmHostKey; confirm != nil { + // The handshake deadline is for a host that stalls, not for a person reading a fingerprint. + store.Confirm(func(host, fp string) bool { + var ok bool + guard.pause(func() { ok = confirm(host, fp) }) + return ok + }) + } cfg := &ssh.ClientConfig{ User: t.User, Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, @@ -102,7 +169,7 @@ func Dial(t Target) (*Client, error) { HostKeyAlgorithms: store.Algorithms(addr), Timeout: 15 * time.Second, } - c, err := dialWithHandshakeDeadline(addr, cfg, handshakeTimeout) + c, err := dialGuarded(addr, cfg, handshakeTimeout, guard) if err != nil { return nil, fmt.Errorf("ssh dial %s: %w", addr, err) } @@ -121,9 +188,44 @@ var ( keepAliveReplyTimeout = 20 * time.Second ) +// handshakeGuard lets the handshake deadline be set aside while something waits on a person. +type handshakeGuard struct { + mu sync.Mutex + conn net.Conn + handshake time.Duration +} + +func (g *handshakeGuard) set(conn net.Conn, handshake time.Duration) { + g.mu.Lock() + g.conn, g.handshake = conn, handshake + g.mu.Unlock() +} + +// pause clears the connection deadline, runs fn, then gives the rest of the handshake a fresh full +// window. The time fn takes is not counted against the deadline. +func (g *handshakeGuard) pause(fn func()) { + g.mu.Lock() + conn, handshake := g.conn, g.handshake + g.mu.Unlock() + if conn != nil { + _ = conn.SetDeadline(time.Time{}) + } + defer func() { + if conn != nil { + _ = conn.SetDeadline(time.Now().Add(handshake)) + } + }() + fn() +} + // dialWithHandshakeDeadline is ssh.Dial with a deadline on the connection until the handshake is // done, then cleared so a long command is not cut off. func dialWithHandshakeDeadline(addr string, cfg *ssh.ClientConfig, handshake time.Duration) (*ssh.Client, error) { + return dialGuarded(addr, cfg, handshake, &handshakeGuard{}) +} + +// dialGuarded is dialWithHandshakeDeadline whose deadline guard can be paused by a host key prompt. +func dialGuarded(addr string, cfg *ssh.ClientConfig, handshake time.Duration, guard *handshakeGuard) (*ssh.Client, error) { conn, err := net.DialTimeout("tcp", addr, cfg.Timeout) if err != nil { return nil, err @@ -132,6 +234,7 @@ func dialWithHandshakeDeadline(addr string, cfg *ssh.ClientConfig, handshake tim _ = conn.Close() return nil, err } + guard.set(conn, handshake) sc, chans, reqs, err := ssh.NewClientConn(conn, addr, cfg) if err != nil { _ = conn.Close() diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 380fa82..51d0590 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -12,6 +12,7 @@ import ( "encoding/json" "fmt" "os" + "sync" "time" "github.com/charmbracelet/lipgloss" @@ -136,6 +137,22 @@ func Emit(r Result) { } } +// frameMu is held while the spinner draws a frame and while a prompt owns the line, so the two never +// write at once. +var frameMu sync.Mutex + +// Pause runs fn with any spinner stopped and its line cleared, for a prompt that has to be read +// and answered. The spinner redraws every 80ms, which would erase a prompt drawn under it. It +// resumes when fn returns. Safe to call with no spinner running. +func Pause(fn func()) { + frameMu.Lock() + defer frameMu.Unlock() + if !jsonMode && isTTY() { + fmt.Fprint(os.Stderr, "\r\033[K") + } + fn() +} + var dotFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} // Step runs fn while showing a dot spinner (baryo-cli's spinner.Dot), then @@ -157,7 +174,9 @@ func Step(msg string, fn func() error) error { return case <-t.C: frame := AccentStyle.Render(dotFrames[i%len(dotFrames)]) + frameMu.Lock() fmt.Fprintf(os.Stderr, "\r%s %s", frame, DimStyle.Render(msg)) + frameMu.Unlock() i++ } } From 7a4005c6a62d73c44937147169003ff34cdac758 Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:00:56 +0800 Subject: [PATCH 2/6] let the vm add detection test learn its test server's key --- internal/cli/vm_add_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/cli/vm_add_test.go b/internal/cli/vm_add_test.go index cc16491..e29e5ff 100644 --- a/internal/cli/vm_add_test.go +++ b/internal/cli/vm_add_test.go @@ -158,6 +158,9 @@ func TestVMAddHostKeyMismatchStillFailsAndSavesNothing(t *testing.T) { func TestVMAddDetectionFailureKeepsTheErrorAndDoesNotSayUnreachable(t *testing.T) { t.Setenv("BARYOVM_HOME", t.TempDir()) t.Setenv("HOME", t.TempDir()) + // The test server's key is new and there is no terminal, which is refused by default. This test + // is about detection, so it learns the key the way releases before host key prompts did. + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") cfg := &ssh.ServerConfig{NoClientAuth: true} cfg.AddHostKey(newSigner(t)) From b2eb2db0c18980ec0b43a6de59b18f3552ba85b9 Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:06:47 +0800 Subject: [PATCH 3/6] name why a new host key was refused and let vm add trust a checked fingerprint --- CHANGELOG.md | 8 +- USAGE.md | 11 +- docs/commands/baryovm_vm_add.md | 7 ++ docs/indie.md | 3 +- docs/real-hosts/azure-ubuntu-x86.md | 6 +- docs/sme.md | 4 +- docs/troubleshooting.md | 31 ++++-- internal/cli/project_test.go | 46 +++++++++ internal/cli/root.go | 23 ++++- internal/cli/vm.go | 17 ++- internal/cli/vm_add_test.go | 119 +++++++++++++++++++++ internal/hostkeys/hostkeys.go | 154 ++++++++++++++++++++++++---- internal/hostkeys/hostkeys_test.go | 127 +++++++++++++++++++++-- internal/sshx/askhostkey_test.go | 83 ++++++++++++++- internal/sshx/sshx.go | 70 +++++++++++-- 15 files changed, 649 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2bc176..5d8439a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,13 @@ previously accepted is called out here rather than left to be discovered. `known_hosts` first, or set `BARYOVM_STRICT_HOST_KEYS=0`. To get the old learn-on-first-use behaviour everywhere, set `BARYOVM_STRICT_HOST_KEYS=0` or pass `--strict-host-keys=false` (the flag wins over the environment). Known keys and changed keys behave as before, and time spent at - the prompt does not count against the 30 second handshake deadline. + the prompt does not count against the 30 second handshake deadline. The refusal says why nobody + was asked (no terminal, JSON, strict, a project release, declined) and only advises + `BARYOVM_STRICT_HOST_KEYS=0` where it applies. `vm add --host-key-fingerprint SHA256:...` lets a + script or app that has had a person check the key trust it without a prompt: a host offering + exactly that key is recorded, any other key is refused, and a changed key is still refused. Under + `-o json` the unknown-host error carries `host`, `offered` and `reason` as `data` fields. The + `ssh-keyscan` hint now includes `rsa`, and parallel dials to one new host prompt once. ### Fixed diff --git a/USAGE.md b/USAGE.md index c6e9b33..f1ee2f4 100644 --- a/USAGE.md +++ b/USAGE.md @@ -56,7 +56,7 @@ a terminal you see the host and the fingerprint it offered, and a prompt: ```text ! 203.0.113.10:22 has no recorded host key offered: SHA256:9KpQ... - verify it: ssh-keyscan -p 22 -t ecdsa,ed25519 203.0.113.10 | ssh-keygen -lf - + verify it: ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 203.0.113.10 | ssh-keygen -lf - Trust this host key? [y/N] ``` @@ -103,7 +103,7 @@ So a CI job records the key first, and fails rather than trusting a new one: - name: Pin the host key run: | mkdir -p ~/.baryovm - ssh-keyscan -t ecdsa,ed25519 "$VM_HOST" >> ~/.baryovm/known_hosts + ssh-keyscan -t ecdsa,ed25519,rsa "$VM_HOST" >> ~/.baryovm/known_hosts - name: Deploy env: @@ -174,6 +174,13 @@ give `--os linux|windows` and it does not connect at all. Any host with a POSIX (Linux, macOS, FreeBSD) is recorded as `linux`. If the host cannot be reached (refused, timed out) or does not answer the probe, `vm add` still saves it, with no OS, which reads as Linux, and warns; run `vm add` again when the host is up, or pass `--os windows`. +A new host's key is asked about on a terminal. A script or app (`-o json`, no terminal) cannot be +asked, so `vm add` refuses and the JSON error carries `data.host`, `data.offered` and `data.reason`. +Show that fingerprint to the person, and once they have checked it against the machine, run again +with `--host-key-fingerprint SHA256:...`: a host offering exactly that key is recorded and the add +continues, and any other key is refused with both fingerprints. The flag does not apply to a host +that already has a different key on record, which is still a changed key, and a `project release` +ignores it. A host key that does not match the one on record is not "unreachable": `vm add` fails and saves nothing. Entries from before this existed are read as Linux, and an `os` that is neither `linux` nor `windows` is refused by every command that uses it. diff --git a/docs/commands/baryovm_vm_add.md b/docs/commands/baryovm_vm_add.md index 778c3d2..3884f27 100644 --- a/docs/commands/baryovm_vm_add.md +++ b/docs/commands/baryovm_vm_add.md @@ -11,6 +11,12 @@ linux) and a warning; a host key mismatch still fails. With --os windows the SSH shell is recorded as cmd, the OpenSSH default; pass --shell powershell if the host's default shell is powershell.exe. +An unknown host key is asked about on a terminal and refused with no terminal or +under -o json. A script or app that has had a person check the key can pass its +SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key +is recorded and the command continues, and any other key is refused. A host with +a different recorded key is still refused. + ``` baryovm vm add [flags] ``` @@ -20,6 +26,7 @@ baryovm vm add [flags] ``` -h, --help help for add --host string public IP or hostname (required) + --host-key-fingerprint string trust an unknown host that offers exactly this SHA256 fingerprint, without asking --key string path to the private SSH key (required) --os string host OS, linux or windows (default: detect over SSH) --port int SSH port (default 22) diff --git a/docs/indie.md b/docs/indie.md index 34888fc..5ff1907 100644 --- a/docs/indie.md +++ b/docs/indie.md @@ -19,7 +19,8 @@ baryovm vm add myvm --host --user ubuntu --key ~/.ssh/id_ed25519 baryovm vm ping myvm ``` -`vm add` connects once to detect the OS and records the host key in `~/.baryovm/known_hosts`. +`vm add` connects once to detect the OS. On a terminal it shows the host key fingerprint and asks +before recording it in `~/.baryovm/known_hosts`. `vm ping` reports the host and the Docker version. If either fails, see [troubleshooting](troubleshooting.md). diff --git a/docs/real-hosts/azure-ubuntu-x86.md b/docs/real-hosts/azure-ubuntu-x86.md index 52fab54..61c7e60 100644 --- a/docs/real-hosts/azure-ubuntu-x86.md +++ b/docs/real-hosts/azure-ubuntu-x86.md @@ -30,8 +30,10 @@ $ baryovm vm ping azure-x86 host: Linux 7.0.0-1017-azure docker: not installed ✓ azure-x86 reachable -! learned the host key for :22: SHA256:... - verify it: ssh-keyscan -t ecdsa,ed25519 :22 | ssh-keygen -lf - +! :22 has no recorded host key + offered: SHA256:... + verify it: ssh-keyscan -p 22 -t ecdsa,ed25519,rsa | ssh-keygen -lf - +Trust this host key? [y/N] y $ baryovm vm exec azure-x86 -- cat /etc/os-release PRETTY_NAME="Ubuntu 24.04.5 LTS" diff --git a/docs/sme.md b/docs/sme.md index 2d2d8b2..57f453d 100644 --- a/docs/sme.md +++ b/docs/sme.md @@ -14,8 +14,8 @@ baryovm vm add prod --host --user deploy --key ~/.ssh/id_ed25519 baryovm vm ping prod ``` -`vm add` records the host key the first time it connects. Check the fingerprint against the -machine. +`vm add` asks about the host key the first time it connects, and records it only if you answer +`y`. Check the fingerprint against the machine first. With no terminal it refuses an unknown host. ## 2. Find what is running diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index f19ba37..c0a7572 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -142,23 +142,36 @@ be. The tool cannot tell, so it stops. If you rebuilt the machine: baryovm vm forget-key myvm ``` -The next connection learns the new key and prints its fingerprint, with an `ssh-keyscan` line to -check it. +The next connection asks about the new key (on a terminal) and shows its fingerprint, with an +`ssh-keyscan` line to check it. With no terminal it is refused until you record the key. -## `no recorded host key for , and strict host key checking is on` +## `no recorded host key for , and ...` -You passed `--strict-host-keys` (or set `BARYOVM_STRICT_HOST_KEYS=1`) for a host the tool has not -seen. The message carries the offered fingerprint and a command to record it: +The tool has not seen this host, and nobody could say yes to its key. The second half of the first +line says why. Every one of them carries the offered fingerprint and a command to record it, after +you compare the fingerprint to the machine: ```text -no recorded host key for 203.0.113.10:22, and strict host key checking is on. +no recorded host key for 203.0.113.10:22, and there is no terminal to ask on. offered SHA256:... ... - ssh-keyscan -t ecdsa,ed25519 203.0.113.10 >> ~/.baryovm/known_hosts + ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 203.0.113.10 >> ~/.baryovm/known_hosts ``` -Compare the fingerprint to the machine, then run that line. Or connect once without the flag to -learn the key. `--strict-host-keys=false` turns strict mode off for one command. +- `there is no terminal to ask on`: stdin or stderr is not a terminal (a pipe, CI). Record the key + first. To learn on first use instead, set `BARYOVM_STRICT_HOST_KEYS=0` or pass + `--strict-host-keys=false`. +- `output is JSON, so nobody can be asked`: `-o json` is for programs, so there is no prompt. Record + the key, or call `vm add` again with `--host-key-fingerprint SHA256:...` once a person has checked + the fingerprint. The JSON error carries `host`, `offered` and `reason` as fields. +- `strict host key checking was requested`: you passed `--strict-host-keys` or set + `BARYOVM_STRICT_HOST_KEYS=1`. That always refuses an unknown host. Unset it to be asked instead. +- `a project release never trusts a new host`: `project release` does not ask and does not learn. + Pin the key as `hostKey` in the project file (see below). +- `host key for not trusted`: you were asked and did not answer `y` or `yes`. Nothing was + recorded. +- `does not match the fingerprint you gave`: `--host-key-fingerprint` was given and the host offered + another key. Nothing was recorded, and it is not the machine whose key you checked. ## `no recorded host key for in ` diff --git a/internal/cli/project_test.go b/internal/cli/project_test.go index 4906c32..e1f2499 100644 --- a/internal/cli/project_test.go +++ b/internal/cli/project_test.go @@ -8,6 +8,8 @@ import ( "crypto/ed25519" "crypto/rand" "encoding/json" + "errors" + "net" "os" "os/exec" "path/filepath" @@ -15,6 +17,8 @@ import ( "testing" "github.com/BaryoDev/BaryoVM/internal/fleet" + "github.com/BaryoDev/BaryoVM/internal/hostkeys" + "github.com/BaryoDev/BaryoVM/internal/sshx" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" ) @@ -491,3 +495,45 @@ func TestProjectExportWillNotOverwriteWithoutForce(t *testing.T) { t.Fatalf("want a refusal that names --force, got %v", err) } } + +// A project release never asks about a host and never learns one, whatever the flag, the +// environment or the terminal say. The connect it makes must see a refusal with the Release reason. +func TestProjectReleaseRefusesAnUnknownHostEvenWhenAskingOrLearningIsOn(t *testing.T) { + dir, _ := projectDir(t, nil) + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + prevConfirm := sshx.ConfirmHostKey + sshx.SetInteractive(true) + sshx.ConfirmHostKey = func(string, string) bool { return true } + t.Cleanup(func() { sshx.SetInteractive(false); sshx.ConfirmHostKey = prevConfirm }) + + key, _, _, _, err := ssh.ParseAuthorizedKey([]byte(newHostKey(t))) + if err != nil { + t.Fatal(err) + } + remote := &net.TCPAddr{IP: net.IPv4(198, 51, 100, 7), Port: 22} + + f := &fakeRunner{answers: verifyAnswers("api", "console", "site")} + withLookPath(t, hasRsync) + var decided error + prevDial, prevLocal := dialRelease, runLocal + dialRelease = func(vm *fleet.VM) (remoteSession, error) { + decided = sshx.HostKeyStore().Callback(nil)("198.51.100.7:22", remote, key) + return fakeSession{f}, nil + } + runLocal = func(c *exec.Cmd) (string, error) { return "", nil } + t.Cleanup(func() { dialRelease, runLocal = prevDial, prevLocal }) + + _, _, _ = runCmdE(t, newProjectReleaseCmd(), f, true, "--file", filepath.Join(dir, fleet.DefaultProjectFile)) + + var unknown *hostkeys.ErrUnknownHost + if !errors.As(decided, &unknown) || unknown.Reason != hostkeys.ReasonRelease { + t.Fatalf("a release must refuse an unknown host with the Release reason, got %v", decided) + } + if _, statErr := os.Stat(filepath.Join(os.Getenv("BARYOVM_HOME"), "known_hosts")); statErr == nil { + t.Error("a release must not write known_hosts") + } + // ForceRefuse is undone when the release ends. + if got := sshx.HostKeyMode(); got != hostkeys.Learn { + t.Errorf("after the release HostKeyMode() = %v, want Learn (env 0)", got) + } +} diff --git a/internal/cli/root.go b/internal/cli/root.go index af1d294..b2696c2 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -46,6 +46,7 @@ func newRoot() *cobra.Command { } // A person can be asked about an unknown host only on a terminal and not in JSON mode. sshx.SetInteractive(ui.IsTTY() && !ui.JSON()) + sshx.SetOutputJSON(ui.JSON()) }, } jsonHelp(root) @@ -161,6 +162,7 @@ func execute(root *cobra.Command, args []string) error { outputFormat = "json" ui.SetJSON(true) } + sshx.SetOutputJSON(ui.JSON()) root.SetArgs(args) return runRoot(root) } @@ -184,7 +186,7 @@ func reportError(err error) int { if ui.JSON() { action = actionOf(failedPath) } - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return code } @@ -215,6 +217,25 @@ func Execute() { } } +// errData is the structured part of a failed result, for the errors a program can act on. An unknown +// host carries the host, the fingerprint it offered and why it was refused, so an app can show the +// fingerprint, ask the person, and call again with --host-key-fingerprint. Other errors carry none. +func errData(err error) any { + var u *hostkeys.ErrUnknownHost + if !errors.As(err, &u) { + return nil + } + reason := string(u.Reason) + if reason == "" { + reason = "no-terminal" + } + d := map[string]any{"host": u.Host, "offered": u.Offered, "reason": reason, "store": u.Store} + if u.Expected != "" { + d["expected"] = u.Expected + } + return d +} + // hostKeyPromptMu keeps two prompts apart when a fleet command dials several VMs at once. var hostKeyPromptMu sync.Mutex diff --git a/internal/cli/vm.go b/internal/cli/vm.go index 6c67bb5..daab6c5 100644 --- a/internal/cli/vm.go +++ b/internal/cli/vm.go @@ -28,7 +28,7 @@ func newVMCmd() *cobra.Command { } func newVMAddCmd() *cobra.Command { - var host, user, key, osName, shellName, remoteMode string + var host, user, key, osName, shellName, remoteMode, hostKeyFP string var port int cmd := &cobra.Command{ Use: "add ", @@ -40,6 +40,12 @@ connection. If the host cannot be reached it is saved with no OS (read as linux) and a warning; a host key mismatch still fails. With --os windows the SSH shell is recorded as cmd, the OpenSSH default; pass --shell powershell if the host's default shell is powershell.exe. + +An unknown host key is asked about on a terminal and refused with no terminal or +under -o json. A script or app that has had a person check the key can pass its +SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key +is recorded and the command continues, and any other key is refused. A host with +a different recorded key is still refused. `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -48,6 +54,12 @@ host's default shell is powershell.exe. if err != nil { return err } + if hostKeyFP != "" { + if !strings.HasPrefix(hostKeyFP, "SHA256:") { + return fmt.Errorf("--host-key-fingerprint must look like SHA256:..., as ssh-keygen -lf prints it") + } + defer sshx.TrustFingerprint(hostKeyFP)() + } vm := fleet.VM{Name: name, Host: host, Port: port, User: user, KeyPath: key, Provider: "ssh"} var unreached bool var detectErr error @@ -91,7 +103,7 @@ host's default shell is powershell.exe. return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "vm add", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "vm add", Error: err.Error(), Data: errData(err)}) return err } } @@ -122,6 +134,7 @@ host's default shell is powershell.exe. cmd.Flags().StringVar(&osName, "os", "", "host OS, linux or windows (default: detect over SSH)") cmd.Flags().StringVar(&shellName, "shell", "", "SSH shell of a Windows host, cmd or powershell (with --os windows; default cmd)") cmd.Flags().StringVar(&remoteMode, "remote", "", "\"forced\" when the key is pinned to `baryovm remote serve` (see `vm remote install`)") + cmd.Flags().StringVar(&hostKeyFP, "host-key-fingerprint", "", "trust an unknown host that offers exactly this SHA256 fingerprint, without asking") _ = cmd.MarkFlagRequired("host") _ = cmd.MarkFlagRequired("key") return cmd diff --git a/internal/cli/vm_add_test.go b/internal/cli/vm_add_test.go index e29e5ff..5e92e0d 100644 --- a/internal/cli/vm_add_test.go +++ b/internal/cli/vm_add_test.go @@ -8,6 +8,7 @@ import ( "crypto/ed25519" "crypto/rand" "crypto/x509" + "encoding/json" "encoding/pem" "net" "os" @@ -218,3 +219,121 @@ func TestVMAddDetectionFailureKeepsTheErrorAndDoesNotSayUnreachable(t *testing.T t.Error("the VM must still be added") } } + +// serveOneKey runs an SSH server on loopback with one host key and returns its host, port and key. +func serveOneKey(t *testing.T) (string, string, ssh.Signer) { + t.Helper() + served := newSigner(t) + cfg := &ssh.ServerConfig{NoClientAuth: true} + cfg.AddHostKey(served) + l, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { l.Close() }) + go func() { + for { + conn, err := l.Accept() + if err != nil { + return + } + go func() { + defer conn.Close() + if sc, _, _, err := ssh.NewServerConn(conn, cfg); err == nil { + sc.Close() + } + }() + } + }() + host, port, _ := net.SplitHostPort(l.Addr().String()) + return host, port, served +} + +func TestVMAddHostKeyFingerprintRecordsAMatchingKey(t *testing.T) { + bvmHome := t.TempDir() + t.Setenv("BARYOVM_HOME", bvmHome) + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port, served := serveOneKey(t) + + _, _, err := runCmdE(t, newVMAddCmd(), nil, true, "box", "--host", host, "--port", port, "--key", writeTestKey(t), + "--host-key-fingerprint", ssh.FingerprintSHA256(served.PublicKey())) + if err != nil { + t.Fatalf("a matching fingerprint must register the VM: %v", err) + } + if b, _ := os.ReadFile(filepath.Join(bvmHome, "known_hosts")); !strings.Contains(string(b), host) { + t.Errorf("the key must be recorded, known_hosts is %q", b) + } + if store, _ := fleet.Load(); store.Find("box") == nil { + t.Error("the VM must be saved") + } +} + +func TestVMAddHostKeyFingerprintMismatchRefusesAndWritesNothing(t *testing.T) { + bvmHome := t.TempDir() + t.Setenv("BARYOVM_HOME", bvmHome) + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + host, port, _ := serveOneKey(t) + + stdout, _, err := runCmdE(t, newVMAddCmd(), nil, true, "box", "--host", host, "--port", port, "--key", writeTestKey(t), + "--host-key-fingerprint", ssh.FingerprintSHA256(newSigner(t).PublicKey())) + if err == nil || !strings.Contains(err.Error(), "does not match the fingerprint you gave") { + t.Fatalf("want a mismatch refusal, got %v", err) + } + if _, statErr := os.Stat(filepath.Join(bvmHome, "known_hosts")); statErr == nil { + t.Error("a mismatch must write nothing") + } + if store, _ := fleet.Load(); store.Find("box") != nil { + t.Error("the VM must not be saved") + } + if !strings.Contains(stdout, `"reason"`) || !strings.Contains(stdout, `"fingerprint"`) { + t.Errorf("the JSON error must carry the structured reason:\n%s", stdout) + } +} + +// The fingerprint vouches for an unknown host only. A host already recorded with another key is a +// changed key and stays refused, even when the given fingerprint is the one it now offers. +func TestVMAddHostKeyFingerprintDoesNotOverrideAChangedKey(t *testing.T) { + bvmHome := t.TempDir() + t.Setenv("BARYOVM_HOME", bvmHome) + t.Setenv("HOME", t.TempDir()) + host, port, served := serveOneKey(t) + line := knownhosts.Line([]string{net.JoinHostPort(host, port)}, newSigner(t).PublicKey()) + if err := os.WriteFile(filepath.Join(bvmHome, "known_hosts"), []byte(line+"\n"), 0o600); err != nil { + t.Fatal(err) + } + _, _, err := runCmdE(t, newVMAddCmd(), nil, true, "box", "--host", host, "--port", port, "--key", writeTestKey(t), + "--host-key-fingerprint", ssh.FingerprintSHA256(served.PublicKey())) + if err == nil || !strings.Contains(err.Error(), "changed") { + t.Fatalf("a changed key must still be refused, got %v", err) + } +} + +// An unknown host under -o json carries the host and the offered fingerprint as fields, so an app can +// show it, ask the person, and call again with --host-key-fingerprint. +func TestVMAddUnknownHostJSONErrorCarriesTheOfferedFingerprint(t *testing.T) { + t.Setenv("BARYOVM_HOME", t.TempDir()) + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port, served := serveOneKey(t) + + stdout, _, err := runCmdE(t, newVMAddCmd(), nil, true, "box", "--host", host, "--port", port, "--key", writeTestKey(t)) + if err == nil { + t.Fatal("an unknown host under JSON must be refused") + } + var out struct { + OK bool `json:"ok"` + Data struct { + Host string `json:"host"` + Offered string `json:"offered"` + Reason string `json:"reason"` + } `json:"data"` + } + if jerr := json.Unmarshal([]byte(stdout), &out); jerr != nil { + t.Fatalf("not one JSON document (%v): %q", jerr, stdout) + } + if out.OK || out.Data.Offered != ssh.FingerprintSHA256(served.PublicKey()) || !strings.Contains(out.Data.Host, host) { + t.Errorf("structured fields missing or wrong: %+v", out) + } +} diff --git a/internal/hostkeys/hostkeys.go b/internal/hostkeys/hostkeys.go index 2aafb97..05f0b14 100644 --- a/internal/hostkeys/hostkeys.go +++ b/internal/hostkeys/hostkeys.go @@ -69,19 +69,47 @@ func (e *ErrChanged) Error() string { e.Host, e.Stored, e.Offered, e.Host) } -// ErrUnknownHost is returned for a host with no recorded key that was not trusted: refused outright -// (strict, or no terminal to ask on) or declined when asked. It carries the offered fingerprint so an -// operator can pin it after checking it, rather than having to go and fetch it. +// Reason says why an unknown host was not trusted, so the message gives advice that works for that +// case. The zero value is ReasonNoTerminal. +type Reason string + +const ( + // ReasonNoTerminal: nobody could be asked because there is no terminal (a pipe, CI). + ReasonNoTerminal Reason = "" + // ReasonJSON: nobody could be asked because output is JSON, which a program reads. + ReasonJSON Reason = "json" + // ReasonStrict: strict checking was requested by the flag or BARYOVM_STRICT_HOST_KEYS. + ReasonStrict Reason = "strict" + // ReasonRelease: a project release never trusts a new host, by prompt or otherwise. + ReasonRelease Reason = "release" + // ReasonDeclined: a person was asked and did not say yes. + ReasonDeclined Reason = "declined" + // ReasonFingerprint: the caller supplied the fingerprint it expected and the host offered another. + ReasonFingerprint Reason = "fingerprint" +) + +// ErrUnknownHost is returned for a host with no recorded key that was not trusted. It carries the +// offered fingerprint so an operator can pin it after checking it, rather than having to go and +// fetch it, and the Reason so the message and a program reading it know what to do next. type ErrUnknownHost struct { Host string Offered string Store string - // Declined is set when a person was asked and did not say yes. Unset means nobody was asked. - Declined bool + Reason Reason + // Expected is the fingerprint the caller said to trust, set for ReasonFingerprint. + Expected string } func (e *ErrUnknownHost) Error() string { - if e.Declined { + record := fmt.Sprintf( + "Check that fingerprint against the machine, then record it before this runs:\n"+ + "\n"+ + " %s >> %s\n", Keyscan(e.Host), e.Store) + learnAgain := "\n" + + "To learn an unknown host's key on first use instead, as releases before this one did, set\n" + + "BARYOVM_STRICT_HOST_KEYS=0 (or pass --strict-host-keys=false).\n" + switch e.Reason { + case ReasonDeclined: return fmt.Sprintf( "host key for %s not trusted.\n"+ " offered %s\n"+ @@ -91,21 +119,56 @@ func (e *ErrUnknownHost) Error() string { "\n"+ " %s >> %s\n", e.Host, e.Offered, Keyscan(e.Host), e.Store) + case ReasonFingerprint: + return fmt.Sprintf( + "host key for %s does not match the fingerprint you gave.\n"+ + " expected %s\n"+ + " offered %s\n"+ + "\n"+ + "Nothing was recorded. Whatever answered is not the machine whose key you checked.\n", + e.Host, e.Expected, e.Offered) + case ReasonStrict: + return fmt.Sprintf( + "no recorded host key for %s, and strict host key checking was requested (--strict-host-keys or\n"+ + "BARYOVM_STRICT_HOST_KEYS).\n"+ + " offered %s\n"+ + "\n"+ + "Strict checking refuses an unknown host without asking.\n"+ + "\n"+ + "%s"+ + "\n"+ + "To be asked instead, unset BARYOVM_STRICT_HOST_KEYS and drop --strict-host-keys.\n", + e.Host, e.Offered, record) + case ReasonRelease: + return fmt.Sprintf( + "no recorded host key for %s, and a project release never trusts a new host.\n"+ + " offered %s\n"+ + "\n"+ + "It does not ask and it does not learn. Check that fingerprint against the machine and pin\n"+ + "it as hostKey for that VM in the project file, or record it in known_hosts and pass\n"+ + "--strict-host-keys:\n"+ + "\n"+ + " %s >> %s\n", + e.Host, e.Offered, Keyscan(e.Host), e.Store) + case ReasonJSON: + return fmt.Sprintf( + "no recorded host key for %s, and output is JSON, so nobody can be asked.\n"+ + " offered %s\n"+ + "\n"+ + "%s"+ + "%s", + e.Host, e.Offered, record, learnAgain) } return fmt.Sprintf( - "no recorded host key for %s, and there is nobody to ask (strict host key checking, or no terminal).\n"+ + "no recorded host key for %s, and there is no terminal to ask on.\n"+ " offered %s\n"+ "\n"+ "An unknown host is refused here, because nobody can check its key. A runner with no memory\n"+ "between runs would otherwise trust whatever answers on this address, every run.\n"+ "\n"+ - "Check that fingerprint against the machine, then record it before this runs:\n"+ - "\n"+ - " %s >> %s\n"+ - "\n"+ - "To learn an unknown host's key on first use instead, as releases before this one did, set\n"+ - "BARYOVM_STRICT_HOST_KEYS=0 (or pass --strict-host-keys=false).\n", - e.Host, e.Offered, Keyscan(e.Host), e.Store) + "%s"+ + "%s", + e.Host, e.Offered, record, learnAgain) } // Mode is what a Store does with a host that has no recorded key anywhere. @@ -121,14 +184,14 @@ const ( Ask ) -// Keyscan is the ssh-keyscan command that fetches a host's ecdsa and ed25519 keys. ssh-keyscan +// Keyscan is the ssh-keyscan command that fetches a host's ecdsa, ed25519 and rsa keys. ssh-keyscan // takes the port as -p and cannot resolve host:port. func Keyscan(hostport string) string { host, port, err := net.SplitHostPort(hostport) if err != nil { - return "ssh-keyscan -t ecdsa,ed25519 " + hostport + return "ssh-keyscan -t ecdsa,ed25519,rsa " + hostport } - return "ssh-keyscan -p " + port + " -t ecdsa,ed25519 " + host + return "ssh-keyscan -p " + port + " -t ecdsa,ed25519,rsa " + host } // Store is a known_hosts file BaryoVM owns, plus the user's own file as a read-only second source. @@ -146,6 +209,13 @@ type Store struct { // confirm is asked in Ask mode. It must not be called with the store locked by the caller, and it // may block for as long as a person takes to read a fingerprint. confirm func(host, fingerprint string) bool + + // refuseReason is what a Refuse (or an Ask with no hook) reports as the reason. + refuseReason Reason + + // expect is a fingerprint the caller already checked. An unknown host offering exactly that key is + // trusted without asking, in any mode. Empty means none. + expect string } // New returns the store rooted at dir, which is BaryoVM's home. @@ -174,6 +244,20 @@ func (s *Store) Mode(m Mode) *Store { return s } +// RefuseReason sets the Reason carried by an unknown-host refusal that nobody was asked about. +func (s *Store) RefuseReason(r Reason) *Store { + s.refuseReason = r + return s +} + +// ExpectFingerprint trusts an unknown host whose offered key has exactly this SHA256 fingerprint, +// without asking and in any mode, and refuses one that offers another. It never applies to a host +// that already has a recorded key: a changed key is refused whatever fingerprint is given. +func (s *Store) ExpectFingerprint(fp string) *Store { + s.expect = fp + return s +} + // Confirm sets the hook Ask mode calls with the host and the offered fingerprint. Only a true answer // trusts the key. The hostkeys package never prints or reads input, so whoever sets this does that. func (s *Store) Confirm(fn func(host, fingerprint string) bool) *Store { @@ -245,16 +329,31 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall } // Unknown everywhere: the fresh VM case. + if s.expect != "" { + if s.expect != offered { + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: ReasonFingerprint, Expected: s.expect} + } + return s.add(hostname, key) + } switch s.mode { case Refuse: - return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path} + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: s.refuseReason} case Ask: // A missing hook means nobody can be asked, which is a refusal, never a yes. if s.confirm == nil { - return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path} + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: s.refuseReason} + } + // One prompt at a time across every dial in the process. A second dial to the same new host + // waits here, and then finds the first answer already recorded instead of asking again. + askMu.Lock() + defer askMu.Unlock() + if err := s.check(s.path, hostname, remote, key); err == nil { + return nil + } else if err := s.refusal(err, s.path, hostname, offered); err != nil { + return err } if !s.confirm(hostname, offered) { - return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Declined: true} + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: ReasonDeclined} } return s.add(hostname, key) } @@ -480,8 +579,21 @@ func (s *Store) storedFingerprint(path, hostname string) (string, error) { return "", errNotFound } -// add appends a host key to BaryoVM's own known_hosts, 0600 the same way fleet.json is written. +// askMu serializes prompts. addMu makes the check-then-append in add one step, so two dials that both +// learn the same host (the Learn mode, or a prompt answered for another host) write one line. +var ( + askMu sync.Mutex + addMu sync.Mutex +) + +// add appends a host key to BaryoVM's own known_hosts, 0600 the same way fleet.json is written. A key +// already recorded for the host is not written twice. func (s *Store) add(hostname string, key ssh.PublicKey) error { + addMu.Lock() + defer addMu.Unlock() + if err := s.check(s.path, hostname, &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 22}, key); err == nil { + return nil + } if err := os.MkdirAll(filepath.Dir(s.path), 0o700); err != nil { return fmt.Errorf("create %s: %w", filepath.Dir(s.path), err) } diff --git a/internal/hostkeys/hostkeys_test.go b/internal/hostkeys/hostkeys_test.go index 9b56a91..dc80a6a 100644 --- a/internal/hostkeys/hostkeys_test.go +++ b/internal/hostkeys/hostkeys_test.go @@ -12,7 +12,10 @@ import ( "os" "path/filepath" "strings" + "sync" + "sync/atomic" "testing" + "time" "golang.org/x/crypto/ssh" ) @@ -289,17 +292,17 @@ func TestStrictStillReportsAChangedKeyAsChanged(t *testing.T) { func TestKeyscanPassesThePortAsAFlag(t *testing.T) { for _, c := range []struct{ in, want string }{ - {"192.0.2.10:22", "ssh-keyscan -p 22 -t ecdsa,ed25519 192.0.2.10"}, - {"192.0.2.10:2222", "ssh-keyscan -p 2222 -t ecdsa,ed25519 192.0.2.10"}, - {"[2001:db8::1]:22", "ssh-keyscan -p 22 -t ecdsa,ed25519 2001:db8::1"}, - {"vm.example", "ssh-keyscan -t ecdsa,ed25519 vm.example"}, + {"192.0.2.10:22", "ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 192.0.2.10"}, + {"192.0.2.10:2222", "ssh-keyscan -p 2222 -t ecdsa,ed25519,rsa 192.0.2.10"}, + {"[2001:db8::1]:22", "ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 2001:db8::1"}, + {"vm.example", "ssh-keyscan -t ecdsa,ed25519,rsa vm.example"}, } { if got := Keyscan(c.in); got != c.want { t.Errorf("Keyscan(%q) = %q, want %q", c.in, got, c.want) } } err := &ErrUnknownHost{Host: "192.0.2.10:2222", Offered: "SHA256:x", Store: "/k"} - if !strings.Contains(err.Error(), "ssh-keyscan -p 2222 -t ecdsa,ed25519 192.0.2.10 >> /k") { + if !strings.Contains(err.Error(), "ssh-keyscan -p 2222 -t ecdsa,ed25519,rsa 192.0.2.10 >> /k") { t.Errorf("strict-mode error must keep the port: %s", err) } } @@ -353,7 +356,7 @@ func TestAskRefusesAndWritesNothingOnNo(t *testing.T) { s := newStore(t).Mode(Ask).Confirm(func(string, string) bool { return false }) err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)) var ue *ErrUnknownHost - if !errors.As(err, &ue) || !ue.Declined { + if !errors.As(err, &ue) || ue.Reason != ReasonDeclined { t.Fatalf("want a declined ErrUnknownHost, got %T: %v", err, err) } if !strings.Contains(err.Error(), "not trusted") { @@ -368,7 +371,7 @@ func TestAskWithNoConfirmHookRefuses(t *testing.T) { s := newStore(t).Mode(Ask) err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)) var ue *ErrUnknownHost - if !errors.As(err, &ue) || ue.Declined { + if !errors.As(err, &ue) || ue.Reason == ReasonDeclined { t.Fatalf("want ErrUnknownHost with nobody asked, got %T: %v", err, err) } if _, err := os.Stat(s.Path()); err == nil { @@ -423,3 +426,113 @@ func TestUnknownHostMessageNamesTheWayBackToLearning(t *testing.T) { t.Error("the message must be right for the no-terminal default too") } } + +func TestUnknownHostMessageMatchesTheReason(t *testing.T) { + base := ErrUnknownHost{Host: "192.0.2.10:22", Offered: "SHA256:off", Store: "/k"} + cases := []struct { + reason Reason + want []string + notWant []string + }{ + {ReasonNoTerminal, []string{"no terminal to ask on", "BARYOVM_STRICT_HOST_KEYS=0", "ssh-keyscan"}, []string{"strict host key checking was requested"}}, + {ReasonJSON, []string{"output is JSON", "BARYOVM_STRICT_HOST_KEYS=0", "ssh-keyscan"}, []string{"no terminal"}}, + {ReasonStrict, []string{"strict host key checking was requested", "ssh-keyscan", "unset BARYOVM_STRICT_HOST_KEYS"}, []string{"to learn an unknown host's key"}}, + {ReasonRelease, []string{"project release never trusts a new host", "hostKey"}, []string{"BARYOVM_STRICT_HOST_KEYS=0"}}, + {ReasonDeclined, []string{"not trusted", "Nothing was recorded"}, []string{"BARYOVM_STRICT_HOST_KEYS=0"}}, + {ReasonFingerprint, []string{"does not match the fingerprint you gave", "expected SHA256:want", "offered SHA256:off"}, []string{"BARYOVM_STRICT_HOST_KEYS=0"}}, + } + for _, c := range cases { + e := base + e.Reason = c.reason + e.Expected = "SHA256:want" + msg := e.Error() + for _, w := range c.want { + if !strings.Contains(msg, w) { + t.Errorf("reason %q: message must mention %q:\n%s", c.reason, w, msg) + } + } + for _, w := range c.notWant { + if strings.Contains(msg, w) { + t.Errorf("reason %q: message must not mention %q:\n%s", c.reason, w, msg) + } + } + } +} + +func TestExpectedFingerprintTrustsAMatchInAnyModeAndWritesIt(t *testing.T) { + for _, m := range []Mode{Learn, Refuse, Ask} { + s := newStore(t).Mode(m) + key := newKey(t) + s.ExpectFingerprint(ssh.FingerprintSHA256(key)) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), key); err != nil { + t.Fatalf("mode %v: a matching fingerprint must trust the key: %v", m, err) + } + if b, _ := os.ReadFile(s.Path()); !strings.Contains(string(b), "192.0.2.10") { + t.Errorf("mode %v: the key must be recorded", m) + } + } +} + +func TestExpectedFingerprintMismatchRefusesWithBothAndWritesNothing(t *testing.T) { + s := newStore(t).Mode(Learn) + key := newKey(t) + s.ExpectFingerprint(ssh.FingerprintSHA256(newKey(t))) + err := s.Callback(nil)("192.0.2.10:22", addr(t), key) + var ue *ErrUnknownHost + if !errors.As(err, &ue) || ue.Reason != ReasonFingerprint { + t.Fatalf("want ErrUnknownHost with ReasonFingerprint, got %T: %v", err, err) + } + if !strings.Contains(err.Error(), ue.Expected) || !strings.Contains(err.Error(), ssh.FingerprintSHA256(key)) { + t.Errorf("both fingerprints must be in the message: %v", err) + } + if _, err := os.Stat(s.Path()); err == nil { + t.Fatal("a mismatch must write nothing") + } +} + +// The fingerprint only vouches for an unknown host. A host with another key on record is changed. +func TestExpectedFingerprintDoesNotOverrideAChangedKey(t *testing.T) { + s := newStore(t) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), newKey(t)); err != nil { + t.Fatal(err) + } + second := newKey(t) + s.ExpectFingerprint(ssh.FingerprintSHA256(second)) + var ce *ErrChanged + if err := s.Callback(nil)("192.0.2.10:22", addr(t), second); !errors.As(err, &ce) { + t.Fatalf("want ErrChanged, got %T: %v", err, err) + } +} + +// Fleet commands dial several VMs at once. Two dials to one new host must prompt once and record one +// line, the second answered from the first. +func TestConcurrentAskForOneHostPromptsOnceAndRecordsOnce(t *testing.T) { + dir := t.TempDir() + key := newKey(t) + var asked atomic.Int32 + confirm := func(string, string) bool { + asked.Add(1) + time.Sleep(100 * time.Millisecond) + return true + } + var wg sync.WaitGroup + for i := 0; i < 2; i++ { + wg.Add(1) + go func() { + defer wg.Done() + s := New(dir).Mode(Ask).Confirm(confirm) + s.extraPath = "" + if err := s.Callback(nil)("192.0.2.10:22", addr(t), key); err != nil { + t.Errorf("callback: %v", err) + } + }() + } + wg.Wait() + if asked.Load() != 1 { + t.Errorf("asked %d times, want once", asked.Load()) + } + b, _ := os.ReadFile(filepath.Join(dir, "known_hosts")) + if n := strings.Count(strings.TrimSpace(string(b)), "\n") + 1; n != 1 { + t.Errorf("known_hosts has %d lines, want 1:\n%s", n, b) + } +} diff --git a/internal/sshx/askhostkey_test.go b/internal/sshx/askhostkey_test.go index 671b587..9c19456 100644 --- a/internal/sshx/askhostkey_test.go +++ b/internal/sshx/askhostkey_test.go @@ -161,7 +161,7 @@ func TestDialRefusesAndRecordsNothingWhenTheAnswerIsNo(t *testing.T) { setHostKeyState(t, nil, true, func(string, string) bool { return false }) home, err := dialUnknownHost(t, host, port) var unknown *hostkeys.ErrUnknownHost - if !errors.As(err, &unknown) || !unknown.Declined { + if !errors.As(err, &unknown) || unknown.Reason != hostkeys.ReasonDeclined { t.Fatalf("want a declined ErrUnknownHost, got %v", err) } if recorded(home) != "" { @@ -176,7 +176,7 @@ func TestDialRefusesAnUnknownHostWithNoTerminal(t *testing.T) { setHostKeyState(t, nil, false, func(string, string) bool { asked.Add(1); return true }) home, err := dialUnknownHost(t, host, port) var unknown *hostkeys.ErrUnknownHost - if !errors.As(err, &unknown) || unknown.Declined { + if !errors.As(err, &unknown) || unknown.Reason == hostkeys.ReasonDeclined { t.Fatalf("want ErrUnknownHost that nobody was asked about, got %v", err) } if asked.Load() != 0 { @@ -273,3 +273,82 @@ func netPipe(t *testing.T) (net.Conn, net.Conn) { } return <-acc, cli } + +func TestRefusalReasonFollowsHowTheRunWasStarted(t *testing.T) { + cases := []struct { + name string + env string + json bool + force bool + override *bool + want hostkeys.Reason + }{ + {"no terminal", "", false, false, nil, hostkeys.ReasonNoTerminal}, + {"json", "", true, false, nil, hostkeys.ReasonJSON}, + {"strict by env", "1", false, false, nil, hostkeys.ReasonStrict}, + {"strict by flag", "", true, false, boolPtr(true), hostkeys.ReasonStrict}, + {"release beats the rest", "1", true, true, boolPtr(true), hostkeys.ReasonRelease}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", c.env) + setHostKeyState(t, c.override, false, nil) + oldJSON := outputJSON + t.Cleanup(func() { outputJSON = oldJSON }) + SetOutputJSON(c.json) + if c.force { + defer ForceRefuse()() + } + if got := refuseReason(); got != c.want { + t.Errorf("refuseReason() = %q, want %q", got, c.want) + } + }) + } +} + +func TestDialTrustsAMatchingFingerprintWithNoPrompt(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + signer := ed25519Signer(t) + host, port := serveHostKeys(t, signer) + setHostKeyState(t, nil, false, nil) + defer TrustFingerprint(ssh.FingerprintSHA256(signer.PublicKey()))() + home, err := dialUnknownHost(t, host, port) + if err != nil { + t.Fatalf("a matching fingerprint must let the dial through: %v", err) + } + if recorded(home) == "" { + t.Error("the key must be recorded") + } +} + +func TestDialRefusesAMismatchedFingerprintAndWritesNothing(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "0") + host, port := serveHostKeys(t, ed25519Signer(t)) + setHostKeyState(t, nil, false, nil) + defer TrustFingerprint(ssh.FingerprintSHA256(ed25519Signer(t).PublicKey()))() + home, err := dialUnknownHost(t, host, port) + var unknown *hostkeys.ErrUnknownHost + if !errors.As(err, &unknown) || unknown.Reason != hostkeys.ReasonFingerprint { + t.Fatalf("want ReasonFingerprint, got %v", err) + } + if recorded(home) != "" { + t.Error("a mismatch must write nothing") + } +} + +func TestTrustFingerprintIsIgnoredDuringARelease(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + signer := ed25519Signer(t) + host, port := serveHostKeys(t, signer) + setHostKeyState(t, nil, false, nil) + defer TrustFingerprint(ssh.FingerprintSHA256(signer.PublicKey()))() + defer ForceRefuse()() + home, err := dialUnknownHost(t, host, port) + var unknown *hostkeys.ErrUnknownHost + if !errors.As(err, &unknown) || unknown.Reason != hostkeys.ReasonRelease { + t.Fatalf("a release must refuse a new host whatever fingerprint is given, got %v", err) + } + if recorded(home) != "" { + t.Error("nothing may be recorded") + } +} diff --git a/internal/sshx/sshx.go b/internal/sshx/sshx.go index 1387729..5501918 100644 --- a/internal/sshx/sshx.go +++ b/internal/sshx/sshx.go @@ -57,7 +57,8 @@ func ForceRefuse() (restore func()) { prev := strictOverride on := true strictOverride = &on - return func() { strictOverride = prev } + forceRefuse++ + return func() { strictOverride, forceRefuse = prev, forceRefuse-1 } } // strictSetting reports an explicit choice: 1 strict (refuse), 0 learn on first use, -1 nothing set. @@ -111,6 +112,63 @@ func StrictHostKeys() bool { return HostKeyMode() == hostkeys.Refuse } // request before it connects. func StrictHostKeysRequested() bool { return strictSetting() == 1 } +// outputJSON is set by the cli layer, so a refusal can say JSON was why nobody was asked. +var outputJSON bool + +// SetOutputJSON tells sshx that output is JSON. +func SetOutputJSON(on bool) { outputJSON = on } + +// forceRefuse counts open ForceRefuse calls. +var forceRefuse int + +// expectedFingerprint is a SHA256 fingerprint the caller already checked, for one run. +var expectedFingerprint string + +// TrustFingerprint trusts an unknown host whose offered key has this SHA256 fingerprint, without +// asking, until the returned function is called. A different key is refused with both fingerprints, +// and a host that already has a recorded key is unaffected (a changed key is still refused). It has +// no effect during a project release. +func TrustFingerprint(fp string) (restore func()) { + prev := expectedFingerprint + expectedFingerprint = fp + return func() { expectedFingerprint = prev } +} + +// refuseReason is why an unknown host is refused without asking, for the error text. +func refuseReason() hostkeys.Reason { + switch { + case forceRefuse > 0: + return hostkeys.ReasonRelease + case strictSetting() == 1: + return hostkeys.ReasonStrict + case outputJSON: + return hostkeys.ReasonJSON + } + return hostkeys.ReasonNoTerminal +} + +// newHostKeyStore builds the store a dial uses, with the mode, the reason, the confirm hook and any +// trusted fingerprint resolved. +func newHostKeyStore(guard *handshakeGuard) *hostkeys.Store { + store := hostkeys.New(home()).Mode(HostKeyMode()).RefuseReason(refuseReason()) + if confirm := ConfirmHostKey; confirm != nil { + // The handshake deadline is for a host that stalls, not for a person reading a fingerprint. + store.Confirm(func(host, fp string) bool { + var ok bool + guard.pause(func() { ok = confirm(host, fp) }) + return ok + }) + } + if expectedFingerprint != "" && forceRefuse == 0 { + store.ExpectFingerprint(expectedFingerprint) + } + return store +} + +// HostKeyStore is the store Dial would use right now. The cli layer's tests use it to see what a +// dial would decide without opening a connection. +func HostKeyStore() *hostkeys.Store { return newHostKeyStore(&handshakeGuard{}) } + // OnLearnHostKey is called the first time a host key is recorded, so the operator sees the // fingerprint they are now trusting. The cli layer sets it; sshx does not print (see CLAUDE.md on // the dependency direction), so a nil hook means the learning is silent. @@ -151,15 +209,7 @@ func Dial(t Target) (*Client, error) { defer closeAgent() // signing happens during the handshake, so the agent is done once Dial returns addr := net.JoinHostPort(t.Host, fmt.Sprintf("%d", t.Port)) guard := &handshakeGuard{} - store := hostkeys.New(home()).Mode(HostKeyMode()) - if confirm := ConfirmHostKey; confirm != nil { - // The handshake deadline is for a host that stalls, not for a person reading a fingerprint. - store.Confirm(func(host, fp string) bool { - var ok bool - guard.pause(func() { ok = confirm(host, fp) }) - return ok - }) - } + store := newHostKeyStore(guard) cfg := &ssh.ClientConfig{ User: t.User, Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, From 68ac3e37cc4b2a9f42eef4b637a39ce9ce7c7891 Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:08:25 +0800 Subject: [PATCH 4/6] say the fingerprint flag holds under strict mode and pin the no-terminal reason in its test --- USAGE.md | 3 ++- docs/commands/baryovm_vm_add.md | 5 +++-- internal/cli/vm.go | 5 +++-- internal/sshx/askhostkey_test.go | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/USAGE.md b/USAGE.md index f1ee2f4..8630751 100644 --- a/USAGE.md +++ b/USAGE.md @@ -178,7 +178,8 @@ A new host's key is asked about on a terminal. A script or app (`-o json`, no te asked, so `vm add` refuses and the JSON error carries `data.host`, `data.offered` and `data.reason`. Show that fingerprint to the person, and once they have checked it against the machine, run again with `--host-key-fingerprint SHA256:...`: a host offering exactly that key is recorded and the add -continues, and any other key is refused with both fingerprints. The flag does not apply to a host +continues, and any other key is refused with both fingerprints. This holds under strict mode too, +since the fingerprint is the checked key. The flag does not apply to a host that already has a different key on record, which is still a changed key, and a `project release` ignores it. A host key that does not match the one on record is not "unreachable": `vm add` fails diff --git a/docs/commands/baryovm_vm_add.md b/docs/commands/baryovm_vm_add.md index 3884f27..3f9a84c 100644 --- a/docs/commands/baryovm_vm_add.md +++ b/docs/commands/baryovm_vm_add.md @@ -14,8 +14,9 @@ host's default shell is powershell.exe. An unknown host key is asked about on a terminal and refused with no terminal or under -o json. A script or app that has had a person check the key can pass its SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key -is recorded and the command continues, and any other key is refused. A host with -a different recorded key is still refused. +is recorded and the command continues, and any other key is refused. This holds +under --strict-host-keys too, since the flag is the checked key. A host with a +different recorded key is still refused. ``` baryovm vm add [flags] diff --git a/internal/cli/vm.go b/internal/cli/vm.go index daab6c5..1e7c49d 100644 --- a/internal/cli/vm.go +++ b/internal/cli/vm.go @@ -44,8 +44,9 @@ host's default shell is powershell.exe. An unknown host key is asked about on a terminal and refused with no terminal or under -o json. A script or app that has had a person check the key can pass its SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key -is recorded and the command continues, and any other key is refused. A host with -a different recorded key is still refused. +is recorded and the command continues, and any other key is refused. This holds +under --strict-host-keys too, since the flag is the checked key. A host with a +different recorded key is still refused. `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/sshx/askhostkey_test.go b/internal/sshx/askhostkey_test.go index 9c19456..abe84cb 100644 --- a/internal/sshx/askhostkey_test.go +++ b/internal/sshx/askhostkey_test.go @@ -176,8 +176,8 @@ func TestDialRefusesAnUnknownHostWithNoTerminal(t *testing.T) { setHostKeyState(t, nil, false, func(string, string) bool { asked.Add(1); return true }) home, err := dialUnknownHost(t, host, port) var unknown *hostkeys.ErrUnknownHost - if !errors.As(err, &unknown) || unknown.Reason == hostkeys.ReasonDeclined { - t.Fatalf("want ErrUnknownHost that nobody was asked about, got %v", err) + if !errors.As(err, &unknown) || unknown.Reason != hostkeys.ReasonNoTerminal { + t.Fatalf("want ErrUnknownHost refused for having no terminal, got %v", err) } if asked.Load() != 0 { t.Error("with no terminal nobody may be asked") From 591ee484cc91a00eb03b1b66bbd1dcd18d7a235e Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:24:14 +0800 Subject: [PATCH 5/6] drop the dial helper the guarded dial replaced --- internal/sshx/sshx.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/sshx/sshx.go b/internal/sshx/sshx.go index 5501918..cc62913 100644 --- a/internal/sshx/sshx.go +++ b/internal/sshx/sshx.go @@ -268,13 +268,8 @@ func (g *handshakeGuard) pause(fn func()) { fn() } -// dialWithHandshakeDeadline is ssh.Dial with a deadline on the connection until the handshake is -// done, then cleared so a long command is not cut off. -func dialWithHandshakeDeadline(addr string, cfg *ssh.ClientConfig, handshake time.Duration) (*ssh.Client, error) { - return dialGuarded(addr, cfg, handshake, &handshakeGuard{}) -} - -// dialGuarded is dialWithHandshakeDeadline whose deadline guard can be paused by a host key prompt. +// dialGuarded is ssh.Dial with a deadline on the connection until the handshake is done, then +// cleared so a long command is not cut off. A host key prompt pauses the deadline through guard. func dialGuarded(addr string, cfg *ssh.ClientConfig, handshake time.Duration, guard *handshakeGuard) (*ssh.Client, error) { conn, err := net.DialTimeout("tcp", addr, cfg.Timeout) if err != nil { From eebdbfe9afeddf99a6895b16d49b00e7e3a3d4c8 Mon Sep 17 00:00:00 2001 From: Arnel Robles Date: Wed, 18 Nov 2026 10:32:05 +0800 Subject: [PATCH 6/6] refuse a key recorded during the prompt, carry host key data in every json failure, and point the check at a trusted source --- USAGE.md | 15 ++- docs/commands/baryovm.md | 2 +- docs/commands/baryovm_cloud.md | 2 +- docs/commands/baryovm_cloud_firebase.md | 2 +- docs/commands/baryovm_cloud_gcloud.md | 2 +- docs/commands/baryovm_cloud_wrangler.md | 2 +- docs/commands/baryovm_deploy.md | 2 +- docs/commands/baryovm_doctor.md | 2 +- docs/commands/baryovm_gh.md | 2 +- docs/commands/baryovm_git.md | 2 +- docs/commands/baryovm_guard.md | 2 +- docs/commands/baryovm_guard_check.md | 2 +- .../baryovm_guard_check_commit-msg.md | 2 +- .../baryovm_guard_check_pre-commit.md | 2 +- docs/commands/baryovm_guard_check_pre-push.md | 2 +- docs/commands/baryovm_guard_install-hooks.md | 2 +- docs/commands/baryovm_project.md | 2 +- docs/commands/baryovm_project_export.md | 2 +- docs/commands/baryovm_project_release.md | 2 +- docs/commands/baryovm_prove.md | 2 +- docs/commands/baryovm_publish.md | 2 +- docs/commands/baryovm_publish_npm.md | 2 +- docs/commands/baryovm_publish_nuget.md | 2 +- docs/commands/baryovm_repo.md | 2 +- docs/commands/baryovm_repo_init.md | 2 +- docs/commands/baryovm_repo_move.md | 2 +- docs/commands/baryovm_repo_verify.md | 2 +- docs/commands/baryovm_scan.md | 2 +- docs/commands/baryovm_ship.md | 2 +- docs/commands/baryovm_site.md | 2 +- docs/commands/baryovm_site_add.md | 2 +- docs/commands/baryovm_site_deploy.md | 2 +- docs/commands/baryovm_stack.md | 2 +- docs/commands/baryovm_stack_add.md | 2 +- docs/commands/baryovm_stack_backup.md | 2 +- docs/commands/baryovm_stack_backups.md | 2 +- docs/commands/baryovm_stack_deploy.md | 2 +- docs/commands/baryovm_stack_discover.md | 2 +- docs/commands/baryovm_stack_env.md | 2 +- docs/commands/baryovm_stack_env_list.md | 2 +- docs/commands/baryovm_stack_env_set.md | 2 +- docs/commands/baryovm_stack_env_unset.md | 2 +- docs/commands/baryovm_stack_list.md | 2 +- docs/commands/baryovm_stack_logs.md | 2 +- docs/commands/baryovm_stack_ps.md | 2 +- docs/commands/baryovm_stack_publish.md | 2 +- docs/commands/baryovm_stack_pull.md | 2 +- docs/commands/baryovm_stack_release.md | 2 +- docs/commands/baryovm_stack_remove.md | 2 +- docs/commands/baryovm_stack_restore.md | 2 +- docs/commands/baryovm_stack_rollback.md | 2 +- docs/commands/baryovm_stack_set-backup.md | 2 +- docs/commands/baryovm_stack_set-managed.md | 2 +- docs/commands/baryovm_stack_set-publish.md | 2 +- docs/commands/baryovm_stack_set-update.md | 2 +- docs/commands/baryovm_stack_set-verify.md | 2 +- docs/commands/baryovm_stack_tls.md | 2 +- docs/commands/baryovm_stack_update.md | 2 +- docs/commands/baryovm_status.md | 2 +- docs/commands/baryovm_up.md | 2 +- docs/commands/baryovm_version.md | 2 +- docs/commands/baryovm_vm.md | 4 +- docs/commands/baryovm_vm_add.md | 10 +- docs/commands/baryovm_vm_bootstrap.md | 2 +- docs/commands/baryovm_vm_exec.md | 2 +- docs/commands/baryovm_vm_forget-key.md | 16 ++- docs/commands/baryovm_vm_harden.md | 2 +- docs/commands/baryovm_vm_health.md | 2 +- docs/commands/baryovm_vm_list.md | 2 +- docs/commands/baryovm_vm_patch.md | 2 +- docs/commands/baryovm_vm_ping.md | 2 +- docs/commands/baryovm_vm_provision.md | 2 +- docs/commands/baryovm_vm_prune.md | 2 +- docs/commands/baryovm_vm_remote.md | 2 +- docs/commands/baryovm_vm_remote_install.md | 2 +- docs/commands/baryovm_vm_remote_set.md | 2 +- docs/commands/baryovm_vm_remove.md | 2 +- docs/commands/baryovm_vm_runner.md | 2 +- docs/commands/baryovm_vm_runner_remove.md | 2 +- docs/commands/baryovm_vm_threats.md | 2 +- docs/indie.md | 3 +- docs/real-hosts/azure-ubuntu-x86.md | 3 +- docs/sme.md | 4 +- docs/troubleshooting.md | 32 +++++- internal/cli/deploy.go | 4 +- internal/cli/doctor.go | 2 +- internal/cli/dryrun.go | 4 +- internal/cli/guard.go | 4 +- internal/cli/health.go | 2 +- internal/cli/patch.go | 2 +- internal/cli/project.go | 8 +- internal/cli/provision.go | 2 +- internal/cli/prune.go | 2 +- internal/cli/remote.go | 6 +- internal/cli/repo.go | 2 +- internal/cli/repo_init.go | 4 +- internal/cli/root.go | 7 +- internal/cli/scan.go | 2 +- internal/cli/ship.go | 2 +- internal/cli/stack.go | 2 +- internal/cli/stack_backup_pull.go | 2 +- internal/cli/stack_discover.go | 2 +- internal/cli/stack_env.go | 4 +- internal/cli/stack_release_state.go | 4 +- internal/cli/stack_rollback.go | 2 +- internal/cli/stack_tls.go | 2 +- internal/cli/status.go | 2 +- internal/cli/up.go | 8 +- internal/cli/vm.go | 36 +++++-- internal/cli/vm_add_test.go | 83 ++++++++++++++ internal/cli/vm_runner.go | 2 +- internal/hostkeys/hostkeys.go | 93 ++++++++++++---- internal/hostkeys/hostkeys_test.go | 101 ++++++++++++++++++ internal/sshx/askhostkey_test.go | 44 +++++++- internal/sshx/sshx.go | 9 +- 115 files changed, 515 insertions(+), 173 deletions(-) diff --git a/USAGE.md b/USAGE.md index 8630751..8a6d1e9 100644 --- a/USAGE.md +++ b/USAGE.md @@ -56,7 +56,8 @@ a terminal you see the host and the fingerprint it offered, and a prompt: ```text ! 203.0.113.10:22 has no recorded host key offered: SHA256:9KpQ... - verify it: ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 203.0.113.10 | ssh-keygen -lf - + check it: against a fingerprint from the cloud console or ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub on the machine + not a check: a keyscan of this address, a man in the middle answers it too Trust this host key? [y/N] ``` @@ -103,7 +104,8 @@ So a CI job records the key first, and fails rather than trusting a new one: - name: Pin the host key run: | mkdir -p ~/.baryovm - ssh-keyscan -t ecdsa,ed25519,rsa "$VM_HOST" >> ~/.baryovm/known_hosts + # VM_KNOWN_HOSTS is the known_hosts line you checked against the cloud console or the machine + echo "$VM_KNOWN_HOSTS" >> ~/.baryovm/known_hosts - name: Deploy env: @@ -113,7 +115,10 @@ So a CI job records the key first, and fails rather than trusting a new one: Better still, commit the expected `known_hosts` or keep it in a secret, so the pin is reviewed rather than fetched from the network on every run. `ssh-keyscan` -at deploy time trusts whatever answers; a committed file does not. +at deploy time shows only what the host offers, and a man in the middle answers it too, so it is +not verification. Compare the fingerprint with one from a separate trusted channel (the cloud +console, the provider's serial console, or `ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub` run on the +machine) and keep the checked line, not a fresh scan. The flag beats the environment, so `--strict-host-keys=false` is how a human turns it off for one command on a machine where the workflow sets it globally. @@ -1195,8 +1200,8 @@ What the file may and may not hold: file's directory. A literal private key, token or password in any field, including fields this version does not know, is refused with the field named, before anything connects. The error never repeats the value. -- `hostKey` is the VM's public host key (`ssh-keyscan -t ed25519 `, then check the - fingerprint). It is public, so it is committed. +- `hostKey` is the VM's public host key (`ssh-keyscan -t ed25519 ` shows what the host + offers; check its fingerprint against the cloud console or the machine, not the scan). It is public, so it is committed. - `order` lists the stacks to release. Leave it out and every stack is released in the order written. `project release` stops at the first failed release or verify and leaves later stacks untouched. The diff --git a/docs/commands/baryovm.md b/docs/commands/baryovm.md index ea64619..3513cf7 100644 --- a/docs/commands/baryovm.md +++ b/docs/commands/baryovm.md @@ -12,7 +12,7 @@ CLI-first: the MAUI app and MCP server drive this same CLI (with -o json). ``` -h, --help help for baryovm -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud.md b/docs/commands/baryovm_cloud.md index 66fe07f..3fd25ee 100644 --- a/docs/commands/baryovm_cloud.md +++ b/docs/commands/baryovm_cloud.md @@ -16,7 +16,7 @@ baryovm cloud [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_firebase.md b/docs/commands/baryovm_cloud_firebase.md index c71517a..4c54d04 100644 --- a/docs/commands/baryovm_cloud_firebase.md +++ b/docs/commands/baryovm_cloud_firebase.md @@ -51,7 +51,7 @@ baryovm cloud firebase [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_gcloud.md b/docs/commands/baryovm_cloud_gcloud.md index 5c7d697..24ea186 100644 --- a/docs/commands/baryovm_cloud_gcloud.md +++ b/docs/commands/baryovm_cloud_gcloud.md @@ -40,7 +40,7 @@ baryovm cloud gcloud [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_cloud_wrangler.md b/docs/commands/baryovm_cloud_wrangler.md index e7a929a..cbab101 100644 --- a/docs/commands/baryovm_cloud_wrangler.md +++ b/docs/commands/baryovm_cloud_wrangler.md @@ -42,7 +42,7 @@ baryovm cloud wrangler [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_deploy.md b/docs/commands/baryovm_deploy.md index 8fdd8a7..f966247 100644 --- a/docs/commands/baryovm_deploy.md +++ b/docs/commands/baryovm_deploy.md @@ -33,7 +33,7 @@ baryovm deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_doctor.md b/docs/commands/baryovm_doctor.md index 821be92..e4955cc 100644 --- a/docs/commands/baryovm_doctor.md +++ b/docs/commands/baryovm_doctor.md @@ -23,7 +23,7 @@ baryovm doctor [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_gh.md b/docs/commands/baryovm_gh.md index ec16365..2fcde39 100644 --- a/docs/commands/baryovm_gh.md +++ b/docs/commands/baryovm_gh.md @@ -42,7 +42,7 @@ baryovm gh [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_git.md b/docs/commands/baryovm_git.md index d138de9..0978733 100644 --- a/docs/commands/baryovm_git.md +++ b/docs/commands/baryovm_git.md @@ -59,7 +59,7 @@ baryovm git [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard.md b/docs/commands/baryovm_guard.md index a74e263..ea84d3c 100644 --- a/docs/commands/baryovm_guard.md +++ b/docs/commands/baryovm_guard.md @@ -16,7 +16,7 @@ baryovm guard [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check.md b/docs/commands/baryovm_guard_check.md index e54217b..5ec1453 100644 --- a/docs/commands/baryovm_guard_check.md +++ b/docs/commands/baryovm_guard_check.md @@ -16,7 +16,7 @@ baryovm guard check [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_commit-msg.md b/docs/commands/baryovm_guard_check_commit-msg.md index d3d4c57..a19f455 100644 --- a/docs/commands/baryovm_guard_check_commit-msg.md +++ b/docs/commands/baryovm_guard_check_commit-msg.md @@ -16,7 +16,7 @@ baryovm guard check commit-msg [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_pre-commit.md b/docs/commands/baryovm_guard_check_pre-commit.md index e98e1a4..1b186fe 100644 --- a/docs/commands/baryovm_guard_check_pre-commit.md +++ b/docs/commands/baryovm_guard_check_pre-commit.md @@ -16,7 +16,7 @@ baryovm guard check pre-commit [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_check_pre-push.md b/docs/commands/baryovm_guard_check_pre-push.md index a53bdab..7127d48 100644 --- a/docs/commands/baryovm_guard_check_pre-push.md +++ b/docs/commands/baryovm_guard_check_pre-push.md @@ -16,7 +16,7 @@ baryovm guard check pre-push [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_guard_install-hooks.md b/docs/commands/baryovm_guard_install-hooks.md index 31de903..6105014 100644 --- a/docs/commands/baryovm_guard_install-hooks.md +++ b/docs/commands/baryovm_guard_install-hooks.md @@ -24,7 +24,7 @@ baryovm guard install-hooks [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project.md b/docs/commands/baryovm_project.md index 3bc6f27..eca3e3d 100644 --- a/docs/commands/baryovm_project.md +++ b/docs/commands/baryovm_project.md @@ -16,7 +16,7 @@ baryovm project [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project_export.md b/docs/commands/baryovm_project_export.md index ed6b507..a6d1346 100644 --- a/docs/commands/baryovm_project_export.md +++ b/docs/commands/baryovm_project_export.md @@ -33,7 +33,7 @@ baryovm project export [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_project_release.md b/docs/commands/baryovm_project_release.md index 2fab735..9ea6567 100644 --- a/docs/commands/baryovm_project_release.md +++ b/docs/commands/baryovm_project_release.md @@ -35,7 +35,7 @@ baryovm project release [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_prove.md b/docs/commands/baryovm_prove.md index d460654..72e884d 100644 --- a/docs/commands/baryovm_prove.md +++ b/docs/commands/baryovm_prove.md @@ -33,7 +33,7 @@ baryovm prove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish.md b/docs/commands/baryovm_publish.md index 0e126ad..57b725b 100644 --- a/docs/commands/baryovm_publish.md +++ b/docs/commands/baryovm_publish.md @@ -16,7 +16,7 @@ baryovm publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish_npm.md b/docs/commands/baryovm_publish_npm.md index e1b77d6..4ab8290 100644 --- a/docs/commands/baryovm_publish_npm.md +++ b/docs/commands/baryovm_publish_npm.md @@ -49,7 +49,7 @@ baryovm publish npm [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_publish_nuget.md b/docs/commands/baryovm_publish_nuget.md index b380459..384402b 100644 --- a/docs/commands/baryovm_publish_nuget.md +++ b/docs/commands/baryovm_publish_nuget.md @@ -46,7 +46,7 @@ baryovm publish nuget [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo.md b/docs/commands/baryovm_repo.md index 83ebe88..6cca1a1 100644 --- a/docs/commands/baryovm_repo.md +++ b/docs/commands/baryovm_repo.md @@ -16,7 +16,7 @@ baryovm repo [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_init.md b/docs/commands/baryovm_repo_init.md index f1aa58f..24dc722 100644 --- a/docs/commands/baryovm_repo_init.md +++ b/docs/commands/baryovm_repo_init.md @@ -70,7 +70,7 @@ baryovm repo init [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_move.md b/docs/commands/baryovm_repo_move.md index 173cf0a..220611d 100644 --- a/docs/commands/baryovm_repo_move.md +++ b/docs/commands/baryovm_repo_move.md @@ -65,7 +65,7 @@ baryovm repo move [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_repo_verify.md b/docs/commands/baryovm_repo_verify.md index f7ec64d..fc70d9b 100644 --- a/docs/commands/baryovm_repo_verify.md +++ b/docs/commands/baryovm_repo_verify.md @@ -46,7 +46,7 @@ baryovm repo verify [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_scan.md b/docs/commands/baryovm_scan.md index cd7e0b6..109d1a8 100644 --- a/docs/commands/baryovm_scan.md +++ b/docs/commands/baryovm_scan.md @@ -35,7 +35,7 @@ baryovm scan --url [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_ship.md b/docs/commands/baryovm_ship.md index bcd2fae..182d715 100644 --- a/docs/commands/baryovm_ship.md +++ b/docs/commands/baryovm_ship.md @@ -43,7 +43,7 @@ baryovm ship [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site.md b/docs/commands/baryovm_site.md index 42527c4..3c74bdd 100644 --- a/docs/commands/baryovm_site.md +++ b/docs/commands/baryovm_site.md @@ -16,7 +16,7 @@ baryovm site [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site_add.md b/docs/commands/baryovm_site_add.md index f94c061..aa92657 100644 --- a/docs/commands/baryovm_site_add.md +++ b/docs/commands/baryovm_site_add.md @@ -48,7 +48,7 @@ baryovm site add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_site_deploy.md b/docs/commands/baryovm_site_deploy.md index 9eaf60e..a6be318 100644 --- a/docs/commands/baryovm_site_deploy.md +++ b/docs/commands/baryovm_site_deploy.md @@ -32,7 +32,7 @@ baryovm site deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack.md b/docs/commands/baryovm_stack.md index f8bfe9f..4a86bad 100644 --- a/docs/commands/baryovm_stack.md +++ b/docs/commands/baryovm_stack.md @@ -16,7 +16,7 @@ baryovm stack [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_add.md b/docs/commands/baryovm_stack_add.md index e0d1c3d..5476db0 100644 --- a/docs/commands/baryovm_stack_add.md +++ b/docs/commands/baryovm_stack_add.md @@ -30,7 +30,7 @@ baryovm stack add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_backup.md b/docs/commands/baryovm_stack_backup.md index 77fe0d3..103e452 100644 --- a/docs/commands/baryovm_stack_backup.md +++ b/docs/commands/baryovm_stack_backup.md @@ -18,7 +18,7 @@ baryovm stack backup [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_backups.md b/docs/commands/baryovm_stack_backups.md index 12e3b90..0027d11 100644 --- a/docs/commands/baryovm_stack_backups.md +++ b/docs/commands/baryovm_stack_backups.md @@ -16,7 +16,7 @@ baryovm stack backups [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_deploy.md b/docs/commands/baryovm_stack_deploy.md index 489a7ef..b85b9bd 100644 --- a/docs/commands/baryovm_stack_deploy.md +++ b/docs/commands/baryovm_stack_deploy.md @@ -29,7 +29,7 @@ baryovm stack deploy [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_discover.md b/docs/commands/baryovm_stack_discover.md index 5685f0b..1e34980 100644 --- a/docs/commands/baryovm_stack_discover.md +++ b/docs/commands/baryovm_stack_discover.md @@ -40,7 +40,7 @@ baryovm stack discover [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env.md b/docs/commands/baryovm_stack_env.md index 652ef3e..354898e 100644 --- a/docs/commands/baryovm_stack_env.md +++ b/docs/commands/baryovm_stack_env.md @@ -27,7 +27,7 @@ baryovm stack env [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_list.md b/docs/commands/baryovm_stack_env_list.md index 2854d2a..c8d132d 100644 --- a/docs/commands/baryovm_stack_env_list.md +++ b/docs/commands/baryovm_stack_env_list.md @@ -16,7 +16,7 @@ baryovm stack env list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_set.md b/docs/commands/baryovm_stack_env_set.md index 242fa42..e0d3f8d 100644 --- a/docs/commands/baryovm_stack_env_set.md +++ b/docs/commands/baryovm_stack_env_set.md @@ -17,7 +17,7 @@ baryovm stack env set [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_env_unset.md b/docs/commands/baryovm_stack_env_unset.md index f07c81a..0083d48 100644 --- a/docs/commands/baryovm_stack_env_unset.md +++ b/docs/commands/baryovm_stack_env_unset.md @@ -17,7 +17,7 @@ baryovm stack env unset [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_list.md b/docs/commands/baryovm_stack_list.md index d511196..e05fc1d 100644 --- a/docs/commands/baryovm_stack_list.md +++ b/docs/commands/baryovm_stack_list.md @@ -16,7 +16,7 @@ baryovm stack list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_logs.md b/docs/commands/baryovm_stack_logs.md index 442de6c..02ba9dd 100644 --- a/docs/commands/baryovm_stack_logs.md +++ b/docs/commands/baryovm_stack_logs.md @@ -18,7 +18,7 @@ baryovm stack logs [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_ps.md b/docs/commands/baryovm_stack_ps.md index 9e84058..c465dff 100644 --- a/docs/commands/baryovm_stack_ps.md +++ b/docs/commands/baryovm_stack_ps.md @@ -16,7 +16,7 @@ baryovm stack ps [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_publish.md b/docs/commands/baryovm_stack_publish.md index 989d64a..b9dbb1d 100644 --- a/docs/commands/baryovm_stack_publish.md +++ b/docs/commands/baryovm_stack_publish.md @@ -35,7 +35,7 @@ baryovm stack publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_pull.md b/docs/commands/baryovm_stack_pull.md index 39460ad..ab90fd3 100644 --- a/docs/commands/baryovm_stack_pull.md +++ b/docs/commands/baryovm_stack_pull.md @@ -17,7 +17,7 @@ baryovm stack pull [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_release.md b/docs/commands/baryovm_stack_release.md index dcbb747..ae901bb 100644 --- a/docs/commands/baryovm_stack_release.md +++ b/docs/commands/baryovm_stack_release.md @@ -32,7 +32,7 @@ baryovm stack release [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_remove.md b/docs/commands/baryovm_stack_remove.md index 883624d..a986472 100644 --- a/docs/commands/baryovm_stack_remove.md +++ b/docs/commands/baryovm_stack_remove.md @@ -16,7 +16,7 @@ baryovm stack remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_restore.md b/docs/commands/baryovm_stack_restore.md index 2f21d3c..46280dd 100644 --- a/docs/commands/baryovm_stack_restore.md +++ b/docs/commands/baryovm_stack_restore.md @@ -28,7 +28,7 @@ baryovm stack restore [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_rollback.md b/docs/commands/baryovm_stack_rollback.md index a43d31c..4ca9631 100644 --- a/docs/commands/baryovm_stack_rollback.md +++ b/docs/commands/baryovm_stack_rollback.md @@ -30,7 +30,7 @@ baryovm stack rollback [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-backup.md b/docs/commands/baryovm_stack_set-backup.md index 0d6a8f4..8402c68 100644 --- a/docs/commands/baryovm_stack_set-backup.md +++ b/docs/commands/baryovm_stack_set-backup.md @@ -40,7 +40,7 @@ baryovm stack set-backup [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-managed.md b/docs/commands/baryovm_stack_set-managed.md index 881d043..28e5955 100644 --- a/docs/commands/baryovm_stack_set-managed.md +++ b/docs/commands/baryovm_stack_set-managed.md @@ -42,7 +42,7 @@ baryovm stack set-managed [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-publish.md b/docs/commands/baryovm_stack_set-publish.md index 06d545a..dd1cd6e 100644 --- a/docs/commands/baryovm_stack_set-publish.md +++ b/docs/commands/baryovm_stack_set-publish.md @@ -30,7 +30,7 @@ baryovm stack set-publish [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-update.md b/docs/commands/baryovm_stack_set-update.md index f18c7ba..cbd8139 100644 --- a/docs/commands/baryovm_stack_set-update.md +++ b/docs/commands/baryovm_stack_set-update.md @@ -28,7 +28,7 @@ baryovm stack set-update [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_set-verify.md b/docs/commands/baryovm_stack_set-verify.md index 203f7c8..459f0a0 100644 --- a/docs/commands/baryovm_stack_set-verify.md +++ b/docs/commands/baryovm_stack_set-verify.md @@ -35,7 +35,7 @@ baryovm stack set-verify [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_tls.md b/docs/commands/baryovm_stack_tls.md index 9d7f9fb..625b6b0 100644 --- a/docs/commands/baryovm_stack_tls.md +++ b/docs/commands/baryovm_stack_tls.md @@ -33,7 +33,7 @@ baryovm stack tls [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_stack_update.md b/docs/commands/baryovm_stack_update.md index 9905b9a..eb46aac 100644 --- a/docs/commands/baryovm_stack_update.md +++ b/docs/commands/baryovm_stack_update.md @@ -52,7 +52,7 @@ baryovm stack update [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_status.md b/docs/commands/baryovm_status.md index bd73d6c..9d66a67 100644 --- a/docs/commands/baryovm_status.md +++ b/docs/commands/baryovm_status.md @@ -45,7 +45,7 @@ baryovm status [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_up.md b/docs/commands/baryovm_up.md index 85ce510..d096feb 100644 --- a/docs/commands/baryovm_up.md +++ b/docs/commands/baryovm_up.md @@ -46,7 +46,7 @@ baryovm up [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_version.md b/docs/commands/baryovm_version.md index 7eb843a..42f5173 100644 --- a/docs/commands/baryovm_version.md +++ b/docs/commands/baryovm_version.md @@ -16,7 +16,7 @@ baryovm version [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm.md b/docs/commands/baryovm_vm.md index a4e874b..93f6ac1 100644 --- a/docs/commands/baryovm_vm.md +++ b/docs/commands/baryovm_vm.md @@ -16,7 +16,7 @@ baryovm vm [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO @@ -25,7 +25,7 @@ baryovm vm [flags] * [baryovm vm add](baryovm_vm_add.md) - Register an existing VM by host + SSH key * [baryovm vm bootstrap](baryovm_vm_bootstrap.md) - Install the container runtime (docker or podman) on a VM (idempotent) * [baryovm vm exec](baryovm_vm_exec.md) - Run a command on a registered VM over SSH -* [baryovm vm forget-key](baryovm_vm_forget-key.md) - Forget a VM's recorded SSH host key, so the next connection asks about it again +* [baryovm vm forget-key](baryovm_vm_forget-key.md) - Forget a VM's recorded SSH host key, so the next connection treats it as unknown * [baryovm vm harden](baryovm_vm_harden.md) - Apply the SSH hardening policy to a VM * [baryovm vm health](baryovm_vm_health.md) - Ask a VM the questions an owner should ask monthly (read only) * [baryovm vm list](baryovm_vm_list.md) - List registered VMs diff --git a/docs/commands/baryovm_vm_add.md b/docs/commands/baryovm_vm_add.md index 3f9a84c..b44dc97 100644 --- a/docs/commands/baryovm_vm_add.md +++ b/docs/commands/baryovm_vm_add.md @@ -14,9 +14,11 @@ host's default shell is powershell.exe. An unknown host key is asked about on a terminal and refused with no terminal or under -o json. A script or app that has had a person check the key can pass its SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key -is recorded and the command continues, and any other key is refused. This holds -under --strict-host-keys too, since the flag is the checked key. A host with a -different recorded key is still refused. +is recorded and the command continues, and any other key is refused, also for a +host that already has a recorded key. This holds under --strict-host-keys too, +since the flag is the checked key. It cannot be combined with --os or --remote +forced, which make no connection. A host with a different recorded key is still +refused. ``` baryovm vm add [flags] @@ -40,7 +42,7 @@ baryovm vm add [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_bootstrap.md b/docs/commands/baryovm_vm_bootstrap.md index b7c73a8..b452d67 100644 --- a/docs/commands/baryovm_vm_bootstrap.md +++ b/docs/commands/baryovm_vm_bootstrap.md @@ -18,7 +18,7 @@ baryovm vm bootstrap [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_exec.md b/docs/commands/baryovm_vm_exec.md index d42909d..9eb650d 100644 --- a/docs/commands/baryovm_vm_exec.md +++ b/docs/commands/baryovm_vm_exec.md @@ -40,7 +40,7 @@ baryovm vm exec -- ... [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_forget-key.md b/docs/commands/baryovm_vm_forget-key.md index d52cffa..4b6a525 100644 --- a/docs/commands/baryovm_vm_forget-key.md +++ b/docs/commands/baryovm_vm_forget-key.md @@ -1,6 +1,18 @@ ## baryovm vm forget-key -Forget a VM's recorded SSH host key, so the next connection asks about it again +Forget a VM's recorded SSH host key, so the next connection treats it as unknown + +### Synopsis + +Forget the host key BaryoVM recorded for a VM, for when the VM was rebuilt and now has a new one. + +This clears only BaryoVM's own store. If ~/.ssh/known_hosts still holds the old key, the rebuilt +host is refused again as a changed key; remove that line with ssh-keygen -R too. + +After that the host is unknown, and the next connection depends on the mode: on a terminal it asks +whether to trust the new key, with no terminal, under -o json or with --strict-host-keys it is +refused, and with --strict-host-keys=false (or BARYOVM_STRICT_HOST_KEYS=0) it learns the new key +without asking. Check the new fingerprint against the cloud console or the machine itself first. ``` baryovm vm forget-key [flags] @@ -16,7 +28,7 @@ baryovm vm forget-key [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_harden.md b/docs/commands/baryovm_vm_harden.md index 6a06aed..4229458 100644 --- a/docs/commands/baryovm_vm_harden.md +++ b/docs/commands/baryovm_vm_harden.md @@ -58,7 +58,7 @@ baryovm vm harden [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_health.md b/docs/commands/baryovm_vm_health.md index 0c0a323..aff92d7 100644 --- a/docs/commands/baryovm_vm_health.md +++ b/docs/commands/baryovm_vm_health.md @@ -35,7 +35,7 @@ baryovm vm health [name] [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_list.md b/docs/commands/baryovm_vm_list.md index 4c0a330..937dfd8 100644 --- a/docs/commands/baryovm_vm_list.md +++ b/docs/commands/baryovm_vm_list.md @@ -16,7 +16,7 @@ baryovm vm list [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_patch.md b/docs/commands/baryovm_vm_patch.md index 34f1d00..75f57a1 100644 --- a/docs/commands/baryovm_vm_patch.md +++ b/docs/commands/baryovm_vm_patch.md @@ -33,7 +33,7 @@ baryovm vm patch [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_ping.md b/docs/commands/baryovm_vm_ping.md index af1367b..95c9fd8 100644 --- a/docs/commands/baryovm_vm_ping.md +++ b/docs/commands/baryovm_vm_ping.md @@ -16,7 +16,7 @@ baryovm vm ping [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_provision.md b/docs/commands/baryovm_vm_provision.md index 074d0d2..8998dd7 100644 --- a/docs/commands/baryovm_vm_provision.md +++ b/docs/commands/baryovm_vm_provision.md @@ -26,7 +26,7 @@ baryovm vm provision [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_prune.md b/docs/commands/baryovm_vm_prune.md index da4552c..e8f3f9a 100644 --- a/docs/commands/baryovm_vm_prune.md +++ b/docs/commands/baryovm_vm_prune.md @@ -38,7 +38,7 @@ baryovm vm prune [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote.md b/docs/commands/baryovm_vm_remote.md index b389b85..08eac27 100644 --- a/docs/commands/baryovm_vm_remote.md +++ b/docs/commands/baryovm_vm_remote.md @@ -24,7 +24,7 @@ baryovm vm remote [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote_install.md b/docs/commands/baryovm_vm_remote_install.md index 47c3d2c..940511e 100644 --- a/docs/commands/baryovm_vm_remote_install.md +++ b/docs/commands/baryovm_vm_remote_install.md @@ -28,7 +28,7 @@ baryovm vm remote install [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remote_set.md b/docs/commands/baryovm_vm_remote_set.md index 2c8c2f4..675c866 100644 --- a/docs/commands/baryovm_vm_remote_set.md +++ b/docs/commands/baryovm_vm_remote_set.md @@ -16,7 +16,7 @@ baryovm vm remote set [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_remove.md b/docs/commands/baryovm_vm_remove.md index b6f1aef..c1a04bc 100644 --- a/docs/commands/baryovm_vm_remove.md +++ b/docs/commands/baryovm_vm_remove.md @@ -16,7 +16,7 @@ baryovm vm remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_runner.md b/docs/commands/baryovm_vm_runner.md index e2b7360..676c92b 100644 --- a/docs/commands/baryovm_vm_runner.md +++ b/docs/commands/baryovm_vm_runner.md @@ -38,7 +38,7 @@ baryovm vm runner [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_runner_remove.md b/docs/commands/baryovm_vm_runner_remove.md index 05f790e..76d68c6 100644 --- a/docs/commands/baryovm_vm_runner_remove.md +++ b/docs/commands/baryovm_vm_runner_remove.md @@ -25,7 +25,7 @@ baryovm vm runner remove [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/commands/baryovm_vm_threats.md b/docs/commands/baryovm_vm_threats.md index 249093a..6053a65 100644 --- a/docs/commands/baryovm_vm_threats.md +++ b/docs/commands/baryovm_vm_threats.md @@ -25,7 +25,7 @@ baryovm vm threats [flags] ``` -o, --output string output format: human | json (default "human") - --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0) + --strict-host-keys always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false ``` ### SEE ALSO diff --git a/docs/indie.md b/docs/indie.md index 5ff1907..9d9b6c1 100644 --- a/docs/indie.md +++ b/docs/indie.md @@ -20,7 +20,8 @@ baryovm vm ping myvm ``` `vm add` connects once to detect the OS. On a terminal it shows the host key fingerprint and asks -before recording it in `~/.baryovm/known_hosts`. +before recording it in `~/.baryovm/known_hosts`. Asking on a terminal and refusing with no terminal +is the default. `BARYOVM_STRICT_HOST_KEYS=0` learns a new host without asking. `vm ping` reports the host and the Docker version. If either fails, see [troubleshooting](troubleshooting.md). diff --git a/docs/real-hosts/azure-ubuntu-x86.md b/docs/real-hosts/azure-ubuntu-x86.md index 61c7e60..1136c69 100644 --- a/docs/real-hosts/azure-ubuntu-x86.md +++ b/docs/real-hosts/azure-ubuntu-x86.md @@ -32,7 +32,8 @@ $ baryovm vm ping azure-x86 ✓ azure-x86 reachable ! :22 has no recorded host key offered: SHA256:... - verify it: ssh-keyscan -p 22 -t ecdsa,ed25519,rsa | ssh-keygen -lf - + check it: against a fingerprint from the cloud console or ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub on the machine + not a check: a keyscan of this address, a man in the middle answers it too Trust this host key? [y/N] y $ baryovm vm exec azure-x86 -- cat /etc/os-release diff --git a/docs/sme.md b/docs/sme.md index 57f453d..f5d12ad 100644 --- a/docs/sme.md +++ b/docs/sme.md @@ -15,7 +15,9 @@ baryovm vm ping prod ``` `vm add` asks about the host key the first time it connects, and records it only if you answer -`y`. Check the fingerprint against the machine first. With no terminal it refuses an unknown host. +`y`. Check the fingerprint against the cloud console or the machine itself first, not against a +scan of the same address. Asking on a terminal and refusing with no terminal is the default. +`BARYOVM_STRICT_HOST_KEYS=0` learns a new host without asking. ## 2. Find what is running diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index c0a7572..8f38cfe 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -142,14 +142,26 @@ be. The tool cannot tell, so it stops. If you rebuilt the machine: baryovm vm forget-key myvm ``` -The next connection asks about the new key (on a terminal) and shows its fingerprint, with an -`ssh-keyscan` line to check it. With no terminal it is refused until you record the key. +`forget-key` clears only BaryoVM's own store. If `~/.ssh/known_hosts` still holds the old key, the +rebuilt host is refused again as a changed key; remove that line with `ssh-keygen -R ` too. + +After that the host is unknown, and the next connection depends on the mode: + +- On a terminal it asks about the new key and shows its fingerprint. Compare it with the cloud + console or the machine itself. +- With no terminal, under `-o json` or with `--strict-host-keys` it is refused until you record the + key. +- With `--strict-host-keys=false` (or `BARYOVM_STRICT_HOST_KEYS=0`) it learns the new key without + asking. ## `no recorded host key for , and ...` The tool has not seen this host, and nobody could say yes to its key. The second half of the first -line says why. Every one of them carries the offered fingerprint and a command to record it, after -you compare the fingerprint to the machine: +line says why. Every one of them carries the offered fingerprint and a command to record it. First +compare the fingerprint with one from a separate trusted source (the cloud console, the provider's +serial console, or `ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub` on the machine). A keyscan of the +same address is not a check, because a man in the middle answers it too. The command below only +records what the host offers: ```text no recorded host key for 203.0.113.10:22, and there is no terminal to ask on. @@ -158,6 +170,16 @@ no recorded host key for 203.0.113.10:22, and there is no terminal to ask on. ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 203.0.113.10 >> ~/.baryovm/known_hosts ``` +Do not append the scan blindly. Save it to a file, check each key's fingerprint against the one you +verified out of band, and append only the lines that match: + +```sh +ssh-keyscan -p 22 -t ecdsa,ed25519,rsa 203.0.113.10 > /tmp/scan.keys +ssh-keygen -lf /tmp/scan.keys +# keep only the lines whose fingerprint matches, then: +cat /tmp/scan.keys >> ~/.baryovm/known_hosts +``` + - `there is no terminal to ask on`: stdin or stderr is not a terminal (a pipe, CI). Record the key first. To learn on first use instead, set `BARYOVM_STRICT_HOST_KEYS=0` or pass `--strict-host-keys=false`. @@ -185,7 +207,7 @@ vms[0].hostKey: vm "client-vm" has no pinned host key, and a project release nev on first use: add its public key to the file ... ``` -Add `hostKey` to the project file (`ssh-keyscan -t ed25519 `, then check the fingerprint), or +Add `hostKey` to the project file (`ssh-keyscan -t ed25519 ` shows what the host offers; check its fingerprint against the cloud console or the machine, not the scan), or pass `--strict-host-keys` with the key already in `~/.baryovm/known_hosts`. ## `vm add` warns `could not reach ... to detect its OS` diff --git a/internal/cli/deploy.go b/internal/cli/deploy.go index 8710b4d..162b1d9 100644 --- a/internal/cli/deploy.go +++ b/internal/cli/deploy.go @@ -35,7 +35,7 @@ func newDeployCmd() *cobra.Command { } env, err := buildEnv(envs, envRefs, !dryRun) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "deploy", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "deploy", Error: err.Error(), Data: errData(err)}) return err } spec := deploy.Spec{Name: name, Image: image, Ports: ports, Env: env, Pull: pull, Runtime: runtimeName} @@ -57,7 +57,7 @@ func newDeployCmd() *cobra.Command { return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "deploy", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "deploy", Error: err.Error(), Data: errData(err)}) return err } ui.Emit(ui.Result{ diff --git a/internal/cli/doctor.go b/internal/cli/doctor.go index 99f2d0b..1fd191a 100644 --- a/internal/cli/doctor.go +++ b/internal/cli/doctor.go @@ -110,7 +110,7 @@ func newDoctorCmd() *cobra.Command { if !fix { ui.Detail("hint", "run `baryovm doctor --fix` to install what BaryoVM can install") } - ui.Emit(ui.Result{OK: false, Action: "doctor", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "doctor", Error: err.Error(), Data: errData(err)}) return err }, } diff --git a/internal/cli/dryrun.go b/internal/cli/dryrun.go index 77d25f2..4f79774 100644 --- a/internal/cli/dryrun.go +++ b/internal/cli/dryrun.go @@ -114,7 +114,7 @@ func dryStackBackup(name string) error { } script, err := backup.BackupScript(backupConfig(st)) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "stack backup", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack backup", Error: err.Error(), Data: errData(err)}) return err } p := newDryRunPlan(name) @@ -142,7 +142,7 @@ func dryStackRestore(name, file string) error { } script, err := backup.RestoreScriptE(backupConfig(st), file) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "stack restore", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack restore", Error: err.Error(), Data: errData(err)}) return err } p.add("restore", script) diff --git a/internal/cli/guard.go b/internal/cli/guard.go index 043df77..45490af 100644 --- a/internal/cli/guard.go +++ b/internal/cli/guard.go @@ -161,7 +161,7 @@ func finishGuard(v guard.Verdict, tool string, args []string) error { code, err := passthrough(tool, args) if err != nil { auditGuard(v, false, "could not run "+tool, time.Since(start)) - ui.Emit(ui.Result{OK: false, Action: v.Action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: v.Action, Error: err.Error(), Data: errData(err)}) return &exitError{code: 127, msg: err.Error(), silent: true} } if code != 0 { @@ -261,7 +261,7 @@ func newGuardInstallHooksCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { written, err := installHooks(force) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "guard install-hooks", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "guard install-hooks", Error: err.Error(), Data: errData(err)}) return &exitError{code: 1, msg: err.Error(), silent: true} } ui.Emit(ui.Result{OK: true, Action: "guard install-hooks", Message: "installed " + strings.Join(written, ", "), Data: written}) diff --git a/internal/cli/health.go b/internal/cli/health.go index fd0b835..39b8eab 100644 --- a/internal/cli/health.go +++ b/internal/cli/health.go @@ -178,6 +178,6 @@ func withThresholds(r health.Report, o health.Options) health.Report { // failHealth emits a failed result and returns the silent exit error, so Execute exits non-zero // without printing a second JSON document. Every path that emits goes through here. func failHealth(err error) error { - ui.Emit(ui.Result{OK: false, Action: "vm health", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "vm health", Error: err.Error(), Data: errData(err)}) return &exitError{code: 1, msg: err.Error(), silent: true} } diff --git a/internal/cli/patch.go b/internal/cli/patch.go index 41c0694..56e9bc6 100644 --- a/internal/cli/patch.go +++ b/internal/cli/patch.go @@ -70,7 +70,7 @@ func newVMPatchCmd() *cobra.Command { var problem *patch.Problem stackBroken := errors.As(runErr, &problem) if runErr != nil && !stackBroken { - ui.Emit(ui.Result{OK: false, Action: action, Error: runErr.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: runErr.Error(), Data: errData(runErr)}) return runErr } diff --git a/internal/cli/project.go b/internal/cli/project.go index f7159cd..347026f 100644 --- a/internal/cli/project.go +++ b/internal/cli/project.go @@ -66,7 +66,7 @@ func newProjectReleaseCmd() *cobra.Command { } p, err := fleet.LoadProject(file) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } order := p.ReleaseOrder() @@ -110,7 +110,7 @@ func newProjectReleaseCmd() *cobra.Command { } if vm.HostKey == "" { if !requested { - return fail(fmt.Errorf("vms[%d].hostKey: vm %q has no pinned host key, and a project release never trusts a host on first use: add its public key to the file (`ssh-keyscan -t ed25519 %s`, check the fingerprint) or pass --strict-host-keys with the key already in known_hosts", i, vm.Name, vm.Host)) + return fail(fmt.Errorf("vms[%d].hostKey: vm %q has no pinned host key, and a project release never trusts a host on first use: add its public key to the file (`ssh-keyscan -t ed25519 %s` shows what the host offers, so check that fingerprint against the cloud console or the machine itself, not against the scan) or pass --strict-host-keys with the key already in known_hosts", i, vm.Name, vm.Host)) } continue } @@ -178,7 +178,7 @@ func newProjectExportCmd() *cobra.Command { } if _, err := os.Stat(abs); err == nil && !force { e := fmt.Errorf("%s already exists: pass --force to replace it", out) - ui.Emit(ui.Result{OK: false, Action: action, Error: e.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: e.Error(), Data: errData(e)}) return e } if name == "" { @@ -193,7 +193,7 @@ func newProjectExportCmd() *cobra.Command { } p, b, err := exportProject(store, filepath.Dir(abs), name, keyEnv, stacks, known) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } if err := os.WriteFile(abs, b, 0o644); err != nil { // #nosec G306 -- meant to be committed diff --git a/internal/cli/provision.go b/internal/cli/provision.go index 8744a4b..151a1ba 100644 --- a/internal/cli/provision.go +++ b/internal/cli/provision.go @@ -238,7 +238,7 @@ func newVMProvisionCmd() *cobra.Command { return nil } if err != nil { - ui.Emit(ui.Result{OK: false, Action: "vm provision", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "vm provision", Error: err.Error(), Data: errData(err)}) return err } ui.Emit(ui.Result{OK: true, Action: "vm provision", Message: fmt.Sprintf("%s ready at %s", vm.Name, vm.Host), Data: vm}) diff --git a/internal/cli/prune.go b/internal/cli/prune.go index c9eea3f..ececb39 100644 --- a/internal/cli/prune.go +++ b/internal/cli/prune.go @@ -47,7 +47,7 @@ func newVMPruneCmd() *cobra.Command { action = "vm prune (plan)" } fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } diff --git a/internal/cli/remote.go b/internal/cli/remote.go index da6b05d..2c9bdc1 100644 --- a/internal/cli/remote.go +++ b/internal/cli/remote.go @@ -128,7 +128,7 @@ func refuseForcedFlags(stack, action, flags string) error { return nil } err = fmt.Errorf("on a forced VM `%s` returns the fixed tail the VM allows: %s are not available", action, flags) - ui.Emit(ui.Result{OK: false, Action: action, Message: stack, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Message: stack, Error: err.Error(), Data: errData(err)}) return err } @@ -151,7 +151,7 @@ func forcedOp(vm *fleet.VM, stack, action string, op remote.Op) error { return e }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Message: stack, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Message: stack, Error: err.Error(), Data: errData(err)}) return err } var note string @@ -256,7 +256,7 @@ func newVMRemoteInstallCmd() *cobra.Command { func runRemoteInstall(name, binary, pubKey string) error { const action = "vm remote install" fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Message: name, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Message: name, Error: err.Error(), Data: errData(err)}) return err } vm, err := requireVM(name) diff --git a/internal/cli/repo.go b/internal/cli/repo.go index 6e810a1..2f41002 100644 --- a/internal/cli/repo.go +++ b/internal/cli/repo.go @@ -144,7 +144,7 @@ for git's credential store. URLs that carry a user or token are refused. RunE: func(cmd *cobra.Command, args []string) error { err := runRepoMove(args[0], f) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "repo move", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "repo move", Error: err.Error(), Data: errData(err)}) } return err }, diff --git a/internal/cli/repo_init.go b/internal/cli/repo_init.go index 94e7c99..c764188 100644 --- a/internal/cli/repo_init.go +++ b/internal/cli/repo_init.go @@ -88,7 +88,7 @@ complains until the first publish. RunE: func(cmd *cobra.Command, args []string) error { err := runRepoInit(args[0], templateName, templatesDir, path, codeowner, branch, tokenRef, checks, approvals, force, replaceProt, yes && !dryRun) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "repo init", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "repo init", Error: err.Error(), Data: errData(err)}) } return err }, @@ -258,7 +258,7 @@ the actions write permission on the repository. RunE: func(cmd *cobra.Command, args []string) error { err := runRepoVerify(args[0], templateName, templatesDir, workflow, ref, tokenRef, steps, timeout) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "repo verify", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "repo verify", Error: err.Error(), Data: errData(err)}) } return err }, diff --git a/internal/cli/root.go b/internal/cli/root.go index b2696c2..697e44b 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -52,7 +52,7 @@ func newRoot() *cobra.Command { jsonHelp(root) root.PersistentFlags().StringVarP(&outputFormat, "output", "o", "human", "output format: human | json") root.PersistentFlags().BoolVar(&strictHostKeys, "strict-host-keys", false, - "always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0)") + "always refuse an unknown host; =false learns its key on first use instead of asking (also BARYOVM_STRICT_HOST_KEYS=1 or 0). A project release never learns or asks, even with =false") root.AddCommand(newVersionCmd(), newVMCmd(), newDeployCmd(), newDoctorCmd(), newUpCmd(), newStackCmd(), newProjectCmd(), newScanCmd(), newGitCmd(), newGhCmd(), newPublishCmd(), newCloudCmd(), newGuardCmd(), newSiteCmd(), newRemoteGroupCmd(), newRepoCmd(), newStatusCmd(), newShipCmd(), newProveCmd()) rejectUnknownSubcommands(root) return root @@ -208,7 +208,7 @@ func Execute() { for _, l := range learned { host, fp, _ := strings.Cut(l, " ") ui.Warnf("learned the host key for %s: %s", host, fp) - ui.Detail("verify it", hostkeys.Keyscan(host)+" | ssh-keygen -lf -") + ui.Detail("check it", "against a fingerprint from the cloud console or ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub on the machine") } }() @@ -249,7 +249,8 @@ func confirmHostKey(host, fingerprint string) bool { ui.Pause(func() { ui.Warnf("%s has no recorded host key", host) ui.Detail("offered", fingerprint) - ui.Detail("verify it", hostkeys.Keyscan(host)+" | ssh-keygen -lf -") + ui.Detail("check it", "against a fingerprint from the cloud console, the provider's serial console, or ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub on the machine") + ui.Detail("not a check", "a keyscan of this address, a man in the middle answers it too") ok = askYesNo(bufio.NewReader(os.Stdin), "Trust this host key? [y/N] ") }) return ok diff --git a/internal/cli/scan.go b/internal/cli/scan.go index d166b95..afc2475 100644 --- a/internal/cli/scan.go +++ b/internal/cli/scan.go @@ -77,7 +77,7 @@ func newScanCmd() *cobra.Command { return nil }) if runErr != nil { - ui.Emit(ui.Result{OK: false, Action: "scan", Error: runErr.Error()}) + ui.Emit(ui.Result{OK: false, Action: "scan", Error: runErr.Error(), Data: errData(runErr)}) return &exitError{code: 1, msg: runErr.Error(), silent: true} } diff --git a/internal/cli/ship.go b/internal/cli/ship.go index dd3827d..a6a3904 100644 --- a/internal/cli/ship.go +++ b/internal/cli/ship.go @@ -276,7 +276,7 @@ func newStackSetPublishCmd() *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: "stack set-publish", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack set-publish", Error: err.Error(), Data: errData(err)}) return err } if clear == (file != "") { diff --git a/internal/cli/stack.go b/internal/cli/stack.go index a8d748f..a76f651 100644 --- a/internal/cli/stack.go +++ b/internal/cli/stack.go @@ -1366,7 +1366,7 @@ func runStackOpDescribed(name, action, step string, fn func(c sshx.Runner, cs co return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } emitOp(name, action, o) diff --git a/internal/cli/stack_backup_pull.go b/internal/cli/stack_backup_pull.go index 0885dfa..0fb8bde 100644 --- a/internal/cli/stack_backup_pull.go +++ b/internal/cli/stack_backup_pull.go @@ -116,7 +116,7 @@ func pullBackupSet(c sshx.Runner, cfg backup.Config, out, dir string) ([]PulledF func runStackBackupPull(name string) error { const action = "stack backup" fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Message: name, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Message: name, Error: err.Error(), Data: errData(err)}) return err } store, err := fleet.Load() diff --git a/internal/cli/stack_discover.go b/internal/cli/stack_discover.go index d71d642..24d170b 100644 --- a/internal/cli/stack_discover.go +++ b/internal/cli/stack_discover.go @@ -80,7 +80,7 @@ func newStackDiscoverCmd() *cobra.Command { return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return &exitError{code: 1, msg: err.Error(), silent: true} } planProjects(projects, store, vm.Name, useSudo, runtimeName) diff --git a/internal/cli/stack_env.go b/internal/cli/stack_env.go index 77a8129..bcf02fe 100644 --- a/internal/cli/stack_env.go +++ b/internal/cli/stack_env.go @@ -159,7 +159,7 @@ func runEnvOp(name, action, step string, fn func(c sshx.Runner, st *fleet.Stack, return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } emitOp(name, action, o) @@ -167,7 +167,7 @@ func runEnvOp(name, action, step string, fn func(c sshx.Runner, st *fleet.Stack, } func emitEnvFailure(action string, err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } diff --git a/internal/cli/stack_release_state.go b/internal/cli/stack_release_state.go index f9f45fb..bcfc17e 100644 --- a/internal/cli/stack_release_state.go +++ b/internal/cli/stack_release_state.go @@ -118,7 +118,7 @@ func refuseState(l releasestate.Loc, s *releasestate.State, name string) error { func runReleaseClear(vm *fleet.VM, l releasestate.Loc, bcfg backup.Config, name string) error { sc, err := dialRelease(vm) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "stack release", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack release", Error: err.Error(), Data: errData(err)}) return err } defer sc.Close() @@ -135,7 +135,7 @@ func runReleaseClear(vm *fleet.VM, l releasestate.Loc, bcfg backup.Config, name err = releasestate.Remove(sc, l) } if err != nil { - ui.Emit(ui.Result{OK: false, Action: "stack release", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack release", Error: err.Error(), Data: errData(err)}) return err } data := map[string]any{"stateFile": l.File, "cleared": prev != nil} diff --git a/internal/cli/stack_rollback.go b/internal/cli/stack_rollback.go index a576682..c2f9af8 100644 --- a/internal/cli/stack_rollback.go +++ b/internal/cli/stack_rollback.go @@ -38,7 +38,7 @@ func newStackRollbackCmd() *cobra.Command { func runStackRollback(name string, list bool) error { const action = "stack rollback" fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } store, err := fleet.Load() diff --git a/internal/cli/stack_tls.go b/internal/cli/stack_tls.go index 614476c..8a1f780 100644 --- a/internal/cli/stack_tls.go +++ b/internal/cli/stack_tls.go @@ -35,7 +35,7 @@ func newStackTLSCmd() *cobra.Command { " baryovm stack tls app --config ./baryovm.release.json", RunE: func(cmd *cobra.Command, args []string) error { fail := func(e error) error { - ui.Emit(ui.Result{OK: false, Action: "stack tls", Error: e.Error()}) + ui.Emit(ui.Result{OK: false, Action: "stack tls", Error: e.Error(), Data: errData(e)}) return e } store, err := fleet.Load() diff --git a/internal/cli/status.go b/internal/cli/status.go index 9e392d2..671e026 100644 --- a/internal/cli/status.go +++ b/internal/cli/status.go @@ -59,7 +59,7 @@ func newStatusCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { const action = "status" fail := func(err error) error { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return &exitError{code: 1, msg: err.Error(), silent: true} } if workers < 1 { diff --git a/internal/cli/up.go b/internal/cli/up.go index ac5c798..42a5945 100644 --- a/internal/cli/up.go +++ b/internal/cli/up.go @@ -44,7 +44,7 @@ func newUpCmd() *cobra.Command { // does not resolve must stop the command with nothing created. env, err := buildEnv(envs, envRefs, true) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error(), Data: errData(err)}) return err } @@ -65,7 +65,7 @@ func newUpCmd() *cobra.Command { return nil } if err != nil { - ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error(), Data: errData(err)}) return err } vm = provisioned @@ -86,7 +86,7 @@ func newUpCmd() *cobra.Command { boot, err = bootstrap.EnsureRuntime(c, runtimeName) return err }); err != nil { - ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error(), Data: errData(err)}) return err } @@ -101,7 +101,7 @@ func newUpCmd() *cobra.Command { rep, err = deploy.Run(c, deploy.Spec{Name: container, Image: image, Ports: ports, Env: env, Pull: pull, Runtime: runtimeName}) return err }); err != nil { - ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "up", Error: err.Error(), Data: errData(err)}) return err } diff --git a/internal/cli/vm.go b/internal/cli/vm.go index 1e7c49d..54f9542 100644 --- a/internal/cli/vm.go +++ b/internal/cli/vm.go @@ -44,9 +44,11 @@ host's default shell is powershell.exe. An unknown host key is asked about on a terminal and refused with no terminal or under -o json. A script or app that has had a person check the key can pass its SHA256 fingerprint with --host-key-fingerprint: a host offering exactly that key -is recorded and the command continues, and any other key is refused. This holds -under --strict-host-keys too, since the flag is the checked key. A host with a -different recorded key is still refused. +is recorded and the command continues, and any other key is refused, also for a +host that already has a recorded key. This holds under --strict-host-keys too, +since the flag is the checked key. It cannot be combined with --os or --remote +forced, which make no connection. A host with a different recorded key is still +refused. `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -59,6 +61,11 @@ different recorded key is still refused. if !strings.HasPrefix(hostKeyFP, "SHA256:") { return fmt.Errorf("--host-key-fingerprint must look like SHA256:..., as ssh-keygen -lf prints it") } + // With a manual OS or a forced key no connection is made, so the fingerprint would never + // be checked. Say so before anything is saved. + if osName != "" || remoteMode == fleet.RemoteForced { + return fmt.Errorf("--host-key-fingerprint needs a connection to check the key, but --os and --remote %s skip it; drop one of them", fleet.RemoteForced) + } defer sshx.TrustFingerprint(hostKeyFP)() } vm := fleet.VM{Name: name, Host: host, Port: port, User: user, KeyPath: key, Provider: "ssh"} @@ -220,7 +227,7 @@ func newVMPingCmd() *cobra.Command { return nil }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "vm ping", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "vm ping", Error: err.Error(), Data: errData(err)}) return err } data := map[string]string{"host": strings.TrimSpace(uname), "docker": strings.TrimSpace(docker)} @@ -266,7 +273,7 @@ func newVMBootstrapCmd() *cobra.Command { return err }) if err != nil { - ui.Emit(ui.Result{OK: false, Action: "vm bootstrap", Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: "vm bootstrap", Error: err.Error(), Data: errData(err)}) return err } msg := vm.Name + " ready: " + rep.DockerVersion @@ -298,7 +305,7 @@ func requireVM(name string) (fleet.VM, error) { return *vm, nil } -// newVMForgetKeyCmd drops a recorded host key so the next connection asks about the new one. +// newVMForgetKeyCmd drops a recorded host key so the next connection treats the new one as unknown. // // This exists because refusing a changed key is only useful if there is a stated way through it. A // rebuilt VM presents a new key legitimately, and without this command the operator's options are @@ -307,8 +314,19 @@ func requireVM(name string) (fleet.VM, error) { func newVMForgetKeyCmd() *cobra.Command { return &cobra.Command{ Use: "forget-key ", - Short: "Forget a VM's recorded SSH host key, so the next connection asks about it again", - Args: cobra.ExactArgs(1), + Short: "Forget a VM's recorded SSH host key, so the next connection treats it as unknown", + Long: strings.TrimSpace(` +Forget the host key BaryoVM recorded for a VM, for when the VM was rebuilt and now has a new one. + +This clears only BaryoVM's own store. If ~/.ssh/known_hosts still holds the old key, the rebuilt +host is refused again as a changed key; remove that line with ssh-keygen -R too. + +After that the host is unknown, and the next connection depends on the mode: on a terminal it asks +whether to trust the new key, with no terminal, under -o json or with --strict-host-keys it is +refused, and with --strict-host-keys=false (or BARYOVM_STRICT_HOST_KEYS=0) it learns the new key +without asking. Check the new fingerprint against the cloud console or the machine itself first. +`), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { target := args[0] @@ -335,7 +353,7 @@ func newVMForgetKeyCmd() *cobra.Command { ui.Emit(ui.Result{ OK: true, Action: "vm forget-key", - Message: fmt.Sprintf("forgot %d host key(s) for %s, the next connection will ask about the new one", n, target), + Message: fmt.Sprintf("forgot %d host key(s) for %s, the next connection treats the new one as unknown (ask, refuse or learn, by mode)", n, target), }) return nil }, diff --git a/internal/cli/vm_add_test.go b/internal/cli/vm_add_test.go index 5e92e0d..c089761 100644 --- a/internal/cli/vm_add_test.go +++ b/internal/cli/vm_add_test.go @@ -13,9 +13,11 @@ import ( "net" "os" "path/filepath" + "strconv" "strings" "testing" + "github.com/spf13/cobra" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" @@ -337,3 +339,84 @@ func TestVMAddUnknownHostJSONErrorCarriesTheOfferedFingerprint(t *testing.T) { t.Errorf("structured fields missing or wrong: %+v", out) } } + +// With --os or a forced key no connection is made, so the fingerprint would never be checked. That is +// refused before anything is saved. +func TestVMAddHostKeyFingerprintIsRefusedWhenNoConnectionIsMade(t *testing.T) { + fp := ssh.FingerprintSHA256(newSigner(t).PublicKey()) + for _, extra := range [][]string{{"--os", "linux"}, {"--remote", "forced"}} { + t.Run(strings.Join(extra, " "), func(t *testing.T) { + t.Setenv("BARYOVM_HOME", t.TempDir()) + t.Setenv("HOME", t.TempDir()) + args := append([]string{"box", "--host", "192.0.2.1", "--key", writeTestKey(t), "--host-key-fingerprint", fp}, extra...) + _, _, err := runCmdE(t, newVMAddCmd(), nil, true, args...) + if err == nil || !strings.Contains(err.Error(), "--host-key-fingerprint needs a connection") { + t.Fatalf("want the no-connection refusal, got %v", err) + } + if store, _ := fleet.Load(); store.Find("box") != nil { + t.Error("the VM must not be saved") + } + }) + } +} + +// A host that already has key B recorded and offers B must still refuse a supplied fingerprint A, with +// both fingerprints, rather than ignore it. +func TestVMAddHostKeyFingerprintIsCheckedAgainstARecordedHost(t *testing.T) { + bvmHome := t.TempDir() + t.Setenv("BARYOVM_HOME", bvmHome) + t.Setenv("HOME", t.TempDir()) + host, port, served := serveOneKey(t) + line := knownhosts.Line([]string{net.JoinHostPort(host, port)}, served.PublicKey()) + if err := os.WriteFile(filepath.Join(bvmHome, "known_hosts"), []byte(line+"\n"), 0o600); err != nil { + t.Fatal(err) + } + wrong := ssh.FingerprintSHA256(newSigner(t).PublicKey()) + _, _, err := runCmdE(t, newVMAddCmd(), nil, true, "box", "--host", host, "--port", port, "--key", writeTestKey(t), + "--host-key-fingerprint", wrong) + if err == nil || !strings.Contains(err.Error(), wrong) || !strings.Contains(err.Error(), ssh.FingerprintSHA256(served.PublicKey())) { + t.Fatalf("want a refusal naming both fingerprints, got %v", err) + } + if store, _ := fleet.Load(); store.Find("box") != nil { + t.Error("the VM must not be saved") + } +} + +// ping and bootstrap write their own failure before returning, and ui.Emit drops every later call, so +// the structured fields have to be in that first one. +func TestVMPingAndBootstrapUnknownHostJSONErrorCarriesTheOfferedFingerprint(t *testing.T) { + for _, c := range []struct { + name string + cmd func() *cobra.Command + }{{"vm ping", newVMPingCmd}, {"vm bootstrap", newVMBootstrapCmd}} { + t.Run(c.name, func(t *testing.T) { + t.Setenv("BARYOVM_HOME", t.TempDir()) + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port, served := serveOneKey(t) + p, _ := strconv.Atoi(port) + store, _ := fleet.Load() + store.Upsert(fleet.VM{Name: "box", Host: host, Port: p, User: "u", KeyPath: writeTestKey(t), Provider: "ssh", OS: "linux"}) + if err := store.Save(); err != nil { + t.Fatal(err) + } + stdout, _, err := runCmdE(t, c.cmd(), nil, true, "box") + if err == nil { + t.Fatal("an unknown host under JSON must be refused") + } + var out struct { + Data struct { + Host string `json:"host"` + Offered string `json:"offered"` + Reason string `json:"reason"` + } `json:"data"` + } + if jerr := json.Unmarshal([]byte(stdout), &out); jerr != nil { + t.Fatalf("not one JSON document (%v): %q", jerr, stdout) + } + if out.Data.Offered != ssh.FingerprintSHA256(served.PublicKey()) || out.Data.Reason == "" || !strings.Contains(out.Data.Host, host) { + t.Errorf("host, offered and reason must be in the result: %+v", out) + } + }) + } +} diff --git a/internal/cli/vm_runner.go b/internal/cli/vm_runner.go index c844ca8..cc411c0 100644 --- a/internal/cli/vm_runner.go +++ b/internal/cli/vm_runner.go @@ -98,7 +98,7 @@ func runRunner(action string, o ghrunner.Options, remove bool) error { err = requireLinux(&vm, action) } if err != nil { - ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error()}) + ui.Emit(ui.Result{OK: false, Action: action, Error: err.Error(), Data: errData(err)}) return err } dial := func() (ghrunner.Remote, error) { return dialChecked(&vm) } diff --git a/internal/hostkeys/hostkeys.go b/internal/hostkeys/hostkeys.go index 05f0b14..46ff7e8 100644 --- a/internal/hostkeys/hostkeys.go +++ b/internal/hostkeys/hostkeys.go @@ -100,9 +100,18 @@ type ErrUnknownHost struct { Expected string } +// verifyNote says where to get a fingerprint worth comparing against. A keyscan of the same address +// is not one: whoever answers the connection answers the scan too. +const verifyNote = "Compare that fingerprint with one from a separate trusted source: the cloud console, the\n" + + "provider's serial console, or ssh-keygen -lf /etc/ssh/ssh_host_*_key.pub run on the machine\n" + + "itself. A keyscan of the same address is not a check, because a man in the middle answers\n" + + "it too.\n" + + "\n" + func (e *ErrUnknownHost) Error() string { record := fmt.Sprintf( - "Check that fingerprint against the machine, then record it before this runs:\n"+ + verifyNote+ + "Once it matches, record what the host offers before this runs:\n"+ "\n"+ " %s >> %s\n", Keyscan(e.Host), e.Store) learnAgain := "\n" + @@ -114,11 +123,13 @@ func (e *ErrUnknownHost) Error() string { "host key for %s not trusted.\n"+ " offered %s\n"+ "\n"+ - "Nothing was recorded. To trust it later, check that fingerprint against the machine and\n"+ - "record it:\n"+ + "Nothing was recorded. To trust it later:\n"+ + "\n"+ + "%s"+ + "Once it matches, record what the host offers:\n"+ "\n"+ " %s >> %s\n", - e.Host, e.Offered, Keyscan(e.Host), e.Store) + e.Host, e.Offered, verifyNote, Keyscan(e.Host), e.Store) case ReasonFingerprint: return fmt.Sprintf( "host key for %s does not match the fingerprint you gave.\n"+ @@ -144,12 +155,14 @@ func (e *ErrUnknownHost) Error() string { "no recorded host key for %s, and a project release never trusts a new host.\n"+ " offered %s\n"+ "\n"+ - "It does not ask and it does not learn. Check that fingerprint against the machine and pin\n"+ - "it as hostKey for that VM in the project file, or record it in known_hosts and pass\n"+ - "--strict-host-keys:\n"+ + "It does not ask and it does not learn.\n"+ + "\n"+ + "%s"+ + "Once it matches, pin it as hostKey for that VM in the project file, or record what the\n"+ + "host offers in known_hosts and pass --strict-host-keys:\n"+ "\n"+ " %s >> %s\n", - e.Host, e.Offered, Keyscan(e.Host), e.Store) + e.Host, e.Offered, verifyNote, Keyscan(e.Host), e.Store) case ReasonJSON: return fmt.Sprintf( "no recorded host key for %s, and output is JSON, so nobody can be asked.\n"+ @@ -210,6 +223,10 @@ type Store struct { // may block for as long as a person takes to read a fingerprint. confirm func(host, fingerprint string) bool + // guard, when set, wraps the whole wait-and-ask section of Ask mode, including the wait for + // another prompt to finish. The caller uses it to set a handshake deadline aside meanwhile. + guard func(fn func()) + // refuseReason is what a Refuse (or an Ask with no hook) reports as the reason. refuseReason Reason @@ -265,6 +282,13 @@ func (s *Store) Confirm(fn func(host, fingerprint string) bool) *Store { return s } +// Guard sets a wrapper that Ask mode runs the whole waiting-and-asking section inside. It is called +// only when an unknown host is about to be asked about, never for a known key. +func (s *Store) Guard(fn func(fn func())) *Store { + s.guard = fn + return s +} + // Callback returns an ssh.HostKeyCallback implementing the Store's mode for unknown hosts. // // learned is called with the fingerprint when a key is recorded for the first time in Learn mode, so @@ -309,7 +333,7 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall // Our own file first. A key we recorded is the one we mean to check against. err := s.check(s.path, hostname, remote, key) if err == nil { - return nil + return s.expectMatches(hostname, offered) } if err := s.refusal(err, s.path, hostname, offered); err != nil { return err @@ -320,6 +344,9 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall if s.extraPath != "" { err := s.check(s.extraPath, hostname, remote, key) if err == nil { + if err := s.expectMatches(hostname, offered); err != nil { + return err + } // Record it in ours too, so the trust does not depend on a file we do not own. return s.add(hostname, key) } @@ -344,18 +371,31 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: s.refuseReason} } // One prompt at a time across every dial in the process. A second dial to the same new host - // waits here, and then finds the first answer already recorded instead of asking again. - askMu.Lock() - defer askMu.Unlock() - if err := s.check(s.path, hostname, remote, key); err == nil { - return nil - } else if err := s.refusal(err, s.path, hostname, offered); err != nil { - return err + // waits here, and then finds the first answer already recorded instead of asking again. The + // guard covers the wait as well as the prompt, so time spent queued behind another prompt is + // not counted against the handshake deadline either. + var res error + locked := func() { + askMu.Lock() + defer askMu.Unlock() + if err := s.check(s.path, hostname, remote, key); err == nil { + return + } else if err := s.refusal(err, s.path, hostname, offered); err != nil { + res = err + return + } + if !s.confirm(hostname, offered) { + res = &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: ReasonDeclined} + return + } + res = s.add(hostname, key) } - if !s.confirm(hostname, offered) { - return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: ReasonDeclined} + if s.guard != nil { + s.guard(locked) + } else { + locked() } - return s.add(hostname, key) + return res } // Learn it. if err := s.add(hostname, key); err != nil { @@ -371,6 +411,16 @@ func (s *Store) Callback(learned func(host, fingerprint string)) ssh.HostKeyCall // refusal turns a failed check into the error to return, or nil when the host is simply absent from // path. Everything that is not "absent" refuses: a file that cannot be read may hold the very key that // would have refused this one, so learning past it fails open. +// expectMatches is the check for a host that already has a recorded key. A fingerprint the caller +// said it verified must still be the key on offer, so a wrong one is refused with both fingerprints +// instead of being ignored because the host happens to be known. +func (s *Store) expectMatches(hostname, offered string) error { + if s.expect != "" && s.expect != offered { + return &ErrUnknownHost{Host: hostname, Offered: offered, Store: s.path, Reason: ReasonFingerprint, Expected: s.expect} + } + return nil +} + func (s *Store) refusal(err error, path, hostname, offered string) error { var re *knownhosts.RevokedError switch { @@ -591,8 +641,13 @@ var ( func (s *Store) add(hostname string, key ssh.PublicKey) error { addMu.Lock() defer addMu.Unlock() + // Only a host with no entry at all may be written. A matching key is already there, and a changed, + // revoked or unreadable entry means someone recorded something else since the decision was made, + // so it is refused the way a changed key always is and nothing is written. if err := s.check(s.path, hostname, &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 22}, key); err == nil { return nil + } else if err := s.refusal(err, s.path, hostname, ssh.FingerprintSHA256(key)); err != nil { + return err } if err := os.MkdirAll(filepath.Dir(s.path), 0o700); err != nil { return fmt.Errorf("create %s: %w", filepath.Dir(s.path), err) diff --git a/internal/hostkeys/hostkeys_test.go b/internal/hostkeys/hostkeys_test.go index dc80a6a..937873e 100644 --- a/internal/hostkeys/hostkeys_test.go +++ b/internal/hostkeys/hostkeys_test.go @@ -536,3 +536,104 @@ func TestConcurrentAskForOneHostPromptsOnceAndRecordsOnce(t *testing.T) { t.Errorf("known_hosts has %d lines, want 1:\n%s", n, b) } } + +// The answer to a prompt can arrive after something else recorded a different key for the host. The +// add must then refuse like any changed key and leave the file alone. +func TestAddAfterTheAnswerRefusesWhenAnotherKeyWasRecordedMeanwhile(t *testing.T) { + dir := t.TempDir() + a, b := newKey(t), newKey(t) + s := New(dir).Mode(Ask) + s.extraPath = "" + s.Confirm(func(string, string) bool { + other := New(dir) + other.extraPath = "" + if err := other.Callback(nil)("192.0.2.10:22", addr(t), b); err != nil { + t.Errorf("record the other key: %v", err) + } + return true + }) + var ce *ErrChanged + if err := s.Callback(nil)("192.0.2.10:22", addr(t), a); !errors.As(err, &ce) { + t.Fatalf("want ErrChanged, got %T: %v", err, err) + } + data, _ := os.ReadFile(filepath.Join(dir, "known_hosts")) + if strings.Count(string(data), "\n") != 1 || strings.Contains(string(data), sshBase64(a)) || !strings.Contains(string(data), sshBase64(b)) { + t.Errorf("only key B may be on file:\n%s", data) + } +} + +// A key that is already recorded is a success that writes nothing. +func TestAddOfAnAlreadyRecordedKeyWritesNothing(t *testing.T) { + s := newStore(t) + key := newKey(t) + if err := s.add("192.0.2.10:22", key); err != nil { + t.Fatal(err) + } + before, _ := os.ReadFile(s.Path()) + if err := s.add("192.0.2.10:22", key); err != nil { + t.Fatalf("a recorded key is a success: %v", err) + } + after, _ := os.ReadFile(s.Path()) + if string(before) != string(after) { + t.Errorf("nothing may be written:\nbefore %s\nafter %s", before, after) + } +} + +// The fingerprint a caller verified must still be the key on offer for a host that is already +// known, or it would be ignored and the caller would think the check happened. +func TestExpectedFingerprintIsCheckedForAnAlreadyRecordedHost(t *testing.T) { + s := newStore(t) + b := newKey(t) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), b); err != nil { + t.Fatal(err) + } + wrong := ssh.FingerprintSHA256(newKey(t)) + s.ExpectFingerprint(wrong) + err := s.Callback(nil)("192.0.2.10:22", addr(t), b) + var ue *ErrUnknownHost + if !errors.As(err, &ue) || ue.Reason != ReasonFingerprint { + t.Fatalf("want ReasonFingerprint, got %T: %v", err, err) + } + if !strings.Contains(err.Error(), wrong) || !strings.Contains(err.Error(), ssh.FingerprintSHA256(b)) { + t.Errorf("both fingerprints must be in the message: %v", err) + } + s.ExpectFingerprint(ssh.FingerprintSHA256(b)) + if err := s.Callback(nil)("192.0.2.10:22", addr(t), b); err != nil { + t.Fatalf("a matching fingerprint for the recorded key is fine: %v", err) + } +} + +// The guard wraps the whole wait-and-ask section, so the lock wait is inside it. +func TestGuardWrapsTheWaitForAnotherPrompt(t *testing.T) { + dir := t.TempDir() + key := newKey(t) + release := make(chan struct{}) + started := make(chan struct{}) + first := New(dir).Mode(Ask).Confirm(func(string, string) bool { + close(started) + <-release + return true + }) + first.extraPath = "" + done := make(chan error, 1) + go func() { done <- first.Callback(nil)("192.0.2.10:22", addr(t), key) }() + <-started + + var inGuard atomic.Bool + second := New(dir).Mode(Ask).Confirm(func(string, string) bool { t.Error("asked a second time"); return false }) + second.extraPath = "" + second.Guard(func(fn func()) { inGuard.Store(true); fn() }) + res := make(chan error, 1) + go func() { res <- second.Callback(nil)("192.0.2.10:22", addr(t), key) }() + time.Sleep(50 * time.Millisecond) + if !inGuard.Load() { + t.Error("the guard must be entered before the wait for the other prompt") + } + close(release) + if err := <-done; err != nil { + t.Fatal(err) + } + if err := <-res; err != nil { + t.Fatal(err) + } +} diff --git a/internal/sshx/askhostkey_test.go b/internal/sshx/askhostkey_test.go index abe84cb..2ea6800 100644 --- a/internal/sshx/askhostkey_test.go +++ b/internal/sshx/askhostkey_test.go @@ -105,6 +105,13 @@ func dialUnknownHost(t *testing.T, host string, port int) (string, error) { home := t.TempDir() t.Setenv("HOME", t.TempDir()) t.Setenv("BARYOVM_HOME", home) + return home, dialWithLoginKey(t, host, port) +} + +// dialWithLoginKey dials with a fresh login key and the home already in the environment, so two +// calls share one known_hosts. +func dialWithLoginKey(t *testing.T, host string, port int) error { + t.Helper() _, priv, err := ed25519.GenerateKey(rand.Reader) if err != nil { t.Fatalf("generate login key: %v", err) @@ -121,7 +128,7 @@ func dialUnknownHost(t *testing.T, host string, port int) (string, error) { if err == nil { c.c.Close() } - return home, err + return err } func recorded(home string) string { @@ -234,6 +241,41 @@ func TestPromptTimeIsNotCountedAgainstTheHandshakeDeadline(t *testing.T) { } } +// A second dial to the same new host waits for the first prompt to finish. That wait is not the +// host stalling either, so it must not run the second dial's handshake deadline out. +func TestWaitingBehindAnotherPromptIsNotCountedAgainstTheHandshakeDeadline(t *testing.T) { + t.Setenv("BARYOVM_STRICT_HOST_KEYS", "") + host, port := serveHostKeys(t, ed25519Signer(t)) + t.Setenv("HOME", t.TempDir()) + t.Setenv("BARYOVM_HOME", t.TempDir()) + asking := make(chan struct{}) + var asked atomic.Int32 + setHostKeyState(t, nil, true, func(string, string) bool { + asked.Add(1) + close(asking) + time.Sleep(900 * time.Millisecond) + return true + }) + old := handshakeTimeout + handshakeTimeout = 300 * time.Millisecond + defer func() { handshakeTimeout = old }() + + first := make(chan error, 1) + go func() { first <- dialWithLoginKey(t, host, port) }() + <-asking + second := make(chan error, 1) + go func() { second <- dialWithLoginKey(t, host, port) }() + if err := <-first; err != nil { + t.Fatalf("first dial: %v", err) + } + if err := <-second; err != nil { + t.Fatalf("the dial that waited behind the prompt must not hit the handshake deadline: %v", err) + } + if asked.Load() != 1 { + t.Errorf("asked %d times, want once", asked.Load()) + } +} + // The deadline still bounds a host that stalls after the prompt is answered. func TestHandshakeDeadlineIsRearmedAfterThePrompt(t *testing.T) { g := &handshakeGuard{} diff --git a/internal/sshx/sshx.go b/internal/sshx/sshx.go index cc62913..aec3904 100644 --- a/internal/sshx/sshx.go +++ b/internal/sshx/sshx.go @@ -152,12 +152,9 @@ func refuseReason() hostkeys.Reason { func newHostKeyStore(guard *handshakeGuard) *hostkeys.Store { store := hostkeys.New(home()).Mode(HostKeyMode()).RefuseReason(refuseReason()) if confirm := ConfirmHostKey; confirm != nil { - // The handshake deadline is for a host that stalls, not for a person reading a fingerprint. - store.Confirm(func(host, fp string) bool { - var ok bool - guard.pause(func() { ok = confirm(host, fp) }) - return ok - }) + // The handshake deadline is for a host that stalls, not for a person reading a fingerprint or + // a dial queued behind another prompt, so the guard covers the whole waiting-and-asking section. + store.Confirm(confirm).Guard(guard.pause) } if expectedFingerprint != "" && forceRefuse == 0 { store.ExpectFingerprint(expectedFingerprint)