Fix PermissionError reading config_secrets.json in web interface - #416
Conversation
ledmatrix.service (main display) runs as root while ledmatrix-web.service runs as the non-root install user (install_web_service.sh). Both config_manager.py and config_manager_atomic.py only chmod'd config_secrets.json to 0o640 without ever fixing its group, so a file written by the root service ended up group-owned by root and unreadable by the web user, crashing the settings page with a raw PermissionError. Add ensure_shared_group_ownership() to chgrp secrets/config files (best effort, root-only) to the project directory's owning group whenever they are created or saved, and self-heal existing files on load. Also make get_raw_file_content() tolerate an unreadable secrets file the same way load_config() already does, degrading to empty secrets instead of a 500.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughShared-group permission helpers now resolve the project group and correct file ownership when running as root. Configuration loading, creation, regular saves, and atomic saves invoke the helper; unreadable secrets files now degrade to an empty object. ChangesShared group permissions
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ConfigManager
participant permission_utils
participant Filesystem
ConfigManager->>permission_utils: Resolve shared group GID
permission_utils->>Filesystem: Read project-root group
ConfigManager->>permission_utils: Ensure file group ownership
permission_utils->>Filesystem: Apply chown when required
ConfigManager->>Filesystem: Read or atomically save configuration
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
ledmatrix.service(main display) runs asroot, whileledmatrix-web.serviceruns as the non-root install user (seeinstall_web_service.sh, which templatesUser=${ACTUAL_USER}).config/config_secrets.jsonwas only everchmod'd to0o640on write, neverchgrp'd, so when the root-run display service created/rewrote the file it ended up group-owned byroot— unreadable by the non-root web user. That produced the reportedPermissionError: [Errno 13] Permission denied: 'config/config_secrets.json'and a raw 500 traceback out ofpages_v3.py's settings page (get_raw_file_content('secrets')).Type of change
Related issues
N/A
Changes
src/common/permission_utils.py: addedget_shared_group_gid()(resolves the project root directory's owning gid — stable across reinstalls) andensure_shared_group_ownership()(best-effortchgrpto that gid, root-only, no-op otherwise).src/config_manager.py: calls the new helper after every secrets/config write (save_raw_file_content,_create_config_from_template) and self-heals stale group ownership on everyload_config()/get_raw_file_content()call, so a previously-broken install repairs itself the next time the root-run service touches the file.src/config_manager_atomic.py: samechgrpfix in_atomic_move, the atomic save path used by the settings UI.src/config_manager.py:get_raw_file_content('secrets')now toleratesPermissionErrorthe same wayload_config()already does — degrades to{}with a warning log instead of raisingConfigError/500, so a still-unreadable file (e.g. before the root service next runs the self-heal) no longer crashes the settings page.Test plan
pytest) — n/a subset touching these files has no existing coverage; verified withpython3 -m py_compileon the changed modules (sandbox lackspytest/PIL)Documentation
Plugin compatibility
Checklist
Notes for reviewer
This is a best-effort self-heal, not a hard guarantee: it only fixes ownership when the root-run process (
ledmatrix.service) touches the file (root canchownto any group; the non-root web process cannot). If a user's install never restarts/reloads the root service, an already-brokenconfig_secrets.jsonstays unreadable to the web UI until it does — but the settings page will no longer crash, it'll just show empty secrets in the meantime.Generated by Claude Code
Summary by CodeRabbit