Skip to content

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

Closed

Description

@groupsky

Problem

With the units from contrib/systemd/ of v0.1.0, the first pullgate run NAME always fails:

level=ERROR msg=failed instance=NAME step=run result="" err="fix /var/spool/pullgate/NAME/outbox: chmod /var/spool/pullgate/NAME/outbox: operation not permitted"

and then the listener logs read the outbox ... permission denied, because the outbox is left as root:pullgate 0700.

Cause: pullgate-run@.service sets RestrictSUIDSGID=yes. That seccomp filter refuses every chmod that sets the setuid or setgid bit, with EPERM. But spool.Ensure (internal/spool/spool.go, the outbox entry) sets the outbox to 0770 | os.ModeSetgid. The tests and the end-to-end test do not run under the unit, so CI did not see it.

Found on 2026-11-16, in the first real install of v0.1.0.

Workaround: a drop-in for the run unit with RestrictSUIDSGID=no.

Proposal

Decide which side changes, and write why in DESIGN.md section 4:

  • a) The outbox does not need setgid: root writes each outbox file with group pullgate itself (an explicit fchown), so RestrictSUIDSGID=yes can stay. Preferred: it keeps the unit tighter.
  • b) Keep setgid, and remove RestrictSUIDSGID=yes from pullgate-run@.service, with a comment that says why. Update the systemd-analyze security table in the README.

Done when

  • A fresh install with the units of contrib/systemd/, with no drop-in, makes the spool and finishes the first pullgate run NAME with no error.
  • A CI test runs pullgate run under the real pullgate-run@.service sandbox (for example systemd-run --wait -p ... with the unit's settings, or a container with systemd), so a unit setting that breaks a run fails CI.
  • The listener reads the outbox after that first run (a test covers the modes and owners of DESIGN.md section 4).
  • The README says what to do on a host that has the v0.1.0 workaround drop-in (remove it after the update).

Activity

  1. groupsky commented on Nov 16, 2026

    @groupsky
    ContributorAuthor

    More on the cause (2026-11-16): RestrictSUIDSGID=no alone is not enough. Then the chmod succeeds, but the kernel clears the setgid bit without an error: root is not in the group pullgate, and pullgate-run@.service has no CAP_FSETID in its CapabilityBoundingSet. The outbox ends as drwxrwx--- root pullgate, so Send writes each message as root:root 0640 and the listener cannot read it (open .../outbox/...: permission denied), and no question reaches Telegram. The run itself logs result=asked, so nothing shows the failure on the root side.

    The workaround needs both lines in the drop-in: RestrictSUIDSGID=no and CapabilityBoundingSet=CAP_FSETID.

    This makes option a) (no setgid; root sets the group of each outbox file with an explicit fchown to the listener group) more attractive: it needs neither. Add to "Done when": a message that root writes to the outbox can be read by the listener user under the real units (a test that checks the group of the written file, not only the directory mode).

  2. groupsky commented on Nov 16, 2026

    @groupsky
    ContributorAuthor

    Fixed in #21 (squash commit 1236625). I chose option a): no setgid bit, and RestrictSUIDSGID=yes stays in pullgate-run@.service. Root gives each outbox file the listener's group itself, with fchown on the open file before the rename. The reason is in DESIGN.md section 4 ("No setgid bit on the outbox").

    Evidence for each box:

    • A fresh install with the units of contrib/systemd/, with no drop-in, makes the spool and finishes the first pullgate run NAME with no error. The new CI job "first run under the units" (test/units/first-run.sh) does exactly this on the CI runner, as root, following the README. On the merged code it logs msg=asked ... result=asked, with no ERROR or WARN line.
    • A CI test runs pullgate run under the real pullgate-run@.service sandbox. The same job starts the real unit with systemctl start pullgate-run@config-repo.service. The first commit of fix: the first run works under RestrictSUIDSGID=yes (no setgid outbox) #21 had only this test, and it failed on the old code with the error of this issue: fix /var/spool/pullgate/config-repo/outbox: chmod /var/spool/pullgate/config-repo/outbox: operation not permitted.
    • The listener reads the outbox after that first run (a test covers the modes and owners of DESIGN.md section 4). The CI job checks the owners and modes of section 4 (root pullgate 770 for the outbox, root pullgate 640 for its file, and the others). Then it starts the real pullgate-listen.service against a fake Telegram on 127.0.0.1, and checks that the listener sent the question (msg="question sent") and removed the file from the outbox. Go tests: TestOwnersAndModes and TestSendDeny in internal/spool/spool_test.go.
    • The README says what to do on a host that has the v0.1.0 workaround drop-in. README, "The systemd units" → "Update from 0.1.0": find the drop-in with systemctl cat, remove RestrictSUIDSGID=no, systemctl daemon-reload. The next run takes the setgid bit off the outbox by itself.
    • The fix is in a released version. Waits for the next release, which also holds fix: pullgate --version fails with "flag provided but not defined" #14 and fix: pullgate-listen.service has no [Install] section, so enable fails and the listener does not start after a reboot #20.

    Both reviews ran (the security reviewer and a correctness review). What they found and what was fixed is in the description of #21.

  3. groupsky commented on Nov 16, 2026

    @groupsky
    ContributorAuthor

    Reopened: GitHub closed this on the merge, but the last "Done when" box (the fix is in a released version) is still open. The release PR #18 waits for the owner's OK. Close this after the release.

  4. groupsky commented on Nov 16, 2026

    @groupsky
    ContributorAuthor

    All boxes are met, so I close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: highDo this first

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions