Skip to content

Restrict config file permissions to root and pimonitor group#35

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-20-1uz37w
Jul 13, 2026
Merged

Restrict config file permissions to root and pimonitor group#35
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-20-1uz37w

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

packaging/install.sh installed /etc/pimonitor/config.yaml with mode 644, so any local user or compromised service on the Pi could read the api_key secret, defeating the point of enabling API authentication.

This PR tightens the installer:

  • Fresh install: the config is written with install -m 640 -o root -g pimonitor (the pimonitor group already exists at that point — the useradd --system block runs earlier in the script).
  • /etc/pimonitor is set to 750 root:pimonitor after mkdir -p.
  • Upgrade (config already exists): permissions are tightened to 640 root:pimonitor without touching the file's content.
  • Documented the restricted permissions in README.md and in the api_key comment block of packaging/pimonitor.example.yaml (including the chown/chmod commands for manually copied configs).

The service (running as user pimonitor per the systemd unit) can still read the config via group membership.

Verified by exercising the exact fresh-install and upgrade code paths as root in a container: fresh install yields 640 root pimonitor / dir 750 root pimonitor; re-running on an existing loose-permission config tightens it to the same without altering content; user pimonitor can read the file while nobody cannot. bash -n packaging/install.sh passes. Not verified on physical Pi hardware / a live systemd install, but the changed code paths were exercised verbatim.

Related Issue

Closes #20

Checklist

  • Tests added/updated for the change (go test ./... passes locally) — no Go code changed; the shell-script paths were exercised manually as described above, full Go suite passes
  • go vet ./... and golangci-lint run are clean
  • Documentation updated if this changes the REST API (docs/API.md),
    configuration (README.md, packaging/pimonitor.example.yaml), or
    installation/packaging (packaging/install.sh, systemd units)
  • No breaking change to /api/v1/... response shapes, or a new API
    version was introduced instead

install.sh previously wrote /etc/pimonitor/config.yaml with mode 644,
so any local user or compromised service could read the api_key secret,
defeating the point of enabling API authentication.

Install the config as 640 root:pimonitor and the directory as 750
root:pimonitor, and tighten the permissions of a pre-existing config on
upgrade without touching its content. The service (running as user
pimonitor) can still read the file via group membership.

Closes #20

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ErDJ9Yxv9pHYHjF2a26Go6
@LarsLaskowski
LarsLaskowski merged commit 9be885d into main Jul 13, 2026
3 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-20-1uz37w branch July 13, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: install.sh writes /etc/pimonitor/config.yaml world-readable although it may contain the API key

2 participants