feat(ops): read-only device audit + devices registry template (#15) #21
No reviewers
Labels
No labels
agent:felinus
agent:human
agent:maximus
merge-train
bounced
merge-train
now
merge-train
queued
merge-train
riding
priority:p0
priority:p1
priority:p2
priority:p3
status:blocked
status:needs-review
status:wip
type:chore
type:docs
type:feat
type:fix
type:perf
type:refactor
type:test
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/matrix-bridge!21
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/device-audit-15"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements most of #15: a read-only device audit plus a registry template. Does not close #15 — two acceptance items are deliberately left for Bear (see "Deviations").
What
scripts/audit_devices.py(single-file uv script, PEP 723 deps: pyyaml): loads a registry, callsGET /_synapse/admin/v2/users/<mxid>/devicesonce per registered user (plus optional extrausers:), and reports(mxid, device_id), so a reused id on another account is also unexpected),last_seenolder than--idle-days, default 30, per-devicemax_idle_daysoverride; never-seen counts as idle).Output follows the shape in the issue; summary line
N registered + M missing + U unexpected + I idle = OK | ACTION REQUIRED.0OK,1ACTION REQUIRED,2registry/usage/API error (so cron/alerts can distinguish "fleet drifted" from "audit broken").SYNAPSE_ADMIN_TOKEN,--token-envto rename), never printed; HTTP errors report only the status code; non-https homeservers rejected (excepthttp://localhost).devices.example.yaml: template with the<PLACEHOLDER>names already used in the docs. The audit refuses to run while any placeholder is left in.docs/bridge-client-setup.md: rotation procedure gains step 8 "Update the device registry"; new section "Auditing the device fleet" (usage, read-only contract, where the registry lives, scheduling)..gitignore:/devices.yaml+ Python caches.scripts/ruff.toml: line length 100 / py312.Deviations from the issue (decisions for Bear)
devices.yamlnot committed. This repo is public and was explicitly scrubbed of deployment identifiers (6534ffe,7f042e5:<MAXIMUS_MXID>,<MAXIMUS_NAS_DEVICE>, …). Committing the fleet's mxids/device ids would undo that, so only the template is here and the real file is gitignored. Suggested home: the private deployment repo next to the bridge (nas-docker-compose / wherever the NAS bridge config lives). The current ids appear in the #15 issue text (mba/nas/rpi5 for Maximus as of 2026-05-27) but I could not confirm they are still current (rotations since), and Felinus/jmz/kitty ids are not in the repo or docs — fill them from a first run (it lists every live device as unexpected until registered).msc3861.admin_token, god-mode) on the scheduling host; where that token may live is Bear's call. A weekly systemd timer on the NAS that posts to the bridge room on exit 1/2 is the suggested shape.checkjob runs on the rpi5 runner with only a Rust toolchain; adding a Python job is a separate small change if wanted.Security: output escaping
Strings from the Synapse API (device id, display name) and from the registry (mxid, host, role) are never printed raw. A newline,
\r, ANSI escape or bidi override in a device id could otherwise fake report lines, e.g. a forged--- summary --- ... OK. Free text is rendered viarepr(). Device ids outside[A-Za-z0-9._=-]and malformed mxids are prefixed(suspicious id)and shown escaped. Non-string display names are dropped.last_seen_tsis only used if it is an int, and the IP is not printed. Tests cover hostile ids and names (\n,\r,\x1b[2J, a faked─── summary ───\n OK): the report keeps the same line count, has no unprintable characters, and its only summary line is the real last one.Tests
uv run --no-project --with pytest --with pyyaml python -m pytest scripts/tests→ 38 passed (mocked Synapse: output-injection cases, clean fleet, unexpected/missing/idle, idle boundary and per-device override, never-seen, extra users, cross-account id reuse, rendering, registry validation incl. placeholders/duplicates, exit codes, missing token, HTTP 401 path never leaks the token, GET + URL-encoded mxid + bearer header, plain-http rejected).ruff check+ruff format --checkclean;mypy --strictclean. CLI smoke:uv run scripts/audit_devices.py --config devices.example.yaml→ exit 2 "placeholder value left in registry". Not run against live Synapse (no admin token used overnight).Refs #15. No merge, no deploy.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XMf4EKNjKMd6bwCpS7K4jU