mcpField
I
implementing-aqua-security-for-container-scanning

implementing-aqua-security-for-container-scanning

github.com/mukul975安全35.2k57 次安装8 周前更新
代码仓库

关于 implementing-aqua-security-for-container-scanning

这是关于使用 Aqua Security 的 Trivy 进行容器及相关环境安全扫描的实践指南,面向负责安全和 CI/CD 的团队。内容涵盖漏洞与配置检查、Kubernetes 扫描、策略执行及 SBOM 管理。

主要功能

  1. 01容器镜像漏洞扫描
  2. 02文件系统与代码仓库扫描
  3. 03Kubernetes 工作负载持续扫描
  4. 04IaC 配置检查
  5. 05CI/CD 集成与策略执行
  6. 06SBOM 生成与扫描

适用场景

  1. 01在 CI 流水线中阻止含严重漏洞的镜像
  2. 02检查 Kubernetes 工作负载的漏洞与配置
  3. 03扫描 Terraform 和 Kubernetes 清单
  4. 04生成并重新检查镜像 SBOM

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill implementing-aqua-security-for-container-scanning

安装后在 Claude Code 中输入/implementing-aqua-security-for-container-scanning确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py
process.py

详细介绍

为容器扫描实施 Aqua Security

概述

Aqua Security 提供 Trivy,这是全球最受欢迎的开源通用安全扫描器,旨在发现容器、Kubernetes、代码仓库和云环境中的漏洞、错误配置、密钥、SBOM 数据和许可证问题。Trivy 覆盖操作系统软件包(Alpine、Debian、Ubuntu、RHEL 等)以及特定语言的依赖项(npm、pip、Maven、Go modules、Cargo 等),其漏洞数据库来源于 NVD、供应商公告和 GitHub Security Advisories。企业版 Aqua Platform 通过集中式策略管理、运行时保护和合规报告对 Trivy 进行了扩展。

使用场景

  • 在你的环境中部署或配置容器扫描的 Aqua Security 实施能力时
  • 建立与合规要求一致的安全控制时
  • 为该领域构建或改进安全架构时
  • 开展需要此实施的安全评估时

前置条件

  • 安装 Docker 以进行本地镜像扫描
  • CI/CD 平台(GitHub Actions、GitLab CI、Jenkins 等)
  • 容器镜像仓库访问权限(Docker Hub、ECR、GCR、ACR、Harbor)
  • Trivy CLI(trivy)或用于 Kubernetes 的 Trivy Operator
  • 用于企业功能的 Aqua Platform 许可证(可选)

核心扫描能力

镜像漏洞扫描

Trivy 逐层扫描容器镜像,识别操作系统软件包和应用程序依赖项中的 CVE。它支持扫描本地镜像、远程仓库镜像和 tar 归档。

# Scan a remote image
trivy image python:3.11-slim

# Scan with severity filter
trivy image --severity HIGH,CRITICAL nginx:latest

# Scan and fail CI if critical CVEs found
trivy image --exit-code 1 --severity CRITICAL myapp:latest

# Generate SBOM in CycloneDX format
trivy image --format cyclonedx --output sbom.json myapp:latest
文件系统和仓库扫描
# Scan project directory for vulnerabilities in dependencies
trivy fs --scanners vuln,secret,misconfig .

# Scan a specific lockfile
trivy fs --scanners vuln package-lock.json

# Scan git repository
trivy repo https://github.com/org/project
使用 Trivy Operator 进行 Kubernetes 扫描

Trivy Operator 在 Kubernetes 集群内运行,并持续扫描工作负载:

# Install Trivy Operator via Helm
helm repo add aqua https://aquasecurity.github.io/helm-charts/
helm repo update
helm install trivy-operator aqua/trivy-operator \
  --namespace trivy-system \
  --create-namespace \
  --set trivy.severity="HIGH,CRITICAL" \
  --set operator.scanJobTimeout="5m"

该 Operator 会为每个工作负载创建 VulnerabilityReport 和 ConfigAuditReport 自定义资源。

IaC 错误配置
# Scan Terraform files
trivy config --severity HIGH,CRITICAL ./terraform/

# Scan Dockerfile for misconfigurations
trivy config Dockerfile

# Scan Kubernetes manifests
trivy config ./k8s-manifests/

CI/CD 集成

GitHub Actions
name: Container Security Scan
on:
  push:
    branches: [main]
  pull_request:

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build Docker image
        run: docker build -t myapp:${{ github.sha }} .

      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: 'myapp:${{ github.sha }}'
          format: 'sarif'
          output: 'trivy-results.sarif'
          severity: 'CRITICAL,HIGH'
          exit-code: '1'

      - name: Upload Trivy scan results to GitHub Security tab
        uses: github/codeql-action/upload-sarif@v3
        if: always()
        with:
          sarif_file: 'trivy-results.sarif'
GitLab CI
container_scanning:
  stage: security
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  variables:
    FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  script:
    - trivy image --exit-code 0 --format template --template "@/contrib/gitlab.tpl"
      --output gl-container-scanning-report.json $FULL_IMAGE_NAME
    - trivy image --exit-code 1 --severity CRITICAL $FULL_IMAGE_NAME
  artifacts:
    reports:
      container_scanning: gl-container-scanning-report.json
Jenkins Pipeline
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'docker build -t myapp:${BUILD_NUMBER} .'
            }
        }
        stage('Security Scan') {
            steps {
                sh '''
                    trivy image --exit-code 1 \
                      --severity HIGH,CRITICAL \
                      --format json \
                      --output trivy-report.json \
                      myapp:${BUILD_NUMBER}
                '''
            }
            post {
                always {
                    archiveArtifacts artifacts: 'trivy-report.json'
                }
            }
        }
    }
}

策略配置

使用 OPA/Rego 的 Trivy 策略

创建 .trivy/policy.rego 以配置自定义策略:

package trivy

deny[msg] {
    input.Results[_].Vulnerabilities[_].Severity == "CRITICAL"
    msg := "Critical vulnerabilities found in image"
}

deny[msg] {
    input.Results[_].Vulnerabilities[vuln]
    vuln.FixedVersion != ""
    vuln.Severity == "HIGH"
    msg := sprintf("Fixable HIGH vulnerability: %s", [vuln.VulnerabilityID])
}
忽略文件配置

创建 .trivyignore 以记录已接受的风险:

# Accepted risk: vulnerability in test dependency only
CVE-2023-12345

# Accepted until expiry date
CVE-2024-67890 exp:2025-06-01

SBOM 生成与管理

# Generate CycloneDX SBOM
trivy image --format cyclonedx --output sbom-cyclonedx.json myapp:latest

# Generate SPDX SBOM
trivy image --format spdx-json --output sbom-spdx.json myapp:latest

# Scan an existing SBOM for new vulnerabilities
trivy sbom sbom-cyclonedx.json

监控与报告

指标描述目标
每日扫描镜像数通过扫描流水线的镜像总数所有生产镜像
严重 CVE 数量所有镜像中未修复的严重漏洞生产环境为 0
平均修复时间从 CVE 公布到镜像修复的平均天数< 7 天
SBOM 覆盖率已生成 SBOM 的生产镜像百分比100%
扫描时长每个镜像扫描的平均时间< 2 分钟

参考资料

评论

支持 Markdown