Repository navigation
Add a browser setup wizard, env-var config and a redesigned admin dashboard - #176
virtitnerd wants to merge 36 commits into
Conversation
bdaf287 to
3f6a54a
Compare
|
A status note, in case it helps with review: this PR is still mergeable and clean against main after today's commits. Other work now builds on it:
It is a large PR (23 commits). If that makes it hard to review, I can split it into smaller ones, for example the env-var config, the setup wizard and the dashboard, each on its own. Tell me which order suits you and I will do it, or point me at anything you want changed first. |
3329199 to
354375e
Compare
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: needs rebase
This PR has merge conflicts with current main, so it hasn't been reviewed yet. Please rebase it onto main, resolve the conflicts, and mark it ready for review again. It will then go through the automated review.
I've converted it to draft until then.
This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.
e7e9cec to
addd286
Compare
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: changes requested
This is the first full review. The PR is rebased on current main (c836f4f) with no conflicts, and the full suite passes (884 passed).
Blocking
- An existing install can be taken over by an unauthenticated request, which also corrupts its config.
diagnose_configreturnsmissing_adminfor anyValueErrorin[admin](config.py:471-474), including a section that exists but fails validation, for example asession_secretshorter than 24 characters.run_serverthen serves the wizard over plain HTTP on0.0.0.0(server.py:2347,:2315).complete_admin_sectionappends a second[admin]table (management_app.py:157-186,:620). I confirmed this with a probe. A cross-originContent-Type: text/plainPOST to/admin/api/setupreturned 200 and set the attacker's password, and the file then held two[admin]tables. The config was theninvalidand the server would not start. Fix: returnmissing_adminonly when there is no[admin]table at all. Write the new config through a temp file,os.replaceand a lock. - The wizard has no CSRF protection.
submit_setupparses the body whatever its Content-Type is and never checksOrigin(management_app.py:607-614). Any web page a LAN user opens can therefore configure the server on first run. Fix: requireapplication/json(which forces a preflight), reject a foreignOrigin/Host, and ideally require a one-time setup token that is printed to the container log.
Should fix
- Unmatched requests are no longer written to
decompiled_http.jsonl(server.py:1528). Real app endpoints go through the catchall (endpoint_rules.py:660), for example/api/v1/activity/latest, which the app calls inRR_API/jadx/com.roborock.smart/4.64.06_APKPure/resources/assets/plugin/features/feature_login_page/feature_login_page/index.android.bundle:1344. That log is how we find routes that newer models (B01 / Q7 / Q10, mowers) need and we haven't implemented. Keep writing them, and filter them out in the Activity reader instead. - The admin page and the wizard (which collects passwords and the Cloudflare token) load Materialize JS from a CDN with no
integrityattribute (web_theme.py:18-21). That page can also readadmin_session_secret(server.py:1695, pre-existing). Add SRI or bundle the assets locally.5.write_config_from_envwritesconfig.tomlin place with the default umask (env_config.py:599). Use the same temp-file +os.replaceaspatch_config_from_env(:576-579), with mode 0600. - The MITM sync stores Roborock cloud tokens unredacted, and only the default rotation limits apply to that log, not
[logging](server.py:457,log_retention.py:152). Registermitm_activity_jsonl_paththere too.
Claims
- Activity panel is redacted by default: confirmed (
activity_log.py:1-17). Raw output needsROBOROCK_SERVER_ACTIVITY_RAW. - Dashboard has no XSS: confirmed for the changed code. Device strings are written with
textContent, andinnerHTMLis only used to clear elements (standalone_admin.py). - New admin routes require auth: confirmed (
/admin/api/activitycalls_require_admin). The bootstrap wizard has none, by design (items 1 and 2). - Environment variables only change their own keys, and a mounted
/app/config.tomlis left alone: confirmed (env_config.py:534-584,container_entrypoint.py:39-41). - "The wizard can't generate
trusted_proxies": confirmed, though the env vars can (env_config.py:461). - Tested live against a real vacuum: unverifiable. Behaviour on B01 and mower devices is also unverifiable, but the PR does not touch protocol code.
Other PRs: this PR conflicts with #255 and #252 in config.py and server.py. It merges cleanly with #261 and #250. #214 is built on the commits from before the rebase, so it will need a rebase too, with a new conflict in docs/installation.md.
I've converted this PR to draft while these are addressed. Mark it ready for review again once they're fixed and it will go through another review.
This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.
|
Thanks for the review. I checked each finding against the code first and all six were right. Pushed as six commits on top of the rebased branch (49ad0c5):
Every item has tests. The full suite is 893 passed and 3 failed: two Windows-only I'll sort out the conflicts with #255 and #252 in |
|
Hey @virtitnerd can you handle the conflicts? Sorry you have to do this again. Lots of PRS I have been bouncing between |
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed (nits)
Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.
Needs a rebase. This conflicts with current main in one hunk of src/roborock_local_server/server.py (around line 80). #292 removed _REGION_COUNTRY_CODE from main, and this branch adds MITM_ACTIVITY_SYNC_PATH next to it. Keep the new constant, drop _REGION_COUNTRY_CODE as main does, and make sure nothing on the branch still references it. Everything else merges cleanly.
Since the last review (addd286 → 49ad0c5)
All six earlier items are fixed. I checked each one against the code and probed the wizard directly:
- Takeover of an existing install: fixed (
config.py:476,management_app.py:189-202). An[admin]table that fails validation now givesinvalid_admin, so/adminshows the "needs attention" page and setup returns 409, even with a valid token. The file is left byte-for-byte unchanged.complete_admin_sectionre-checks for[admin]under the lock and writes through a 0600 temp file andos.replace. Two back-to-back admin-only submissions gave 200 and then 409, leaving a single[admin]table. The full wizard still refuses to overwrite an existing file (configure.py:418-422). - CSRF: fixed (
management_app.py:690-697). Atext/plainPOST gets 415, a foreignOrigingets 403, and a missing or wrongX-Setup-Tokengets 403. The token is per-process (token_urlsafe(24)), compared withcompare_digest, and only logged to the container log (server.py:2328). Because of the token, the same-Host check doesn't need to stop DNS rebinding on its own. - Unmatched requests: fixed. They are written to
decompiled_http.jsonlagain (server.py:1532-1534), andread_recent_activitydropsroute == "catchall"before formatting (activity_log.py:169-173). - SRI: fixed (
web_theme.py:21-22). Both sha384 values match the pinned cdnjs 1.0.0 files. Their sha512 digests also match the values cdnjs publishes. write_config_from_env: fixed (env_config.py:587-599). It writes a 0600 temp file and renames it.- MITM log retention: fixed (
server.py:457-465). The log now follows[logging].
Nothing in the delta changes what the server returns to the app or the vacuums. Catchall requests are only logged again; their responses are unchanged. Device compatibility remains unverified for the new dashboard paths, but they don't touch protocol code.
Nits (non-blocking)
management_app.py:197-202: ifos.replacefails, for example on aconfig.tomlthat is bind-mounted as a single file, theOSErrorisn't caught bysubmit_setup(:726only catchesValueError/FileExistsError). The browser then just shows "Invalid response". CatchOSErrorand return a clear 409/500 JSON message that says the file can't be replaced.env_config.py:597-599: the bind-mount fallback writes in place with the default umask, so the file loses the 0600 mode there. Consideros.chmod(path, 0o600)after the fallback write, or a comment saying it's intentionally left alone.- The wizard is plain HTTP, so on first setup the token and admin password cross the LAN unencrypted. That's by design. One sentence in
docs/installation.mdsaying so would help.
Other PRs: #214 contains an older copy of this branch. When it is rebased onto this one, it must take this version of server.py around line 1528 (its copy still skips catchall entries) and the setup-token changes in management_app.py and server.py. Otherwise it would undo items 2 and 3.
Full suite on 49ad0c5: 896 passed.
This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.
decompiled_http.jsonl / decompiled_mqtt.jsonl have no rotation and can carry sensitive data (auth headers, onboarding localKey/passwords in HTTP bodies, fully-decrypted device RPC payloads in MQTT entries). This tails both files (they grow unbounded, so a full read is out) and returns metadata-only summaries by default - method/path/topic/RPC method name, sizes, timestamps, never raw headers/bodies/payloads. ROBOROCK_SERVER_ACTIVITY_RAW=1 switches to complete, unredacted entries - an explicit deployment-time opt-in, matching how rethink exposes its own traffic view, rather than a per-view UI toggle. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 9c9943d)
Adds ReleaseSupervisor._activity_payload() and GET /admin/api/activity (auth-gated like every other admin route, ?limit= clamped to 1-500), plus an Activity section on the dashboard following the existing 2s-polling pattern - there's no real-time push mechanism in this app today (websockets/SSE), so this matches how every other panel already refreshes. Note: a full-suite run flagged test_admin_onboarding_start_is_blocked_when_new_connections_disabled as failing once (256 passed/1 failed), but it passes reliably alone, with just this file plus test_activity_log.py, and on a clean rerun of the entire suite (257/257). AdminSessionManager (security.py) is stateless and per-instance with no shared/global auth state for this change to touch, so this looks like a pre-existing flaky/timing- sensitive test that more total tests nudged into failing once, not a regression from this change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit dd825d2)
New /internal/protocol/mitm-activity, gated by the same admin.session_secret-based auth as the existing /internal/protocol/user-data sync - no new trust mechanism. Appends posted entries to a new mitm_activity.jsonl (AppPaths.mitm_activity_jsonl_path). The sync request's own body is now also redacted in the regular HTTP activity log, the same way the existing user-data sync already is, since it can carry real Roborock account tokens. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 5181022)
read_recent_activity() gains an optional mitm_jsonl_path, tailed and merged alongside the existing HTTP/MQTT sources with the same redact-by-default / ROBOROCK_SERVER_ACTIVITY_RAW behavior. Dashboard gets a distinct color/label for [MITM] entries. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit c9647f4)
Off by default. When enabled (and a sync secret is configured), each redirected Roborock-domain request/response is posted to the server's new mitm-activity endpoint, so the official app's traffic is visible in the admin dashboard's Activity panel without a separate viewer. Sync failures are caught and logged, never allowed to interrupt the actual MITM redirect/rewrite - this is telemetry, not part of the redirect's own correctness. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 6318cc1)
Same recipe as rethink's own management panel: Materialize CSS/JS and Google Fonts loaded from CDN (no build step - this project has none and isn't taking one on for this), plus one small theme stylesheet on top for branding, dark mode (prefers-color-scheme), and a couple of Materialize defaults that need overriding (fixed-height nav, focus rings suppressed by its own box-shadow reset, etc). Served from one route (register_theme_routes) so both the Setup Wizard and the real dashboard pull the same theme, not two. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 47f9a54)
Real Materialize form fields/radios/select/buttons instead of hand- built fieldset/input markup, using the same nav/theme as the real dashboard. All required page text and element IDs the wizard's own JS/tests depend on are unchanged; only markup and styling moved. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 6b1b00b)
Login page and dashboard now use the same Materialize theme as the Setup Wizard - real form fields, buttons, nav, cards - instead of raw inline-styled markup. Every element ID the existing JS (refresh(), renderAuth(), renderActivity(), etc.) depends on is unchanged; only markup/styling moved. Dynamically-created cards (vacuum summary, session list, activity feed) now use theme CSS variables instead of hardcoded light-mode hex colors, so they stay readable in dark mode. Also fixes a real XSS-shaped bug introduced partway through this redesign and caught before commit: the activity feed's per-entry badge was briefly built via innerHTML with server-reported traffic fields (method/path/topic/host) interpolated directly in - the same bug class already found and fixed in rethink's own device table. Rewritten with DOM APIs (createElement/textContent) only; no interpolated HTML anywhere in this file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit c045dca)
STACK_FQDN alone is enough to trigger has_env_config(), but the default tls_mode (cloudflare_acme) then requires more vars that may not be set - previously this ValueError propagated raw out of write_config_from_env, uncaught, crashing the container outright and crash-looping it forever under restart:unless-stopped. This only shows up once both env-var config generation (feat/env-var-config) and the Setup Wizard (feat/setup-wizard) exist together, so it's fixed here on their combined branch rather than either alone. Now the failure is caught and falls through into the Setup Wizard at /admin, same as if no env vars had been set at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 6a6760d)
… set Directly motivated by the fallback above: if env-var generation fails partway through, whatever the operator *did* set (stack_fqdn, ports, broker mode/host, tls_mode, base domain, email, acme_server) shouldn't have to be retyped in the browser. Reveals the matching conditional sections (external broker host, provided-cert vs Cloudflare fields, Actalis fields) based on the prefilled values too, rather than always defaulting to embedded/cloudflare_acme/zerossl regardless of intent. Deliberately never pre-fills secrets (cloudflare_token, admin_password, protocol_login_pin) - those are exactly what the wizard exists to collect fresh in the browser rather than a compose file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit eb7659d)
With several vacuums the page stacked every card for every device into one long feed. It now has a row of device chips plus a Server chip. Picking a vacuum shows only its facts, onboarding state and traffic; the global cards (Cloud Import, New Connections, Health) live under Server. Selection is kept in the URL hash. /admin/api/activity takes ?device=<duid or did> and keeps entries that name the vacuum's did, duid or MQTT user as a whole path or topic segment, reading a deeper tail so a quiet vacuum isn't pushed out by a noisy one. The raw view no longer prints the local key. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit a4328d7)
…fig.toml At each start every ROBOROCK_SERVER_* variable that is set is compared with the matching key and only a key that differs is changed. Other keys, comments, sections added by hand and the admin login stay as written. Replaces the generated-from-env marker, which rewrote the whole file. Adds the camera relay (TURN) variables. Invalid values are reported and skipped; a mounted config is read-only, so the log says what the variables would have changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same issue and fix as the HA add-on: DEFAULT_CLOUDFLARE_TOKEN_PATH/ DEFAULT_ACME_EAB_KID_PATH/DEFAULT_ACME_EAB_HMAC_KEY_PATH defaulted to /run/secrets/*, which isn't backed by any persisted volume in this flow's documented deployment (only /data is). Any container recreation wipes the plaintext secret this module wrote there at boot, while config.toml (under /data) survives and keeps pointing at the now-missing file - the next boot fails trying to read a Cloudflare token or EAB credential that no longer exists. Also fixes docs/installation.md's "Environment Variables Only" section, which told users to keep a read-only ./secrets:/run/secrets bind mount - that was already broken advice, since a read-only mount can't be written to by the plaintext-token code path. That mount is no longer needed at all now that secrets live under /data. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ROBOROCK_SERVER_OTA_ENABLE_INSTALL already updates the key in an existing config.toml; a freshly generated file now carries the [ota] section too, off unless the variable turns it on. The installation guide lists the variable with the other commonly set ones. The section is read by the firmware install change (Python-roborock#255); without that change the key is ignored. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patch_config_from_env read the file with read_text() and wrote it with write_text(), so newline translation turned a CRLF file into LF on Linux (the Docker image) while Windows happened to put the CRLF back. Read the bytes as they are and write with newline="", so plan_config_patch's own line-ending detection decides. Fixes the failing test_windows_line_endings_and_array_values_survive on the Linux CI runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49ad0c5 to
47ec235
Compare
…d the setup token in the CA tests
…ll requests and filters them in the Activity reader
A failed os.replace (for example a bind-mounted config.toml) raised an uncaught OSError, so the browser only showed 'Invalid response'. Return a JSON error that says what to do instead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks @Lash-L. All three nits are fixed, each in its own commit (the branch tip is c51aabf, still on top of
The full suite passes apart from the Windows-only |
Problem
Setting up the server meant running the
configureCLI and hand-editingconfig.toml, which doesn't fit Docker or Home Assistant users who configure everything through the environment. The/adminpage was a bare status view with no setup flow, no activity view and no multi-vacuum layout.Changes
These are one design: the dashboard needs the wizard, and the wizard needs the env-var path to be useful in a container.
ROBOROCK_SERVER_*variables generateconfig.tomlin the container entrypoint. The[admin]group is optional, and a partial config can be completed later in the wizard.config.toml, the server falls into a browser wizard at/admininstead of exiting. It pre-fills from any env vars already set and can carry an external broker host.mitm_redirect.py --activity-synccan also push MITM-captured traffic into it.Out of scope
listener_mode,advertised_*_portortrusted_proxiesyet. That's called out inreverse_proxy.md.Tested
pytest: 487 passed. The 2 failures are CRLF fixture assertions intest_activity_log.pyon Windows.local_tlsmode with SWAG's certificate mapped into the container.New tests cover env-var parsing, the entrypoint, config diagnosis, the management app and wizard, the activity log, the device view and the MITM sync.