agent-Specialization/docker/terminal.Dockerfile
JOJO 8257e4d34d feat(security): 沙箱只读真强制与权限模式边界收敛
- docker:只读/审批档 run_command、后台命令与持久终端改用非特权 uid(10001) 执行角色,内核 DAC 强制只读,取代文本特征识别;Dockerfile 加固(agent 用户 / git safe.directory / 去 setuid)
- macOS:只读与可写沙箱 profile 统一为白名单读模型(deny default + 系统目录/工作区/路径授权),修复 deny 顺序导致的工作区 .env 实际可读漏洞;可写 profile 白名单化后审批不再放大读取,越界读取唯一途径为路径授权
- 权限模式:受限档(readonly/approval/auto_approval)与 direct 执行环境硬互斥——进入受限档压回沙箱并记录,切回 unrestricted 恢复,存量受限+direct 对话加载自愈矫正
- 配置:路径授权来源收敛为 host_sandbox_policy.json + 环境变量两个通道(移除 settings.json 映射)
- 修复:新建对话权限模式被个性化默认值覆盖、/new 切只读后回落无限制的继承 bug
- 原生文件工具读边界与沙箱白名单同源对齐
2026-08-30 22:07:14 +08:00

94 lines
3.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FROM python:3.11-slim
ENV DEBIAN_FRONTEND=noninteractive \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8
# 1. 安装系统工具与运行时库
RUN apt-get update && \
apt-get install -y --no-install-recommends \
bash \
curl \
wget \
ca-certificates \
git \
build-essential \
openssh-client \
expect \
zip \
unzip \
locales \
tzdata \
iputils-ping \
# Office 转换
libreoffice \
pandoc \
poppler-utils \
# 图片/视频/媒体
imagemagick \
ffmpeg \
# OCR
tesseract-ocr \
tesseract-ocr-chi-sim \
tesseract-ocr-chi-tra \
# 网页截图 / 自动化
chromium \
# 开发辅助工具
jq \
ripgrep \
fd-find \
tree \
# 字体
fonts-noto-cjk \
fonts-noto-color-emoji \
fonts-liberation && \
sed -i 's/# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen && \
locale-gen && \
rm -rf /var/lib/apt/lists/*
# 2. 允许 ImageMagick 处理 PDF默认被安全策略禁止
RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml; \
fi
# 3. 安装 Node.js 20 LTS复用 curl已在上方安装
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
rm -rf /var/lib/apt/lists/* && \
node --version && \
npm --version
# 3.5 全局安装 office skill 需要的 Node 包
RUN npm install -g docx pptxgenjs && \
npm cache clean --force
WORKDIR /opt/workspace
COPY docker/toolbox-requirements.txt /tmp/toolbox-requirements.txt
# 4. 创建 Python 虚拟环境并安装依赖
RUN python -m venv /opt/agent-venv && \
/opt/agent-venv/bin/pip install --no-cache-dir --upgrade pip && \
/opt/agent-venv/bin/pip install --no-cache-dir -r /tmp/toolbox-requirements.txt && \
rm -f /tmp/toolbox-requirements.txt
ENV AGENT_TOOLBOX_VENV=/opt/agent-venv
ENV PATH="/opt/agent-venv/bin:${PATH}"
ENV NODE_PATH="/usr/lib/node_modules"
# 5. 只读执行角色与安全加固2026-08-30
# - agent 用户uid 10001可用 --build-arg 调整)供只读权限模式的
# docker exec/run --user 使用;容器主进程与可写执行仍为 root。
# 内核 DAC 强制:工作区文件属主为宿主机 rootagent 非属主 → 物理只读;
# uid 需与 DOCKER_READONLY_EXEC_UID 环境变量(默认 10001保持一致。
# - /etc/gitconfig 烤入 safe.directory=*:修复非属主身份跑 git 时的
# "detected dubious ownership" 报错(后端 exec 也会用 env 注入,双保险)。
# - 移除全部 setuid 位:缩小只读身份在容器内的提权面
# su/passwd/newgrp 等在本镜像的使用场景下不需要ping 用的是
# file capabilities 而非 setuid不受影响
ARG AGENT_UID=10001
RUN useradd --create-home --uid ${AGENT_UID} --shell /bin/bash agent && \
printf '[safe]\n\tdirectory = *\n' > /etc/gitconfig && \
find / -xdev -perm -4000 -type f -exec chmod u-s {} + 2>/dev/null || true