Skip to content

feat(start-wrt): encrypt backups with the admin password - #4599

Merged
dr-bonez merged 3 commits into
masterfrom
wrt/backup-encryption
Nov 6, 2026
Merged

dr-bonez merged 3 commits into
masterfrom
wrt/backup-encryption

Conversation

@Dominion5254

@Dominion5254 Dominion5254 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

A StartWRT backup was the bare sysupgrade --create-backup tarball: anyone holding the file had /etc/shadow, the router's CA, intermediate and server TLS keys, Wi-Fi PSKs, WireGuard keys and SSH host keys in cleartext.

backup.create now takes the admin password, verifies it against /etc/shadow, and serves one .swbk file. Its plaintext header carries the fields of StartOS's unencrypted-metadata.json: an Argon2id hash of the password and a random 32-byte key wrapped by start-core's wrap_backup_key (Argon2id + AES-256-GCM since #4480, so the wrap is byte-compatible with StartOS rather than a fresh primitive). The archive follows under AES-256-GCM with that key, with the header as associated data.

backup.restore takes the password. The header's hash must carry exactly the Argon2 parameters format 1 writes, and the upload is checked against it before the key is unwrapped, so a wrong password fails with IncorrectPassword before anything is written, flashed or rebooted, and any tampering fails as an invalid archive. A plain .tar.gz from an earlier release still restores without a password. The decrypted archive is staged at mode 600.

The UI prompts for the password when downloading, and when restoring a file that starts with the encrypted header; startwrt-cli prompts on its TTY in the same two places. Docs, in-app help, all five dictionaries, API_CONTRACT.md, the committed bindings and a minor-security fragment (with translations) are updated.

Closes #3662

Verification

  • Unit tests in backup.rs cover round trip, wrong and empty password, tampering at the wrapped key, header end, nonce and tag, truncation at every boundary, an oversized header length, altered Argon2 parameters in the hash with right and wrong password, a newer format version, and legacy pass-through. make start-wrt-test: 833 passed; make start-wrt-format-check clean.
  • Benched on wrt-bench (K1) 2026-11-05 with the first head (85ff21b) deployed: UI and CLI create with wrong and right password; restore with wrong password, tampered file, and after an admin-password change (current password refused, no reboot); right password restores (marker removed, original admin password back); legacy .tar.gz restore; smoke pass twice. Create takes about 6.7 s in the UI, a wrong-password restore about 2.5 s.
  • Re-benched on wrt-bench (K1) after the Argon2 parameter pin. The previous head, given a router-made backup with the hash's m raised to 4294967295, aborted the daemon on a wrong-password restore (memory allocation of 4398046507008 bytes failed); procd respawned it, but its policy gives up after five such exits in an hour. With the pin, that file and copies with m=3145728 or t=4294967295 are refused as an invalid archive with right and wrong passwords, and the daemon keeps running. The router's own backup still gets IncorrectPassword with a wrong password and restores with the right one; smoke passes after the reboot.

A StartWRT backup was the bare `sysupgrade --create-backup` tarball, so
anyone holding the file had /etc/shadow, the router's CA, intermediate and
server TLS keys, Wi-Fi PSKs, WireGuard keys and SSH host keys in cleartext.

backup.create now takes the admin password, verifies it against
/etc/shadow, and serves one .swbk file. Its plaintext header carries the
fields of StartOS's unencrypted-metadata.json: an Argon2id hash of the
password and a random 32-byte key wrapped by start-core's wrap_backup_key
(Argon2id + AES-256-GCM since #4480, so the wrap is byte-compatible with
StartOS rather than a fresh primitive). The archive follows under
AES-256-GCM with that key, the header as associated data.

backup.restore takes the password. The upload is checked against the
header's hash before the key is unwrapped, so a wrong password fails with
IncorrectPassword before anything is written, flashed or rebooted, and any
tampering fails as an invalid archive. A plain .tar.gz from an earlier
release still restores without a password. The decrypted archive is
staged at mode 600.

The UI prompts for the password when downloading, and when restoring a
file that starts with the encrypted header; startwrt-cli prompts on its
TTY in the same two places.

Closes #3662

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 85ff21b, including the shared key-wrap implementation, create/restore callers, legacy restore path, UI prompts, and bindings. git merge-tree --write-tree origin/master <head> succeeds.

P2 — Bound the header's Argon2 parameters before password verification (projects/start-wrt/backend/ctrl/src/backup.rs, decrypt, call to argon2::verify_encoded). The uploaded passwordHash is unauthenticated at this point, and rust-argon2 derives its allocation size and iteration count directly from its encoded m/t/p fields. Changing m=65536 to a very large valid value in an otherwise ordinary backup can exhaust router memory before either password rejection or GCM authentication. The 4096-byte header limit does not bound those costs. This also affects a restore with an incorrect password; it does not require successfully decrypting or applying an untrusted tarball. The existing legacy path's trust requirements do not require allowing this new pre-authentication allocation.

The proposal accepts the exact Argon2 configuration emitted by format 1 before calling the verifier, deriving that check from the same rfc9106_low_mem() configuration used for creation. It preserves the file format and clean IncorrectPassword result for genuine backups, and adds regression cases for altered parameters with correct and incorrect passwords. Please verify the adopted change; no builds or tests were run during review. CI is currently queued.

Proposed changes: 85ff21b...proposal/4599

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

…sword

A backup's passwordHash is unauthenticated when restore verifies it, and
rust-argon2 sizes its allocation and iteration count from the encoded
m/t/p fields, so an altered header could exhaust router memory before the
password or GCM tag is checked. Accept only the configuration format 1
writes, derived from the same rfc9106_low_mem() preset used to create it.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 6d85aae. The Argon2 finding is resolved: format-1 parameters are checked before the verifier can allocate memory or perform work selected by the uploaded header. The adopted proposal preserves genuine backups and wrong-password errors. The revised head merges cleanly with origin/master; no further correctness findings.

Brief

StartWRT's Settings → Backup page and CLI now require the current admin password to download an encrypted .swbk backup. Restore requests the password used when that file was created, even after an admin-password change. Password or integrity failures occur before the decrypted archive is staged or applied. Successful restore retains the existing configuration-replacement and reboot behavior. Earlier plaintext .tar.gz backups remain accepted without a password; those existing files remain unencrypted.

Contract and storage: BackupCreateParams adds a required password string to backup.create; BackupRestoreParams adds an optional password to backup.restore. The UI, CLI, live/mock facades, and generated bindings change together; external create callers must supply the new argument. The self-contained format-1 file contains a plaintext JSON header with passwordHash and wrappedKey, followed by the archive's nonce, ciphertext, and authentication tag. Unsupported format versions are rejected. Existing backups require no migration.

Approach and tradeoffs: Creation reuses the admin-password check and StartOS's Argon2id/AES-256-GCM key wrapping. A fresh random 32-byte key encrypts the archive with AES-256-GCM, authenticating the header too. A single-file envelope replaces StartOS's mounted-target sidecar arrangement because this backup is downloaded as one immutable file. The separate password hash preserves the requested clean password-error distinction but requires a second Argon2 derivation on successful operations. Format 1 pins each derivation to 64 MiB, three iterations, and one lane; the header is capped at 4096 bytes. Decrypted staging now uses the shared mode-600 atomic writer. Legacy archives retain their existing trusted-admin restore semantics rather than gaining authenticated integrity retroactively.

Implementation diff: +378 / −49 lines in 15 files (excludes lockfiles, tests, docs including in-app help prose, release notes, and changelog).

Verification evidence: The author records 833 passing StartWRT tests and a clean scoped formatting check. Recorded K1 bench runs cover UI/CLI creation, wrong passwords, password changes, tampering, successful encrypted and legacy restores, and post-reboot smoke checks. The author also reproduced the original oversized-Argon2 daemon abort and confirmed the revised implementation rejects oversized memory/time costs with either password while keeping the daemon alive. The initial head's measured create time was about 6.7 seconds; wrong-password restore was about 2.5 seconds.

For the required screenshots, I built the revised-head demo UI and captured its actual create/restore prompts with Chromium and the mock backend; this was not an additional backend or end-to-end restore test. The build succeeded with bundle-size and CommonJS warnings. Screenshots follow in a screenshot-only comment. CI remains pending, including Prettier, changelog/version validation, StartWRT's riscv64 build, and the cross-product build jobs; this approval does not establish their success.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white

Copy link
Copy Markdown
Member

Create-backup prompt requiring the current admin password; revised-head demo UI with mock backend.

Encrypted-backup restore prompt requesting the admin password in effect when the backup was created; revised-head demo UI with mock backend.

helix-white added a commit that referenced this pull request Nov 5, 2026
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previously approved head, 6d85aae, now conflicts with master at 2dcbc75. git merge-tree --write-tree confirms one conflicting file: projects/start-wrt/backend/ctrl/Cargo.toml.

The merge proposal preserves this PR's zeroize production dependency alongside master's new [dev-dependencies] section for ed25519-dalek, and retains master's removal of obsolete production signing dependencies. Cargo.lock merges automatically and still contains all three backup dependencies (base32, rust-argon2, and zeroize). The proposal contains only base integration and that conflict resolution; backup behavior is unchanged.

The author should merge current master with this resolution (or merge the proposal), then re-request my review. This reviewer session has not pushed to the PR branch. The proposal itself merges cleanly with the recorded current master. Scoped manifest/lockfile whitespace checks pass; an unscoped check also flags trailing whitespace inherited from master in generated projects/start-os/man/start-container.1:3, which this proposal leaves unchanged. No builds or tests were run in this review session.

Proposed changes: 6d85aae...proposal/4599

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@helix-white

helix-white commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Resolved by the author’s master integration in 2d38586. The manifest retains both changes, the integrated tree matches the published resolution proposal, and git merge-tree confirms it merges cleanly with current master. Re-review approved; the previous author-integration blocker is cleared.

Repeated implementer-style repair notifications reaching this review-only session are independently tracked in https://github.com/Start9Labs/helix-startos-internal/issues/71.

# Conflicts:
#	projects/start-wrt/backend/ctrl/Cargo.toml

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 2d38586. The author’s merge preserves the proposed manifest resolution: zeroize remains a production dependency and master’s ed25519-dalek dev-dependency section is retained. The complete tree matches the published resolution proposal integrated with current master, and git merge-tree --write-tree origin/master HEAD succeeds. Both earlier findings are resolved; no further correctness findings.

Brief

StartWRT’s Settings → Backup page and CLI now require the current admin password to download an encrypted .swbk file. Restore requires the password used when that backup was created, even after a password change. Password and authentication failures happen before plaintext staging or restore. Successful restore retains the existing configuration replacement and reboot behavior. Earlier plaintext .tar.gz backups remain accepted without a password and remain unencrypted.

Contract and format: BackupCreateParams adds a required password string to backup.create; BackupRestoreParams adds an optional password to backup.restore. UI, CLI, live/mock API implementations, and generated bindings are coordinated; external create callers must supply the new argument. The versioned file contains a plaintext JSON header with passwordHash and wrappedKey, followed by an AES-256-GCM encrypted archive. Existing backups require no migration; unsupported format versions are rejected.

Reuse and tradeoffs: The implementation reuses admin-password verification, StartOS’s Argon2id/AES-256-GCM key wrapping, and the shared mode-600 atomic writer for decrypted staging. A fresh random 32-byte key encrypts each archive and authenticates its header. The self-contained envelope replaces StartOS’s mounted-target sidecar arrangement for a downloaded, immutable file. Retaining a separate password hash gives the requested clean password error but requires two Argon2 derivations on successful operations. Format 1 pins the verifier to the creation configuration—64 MiB, three iterations, one lane—before accepting uploaded parameters; headers are capped at 4096 bytes. Legacy restores retain their trusted-admin semantics without retroactive integrity protection.

Implementation diff: +378 / −49 lines in 15 files (excludes lockfiles, tests, docs including in-app help prose, release notes, and changelog).

Verification: The author’s pre-merge evidence records 833 passing StartWRT tests, clean scoped formatting, and K1 bench coverage of UI/CLI creation, wrong passwords, password changes, tampering, encrypted/legacy restores, and post-reboot smoke checks. It also reproduces the original oversized-Argon2 daemon abort and confirms rejection after the fix while the daemon remains alive. Initial-head measurements were about 6.7 seconds for creation and 2.5 seconds for wrong-password restore. Those results do not establish post-merge execution: current-head CI is queued, including Prettier, changelog/version validation, StartWRT’s riscv64 build, and cross-product builds. No builds or tests were run for this re-review.

The earlier screenshot-only demo build succeeded with bundle-size/CommonJS warnings. These screenshots remain representative because the StartWRT web tree is unchanged by the merge; they show the actual UI with mock data, not end-to-end backend verification.

Create-backup prompt requiring the current admin password.

Encrypted-backup restore prompt requesting the password in effect at creation.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@Dominion5254
Dominion5254 force-pushed the wrt/backup-encryption branch from 2d38586 to 4021579 Compare November 6, 2026 20:57
@dr-bonez
dr-bonez merged commit c0ce44d into master Nov 6, 2026
32 of 33 checks passed
@dr-bonez
dr-bonez deleted the wrt/backup-encryption branch November 6, 2026 21:59
JesseMarkowitz added a commit to JesseMarkowitz/start-technologies that referenced this pull request Nov 7, 2026
Brings in StartWRT 1.4.0 work from master, among it K1 Ethernet flow
offload (Start9Labs#4460), the Ethernet profile-change confirmation (Start9Labs#4473),
encrypted backups (Start9Labs#4599), mDNS kept off the WAN (Start9Labs#4468), the UCI
section-separator fix (Start9Labs#4540) and builder-generated bindings (Start9Labs#4624).

Conflicts:

- web dictionaries: both sides numbered new strings from 599. Upstream
  keeps 599-603; this branch's five strings move to 604-608.
- docs/src/ethernet.md: Start9Labs#4473 dropped "There is no separate save step";
  the Managed-switch sentence now follows the plain dropdown step.

routes/ethernet/table.ts merged without a conflict but would not build:
Start9Labs#4473's dialog read a `fullname` parameter this branch renamed to
`value`. Resolved by giving each change a single confirmation. Choosing
Managed switch shows the trust warning; any other choice shows Start9Labs#4473's
reconnect dialog. Either one carries the published-port deletion notice,
and the separate confirmTrunk dialog is gone, so a trunk change no longer
asks twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RJjVAznSZM3aNW6cCLJ6Xi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StartWRT: encrypt backups with the admin password (StartOS-style flow)

3 participants