fix(backend): re-apply persisted SSH password on boot after OTA slot swap#158
Merged
Conversation
…swap config.json (ssh_pass + ssh_pass_hash) is /data-persisted and survives an A/B OTA slot swap, but the OS-level /etc/shadow entry is rootfs-local — baked fresh into each image and not carried across slots. After an OTA the fresh slot's shadow held the build-time password while config.json still remembered the operator's real one, locking SSH until a manual UI reset on every update (confirmed on real Rock 5B+ hardware). Add ensureSshPasswordSynced(), wired into the boot sequence via guardNonCritical() right before the getSshStatus() probe. It mirrors image-building-pipeline's ceralive-ssh-firstboot.sh::ensure_host_keys() restore pattern: compare the persisted ssh_pass_hash against the live /etc/shadow hash and, on a mismatch, RE-APPLY the EXISTING persisted ssh_pass via the same stdin-only passwd path resetSshPassword() uses — never generating a new password and never rewriting config. Boot-fail-soft (never throws), a no-op under mocks, when ssh_pass is unset, or when the OS already matches. resetSshPassword() and startStopSsh()'s generate-if-missing branch are untouched.
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
ensureSshPasswordSynced()to the backend and wires it into the boot sequence(
main.ts, viaguardNonCritical("ssh-password-sync", …)) immediately before theboot
getSshStatus()probe. On boot it compares the persistedssh_pass_hash(from
config.json) against the live/etc/shadowhash and, on a mismatch,re-applies the existing persisted
ssh_passthrough the same stdin-onlypasswdpath
resetSshPassword()already uses.Touches four files, backend-only:
apps/backend/src/modules/system/ssh.ts,apps/backend/src/main.ts, a newapps/backend/src/tests/ssh-password-sync.test.ts,and the backend
AGENTS.md.Why
An OTA A/B slot swap silently reverts the operator's SSH password to the
factory-baked default — confirmed on real Rock 5B+ hardware.
config.json(
ssh_pass+ssh_pass_hash) is/data-persisted and survives the swap, but theOS-level
/etc/shadowentry is rootfs-local: baked fresh into each image and notcarried across slots. After an OTA the freshly-activated slot holds the build-time
password while
config.jsonstill remembers the operator's real one, locking SSHuntil a manual UI reset — on every update. Nothing re-applied it.
This mirrors the host-key restore the image already does in
ceralive-ssh-firstboot.sh::ensure_host_keys(): compare the persisted identityagainst the live one and re-apply (never regenerate) on a mismatch.
How to verify
cd apps/backend && bun test src/tests/ssh-password-sync.test.ts— coverssame-slot no-op, fresh-slot re-apply (proves the existing plaintext is applied,
not a new one), unset-password no-op, boot-safety (never throws on
passwdorshadow-read failure), and the dev-mock seam.
cd apps/backend && bun test— full backend suite green (1936 pass / 0 fail).cd apps/backend && bunx tsc --noEmitandbunx biome check— both clean.Risks
Low, and contained to a boot-time reconciliation:
ensureSshPasswordSynced()never throws (wrapped inguardNonCritical); a sync failure logs + broadcasts a notification and returns —it can never brick boot.
ssh_passis unset(nothing persisted yet), and on the same-slot boot where the OS already matches.
generates a new one or writes config — only the OS
/etc/shadowentry catches up.resetSshPassword()andstartStopSsh()'s generate-if-missing branch are untouched.readShadow/applyPassword) is injected viaSshPasswordSyncDeps, so the test suite drives it without a realpasswd//etc/shadow.