Skip to content

Commit 3986ea2

Browse files
committed
config: support Ubuntu — replace grep -P with grep -E, add distro-agnostic guideline
1 parent 26fff12 commit 3986ea2

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Add new test files to `bin/test.sh` — don't scatter test invocations across CI
110110
- Skills are deployed from `pi/skills/` → agent's `~/.pi/agent/skills/`.
111111
- Agent commits operational learnings to its own skills dir (not back to source).
112112
- **When changing behavior, update all docs.** Check and update: `README.md`, `CONFIGURATION.md`, skill files (`pi/skills/*/SKILL.md`), and `AGENTS.md`. Inline code examples in docs must match the actual implementation.
113+
- **No distro-specific commands.** Scripts must work on both Arch and Ubuntu (and any standard Linux). Use `grep -E` (not `grep -P`), POSIX-compatible tools, and avoid package manager calls (`pacman`, `apt`, etc.). If a package is needed, document it as a prerequisite rather than auto-installing it.
113114

114115
## Security Notes
115116

bin/hornet-safe-bash

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#
66
# This is defense-in-depth — the agent's instructions also prohibit these,
77
# but a successful injection might override soft instructions.
8+
#
9+
# NOTE: Avoid grep -P (Perl regex) — not available on all distros.
10+
# Use grep -E (extended regex) or awk instead.
811

912
# Patterns that should NEVER be executed by the agent
1013
COMMAND="$*"
@@ -16,64 +19,67 @@ block() {
1619
}
1720

1821
# Fork bomb
19-
if echo "$COMMAND" | grep -qP ':\(\)\s*\{.*\|.*&.*\}'; then
22+
if echo "$COMMAND" | grep -qE ':\(\)[[:space:]]*\{.*\|.*&.*\}'; then
2023
block "fork bomb"
2124
fi
2225

2326
# rm -rf / or rm -rf /* (root filesystem deletion)
24-
if echo "$COMMAND" | grep -qP 'rm\s+(-[a-zA-Z]*f[a-zA-Z]*\s+)?(-[a-zA-Z]*r[a-zA-Z]*\s+)?(\/\s*$|\/\*|\/\s+)'; then
27+
if echo "$COMMAND" | grep -qE 'rm[[:space:]]+(-[a-zA-Z]*f[a-zA-Z]*[[:space:]]+)?(-[a-zA-Z]*r[a-zA-Z]*[[:space:]]+)?(/[[:space:]]*$|/\*|/[[:space:]]+)'; then
2528
block "recursive delete of root filesystem"
2629
fi
27-
if echo "$COMMAND" | grep -qP 'rm\s+(-[a-zA-Z]*r[a-zA-Z]*\s+)?(-[a-zA-Z]*f[a-zA-Z]*\s+)?(\/\s*$|\/\*|\/\s+)'; then
30+
if echo "$COMMAND" | grep -qE 'rm[[:space:]]+(-[a-zA-Z]*r[a-zA-Z]*[[:space:]]+)?(-[a-zA-Z]*f[a-zA-Z]*[[:space:]]+)?(/[[:space:]]*$|/\*|/[[:space:]]+)'; then
2831
block "recursive delete of root filesystem"
2932
fi
3033

3134
# dd writing to block devices
32-
if echo "$COMMAND" | grep -qP 'dd\s+.*of=/dev/(sd|vd|nvme|xvd)'; then
35+
if echo "$COMMAND" | grep -qE 'dd[[:space:]]+.*of=/dev/(sd|vd|nvme|xvd)'; then
3336
block "dd write to block device"
3437
fi
3538

3639
# mkfs on block devices
37-
if echo "$COMMAND" | grep -qP 'mkfs\b.*\/dev\/'; then
40+
if echo "$COMMAND" | grep -qE 'mkfs[^a-zA-Z].*/dev/'; then
3841
block "mkfs on block device"
3942
fi
4043

4144
# chmod 777 on sensitive paths
42-
if echo "$COMMAND" | grep -qP 'chmod\s+(-[a-zA-Z]*\s+)?777\s+(\/|\/etc|\/home|\/root|\/var)'; then
45+
if echo "$COMMAND" | grep -qE 'chmod[[:space:]]+(-[a-zA-Z]*[[:space:]]+)?777[[:space:]]+(/|/etc|/home|/root|/var)'; then
4346
block "chmod 777 on sensitive path"
4447
fi
4548

4649
# Curl/wget piped to shell
47-
if echo "$COMMAND" | grep -qP '(curl|wget)\s+.*\|\s*(ba)?sh'; then
50+
if echo "$COMMAND" | grep -qE '(curl|wget)[[:space:]]+.*\|[[:space:]]*(ba)?sh'; then
4851
block "piping download to shell"
4952
fi
5053

5154
# Reverse shell patterns
52-
if echo "$COMMAND" | grep -qP 'bash\s+-i\s+>(&|\|)\s*/dev/tcp/'; then
55+
if echo "$COMMAND" | grep -qE 'bash[[:space:]]+-i[[:space:]]+>[&|][[:space:]]*/dev/tcp/'; then
5356
block "reverse shell (bash /dev/tcp)"
5457
fi
55-
if echo "$COMMAND" | grep -qP 'nc\s+(-[a-zA-Z]*\s+)*[0-9]+.*-e\s*(\/bin\/)?(ba)?sh'; then
58+
if echo "$COMMAND" | grep -qE 'nc[[:space:]]+(-[a-zA-Z]*[[:space:]]+)*[0-9]+.*-e[[:space:]]*(\/bin\/)?(ba)?sh'; then
5659
block "reverse shell (netcat)"
5760
fi
58-
if echo "$COMMAND" | grep -qP 'python[23]?\s+-c.*socket.*connect.*subprocess'; then
61+
if echo "$COMMAND" | grep -qE 'python[23]?[[:space:]]+-c.*socket.*connect.*subprocess'; then
5962
block "reverse shell (python)"
6063
fi
6164

6265
# crontab modification (persistence)
63-
if echo "$COMMAND" | grep -qP '(crontab\s+-[erl]|echo.*>\s*/etc/cron)'; then
66+
if echo "$COMMAND" | grep -qE '(crontab[[:space:]]+-[erl]|echo.*>[[:space:]]*/etc/cron)'; then
6467
block "crontab modification"
6568
fi
6669

6770
# Modifying /etc/passwd or /etc/shadow
68-
if echo "$COMMAND" | grep -qP '>\s*/etc/(passwd|shadow|sudoers)'; then
71+
if echo "$COMMAND" | grep -qE '>[[:space:]]*/etc/(passwd|shadow|sudoers)'; then
6972
block "write to system auth files"
7073
fi
7174

7275
# SSH key injection to other users
73-
if echo "$COMMAND" | grep -qP '>\s*/home/(?!hornet_agent).*/\.ssh/authorized_keys'; then
74-
block "SSH key injection to another user"
76+
# Can't use negative lookahead without grep -P, so match broadly then exclude our user
77+
if echo "$COMMAND" | grep -qE '>[[:space:]]*/home/.*/.ssh/authorized_keys'; then
78+
if ! echo "$COMMAND" | grep -qE '>[[:space:]]*/home/hornet_agent/.ssh/authorized_keys'; then
79+
block "SSH key injection to another user"
80+
fi
7581
fi
76-
if echo "$COMMAND" | grep -qP '>\s*/root/\.ssh/authorized_keys'; then
82+
if echo "$COMMAND" | grep -qE '>[[:space:]]*/root/.ssh/authorized_keys'; then
7783
block "SSH key injection to root"
7884
fi
7985

setup.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Run as root or with sudo from the admin user account
44
#
55
# Prerequisites:
6-
# - Arch Linux (or similar)
6+
# - Linux (tested on Arch and Ubuntu)
77
# - Docker installed
88
#
99
# This script:
@@ -103,7 +103,16 @@ echo "=== Configuring shared repo permissions ==="
103103
# Set core.sharedRepository=group on all repos so git creates objects
104104
# with group-write perms. Without this, umask 077 in start.sh causes
105105
# new .git/objects to be owner-only, breaking group access (admin user).
106-
for repo in "$REPO_DIR" "$HORNET_HOME/workspace/modem" "$HORNET_HOME/workspace/website"; do
106+
107+
# Source repo — set as admin user (agent can't access admin home, and root
108+
# needs safe.directory due to different ownership)
109+
if [ -d "$REPO_DIR/.git" ]; then
110+
sudo -u "$ADMIN_USER" git -C "$REPO_DIR" config core.sharedRepository group
111+
echo "$REPO_DIR"
112+
fi
113+
114+
# Agent workspace repos — set as agent
115+
for repo in "$HORNET_HOME/workspace/modem" "$HORNET_HOME/workspace/website"; do
107116
if [ -d "$repo/.git" ]; then
108117
sudo -u hornet_agent git -C "$repo" config core.sharedRepository group
109118
echo "$repo"

0 commit comments

Comments
 (0)