Skip to content
KitploitKITPLOIT
工具漏洞利用博客
Log in
提交
工具漏洞利用博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

订阅源联系隐私© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
trivy-action — 作为GitHub Action运行Trivy,扫描您的Docker容器镜像中的漏洞 | Kitploit
工具/GitHubGitHub/aquasecurity/trivy-action
漏洞扫描器容器安全代码分析云安全DevSecOps秘密检测供应链安全错误配置
GitHubaquasecurity/trivy-action

trivy-action

作为GitHub Action运行Trivy,扫描您的Docker容器镜像中的漏洞

查看仓库
1.4k3574913天前Kitploit 审核通过
分享

Trivy Action

用于 Trivy 的 GitHub Action

[![GitHub Release][release-img]][release] [![GitHub Marketplace][marketplace-img]][marketplace] [![License][license-img]][license]

目录

  • 用法
    • 扫描 CI 流水线
    • 扫描 CI 流水线(配合 Trivy Config)
    • 缓存
    • Trivy 设置
    • 扫描 Tarball
    • 配合模板使用 Trivy
    • 配合 GitHub Code Scanning 使用 Trivy
    • 使用 Trivy 扫描你的 Git 仓库
    • 使用 Trivy 扫描你的 rootfs 目录
    • 使用 Trivy 扫描基础设施即代码
    • 使用 Trivy 生成 SBOM
    • 使用 Trivy 扫描你的私有镜像仓库
    • 在未启用代码扫描时使用 Trivy
  • 自定义
    • inputs
    • 环境变量
    • Trivy 配置文件

用法

扫描 CI 流水线

name: build
on:
  push:
    branches:
      - main
  pull_request:
jobs:
  build:
    name: Build
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Build an image from Dockerfile
        run: docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/[email protected]
        with:
          image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
          format: 'table'
          exit-code: '1'
          ignore-unfixed: true
          vuln-type: 'os,library'
          severity: 'CRITICAL,HIGH'

扫描 CI 流水线(使用 Trivy Config)

name: build
on:
  push:
    branches:
    - main
  pull_request:
jobs:
  build:
    name: Build
    runs-on: ubuntu-24.04
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Run Trivy vulnerability scanner in fs mode
      uses: aquasecurity/[email protected]
      with:
        scan-type: 'fs'
        scan-ref: '.'
        trivy-config: trivy.yaml

在这种情况下,trivy.yaml 是一个作为仓库一部分检入的 YAML 配置文件。详细信息可在 Trivy 网站上获取,示例如下:

format: json
exit-code: 1
severity: CRITICAL
secret:
  config: config/trivy/secret.yaml

可以在 trivy.yaml 文件中定义所有选项。通过 action 指定单个选项的做法仅为向后兼容而保留。以下选项必须定义,因为它们无法通过配置文件定义:

  • scan-ref:在使用 fs、repo 扫描时使用。
  • image-ref:在使用 image 扫描时使用。
  • scan-type:用于定义扫描类型,例如 image、fs、repo 等。

选项的优先级顺序

Trivy 使用 Viper,它定义了选项的优先级顺序。顺序如下:

  • GitHub Action 标志
  • 环境变量
  • 配置文件
  • 默认值

缓存

该 action 内置了缓存和恢复 漏洞数据库、Java 数据库 和 检查规则包 的功能(前提是它们在扫描期间被下载)。 缓存默认存储在 $GITHUB_WORKSPACE/.cache/trivy 目录中。 缓存在扫描开始前恢复,并在扫描结束后保存。

它在底层使用 actions/cache,但所需的配置设置更少。 缓存输入是可选的,默认开启缓存。

禁用缓存

如果你想禁用缓存,请将 cache 输入设置为 false,但我们建议保持启用,以避免触发速率限制问题。

    - name: Run Trivy scanner without cache
      uses: aquasecurity/[email protected]
      with:
        scan-type: 'fs'
        scan-ref: '.'
        cache: 'false'

在默认分支中更新缓存

请注意,GitHub Actions 中分支之间的缓存访问存在限制。 默认情况下,工作流可以访问并恢复在当前分支或默认分支(通常是 main 或 master)中创建的缓存。 如果你需要在多个分支之间共享缓存,可能需要先在默认分支中创建缓存,然后在当前分支中恢复它。

为了优化工作流,你可以设置一个 cron 任务来定期更新默认分支中的缓存。 这样,后续扫描就可以直接使用缓存的数据库,而无需再次下载。

# Note: This workflow only updates the cache. You should create a separate workflow for your actual Trivy scans.
# In your scan workflow, set TRIVY_SKIP_DB_UPDATE=true and TRIVY_SKIP_JAVA_DB_UPDATE=true.
name: Update Trivy Cache

on:
  schedule:
    - cron: '0 0 * * *'  # Run daily at midnight UTC
  workflow_dispatch:  # Allow manual triggering

jobs:
  update-trivy-db:
    runs-on: ubuntu-latest
    steps:
      - name: Setup oras
        uses: oras-project/setup-oras@v1

      - name: Get current date
        id: date
        run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

      - name: Download and extract the vulnerability DB
        run: |
          mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
          oras pull ghcr.io/aquasecurity/trivy-db:2
          tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
          rm db.tar.gz

      - name: Download and extract the Java DB
        run: |
          mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
          oras pull ghcr.io/aquasecurity/trivy-java-db:1
          tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
          rm javadb.tar.gz

      - name: Cache DBs
        uses: actions/cache/save@v4
        with:
          path: ${{ github.workspace }}/.cache/trivy
          key: cache-trivy-${{ steps.date.outputs.date }}

在执行扫描时,请设置环境变量 TRIVY_SKIP_DB_UPDATE 和 TRIVY_SKIP_JAVA_DB_UPDATE 以跳过下载过程。

    - name: Run Trivy scanner without downloading DBs
      uses: aquasecurity/[email protected]
      with:
        scan-type: 'image'
        scan-ref: 'myimage'
      env:
        TRIVY_SKIP_DB_UPDATE: true
        TRIVY_SKIP_JAVA_DB_UPDATE: true

Trivy 设置

默认情况下,该 action 会在第一步调用 aquasecurity/setup-trivy, 以安装由 version 输入指定的 trivy 版本。如果你已通过其他方式安装了 trivy, 例如直接调用 aquasecurity/setup-trivy,或多次调用此 action,则可以使用 skip-setup-trivy 输入来禁用此步骤。

手动设置 Trivy

name: build
on:
  push:
    branches:
    - main
  pull_request:
jobs:
  build:
    name: Build
    runs-on: ubuntu-24.04
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Manual Trivy Setup
      uses: aquasecurity/[email protected]
      with:
        cache: true
        version: v0.76.2

    - name: Run Trivy vulnerability scanner in repo mode
      uses: aquasecurity/[email protected]
      with:
        scan-type: 'fs'
        ignore-unfixed: true
        format: 'sarif'
        output: 'trivy-results.sarif'
        severity: 'CRITICAL'
        skip-setup-trivy: true

多次调用 Trivy Action 时跳过安装

另一个常见用例是当一次构建多次调用此 action 时,在这种情况下,我们可以在后续调用中将 skip-setup-trivy 设置为 true,例如

name: build

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Check out Git repository
        uses: actions/checkout@v4

      # The first call to the action will invoke setup-trivy and install trivy
      - name: Generate Trivy Vulnerability Report
        uses: aquasecurity/[email protected]
        with:
          scan-type: "fs"
          output: trivy-report.json
          format: json
          scan-ref: .
          exit-code: 0

      - name: Upload Vulnerability Scan Results
        uses: actions/upload-artifact@v4
        with:
          name: trivy-report
          path: trivy-report.json
          retention-days: 30

      - name: Fail build on High/Criticial Vulnerabilities
        uses: aquasecurity/[email protected]
        with:
          scan-type: "fs"
          format: table
          scan-ref: .
          severity: HIGH,CRITICAL
          ignore-unfixed: true
          exit-code: 1
          # On a subsequent call to the action we know trivy is already installed so can skip this
          skip-setup-trivy: true

使用非默认令牌安装 Trivy

GitHub Enterprise Server (GHES) 会为 https://github.com 服务器使用无效的 github.token。 因此,你无法使用 setup-trivy action 安装 Trivy。

下载工具

最受欢迎

查看全部 →

发现我们社区最常用的工具。

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 终极 OSINT 工具包:调查图谱、置信度评分、别名家族、地图、时间线和报告。49 个模块、400+ 个站点,无需 API 密钥。

    772
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock 一键执行应用(CVE-2026-43499)

    505
  • 3

    ARTEX

    baarai/artex

    基于LLM的多智能体自主渗透测试平台,具备规划器/执行器智能体、资产与探索图谱、MITM流量记录以及漏洞复测功能。

    420
  • 4

    redforge

    cybersecurity91/redforge

    浏览器端红队工具包,包含 102 个离线工具,用于侦察、载荷生成、凭据攻击、加密、编码和交战报告。

    345
  • 5

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    AI原生网络安全的行动系统——在这里,意图转化为受治理的执行,证据沉淀为运营记忆,每一次操作都让下一次更出色。

    260
  • 6

    antifox

    antifox-ai/antifox

    AI multi-agent autonomous penetration testing platform that runs recon, attack-surface discovery, exploitation validation and evidence-backed report delivery.

    251

探索所有工具

浏览我们的工具集合

查看所有工具 →