Repository navigation
Conversation
agent-kit-startup
left a comment
There was a problem hiding this comment.
Thanks for this, the dry-run default and the integer check on --days look good. Deletion is limited to the direct children of actions-runner-*/_work and builds, find -type d does not follow symlinks, and a symlinked base yields nothing. Two things I'd fix before merging:
1. The deletion loop is unsafe with unusual directory names.
IFS='
'
for entry in $(find "$base" -mindepth 1 -maxdepth 1 -type d -mtime +"$DAYS" ...); doThe unquoted command substitution is split on newlines and also goes through pathname expansion. A directory named x<newline>/some/other/path becomes two words, and the second is passed to rm -rf. A directory named * expands to the contents of the current directory. Jobs run as the same user and can create directories under _work, so with --apply this can remove paths outside the work dirs. It is not a privilege escalation, but it is a wrong delete. Suggested shape:
export APPLY
find "$base" -mindepth 1 -maxdepth 1 -type d -mtime +"$DAYS" -exec sh -c '
for e; do
s=$(du -sh "$e" 2>/dev/null | cut -f1)
if [ "$APPLY" -eq 1 ]; then rm -rf -- "$e" && echo "removed ${s:-0} $e"
else echo "would remove ${s:-0} $e"; fi
done' sh {} +(Alternatively set -f and skip any entry containing a newline.) A test with a newline and a * in a directory name would cover it.
2. The active-job check runs only once.
check_no_job_running runs before the loop, and no lock is held while deleting. If a runner picks up a job during the prune, its workspace can be removed under it. Holding runner.lock / gh-runners.lock for the duration, or re-checking before each rm, would close that window.
Minor:
-mtimeon a top-level directory such as_work/<repo>only changes when its direct entries change, so a repo built daily can still look older than N days and be pruned. It is harmless (it gets cloned again), but the README wording "older than N days" overstates the guarantee.- Without a proot rootfs, the defaults target
/root/actions-runner-*/_workand/root/buildson the host. Probably intended, but worth a line indocs/hosts.md.
|
Two corrections to my examples in point 1, the conclusion stands:
Also: the issue asked for scripts/clean-workdirs.sh (hyphen, like the other scripts), and the snippet I suggested drops the "nothing older than N days" line your test checks, so keep that count. |
|
Thanks for the detailed review! I've pushed commit aa97567 to switch the pruning loop to find ... -exec (avoiding word-splitting and pathname expansion on unusual directory names) and re-check active runner pidfiles and locks before each removal while keeping the "nothing older than N days" output. |
Fixes #29
Adds
scripts/clean_workdirs.shto prune old GitHub Actions (actions-runner-*/_work) and GitLab (builds) runner work directories safely:--applyto remove directories.--days NorCLEAN_WORKDIRS_DAYS(default7days).board/tests/test_clean_workdirs.pyand updatesREADME.mdanddocs/hosts.md.