Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ 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. 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

- **A silent SSH host no longer hangs the CLI.** The handshake has its own 30 second deadline (the
Expand Down
11 changes: 9 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name-or-host>` 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
Expand Down
55 changes: 44 additions & 11 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ 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...
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]
```

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
Expand All @@ -63,8 +76,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 <name-or-host>` 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

Expand All @@ -73,7 +90,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
Expand All @@ -85,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 "$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:
Expand All @@ -95,10 +115,15 @@ 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.
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

Expand Down Expand Up @@ -154,6 +179,14 @@ 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. 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
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.
Expand Down Expand Up @@ -1167,16 +1200,16 @@ 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 <host>`, then check the
fingerprint). It is public, so it is committed.
- `hostKey` is the VM's public host key (`ssh-keyscan -t ed25519 <host>` 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
`-o json` report lists every stack as `released`, `failed` or `skipped`, so a partial release reads as
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
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_cloud_firebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ baryovm cloud firebase <firebase arguments> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_cloud_gcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ baryovm cloud gcloud <gcloud arguments> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_cloud_wrangler.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ baryovm cloud wrangler <wrangler arguments> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_doctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_gh.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ baryovm gh <gh arguments> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_git.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ baryovm git <git arguments> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard_check_commit-msg.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ baryovm guard check commit-msg <file> [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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard_check_pre-commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard_check_pre-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ baryovm guard check pre-push <remote> <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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_guard_install-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/baryovm_project_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). A project release never learns or asks, even with =false
```

### SEE ALSO
Expand Down
Loading
Loading