Skip to content

install: harden the systemd unit the installer writes - #237

Merged
TusanHomichi merged 1 commit into
mainfrom
issue-125-harden-systemd-unit
Nov 20, 2026
Merged

TusanHomichi merged 1 commit into
mainfrom
issue-125-harden-systemd-unit

Conversation

@TusanHomichi

Copy link
Copy Markdown
Member

Primary Issue

Closes #125

Problem And Outcome

install/consolebook.service scored 6.8 MEDIUM on systemd-analyze security, leaving capabilities, kernel logs, clock/hostname, namespaces, realtime scheduling, W+X memory, exotic address families, and unrestricted syscalls open even though the service runs as an unprivileged static Rust binary serving HTTP over TCP and writing only to its configured SQLite data and backup-copy directories.

Hardening install/consolebook.service brings the exposure score down to 1.3 OK (well below the 4.0 target).

Changes

  • install/consolebook.service
    • Added defense-in-depth [Service] directives matched to Consolebook's runtime needs (SQLite WAL, TCP HTTP listener, journal logging, paths.conf drop-in for data and backup-copy directories):
      • CapabilityBoundingSet=
      • ProtectClock=true, ProtectHostname=true, ProtectKernelLogs=true
      • ProtectProc=invisible
      • RestrictNamespaces=true, RestrictRealtime=true
      • MemoryDenyWriteExecute=true
      • RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
      • SystemCallArchitectures=native
      • SystemCallFilter=@system-service and SystemCallFilter=~@privileged @resources
    • Kept UMask=0027 deliberately to match ADR 0023's 0750 consolebook:consolebook directories (no other permissions; group-readable only if an operator grants group access to a backup/restore reader).
    • Left out PrivateUsers=true and ProcSubset=pid so network backup shares and container/older systemd environments do not break while still reaching 1.3 OK.
  • crates/consolebook-server/tests/install_command.rs
    • Added the_systemd_unit_carries_its_hardening_directives asserting every required [Service] hardening directive in install/consolebook.service, with negative controls verifying that dropping, commenting out, or moving a directive outside [Service] fails the check.

Verification

systemd-analyze security (systemd 260, --offline=yes)

  • Before (main fb86d20): 6.8 MEDIUM
  • After (d8ba19d): 1.3 OK

Red-first check (before editing install/consolebook.service)

Running cargo test -p consolebook-server --test install_command failed as expected, listing all 12 missing hardening directives. After editing install/consolebook.service, install_command passed 3/3 (including all per-directive negative controls).

Local proof receipt — partial (steps 1–6 passed; step 7 hit 2 unrelated host-load timeouts)

  • Candidate: d8ba19d5dc78a1bac50dd2e9de4fdb6b23046a66 tree 7180c3f075d811a8e84b8ae0f16084bdd1130733; unchanged during run: true
  • Scope: local (local run; hosted pr-gate and release systemd install runs are separate evidence)
  • Command: cargo xtask proof in /data/dev/src/consolebook
  • Started 2026-11-20T16:02:11Z, finished 2026-11-20T16:25:28Z, 1396.2s
  • Host: Linux-6.18.64-x86_64; euid 1001; can bypass file permissions: false (from CapEff); host load average ~18–28 on 12 CPUs during step 7
  • Browser: playwright-managed Chrome for Testing 158.0.8127.18
  • Browser suite: 68 expected, 2 unexpected (e2e/drafts.spec.ts:113 60s timeout as tracked in test(e2e): drafts.spec.ts daily-evaluation flow exceeds its 60s timeout under host load #199, and e2e/installation-export.spec.ts:74 5s sign-in visibility timeout under CPU starvation; this PR touches no Rust server or web code).
# Command Status Exit Seconds Log sha256 (prefix)
1 scripts/check-guidance-names.sh passed 0 0.101 01.log 2b172a8e66c87574
2 (cd web && npm ci && npm run check && npm run build) passed 0 48.699 02.log 3ae53a1d1bfcf5da
3 cargo fmt --check passed 0 1.554 03.log e3b0c44298fc1c14
4 cargo clippy --workspace --all-targets -- -D warnings passed 0 22.957 04.log 1a3a0558ce717aad
5 cargo test --workspace passed 0 658.653 05.log 9260e04339310674
6 cargo build -p consolebook-server passed 0 0.796 06.log 7b89f9d8b45896e6
7 (cd web && npx playwright install chromium && npm run e2e) failed 1 663.363 07.log b9775f89bf376db7

Hosted CI (fmt-clippy-test, build-x86_64, build-aarch64 real systemd install/backup/copy/doctor jobs, and check / check) must pass before merge.

Review And Merge Notes

  • Correction ladder rung: Rung 1 (Codebase) + Rung 2 (Mechanical enforcement) — hardened the shipped unit itself and guarded every directive with negative controls in tests/install_command.rs.
  • All fixtures are invented; no schema migrations or application code changed.

Add defense-in-depth sandboxing directives to install/consolebook.service (CapabilityBoundingSet=, ProtectClock, ProtectHostname, ProtectKernelLogs, ProtectProc=invisible, RestrictNamespaces, RestrictRealtime, MemoryDenyWriteExecute, RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX, SystemCallArchitectures=native, SystemCallFilter=@System-service / ~@PRIVILEGED @resources), keeping UMask=0027 aligned with ADR 0023's 0750 directories. Lowers systemd-analyze security exposure from 6.8 MEDIUM to 1.3 OK.

Closes #125
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T16:28:37.423381Z d8ba19d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fieldmouseworks-steward fieldmouseworks-steward Bot added the waiting: review Its reviewers, or a Claude job judging it, are looking at this head label Nov 20, 2026
@TusanHomichi
TusanHomichi merged commit 61119ff into main Nov 20, 2026
23 of 24 checks passed
@TusanHomichi
TusanHomichi deleted the issue-125-harden-systemd-unit branch November 20, 2026 17:03
@fieldmouseworks-steward fieldmouseworks-steward Bot removed the waiting: review Its reviewers, or a Claude job judging it, are looking at this head label Nov 20, 2026
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.

install: harden the systemd unit the installer writes

1 participant