Repository navigation
Expand file tree
/
Copy pathDockerfile.sandbox
More file actions
88 lines (81 loc) · 5.11 KB
/
Copy pathDockerfile.sandbox
File metadata and controls
88 lines (81 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# syntax=docker/dockerfile:1
#
# ARTEX Worker / Chat Sandbox 镜像:
# 承载所有不受信任的工具执行(Bash / Python 脚本 / 扫描工具 / Playwright 浏览器),
# 不含 ARTEX 主服务、不含 LLM Key、不含数据库凭据,以非 root 用户运行。
#
# 本地构建:
# docker build -f Dockerfile.sandbox -t ruoji6/artex-sandbox:latest .
FROM node:22-bookworm-slim AS node-stage
FROM python:3.12-slim-bookworm
ENV TZ=Asia/Shanghai \
DEBIAN_FRONTEND=noninteractive
# 基础渗透/脚本工具 + Chromium 最小运行库与中文字体:
# 不使用 `playwright install --with-deps`,避免拉入无头容器不需要的
# xvfb / libgl1-mesa-dri / libllvm15 / libz3 及 60MB+ 多语种字体包。
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates ripgrep curl wget vim-tiny git jq unzip \
tzdata procps libcap2-bin libatomic1 \
dnsutils iputils-ping netcat-openbsd inetutils-telnet whois nmap \
libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 \
libcairo2 libcups2 libdbus-1-3 libdrm2 libgbm1 libglib2.0-0 \
libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 libxcomposite1 \
libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 \
libfontconfig1 libfreetype6 fonts-liberation fonts-wqy-microhei \
&& ([ -e /usr/bin/vim ] || ln -s /usr/bin/vim.tiny /usr/bin/vim) \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* \
/usr/share/doc/* /usr/share/man/* /usr/share/info/*
# 从官方 node:22-bookworm-slim 仅复制运行时 node 与 npm/npx,
# 避免 NodeSource apt 源带入 65MB /usr/include/node 头文件、gnupg 与重复 python3.11。
COPY --from=node-stage /usr/local/bin/node /usr/local/bin/node
COPY --from=node-stage /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/npm
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
&& node --version && npm --version
# 预装 Playwright MCP 与 CLI 及 Chromium(直接装到全局路径供非 root 用户运行,
# 浏览器访问目标站点完全隔离在沙箱容器内)。
# 使用 --no-shell 跳过 playwright-mcp --browser chromium 不会使用的 chromium-headless-shell,
# 同时裁剪非中英文语言包与 WidevineCdm DRM 组件。
# 国内构建可传 --build-arg PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright 加速。
ARG PLAYWRIGHT_DOWNLOAD_HOST=""
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
PLAYWRIGHT_DOWNLOAD_HOST=${PLAYWRIGHT_DOWNLOAD_HOST} \
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
NODE_EXTRA_CA_CERTS=/etc/artex/ca.crt \
NMAP_PRIVILEGED=1
RUN mkdir -p /ms-playwright /workspace /etc/artex /usr/local/share/ca-certificates \
&& npm install -g --no-audit --no-fund @playwright/mcp@latest @playwright/cli@latest \
&& playwright-mcp --version \
&& playwright-cli --help \
&& playwright-mcp install-browser --no-shell chromium \
&& playwright-cli install-browser --no-shell chromium \
&& rm -rf /ms-playwright/chromium-*/chrome-linux*/WidevineCdm \
&& (find /ms-playwright/chromium-*/chrome-linux*/locales -type f \
! -name 'en-US.pak' ! -name 'zh-CN.pak' ! -name 'zh-TW.pak' -delete 2>/dev/null || true) \
&& chmod -R a+rX /ms-playwright \
&& npm cache clean --force \
&& rm -rf /root/.npm /tmp/*
# 常用渗透/脚本 Python 依赖
RUN pip install --no-cache-dir requests httpx beautifulsoup4 pyyaml
# 可选系统 CA 刷新辅助脚本(默认运行模式下由主服务直接只读挂载合并后的
# /etc/ssl/certs/ca-certificates.crt,无需容器内 root 权限;若以 root 调试
# 或自定义镜像启动,可运行此脚本通过 update-ca-certificates 注入 /etc/artex/ca.crt)。
RUN printf '#!/bin/sh\nif [ -f /etc/artex/ca.crt ] && [ -w /usr/local/share/ca-certificates ]; then\n cp /etc/artex/ca.crt /usr/local/share/ca-certificates/artex-mitm-ca.crt\n update-ca-certificates >/dev/null 2>&1 || true\nfi\n' > /usr/local/bin/artex-update-ca.sh \
&& chmod +x /usr/local/bin/artex-update-ca.sh
# 非 root 运行用户(UID/GID 1000,与 ARTEX_SANDBOX_USER 默认值对齐)。
RUN groupadd -g 1000 sandbox \
&& useradd -u 1000 -g 1000 -m -s /bin/bash sandbox \
&& chown -R 1000:1000 /workspace
# 剥离所有 SUID/SGID 位防止提权,仅授予 nmap / nping / ping 最小必需的 cap_net_raw+ep
# 文件能力(注意仅 +ep 而非 +eip,确保子进程/NSE os.execute 不继承任何 capability),
# 使非 root 沙箱用户(uid 1000)无需 sudo 即可执行 nmap -sU/-sS、nping 与 ping,
# 同时普通脚本与进程依然保持 CapEff=0。
RUN find / -xdev -perm /6000 -type f -exec chmod a-s {} + 2>/dev/null || true \
&& setcap cap_net_raw+ep /usr/bin/nmap \
&& (setcap cap_net_raw+ep /usr/bin/nping 2>/dev/null || true) \
&& (setcap cap_net_raw+ep /usr/bin/ping 2>/dev/null || setcap cap_net_raw+ep /bin/ping 2>/dev/null || true)
USER 1000:1000
WORKDIR /workspace
CMD ["sleep", "infinity"]