阻止恶意 AI 模型进入你的流水线,只需一行 YAML。
GuardModel 是一个 GitHub Action,可在 CI/CD 流水线中自动扫描 ML 模型文件,检查恶意代码、漏洞和安全风险。它能通过检测 pickle 反序列化攻击、嵌入恶意软件和已知 CVE,在危险模型进入生产环境之前将其阻断。
添加到你的工作流:
name: GuardModel Security Scan
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: guardmodel/scan@v1
就这样!GuardModel 将扫描所有模型文件,并在检测到威胁时使检查失败。
| 扩展名 | 格式 | 扫描器 | 风险级别 |
|---|---|---|---|
.pkl, .pickle | Python Pickle | Pickle 代理 | 严重 |
.pt, .pth | PyTorch | Pickle 代理 | 严重 |
.bin | PyTorch/Transformers | Pickle 代理 | 严重 |
.h5, .hdf5 | HDF5/Keras | Keras 代理 | 高 |
.keras | Keras v3 | Keras 代理 | 高 |
.onnx | ONNX | ONNX 代理 | 中 |
.safetensors | SafeTensors | SafeTensors 代理 | 低 |
在你的仓库中创建 .guardmodel.yml:
version: 1
# Directories to scan
include:
- models/
- weights/
# Directories to ignore
exclude:
- tests/fixtures/
# Severity threshold to fail CI
fail_on: high # critical, high, medium, low, none
# Allowlist known-safe models by SHA256
allowlist:
- sha256: "abc123..."
reason: "Verified by security team"
# Maximum file sizes
max_file_size: 5GB
max_total_size: 20GB
GuardModel 可检测:
os.system、subprocess、eval、execctypes、动态导入GuardModel 安全扫描
状态: 失败 - 检测到 2 个威胁
发现结果会显示在 GitHub Security 选项卡中,包含:
# Install dependencies
npm install
pip install -r requirements.txt
# Build
npm run build
# Test
npm test
pytest tests/
# Package for release
npm run package
guardmodel/
├── action.yml # GitHub Action definition
├── src/ # TypeScript source
│ ├── index.ts # Entry point
│ ├── orchestrator.ts # Scan coordination
│ ├── config.ts # Configuration
│ ├── walker.ts # File discovery
│ └── reporters/ # Output formatters
├── python/
│ ├── agents/ # Scanner agents
│ │ ├── pickle_agent.py
│ │ ├── keras_agent.py
│ │ ├── onnx_agent.py
│ │ └── safetensors_agent.py
│ └── rules/ # Detection rules
└── tests/ # Test suite
GuardModel:
MIT
欢迎贡献!请参阅 CONTRIBUTING.md。
| 输入 | 描述 | 默认值 |
|---|
path | 要扫描的目录 | . |
config | 配置文件路径 | .guardmodel.yml |
fail-on | 触发失败的最低严重性 | high |
output-sarif | 生成 SARIF 输出 | true |
output-json | 生成 JSON 输出 | true |
comment-on-pr | 发布 PR 评论 | true |
max-file-size | 最大文件大小 | 5GB |
| 输出 | 描述 |
|---|
status | 扫描状态(passed、failed、error) |
findings-count | 总发现数 |
critical-count | 严重级别发现数 |
high-count | 高级别发现数 |
sarif-file | SARIF 输出路径 |
json-file | JSON 输出路径 |
scan-duration | 持续时间(毫秒) |
| 文件 | 严重性 | 威胁 | 详情 |
|---|
models/model.pkl | 严重 | CODE_EXECUTION | 检测到 os.system 调用 |
models/utils.pt | 高 | NETWORK | 创建 socket.socket |