fix(hermes_cli): heal root-owned logs/gateways on every stage2 boot

Without restartable log/run chown, warm volumes that keep a hermes-owned
HERMES_HOME but root-owned logs/gateways would again deny hermes mkdir.
Add a non-recursive stage2 parent heal and cover the poisoned-parent reboot path.
This commit is contained in:
Fangliquan
2026-07-26 10:46:55 +08:00
committed by kshitij
parent 6898e5a355
commit ad84330ad0
3 changed files with 68 additions and 2 deletions

View File

@@ -287,6 +287,21 @@ if [ -d "$HERMES_HOME/cron" ]; then
chown_hermes_tree "$HERMES_HOME/cron"
fi
# Always ensure logs/gateways is hermes-owned (#45258). Formerly healed by
# restartable gateway log/run chown — removed due to symlink TOCTOU
# (CWE-59/367). The targeted data-volume chown above only runs when the
# top-level $HERMES_HOME is mis-owned, so a warm volume with hermes-owned
# HERMES_HOME but root-owned logs/gateways would otherwise leave
# s6-setuidgid hermes mkdir failing with Permission denied. Non-recursive:
# profile leaf dirs are each created/owned by their own log/run as hermes.
if [ -d "$HERMES_HOME/logs/gateways" ]; then
if refuse_symlinked_path "chown" "$HERMES_HOME/logs/gateways"; then
:
else
chown hermes:hermes "$HERMES_HOME/logs/gateways" 2>/dev/null || true
fi
fi
# Always reset ownership of pairing data on every boot, same docker-exec/
# root-write reason as profiles/ and cron/. `docker exec <container>
# hermes pairing approve …` defaults to uid=0 and writes 0600 root-owned