container-scan-trivy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Container Scanning with Trivy

使用Trivy进行容器扫描

You are a security engineer running container security scanning using Trivy to detect vulnerabilities, misconfigurations, and secrets in container images.
你是一名安全工程师,正在使用Trivy对容器镜像进行安全扫描,以检测其中的漏洞、配置错误和敏感信息。

When to use

适用场景

Use this skill when asked to scan a Docker/OCI container image for vulnerabilities, or scan a filesystem for security issues.
当你需要扫描Docker/OCI容器镜像以查找漏洞,或扫描文件系统排查安全问题时,可使用此技能。

Prerequisites

前置条件

  • Trivy installed (
    brew install trivy
    or
    apt install trivy
    )
  • Verify:
    trivy --version
  • 已安装Trivy(执行
    brew install trivy
    apt install trivy
    进行安装)
  • 验证安装:
    trivy --version

Instructions

操作步骤

  1. Identify the target — Determine the container image or scan target.
  2. Run the scan:
    Container image:
    bash
    trivy image --format json --output trivy-results.json <image>:<tag>
    Filesystem:
    bash
    trivy fs --format json --output trivy-results.json <path>
    IaC / Config:
    bash
    trivy config --format json --output trivy-results.json <path>
    • Severity filter:
      trivy image --severity HIGH,CRITICAL --format json <image>
    • Ignore unfixed:
      trivy image --ignore-unfixed --format json <image>
    • Scan for secrets too:
      trivy image --scanners vuln,secret --format json <image>
  3. Parse the results — Read JSON output and present findings:
| # | Severity | CVE | Package | Installed | Fixed | Type (OS/library) | Title |
|---|----------|-----|---------|-----------|-------|--------------------|-------|
  1. Summarize — Provide:
    • Total vulnerabilities by severity
    • Base image vulnerabilities vs application dependencies
    • Upgrade commands or base image update recommendations
    • Whether rebuilding the image would resolve the issues
  1. 确定扫描目标 —— 明确要扫描的容器镜像或目标对象。
  2. 运行扫描:
    容器镜像扫描:
    bash
    trivy image --format json --output trivy-results.json <image>:<tag>
    文件系统扫描:
    bash
    trivy fs --format json --output trivy-results.json <path>
    基础设施即代码(IaC)/配置扫描:
    bash
    trivy config --format json --output trivy-results.json <path>
    • 按风险等级过滤:
      trivy image --severity HIGH,CRITICAL --format json <image>
    • 忽略未修复的漏洞:
      trivy image --ignore-unfixed --format json <image>
    • 同时扫描敏感信息:
      trivy image --scanners vuln,secret --format json <image>
  3. 解析扫描结果 —— 读取JSON输出并整理发现的问题:
| 序号 | 风险等级 | CVE编号 | 软件包 | 已安装版本 | 修复版本 | 类型(操作系统/软件库) | 标题 |
|---|----------|-----|---------|-----------|-------|--------------------|-------|
  1. 生成总结 —— 提供以下内容:
    • 各风险等级的漏洞总数
    • 基础镜像漏洞与应用依赖漏洞的对比
    • 升级命令或基础镜像更新建议
    • 重新构建镜像是否能解决这些问题