Skip to content

Commit 2e5fddb

Browse files
committed
Fix Hermes runtime permissions and e2e feedback
1 parent 91e8273 commit 2e5fddb

6 files changed

Lines changed: 67 additions & 29 deletions

File tree

‎agents/hermes/Dockerfile‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ RUN set -eu; \
187187
"$config_dir/workspace" \
188188
"$config_dir/profiles" \
189189
"$config_dir/cache" \
190-
"$config_dir/pairing"; \
190+
"$config_dir/pairing" \
191+
"$config_dir/runtime"; \
191192
if [ -e "$data_dir" ] || [ -L "$data_dir" ]; then \
192193
echo "ERROR: legacy data dir still exists after cleanup: $data_dir" >&2; \
193194
exit 1; \
@@ -211,7 +212,9 @@ RUN set -eu; \
211212
done; \
212213
rm -rf /root/.cache/pip /sandbox/.cache \
213214
&& chown -R sandbox:sandbox /sandbox/.hermes \
214-
&& chmod 770 /sandbox/.hermes \
215+
&& chown gateway:sandbox /sandbox/.hermes/runtime \
216+
&& chmod 750 /sandbox/.hermes \
217+
&& chmod 770 \
215218
/sandbox/.hermes/memories \
216219
/sandbox/.hermes/sessions \
217220
/sandbox/.hermes/skills \
@@ -224,8 +227,13 @@ RUN set -eu; \
224227
/sandbox/.hermes/profiles \
225228
/sandbox/.hermes/cache \
226229
/sandbox/.hermes/pairing \
230+
/sandbox/.hermes/runtime \
227231
&& chmod 640 /sandbox/.hermes/config.yaml \
228-
&& chmod 640 /sandbox/.hermes/.env
232+
&& chmod 640 /sandbox/.hermes/.env \
233+
&& for name in state.db state.db-wal state.db-shm gateway.pid gateway.lock gateway_state.json channel_directory.json; do \
234+
rm -f "/sandbox/.hermes/${name}"; \
235+
ln -s "runtime/${name}" "/sandbox/.hermes/${name}"; \
236+
done
229237

230238
# Pin config hash at build time for integrity verification at startup.
231239
RUN mkdir -p /etc/nemoclaw \

‎agents/hermes/Dockerfile.base‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ RUN groupadd -r sandbox \
6767
&& mkdir -p /sandbox/.nemoclaw \
6868
&& chown -R sandbox:sandbox /sandbox
6969

70-
# Create .hermes with all state subdirs directly (mutable by default).
71-
# No separate .hermes-data or symlink bridge.
70+
# Create .hermes with mutable integration dirs plus a scoped runtime dir.
71+
# Top-level gateway state names redirect into runtime so the config root can
72+
# remain non-group-writable without reintroducing the old .hermes-data bridge.
7273
RUN mkdir -p /sandbox/.hermes/memories \
7374
/sandbox/.hermes/sessions \
7475
/sandbox/.hermes/skills \
@@ -81,8 +82,11 @@ RUN mkdir -p /sandbox/.hermes/memories \
8182
/sandbox/.hermes/profiles \
8283
/sandbox/.hermes/cache \
8384
/sandbox/.hermes/pairing \
85+
/sandbox/.hermes/runtime \
8486
&& chown -R sandbox:sandbox /sandbox/.hermes \
85-
&& chmod 770 /sandbox/.hermes \
87+
&& chown gateway:sandbox /sandbox/.hermes/runtime \
88+
&& chmod 750 /sandbox/.hermes \
89+
&& chmod 770 \
8690
/sandbox/.hermes/memories \
8791
/sandbox/.hermes/sessions \
8892
/sandbox/.hermes/skills \
@@ -94,7 +98,12 @@ RUN mkdir -p /sandbox/.hermes/memories \
9498
/sandbox/.hermes/workspace \
9599
/sandbox/.hermes/profiles \
96100
/sandbox/.hermes/cache \
97-
/sandbox/.hermes/pairing
101+
/sandbox/.hermes/pairing \
102+
/sandbox/.hermes/runtime \
103+
&& for name in state.db state.db-wal state.db-shm gateway.pid gateway.lock gateway_state.json channel_directory.json; do \
104+
rm -f "/sandbox/.hermes/${name}"; \
105+
ln -s "runtime/${name}" "/sandbox/.hermes/${name}"; \
106+
done
98107

99108
# Install Hermes Agent from the selected GitHub release.
100109
# The image prebakes only the extras mapped to NemoClaw-supported onboarding

‎agents/hermes/start.sh‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,38 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
4242
# ── Early stderr/stdout capture ──────────────────────────────────
4343
# Capture all entrypoint output to /tmp/nemoclaw-start.log so startup
4444
# failures before /tmp/gateway.log exists are still diagnosable.
45+
prepare_restricted_log() {
46+
local path="$1"
47+
local owner="${2:-}"
48+
local mode="${3:-600}"
49+
local dir base tmp
50+
51+
dir="$(dirname "$path")"
52+
base="$(basename "$path")"
53+
tmp="$(mktemp "${dir}/.${base}.tmp.XXXXXX")" || return 1
54+
: >"$tmp" || {
55+
rm -f "$tmp"
56+
return 1
57+
}
58+
if [ "$(id -u)" -eq 0 ] && [ -n "$owner" ] && ! chown "$owner" "$tmp"; then
59+
rm -f "$tmp"
60+
return 1
61+
fi
62+
if ! chmod "$mode" "$tmp"; then
63+
rm -f "$tmp"
64+
return 1
65+
fi
66+
if ! mv -f "$tmp" "$path"; then
67+
rm -f "$tmp"
68+
return 1
69+
fi
70+
}
71+
4572
_START_LOG="/tmp/nemoclaw-start.log"
4673
if [ "$(id -u)" -eq 0 ]; then
47-
: >"$_START_LOG"
48-
chown root:root "$_START_LOG"
49-
chmod 600 "$_START_LOG"
74+
prepare_restricted_log "$_START_LOG" root:root 600
5075
else
51-
: >"$_START_LOG"
52-
chmod 600 "$_START_LOG" 2>/dev/null || true
76+
prepare_restricted_log "$_START_LOG" "" 600
5377
fi
5478
exec > >(tee -a "$_START_LOG") 2> >(tee -a "$_START_LOG" >&2)
5579

@@ -91,10 +115,9 @@ PUBLIC_PORT=8642
91115
INTERNAL_PORT=18642
92116
HERMES="$(command -v hermes)" # Resolve once, use absolute path everywhere
93117

94-
# Hermes writes state files (PID, state.db, .channel_directory) directly into
95-
# HERMES_HOME alongside config. Config is mutable by default for the sandbox user
96-
# and group-readable by the gateway user. Runtime state dirs are group-writable
97-
# because the Hermes gateway writes logs, PID files, and channel directory state.
118+
# Hermes resolves config and runtime state relative to HERMES_HOME. The config
119+
# root is mutable by the sandbox owner and readable by the gateway group, while
120+
# gateway-created top-level state is redirected to a scoped runtime directory.
98121
# Immutability is opt-in via `shields up`.
99122
HERMES_DIR="/sandbox/.hermes"
100123
HERMES_HASH_FILE="/etc/nemoclaw/hermes.config-hash"
@@ -474,9 +497,7 @@ if [ "$(id -u)" -ne 0 ]; then
474497
exec "${NEMOCLAW_CMD[@]}"
475498
fi
476499

477-
# TODO(#2277-P2): migrate to shared emit_restricted_log() helper
478-
touch /tmp/gateway.log
479-
chmod 600 /tmp/gateway.log
500+
prepare_restricted_log /tmp/gateway.log "" 600
480501

481502
# Defence-in-depth: verify /tmp file permissions before launching services.
482503
# shellcheck disable=SC2119
@@ -521,10 +542,7 @@ if [ ${#NEMOCLAW_CMD[@]} -gt 0 ]; then
521542
fi
522543

523544
# SECURITY: Protect gateway log from sandbox user tampering
524-
# TODO(#2277-P2): migrate to shared emit_restricted_log() helper
525-
touch /tmp/gateway.log
526-
chown gateway:gateway /tmp/gateway.log
527-
chmod 600 /tmp/gateway.log
545+
prepare_restricted_log /tmp/gateway.log gateway:gateway 600
528546

529547
# Defence-in-depth: verify /tmp file permissions before launching services.
530548
# shellcheck disable=SC2119

‎test/e2e/test-rebuild-hermes.sh‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SANDBOX_NAME="${NEMOCLAW_SANDBOX_NAME:-e2e-rebuild-hm}"
3131
register_sandbox_for_teardown "$SANDBOX_NAME"
3232

3333
OLD_HERMES_VERSION="v2026.4.13"
34+
OLD_HERMES_REGISTRY_VERSION="${OLD_HERMES_VERSION#v}"
3435
OLD_HERMES_TARBALL_SHA256="5e4529b8cb6e4821eb916b81517e48125109b1764d6d1e68a204a9f0ddf2d98c"
3536
MARKER_FILE="/sandbox/.hermes/memories/rebuild-marker.txt"
3637
MARKER_CONTENT="REBUILD_HM_E2E_$(date +%s)"
@@ -199,7 +200,7 @@ reg = {'sandboxes': {'${SANDBOX_NAME}': {
199200
'policies': [],
200201
'policyTier': None,
201202
'agent': 'hermes',
202-
'agentVersion': '2026.4.13'
203+
'agentVersion': '${OLD_HERMES_REGISTRY_VERSION}'
203204
}}, 'defaultSandbox': '${SANDBOX_NAME}'}
204205
with open('${REGISTRY_FILE}', 'w') as f:
205206
json.dump(reg, f, indent=2)
@@ -278,10 +279,10 @@ with open('${REGISTRY_FILE}') as f:
278279
sb = data.get('sandboxes', {}).get('${SANDBOX_NAME}', {})
279280
print(sb.get('agentVersion', 'null'))
280281
" 2>/dev/null || echo "error")
281-
if [ "$REGISTRY_VERSION" != "null" ] && [ "$REGISTRY_VERSION" != "error" ] && [ "$REGISTRY_VERSION" != "2026.3.12" ]; then
282+
if [ "$REGISTRY_VERSION" != "null" ] && [ "$REGISTRY_VERSION" != "error" ] && [ "$REGISTRY_VERSION" != "$OLD_HERMES_REGISTRY_VERSION" ]; then
282283
pass "Registry agentVersion updated to ${REGISTRY_VERSION}"
283284
else
284-
fail "Registry agentVersion not updated: got '${REGISTRY_VERSION}', expected != '2026.3.12'"
285+
fail "Registry agentVersion not updated: got '${REGISTRY_VERSION}', expected != '${OLD_HERMES_REGISTRY_VERSION}'"
285286
fi
286287

287288
# No credentials in backup

‎test/e2e/test-runtime-overrides.sh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ info "Logging Docker stderr to: $LOG_FILE"
5151
run_override() {
5252
local env_args=("$@")
5353
docker run --rm "${env_args[@]}" "$IMAGE" \
54-
bash -c 'cat /sandbox/.openclaw/openclaw.json' 2>>"$LOG_FILE"
54+
bash -c 'cat /sandbox/.openclaw/openclaw.json; printf "\n"' 2>>"$LOG_FILE"
5555
}
5656

5757
# Helper: run entrypoint with env vars and capture stderr for validation messages.
@@ -172,7 +172,8 @@ NEW_LEN=$(echo "$CFG" | jq '.gateway.controlUi.allowedOrigins | length')
172172
if [ "$HAS_ORIGIN" = "true" ] && [ "$NEW_LEN" -gt "$BASELINE_ORIGINS" ]; then
173173
pass "CORS origin added: $CORS"
174174
else
175-
fail "CORS origin not found in allowedOrigins"
175+
ORIGINS=$(echo "$CFG" | jq -c '.gateway.controlUi.allowedOrigins // []' 2>/dev/null || printf '%s' "$CFG")
176+
fail "CORS origin not found in allowedOrigins: ${ORIGINS}"
176177
fi
177178

178179
# ── Test 7: Combined overrides ───────────────────────────────────

‎test/sandbox-provisioning.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ describe("Hermes sandbox provisioning", () => {
9191
`nohup gosu gateway sh -c 'exec "$@" >/tmp/gateway.log 2>&1' sh "$HERMES" gateway run`,
9292
);
9393
for (const dockerSrc of [src, baseSrc]) {
94-
expect(dockerSrc).toContain("chmod 770 /sandbox/.hermes");
94+
expect(dockerSrc).toContain("chmod 750 /sandbox/.hermes");
95+
expect(dockerSrc).toContain("/sandbox/.hermes/runtime");
9596
expect(dockerSrc).toContain("/sandbox/.hermes/logs");
9697
expect(dockerSrc).toContain("/sandbox/.hermes/cache");
9798
}

0 commit comments

Comments
 (0)