@@ -174,31 +174,46 @@ if [ -d "$HORNET_HOME/.pi/session-control" ]; then
174174 fi
175175fi
176176
177- # Check for files owned by wrong user in hornet repo
178- # NOTE: Protected files (bin/, hooks/, tool-guard.ts, security.mjs, etc.) are
179- # intentionally owned by bentlegen/root as an extra defense layer. Only flag
180- # unexpected non-hornet_agent ownership in agent-modifiable areas .
177+ # Verify protected files are NOT writable by hornet_agent.
178+ # Protected files should be owned by bentlegen (or root for .git/hooks/pre-commit)
179+ # so the agent cannot modify them even with full shell access.
180+ # This is a 4th security layer alongside tool-guard, pre-commit hook, and skill guidance .
181181if [ -d " $HORNET_HOME /hornet" ]; then
182- wrong_owner=$( find " $HORNET_HOME /hornet" \
183- -not -user hornet_agent \
184- -not -path ' */.git/*' \
185- -not -path ' */bin/*' \
186- -not -path ' */hooks/*' \
187- -not -path ' */.github/*' -not -path ' */.github' \
188- -not -name ' .secrets.baseline' \
189- -not -path ' */tool-guard.ts' \
190- -not -path ' */tool-guard.test.mjs' \
191- -not -path ' */security.mjs' \
192- -not -path ' */security.test.mjs' \
193- -not -name ' setup.sh' \
194- -not -name ' start.sh' \
195- -not -name ' SECURITY.md' \
196- 2> /dev/null | wc -l)
197- if [ " $wrong_owner " -gt 0 ]; then
198- finding " WARN" " $wrong_owner file(s) in hornet repo with unexpected ownership" \
199- " Review with: find ~/hornet -not -user hornet_agent -not -path '*/bin/*' -not -path '*/.git/*'"
200- else
201- ok " File ownership correct (protected files admin-owned, rest agent-owned)"
182+ PROTECTED_FILES=(
183+ " $HORNET_HOME /hornet/bin/security-audit.sh"
184+ " $HORNET_HOME /hornet/bin/security-audit.test.sh"
185+ " $HORNET_HOME /hornet/bin/setup-firewall.sh"
186+ " $HORNET_HOME /hornet/bin/harden-permissions.sh"
187+ " $HORNET_HOME /hornet/bin/hornet-docker"
188+ " $HORNET_HOME /hornet/bin/hornet-safe-bash"
189+ " $HORNET_HOME /hornet/bin/hornet-safe-bash.test.sh"
190+ " $HORNET_HOME /hornet/bin/scan-extensions.mjs"
191+ " $HORNET_HOME /hornet/bin/scan-extensions.test.mjs"
192+ " $HORNET_HOME /hornet/bin/redact-logs.sh"
193+ " $HORNET_HOME /hornet/bin/redact-logs.test.sh"
194+ " $HORNET_HOME /hornet/bin/hornet-firewall.service"
195+ " $HORNET_HOME /hornet/pi/extensions/tool-guard.ts"
196+ " $HORNET_HOME /hornet/pi/extensions/tool-guard.test.mjs"
197+ " $HORNET_HOME /hornet/slack-bridge/security.mjs"
198+ " $HORNET_HOME /hornet/slack-bridge/security.test.mjs"
199+ " $HORNET_HOME /hornet/setup.sh"
200+ " $HORNET_HOME /hornet/start.sh"
201+ " $HORNET_HOME /hornet/SECURITY.md"
202+ " $HORNET_HOME /hornet/hooks/pre-commit"
203+ )
204+ agent_writable=0
205+ for pf in " ${PROTECTED_FILES[@]} " ; do
206+ [ ! -e " $pf " ] && continue
207+ pf_owner=$( stat -c ' %U' " $pf " 2> /dev/null)
208+ if [ " $pf_owner " = " hornet_agent" ]; then
209+ finding " CRITICAL" " Protected file owned by hornet_agent (agent can modify!): $( basename " $pf " ) " \
210+ " Fix: sudo chown bentlegen:hornet_agent $pf && sudo chmod 644 $pf "
211+ fix_skip " Fix ownership of $( basename " $pf " ) " " Requires root: sudo chown bentlegen:hornet_agent $pf "
212+ agent_writable=$(( agent_writable + 1 ))
213+ fi
214+ done
215+ if [ " $agent_writable " -eq 0 ]; then
216+ ok " All protected files are admin-owned (agent cannot modify)"
202217 fi
203218fi
204219echo " "
0 commit comments