Skip to content

fix: the first run works under RestrictSUIDSGID=yes (no setgid outbox) - #21

Merged
groupsky merged 4 commits into
mainfrom
fix/run-unit-setgid-outbox
Nov 16, 2026
Merged

groupsky merged 4 commits into
mainfrom
fix/run-unit-setgid-outbox

Conversation

@groupsky

@groupsky groupsky commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #19.

What was wrong

pullgate-run@.service sets RestrictSUIDSGID=yes. That filter refuses every chmod that sets a setuid or setgid bit. spool.Ensure made the outbox 0770 | setgid, so the first pullgate run under the unit failed with chmod .../outbox: operation not permitted. Then the listener could not read the outbox.

The fix (option a of the issue)

  • The outbox is root:listener 0770 with no setgid bit.
  • spool.Send(gid, m) gives each outbox file the listener's group itself: fchown(-1, gid) and fchmod 0640 on the open file, before the rename. The listener never sees a file with another group. Every caller passes e.Owners.ListenerGID, which root takes from its own user lookup.
  • Ensure takes the setgid bit off an outbox made by 0.1.0. Removing a bit is allowed under RestrictSUIDSGID=yes.
  • RestrictSUIDSGID=yes stays in the run unit. The reason is in DESIGN.md section 4.

Tests

  • New CI job "first run under the units" (test/units/first-run.sh): it runs as root on the throwaway CI runner. It installs the binary and the units of contrib/systemd/ as the README says, with no drop-in. It starts pullgate-run@config-repo.service, checks the owners and modes of DESIGN.md section 4, then starts pullgate-listen.service against a fake Telegram on 127.0.0.1 (test/units/faketg.py). It checks that the listener sent the question and removed it from the outbox. It fails on any level=ERROR or level=WARN line.
    • The first commit of this PR had only the test. On the old code it failed with the exact error of the issue: fix /var/spool/pullgate/config-repo/outbox: chmod /var/spool/pullgate/config-repo/outbox: operation not permitted, and the listener logged open .../outbox: permission denied.
  • TestOwnersAndModes (internal/spool): no setgid bit, the modes of section 4, an old setgid outbox gets fixed, and an outbox file has the listener's group and mode 0640.
  • TestSendDeny: no group is refused; a group the chown cannot give is an error, and no file stays.

Docs

  • DESIGN.md section 4 (table, "No setgid bit on the outbox", the CAP_CHOWN need), section 14 (the new test).
  • THREAT-MODEL.md T2.
  • README: "Update from 0.1.0": remove the RestrictSUIDSGID=no drop-in after the update.
  • The comments of pullgate-run@.service and pullgate-apply@.service: keep CAP_CHOWN.
  • CI: ShellCheck also checks test/units/first-run.sh.

Reviews

The security reviewer (.claude/agents/security-reviewer.md) and a correctness review ran on the diff. Fixed:

  • the log check of the run could never fail (the unit's invocation ID was empty after success): it now reads the unit's journal after journalctl --sync and needs the asked line;
  • a start race with the fake Telegram: the script waits for its port;
  • docs and unit comments now say that CAP_CHOWN is needed;
  • ShellCheck runs on the new script;
  • the group test logs when the test user has only one group.

Not done: a CI test of pullgate-apply@.service. The apply unit sets no capability limit, and the same Send path is covered by the run unit test. The level= check was found to work: the failing run showed level=ERROR text lines.

🤖 Generated with Claude Code

groupsky and others added 4 commits November 16, 2026 14:32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Root gives each outbox file the listener's group with fchown on the open
file. Ensure makes the outbox 0770 with no setgid bit, and takes the bit
off an outbox made by 0.1.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

fix: the first run fails: RestrictSUIDSGID=yes in pullgate-run@.service blocks the setgid outbox

1 participant