加固:executor 根文件系统只读,tmpfs 提供可写点

- agent-executor 增加 read_only: true,AI 命令无法往镜像层(/usr、/root 等)写文件做持久化/篡改。

- tmpfs 配 /tmp、/var/tmp、/run。/run 必须有:隔离 wrapper 要在 /run/agent-exec 建私有 anchor/rundir,只读下 mkdir 报 EROFS 会中断每条命令(已实测:Linux + Docker 29 重建后 ReadonlyRootfs=true,session 隔离与技能执行均正常,touch 根目录报 Read-only file system、ls /workspace/tasks 仅见本会话)。

- ARCHITECTURE §6 同步。
This commit is contained in:
2026-09-11 21:11:42 +08:00
parent 4e8560982f
commit 3e389747c8
2 changed files with 13 additions and 0 deletions
+11
View File
@@ -71,6 +71,17 @@ services:
- no-new-privileges:true
# 实测 Docker 29 (Ubuntu) 需 unconfined 才能使用 mount/unshare 系统调用
- apparmor=unconfined
# 根文件系统只读:AI 命令无法往镜像层(/usr、/root 等)写文件做持久化/篡改;
# 合法写盘另走 tmpfs 与 bind 卷(handleExec 已把 HOME/TMPDIR 指向 /tmp)。
read_only: true
tmpfs:
- /tmp
- /var/tmp
# /run 必须可写:隔离 wrapper 要在 /run/agent-exec 下建私有 anchor/rundir,
# 否则 read_only 下 mkdir 报 EROFS,每条命令直接中断。
- /run
networks:
- agent-internal
+2
View File
@@ -360,6 +360,8 @@ stateDiagram-v2
**资源护栏**(compose 层,**不在 server.js**):
`cpus 2.0` / `mem_limit 2g` / `pids_limit 512` / `ulimits.fsize 2G` —— 防 AI 失控命令。残余缺口(只限单文件不限总量)在 compose 注释里已标。
**根文件系统只读**(compose 层):`read_only: true` 挡住 AI 命令往镜像层写文件做持久化/篡改;`tmpfs: /tmp /var/tmp /run` 提供必要可写点。**`/run` 必须给**——隔离 wrapper 要在 `/run/agent-exec` 建私有 anchor/rundir,否则 `read_only` 下 `mkdir` 报 EROFS(`set -e` 直接中断每条命令);正常写盘另走 `handleExec` 的 `HOME=/tmp`/`TMPDIR=/tmp` 与 bind 卷。
---
## 7. HTTP 路由