agentic-actions-auditor:審計 GitHub Actions 裏 AI Agent 集成的安全風險

前言

在 CI 裏接入 Claude Code Action、OpenAI Codex、Gemini CLI 或 GitHub AI Inference 的做法越來越常見:用 Agent 自動審 PR、改代碼、跑推理。這類步驟往往同時接觸倉庫權限、密鑰和可被外部觸發的 GitHub 事件上下文。若把攻擊者可控輸入直接或間接送進 Agent 的 prompt,或把沙箱、工具權限配得過寬,靜態看 workflow YAML 很容易漏掉「環境變量中轉」一類路徑。

下面介紹 Trail of Bits 在 skills 市場裏提供的 agentic-actions-auditor:一套面向 GitHub Actions 的靜態審計指引,教 Agent 如何發現 workflow、識別 AI Action 步驟,並報告與 prompt 注入、沙箱配置相關的風險。它是分析指導,不是自動改文件的修復工具,也不做運行時 exploit 測試。

這是什麼

agentic-actions-auditor 是 Claude Code / Codex 等環境裏可加載的 Skill(SKILL.md 格式),歸屬 Trail of Bits Skills Marketplace,插件目錄爲 plugins/agentic-actions-auditor/。

官方描述概括爲:對調用 AI 編碼 Agent 的 GitHub Actions workflow 做靜態安全分析,覆蓋 Claude Code Action、Gemini CLI、OpenAI Codex、GitHub AI Inference 等集成;檢測攻擊者可控輸入進入在 CI/CD 中運行的 AI Agent 的路徑,包括環境變量中轉、直接表達式注入、危險的沙箱配置、通配符用戶白名單等。

Skill 聲明允許使用的工具爲:Read、Grep、Glob、Bash(Bash 僅用於通過 gh api 拉取遠程倉庫 workflow,且不得把拉取的 YAML 當作 shell 代碼執行)。

核心功能

審計範圍與識別對象

按官方「Known AI Action References」表,在每個 job 的 step(及需留意的 job 級 uses:)上,用 uses: 在 @ 之前的前綴匹配下列 Action(版本/ref 可忽略):

Action Reference 類型
anthropics/claude-code-action Claude Code Action
google-github-actions/run-gemini-cli Gemini CLI
google-gemini/gemini-cli-action Gemini CLI(legacy/archived)
openai/codex-action OpenAI Codex
actions/ai-inference GitHub AI Inference

除主 workflow 外,還會沿 uses: 跟進 composite action 與 reusable workflow,避免 AI 步驟藏在被引用文件裏。

方法論要點

審計按步驟遞進(資料中的 Audit Methodology):

  1. 分析模式:用戶提供 GitHub 倉庫 URL 或 owner/repo(可選 @ref)時走遠程模式;否則在本地用 Glob 掃描倉庫根目錄 .github/workflows/*.yml 與 *.yaml(不掃子目錄、vendor、測試 fixture)。
  2. 發現 workflow:統計文件數量;若無文件則停止並報告。
  3. 識別 AI Action 步驟:對照上表匹配 uses:。
  4. 採集安全相關配置:觸發事件、env:、prompt 相關字段、沙箱與工具權限、用戶 allowlist 等。
  5. 檢測攻擊向量:重點看 GitHub 事件上下文 → env: → Agent prompt 的數據流,以及直接 ${{ }} 注入、危險沙箱項等。

遠程拉取 workflow 時,官方要求用 gh api 兩步:先列目錄,再按文件取 base64 解碼內容;若指定 ref,每一次 API 調用都要帶 ?ref={ref}。不要求事先 gh auth status,失敗再提示認證或權限問題。

常見誤判(審計時要反駁)

Skill 明確列出四類容易自我安慰的理由,審計時不應採納,例如:

  • 僅維護者 PR 就安全 —— 忽略 pull_request_target、issue_comment 等外部可觸發事件。
  • allowed_tools 已限制 —— 受限工具仍可能被濫用(如通過 subshell 泄露環境)。
  • prompt 裏沒有 ${{ }} —— 經典 env var intermediary:數據經 env: 進入 prompt,YAML 表面乾淨。
  • 沙箱夠用 —— danger-full-access、Bash(*)、--yolo 等會關掉防護;配置不當仍可能讀到密鑰或掛載文件。

明確不做什麼

  • 不含 AI Agent 的 workflow:應改用通用 Actions 安全工具。
  • 單獨審 composite/reusable 且沒有 caller workflow 上下文:不適用;應在引用它們的 workflow 裏用本 Skill。
  • 非 GitHub CI(Jenkins、GitLab CI、CircleCI 等)。
  • 不自動修改 workflow,只報告發現。

安裝與啓用

Skill 隨 trailofbits/skills 市場分發,安裝市場後從插件菜單安裝 agentic-actions-auditor 即可。

Claude Code:

/plugin marketplace add trailofbits/skills

然後通過 /plugin menu 瀏覽並安裝對應插件。

Codex:

codex plugin marketplace add trailofbits/skills
codex plugin list
codex plugin add <plugin-name>@trailofbits

(將 <plugin-name> 換爲市場中的插件名,agentic-actions-auditor 在 Code Auditing 分類下。)

本地開發時,在 skills 倉庫的父目錄執行:

/plugins marketplace add ./skills

ChatGPT Workspace 可通過倉庫內 .claude-plugin/marketplace.json 導入;與 Cursor 專用的安裝方式,以你當前環境文檔爲準,本 Skill 官方頁未單獨列出 Cursor 步驟。

Skill 本體路徑:

https://github.com/trailofbits/skills/tree/main/plugins/agentic-actions-auditor/skills/agentic-actions-auditor

典型用法

在已啓用該 Skill 的 Agent 對話中,按場景發起審計即可,例如:

  • 「審計本倉庫 GitHub Actions 裏 AI Agent 的安全配置。」
  • 「檢查 owner/repo 的 workflow,外部輸入能否到達 Claude/Codex 的 prompt。」
  • 「review CI/CD configurations that invoke Claude Code Action」——與官方 When to Use 表述一致。

本地模式:Agent 用 Glob 找 .github/workflows/ 下 YAML,Read 內容後按方法論出報告。

遠程模式:提供 owner/repo、owner/repo@ref 或 https://github.com/owner/repo(及 tree/main/... 等形式)。Agent 用例如下命令拉取文件(示例爲列目錄):

gh api repos/{owner}/{repo}/contents/.github/workflows --paginate --jq '.[].name'

單文件內容:

gh api repos/{owner}/{repo}/contents/.github/workflows/{filename} --jq '.content | @base64d'

完成後應看到 workflow 數量、AI Action 實例與 findings 的彙總;無 workflow 時格式類似:「Analyzed 0 workflows, 0 AI action instances, 0 findings in owner/repo」。

適用場景與注意

適合:

  • 倉庫或組織在 CI 中已使用或計劃使用上述 AI Action。
  • 安全評審、開源貢獻前自查:觸發器是否暴露給 fork PR、issue 評論等;pull_request_target 與 base 分支上下文。
  • 評估沙箱、工具權限、allowed_users 等 agentic 配置,而非只看 prompt 字符串。

限制:

  • 靜態分析指引,不能替代運行時 prompt 注入測試。
  • 遠程分析依賴 gh 認證與對私有倉庫的 token 權限。
  • 拉取的 YAML 僅作數據分析,Skill 禁止用 Bash 將其 pipe 到解釋器或 eval。

結尾

agentic-actions-auditor 把「CI 裏跑 Agent」從功能問題拉回到數據流與配置問題:誰能在什麼事件下觸發 workflow、外部輸入如何進入 prompt、沙箱是否名存實亡。團隊若在 pipeline 裏落地 Claude、Codex、Gemini 或 GitHub AI Inference,可在代碼評審流程里加上這一步靜態審計。

官方 Skill 目錄:

https://github.com/trailofbits/skills/tree/main/plugins/agentic-actions-auditor/skills/agentic-actions-auditor

市場總覽與安裝說明:

https://github.com/trailofbits/skills

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜