implementing-aqua-security-for-container-scanning
部署 Aqua Security 的 Trivy 扫描器,在 CI/CD 管道和镜像仓库中检测容器镜像的漏洞、配置错误、敏感信息和许可证问题。
Best use case
implementing-aqua-security-for-container-scanning is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
部署 Aqua Security 的 Trivy 扫描器,在 CI/CD 管道和镜像仓库中检测容器镜像的漏洞、配置错误、敏感信息和许可证问题。
Teams using implementing-aqua-security-for-container-scanning should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/implementing-aqua-security-for-container-scanning/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How implementing-aqua-security-for-container-scanning Compares
| Feature / Agent | implementing-aqua-security-for-container-scanning | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
部署 Aqua Security 的 Trivy 扫描器,在 CI/CD 管道和镜像仓库中检测容器镜像的漏洞、配置错误、敏感信息和许可证问题。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 为容器扫描实施 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 基础上扩展了集中式策略管理、运行时保护和合规性报告功能。
## 前置条件
- 已安装 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 归档文件。
```bash
# 扫描远程镜像
trivy image python:3.11-slim
# 按严重性过滤扫描
trivy image --severity HIGH,CRITICAL nginx:latest
# 扫描并在发现严重 CVE 时使 CI 失败
trivy image --exit-code 1 --severity CRITICAL myapp:latest
# 以 CycloneDX 格式生成 SBOM
trivy image --format cyclonedx --output sbom.json myapp:latest
```
### 文件系统和仓库扫描
```bash
# 扫描项目目录中依赖项的漏洞
trivy fs --scanners vuln,secret,misconfig .
# 扫描特定锁定文件
trivy fs --scanners vuln package-lock.json
# 扫描 git 仓库
trivy repo https://github.com/org/project
```
### 使用 Trivy Operator 扫描 Kubernetes
Trivy Operator 在 Kubernetes 集群内运行,持续扫描工作负载:
```bash
# 通过 Helm 安装 Trivy Operator
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 配置错误扫描
```bash
# 扫描 Terraform 文件
trivy config --severity HIGH,CRITICAL ./terraform/
# 扫描 Dockerfile 的配置错误
trivy config Dockerfile
# 扫描 Kubernetes 清单
trivy config ./k8s-manifests/
```
## CI/CD 集成
### GitHub Actions
```yaml
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
```yaml
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
```groovy
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` 用于自定义策略执行:
```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 生成和管理
```bash
# 生成 CycloneDX SBOM
trivy image --format cyclonedx --output sbom-cyclonedx.json myapp:latest
# 生成 SPDX SBOM
trivy image --format spdx-json --output sbom-spdx.json myapp:latest
# 扫描现有 SBOM 中的新漏洞
trivy sbom sbom-cyclonedx.json
```
## 监控与报告
| 指标 | 描述 | 目标 |
|------|------|------|
| 每日扫描镜像数 | 通过扫描管道的镜像总数 | 所有生产镜像 |
| 严重 CVE 数量 | 所有镜像中未修复的严重漏洞 | 生产环境为 0 |
| 平均修复时间 | 从 CVE 发布到镜像修补的平均天数 | < 7 天 |
| SBOM 覆盖率 | 已生成 SBOM 的生产镜像百分比 | 100% |
| 扫描时长 | 每次镜像扫描的平均时间 | < 2 分钟 |
## 参考资料
- [Trivy Documentation](https://aquasecurity.github.io/trivy/)
- [Trivy GitHub Repository](https://github.com/aquasecurity/trivy)
- [Trivy Operator for Kubernetes](https://aquasecurity.github.io/trivy-operator/)
- [Aqua Security Platform](https://www.aquasec.com/products/)
- [CycloneDX SBOM Specification](https://cyclonedx.org/specification/overview/)Related Skills
triaging-security-incident
使用 NIST SP 800-61r3 和 SANS PICERL 框架对安全事件进行初始分类,确定严重性、范围和所需响应行动。 按类型对事件分类,根据业务影响分配优先级,并路由到相应的响应团队。适用于事件分类、 安全告警分类、严重性评估、事件优先级排序或初始事件分析等请求场景。
triaging-security-incident-with-ir-playbook
使用结构化 IR Playbook 对安全事件进行分类和优先排序,确定严重性、分配响应团队并启动适当的响应程序。
triaging-security-alerts-in-splunk
在 Splunk Enterprise Security 中对安全告警进行分类,通过 SPL 查询和事件审查(Incident Review) 仪表板对重要事件进行严重性分类、调查、关联相关遥测并做出升级或关闭决策。 适用于 SOC 分析师需要处理关联搜索产生的告警队列、确定调查优先级, 或需要为交接给二/三级分析师记录分类决策时。
testing-websocket-api-security
测试 WebSocket API 实现中的安全漏洞,包括 WebSocket 升级时缺少身份认证、跨站 WebSocket 劫持(Cross-Site WebSocket Hijacking,CSWSH)、通过 WebSocket 消息进行的注入攻击、输入校验不足、通过消息泛洪实施拒绝服务,以及通过 WebSocket 帧造成的信息泄露。测试人员使用 Burp Suite 拦截 WebSocket 握手和消息,构造恶意 payload,并测试 WebSocket 通道上的授权绕过。适用于 WebSocket 安全测试、WS 渗透测试、CSWSH 攻击或实时 API 安全评估相关请求。
testing-jwt-token-security
在安全测试活动中,评估 JSON Web Token(JWT)实现中的密码学弱点、算法混淆攻击和授权绕过漏洞。
testing-api-security-with-owasp-top-10
使用自动化和手工测试技术,针对 OWASP API 安全 Top 10 风险对 REST 和 GraphQL API 端点进行系统性评估。
securing-container-registry-with-harbor
Harbor 是一个开源容器镜像仓库,提供安全功能包括漏洞扫描(集成 Trivy)、镜像签名(Notary/Cosign)、RBAC、内容信任策略(Content Trust)、复制和审计日志。配置这些功能以强制执行镜像来源验证、防止有漏洞镜像部署并维护仓库访问控制。
securing-container-registry-images
通过使用 Trivy 和 Grype 实施漏洞扫描、使用 Cosign 和 Sigstore 强制执行镜像签名、配置镜像仓库访问控制,以及构建阻止部署未扫描或未签名镜像的 CI/CD 流水线,来保护容器仓库(Container Registry)中的镜像安全。
scanning-network-with-nmap-advanced
使用 Nmap 的脚本引擎、时序控制、规避技术和输出解析,对授权目标网络执行高级网络侦察, 发现主机、枚举服务、检测漏洞并识别操作系统。
scanning-kubernetes-manifests-with-kubesec
使用 Kubesec 对 Kubernetes 资源清单执行安全风险分析,识别错误配置、权限提升风险以及与安全最佳实践的偏差。
scanning-infrastructure-with-nessus
Tenable Nessus 是业界领先的漏洞扫描器,用于识别网络基础设施(包括服务器、工作站、网络设备和操作系统)中的安全弱点。
scanning-docker-images-with-trivy
Trivy 是 Aqua Security 开源的综合性漏洞扫描器,用于检测容器镜像中操作系统软件包、语言特定依赖项的漏洞、错误配置、密钥和许可证违规,并集成到 CI/CD 流水线,支持 SARIF、CycloneDX 和 SPDX 等多种输出格式。