Skip to content

fix: give the listener a HOME subdir so orphan reap passes SEC-3 - #188

Merged
ycpss91255 merged 4 commits into
mainfrom
fix/issue-186-reap-home
Nov 29, 2026
Merged

ycpss91255 merged 4 commits into
mainfrom
fix/issue-186-reap-home

Conversation

@ycpss91255

Copy link
Copy Markdown
Member

Summary

Give the listener unit a HOME that is a subdirectory of the runner home (runners/<type>/home, mode 0700), so that the periodic orphan reap passes the SEC-3 guard again.

Motivation

Closes #186. Since #168 the unit set HOME to the runner home itself. The SEC-3 guard in lib/common.sh refuses RUNNER_HOME == HOME, so every orphan reap exited FATAL and stranded containers and work dirs were no longer cleaned.

Changes

  • deploy/scaleset-listener@.service: Environment=HOME=/opt/github-runner-listener/runners/%i/home.
  • lib/listener-deploy.sh:
    • The deploy creates home/ with mode 0700, owned by the service user, for every installed type before it restarts listeners.
    • It refuses a symbolic link at that path.
    • The prefix rewrite covers the new path.
  • The guard in lib/common.sh is unchanged.
  • CHANGELOG Fixed entry.

Red evidence

Stage 1 commit 2f8f88e, run with just test-unit, just test-integration and just lint. Five new or updated assertions failed on the missing behaviour, with no setup errors:

unit        common.bats:47              status != 0: the template HOME still equals RUNNER_HOME
unit        listener_deploy.bats:202    the home dir does not exist
unit        listener_deploy.bats:1087   the template HOME is still the old path
integration deploy_listener.bats:536    the home dir does not exist
integration deploy_listener.bats:741    the installed unit still has the old HOME line

The two new reap regression tests passed already at stage 1, because the guard is intentionally unchanged:

  • reap.sh with HOME=${RUNNER_HOME}/home exits 0 and removes the orphan.
  • reap.sh with HOME == RUNNER_HOME is still refused.

Commits

  • 2f8f88e test
  • 6f38be4 fix
  • 3047dba refactor
  • 6c0de27 review fixes:
    • home dirs exist before other types restart
    • refuse a symlinked home/
    • the reap test reads HOME from the template
    • the dry-run test on an existing tree

Test plan

  • just check
  • just coverage-gate (87.9%)

Notes

After merge, every listener host needs a redeploy, done at an idle gap.

…n reap passes SEC-3 (#186)

Since #168 the unit set HOME to the runner home itself, so the SEC-3 guard
in lib/common.sh (RUNNER_HOME must not equal HOME) aborted every orphan
reap. HOME is now <prefix>/runners/%i/home, which listener_ensure_work_root
creates mode 0700 owned by the service user (no recursive chown). The
renderer's prefix rewrite already covers the new path; lib/common.sh is
unchanged.
…r type paths (#186)

listener_type_paths now owns the <runner_home>/home path alongside LISTENER_RUNNER_HOME and LISTENER_WORK_ROOT, so listener_ensure_work_root no longer recomputes it locally.
- Redeploying one type replaces the shared unit template and restarts the
  other active instances; create or repair each installed sibling's home/
  (mode 0700, service user) before installing the new template, including
  inactive instances, so no listener starts with a missing HOME.
- Refuse a symbolic link at the listener HOME path instead of following it
  and changing the target's mode and owner (listener_ensure_home).
- The reap.sh regression now derives HOME from the unit template and asserts
  that the orphan is removed and its stale work dir pruned; the HOME equal to
  RUNNER_HOME case also asserts nothing is removed.
- Add a dry-run test over an existing runner tree (no work/ or home/ created),
  keeping the original empty-prefix dry-run test.
- CHANGELOG: say the redeploy creates the home dirs before restarting.
@ycpss91255
ycpss91255 enabled auto-merge November 29, 2026 11:34
@ycpss91255
ycpss91255 added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 9c62e74 Nov 29, 2026
9 checks passed
@ycpss91255
ycpss91255 deleted the fix/issue-186-reap-home branch November 29, 2026 11:38
@ycpss91255

Copy link
Copy Markdown
Member Author

中文說明

這個 PR 修正 #186。

問題

  • fix: give the listener a readable HOME so image pulls work under ProtectHome #168 把 listener unit 的 HOME 設成跟 runner home(RUNNER_HOME)同一個路徑。
  • lib/common.sh 有一道安全檢查(SEC-3),會拒絕 RUNNER_HOME 等於 HOME 的設定,所以定期清理殘留 job 的 orphan reap 每次都直接 FATAL 結束。
  • listener 本身照常運作,job 也照常執行,只是殘留的 container 和工作目錄不再被清掉。

修正

  • HOME 改成 runner home 底下的子目錄 runners/<type>/home,權限 0700,擁有者是服務帳號。
  • 部署時,每個 runner type 的這個目錄都會在 listener 重啟之前建好。如果這個路徑是符號連結,部署會拒絕處理。
  • 安全檢查本身沒有改。

Red 證據

  • 上方 PR 內文的 Red evidence 一節列出 5 項斷言失敗。
  • reap 的 2 個回歸測試在 red 階段就已經通過,因為安全檢查刻意保持不變。

合併後

  • 每台 listener 主機都要重新部署,會挑沒有 job 在跑的時候進行。

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.

Orphan reap fails on every listener: unit HOME equals RUNNER_HOME (regression from #168)

1 participant