Skip to content

[master] core: services: commander: Keep .ssh keys on settings reset - #4122

Open
joaoantoniocardoso wants to merge 1 commit into
bluerobotics:masterfrom
joaoantoniocardoso:fix/reset-settings-preserve-ssh-keys
Open

[master] core: services: commander: Keep .ssh keys on settings reset#4122
joaoantoniocardoso wants to merge 1 commit into
bluerobotics:masterfrom
joaoantoniocardoso:fix/reset-settings-preserve-ssh-keys

Conversation

@joaoantoniocardoso

@joaoantoniocardoso joaoantoniocardoso commented Aug 11, 2026

Copy link
Copy Markdown
Member

Fixes #3440 for master

Master counterpart of #4120. Master already has #3677, so the only missing piece here is the .ssh entry.

Problem

Reset Settings deletes everything under /root/.config, including /root/.config/.ssh — the keypair commander uses to run commands on the host. Once it is gone, run_command() falls back to sshpass with the default password (SSH_USER/SSH_PASSWORD), so every commander-backed feature breaks on any vehicle where the default password was changed, and a reboot does not recover it.

The reset already protects ardupilot-manager, bag-of-holding, bootstrap and kraken for the same reason (#3677); .ssh was simply never added to that list.

Changes

  • Add /root/.config/.ssh to the reset_settings ignore list.

Preserving is used instead of regenerating so the key is never absent, and the private key never has to be copied through /tmp. The public half in /home/pi/.ssh/authorized_keys was never removed by reset anyway, so deleting the private key only ever broke auth while leaving a stale entry behind.

Complements #3898, which adds the recovery path (setup_ssh() on startup) — this PR stops the key from being destroyed in the first place.

Test plan

The ignore mechanism is already covered by test_delete_everything and test_delete_everything_single_file, so this change adds no tests.

Behaviour was verified on a Raspberry Pi running 1.4.4-beta.15 via #4120, whose reset_settings is identical to this one after the backport:

  • Before the fix: POST /commander/v1.0/settings/reset leaves /root/.config/.ssh empty, and the next host command logs Failed to run command with SSH key ... trying with sshpass
  • After the fix: the keypair survives with the same fingerprint, and host commands run with ssh -i /root/.config/.ssh/id_rsa (no fallback)
  • Reset still resets: a marker file under /root/.config/beacon is deleted, while markers under the ignored directories survive
  • ./.hooks/pre-push passes

Reset Settings wiped /root/.config/.ssh, which holds the keypair used to
run commands on the host. Without it every host command falls back to
sshpass with the default password, breaking every commander feature on
vehicles where that password was changed.
@github-actions

Copy link
Copy Markdown

Automated PR Review

0. Summary

  • Verdict: LGTM :shipit:

Adds /root/.config/.ssh to the reset_settings ignore list in core/services/commander/main.py so the commander's SSH keypair (used by run_command() to reach the host) survives a settings reset instead of forcing the sshpass fallback with the default password. The new entry is inserted in the existing alphabetically-ordered list (. sorts before letters) alongside ardupilot-manager, bag-of-holding, bootstrap, and kraken, and is accompanied by a two-line "why" comment. Ignore behaviour is already covered by test_delete_everything / test_delete_everything_single_file in core/libs/commonwealth/src/commonwealth/utils/tests/test_general.py, so no new tests are needed.

No further comments, nice job 👍

Generated by PR Review Bot. This is advisory, a human reviewer must still approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Restart Settings is removing the default ssh keys

1 participant