YusufKaramuk1/actionaudit
GitHub: YusufKaramuk1/actionaudit
ActionAudit 是一个针对 GitHub Actions 工作流的静态安全扫描器,能基于 OWASP 风险模型检测配置漏洞和注入问题。
Stars: 0 | Forks: 0
# ActionAudit
[](https://pypi.org/project/actionaudit/)
[](https://github.com/YusufKaramuk1/actionaudit/actions/workflows/tests.yml)
[](https://github.com/YusufKaramuk1/actionaudit/actions/workflows/self-scan.yml)
GitHub Actions 工作流的静态安全扫描器。
ActionAudit 读取 `.github/workflows/*.yml`,解析 YAML,并对其运行一组安全规则。每个发现项都包含精确的位置(`workflow.yml:42`)、严重级别、OWASP CI/CD 类别、*为什么*危险的易读解释以及*如何*修复。
## 为什么选择 ActionAudit
- **本地优先且确定性。** 扫描期间无需网络调用,核心不含 AI。相同的输入始终产生相同的输出。
- **教育性。** 每个发现项都会解释风险和修复方法,而不仅仅是规则名称。`actionaudit explain ` 提供完整背景。
- **与标准对齐。** 每条规则都映射到 [OWASP Top 10 CI/CD Security Risk](https://owasp.org/www-project-top-10-ci-cd-security-risks/) 中。
- **多种输出格式。** 彩色终端、暗色主题 HTML、JSON 以及用于 GitHub Code Scanning 的 SARIF。
## 安装
```
pip install actionaudit
```
或从源码安装:
```
git clone https://github.com/YusufKaramuk1/actionaudit.git
cd actionaudit
pip install -e .
```
## 用法
```
# 扫描当前仓库中的工作流
actionaudit scan .
# 扫描特定文件或目录
actionaudit scan .github/workflows/ci.yml
# 生成 HTML 或 SARIF 报告
actionaudit scan . --format html --output report.html
actionaudit scan . --format sarif --output results.sarif
# 如果存在 HIGH+ 发现则终止进程 (exit 1) -- 在 CI 中很有用
actionaudit scan . --fail-on high
# 列出并解释规则
actionaudit list-rules
actionaudit explain expression-injection-in-run
```
## 高级用法
```
# 应用内置配置文件:strict / balanced / education
actionaudit scan . --profile strict
# 从声明式 YAML 策略文件加载配置(无代码执行)
actionaudit scan . --policy actionaudit-policy.yml
# Brownfield adoption:捕获基线,然后仅针对 NEW 发现失败
actionaudit scan . --format json --output baseline.json
actionaudit scan . --baseline baseline.json --fail-on high
```
请参阅下方的**配置**和**自定义规则**以了解 `--policy` 模式和 `--rules-dir`。
## 作为 GitHub Action 使用
将 ActionAudit 添加到任意仓库的工作流中:
```
- uses: YusufKaramuk1/actionaudit@v1.4.1
with:
path: .github/workflows
fail-on: high
```
发现项会以内联注释的形式显示在拉取请求上,当存在达到或超过 `fail-on` 级别的发现项时,步骤会失败。
## 作为 pre-commit 钩子使用
将 ActionAudit 添加到 `.pre-commit-config.yaml` 中:
```
repos:
- repo: https://github.com/YusufKaramuk1/actionaudit
rev: v1.4.1
hooks:
- id: actionaudit
```
该钩子在工作流文件发生变更时运行,并在发现 HIGH 及以上级别的问题时阻止提交(可通过 `args: ['--fail-on', 'critical']` 覆盖)。
## 规则
| ID | 严重级别 | OWASP | 捕获内容 |
|---|---|---|---|
| `expression-injection-in-run` | CRITICAL | CICD-SEC-4 | 不受信任的 `${{ ... }}` 输入被插值到 `run:` 脚本中 |
| `pull-request-target-with-checkout` | CRITICAL | CICD-SEC-4 | `pull_request_target` 工作流检出了 PR 头部代码(Pwn Request) |
| `workflow-dispatch-input-injection` | HIGH | CICD-SEC-4 | 工作流输入被插值到 `run:` 脚本中 |
| `dangerous-workflow-run-chain` | HIGH | CICD-SEC-4 | `workflow_run` 工作流消费了上游工作流的产物 |
| `untrusted-artifact-execution` | HIGH | CICD-SEC-3 | 下载的产物在同一作业中未经验证即执行 |
| `github-token-write-all` | HIGH | CICD-SEC-5 | `permissions: write-all` 或缺少 `permissions:` 块 |
| `third-party-action-not-pinned-sha` | HIGH | CICD-SEC-3 | 第三方操作固定到可变标签而非提交 SHA |
| `hardcoded-secret` | HIGH | CICD-SEC-6 | 文件中出现字面量凭证(AWS / GitHub / Stripe / Slack / PEM) |
| `inline-curl-pipe-bash` | MEDIUM | CICD-SEC-3 | 远程脚本直接通过管道传给 shell |
| `actions-cache-poisoning-risk` | MEDIUM | CICD-SEC-3 | 缓存键派生自 PR 控制的输入 |
| `taint-propagation-via-env` | MEDIUM | CICD-SEC-4 | 不受信任的输入通过 `env` 到达 `run:` shell(未加引号 / eval) |
| `persist-credentials-default-true` | MEDIUM | CICD-SEC-6 | `actions/checkout` 保留了默认的凭据持久化 |
| `self-hosted-runner-fork-trigger` | MEDIUM | CICD-SEC-7 | 自托管运行器可被 Fork 的拉取请求触发 |
| `bash-with-set-x` | LOW | CICD-SEC-10 | Shell 调试跟踪(`set -x`)可能将机密泄露到日志中 |
## 输出格式
- `--format terminal`(默认)—— 控制台中的彩色摘要。
- `--format json` —— 用于自动化的稳定 JSON 模式。
- `--format html` —— 自带深色主题的报告,包含每个发现项的修复建议。
- `--format sarif` —— 用于 GitHub Code Scanning 的 SARIF v2.1.0。
## 配置
在 `pyproject.toml` 中添加 `[tool.actionaudit]` 部分:
```
[tool.actionaudit]
disabled_rules = ["bash-with-set-x"]
[tool.actionaudit.severity]
hardcoded-secret = "critical"
```
若要忽略某个发现项,请在违规行(或紧接其上的行)添加内联注释:
```
- uses: tj-actions/changed-files@v44 # actionaudit: ignore third-party-action-not-pinned-sha
```
## 自定义规则
编写组织特定的规则,并通过 `--rules-dir` 将其与内置规则一起加载:
```
actionaudit scan . --rules-dir ./company-rules/
```
目录中的每个 `.py` 文件可以定义 `Rule` 子类(详见 [CONTRIBUTING.md](CONTRIBUTING.md))。**注意:** `--rules-dir` 会导入并执行找到的 Python 文件——请只指向你信任的目录。
## 哲学
ActionAudit 仅扫描 GitHub Actions 工作流文件。它不是运行时监视器,不是通用密钥扫描器,也不是多平台 CI 工具——这种专注是有意为之。请参阅 [ROADMAP.md](ROADMAP.md) 了解计划中的内容以及刻意排除的范围。
## 开发
```
pip install -e ".[dev]"
pytest
ruff check src tests
mypy src
```
请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解如何添加规则。
## 土耳其语摘要
ActionAudit, GitHub Actions 工作流(`.github/workflows/*.yml`)中的安全漏洞和错误配置进行静态检测的本地确定性 CLI 扫描器。每个发现项都会报告精确位置(`workflow.yml:42`)、严重级别、OWASP CI/CD 类别、风险*为什么*危险的解释以及*如何*修复。
```
git clone https://github.com/YusufKaramuk1/actionaudit.git
cd actionaudit && pip install -e .
actionaudit scan .
```
目前包含 14 条规则,每条都映射到 OWASP Top 10 CI/CD 风险类别之一。输出格式:终端、JSON、深色主题 HTML、SARIF 和 GitHub 注释。配置可通过 `pyproject.toml` 中的 `[tool.actionaudit` 部分、`--profile` / `--policy` 或行内 `# actionaudit: ignore` 注释进行;支持 `--baseline` 仅报告新的发现项。
## 许可
MIT —— 参见 [LICENSE](LICENSE)。
标签:CI/CD安全, DevSecOps, GitHub Actions, Homebrew安装, Llama, Python, YAML解析, 上游代理, 二进制发布, 云安全监控, 云计算, 代码安全, 多模态安全, 安全扫描, 工作流安全, 开源工具, 指令注入, 无后门, 时序注入, 服务器监控, 漏洞枚举, 自动笔记, 规则引擎, 逆向工具, 静态分析