Sca trivy

From aiskillstore/marketplace · View interactive version

Sca trivy is an AI agent skill from the GitHub repository aiskillstore/marketplace. Software Composition Analysis (SCA) and container vulnerability scanning using Aqua Trivy for identifying CVE vulnerabilities in dependencies, container images, IaC misconfigurations, and license compliance risks. Use when: (1) Scanning container images and filesystems for vulnerabilities and miscon

How to use this skill

Skill file

Software Composition Analysis with Trivy

Overview

Trivy is a comprehensive security scanner for containers, filesystems, and git repositories. It detects

vulnerabilities (CVEs) in OS packages and application dependencies, IaC misconfigurations, exposed secrets,

and software licenses. This skill provides workflows for vulnerability scanning, SBOM generation, CI/CD

integration, and remediation prioritization aligned with CVSS and OWASP standards.

Quick Start

Scan a container image for vulnerabilities:

# Install Trivy
brew install trivy  # macOS
# or: apt-get install trivy  # Debian/Ubuntu
# or: docker pull aquasec/trivy:latest

# Scan container image
trivy image nginx:latest

# Scan local filesystem for dependencies
trivy fs .

# Scan IaC files for misconfigurations
trivy config .

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

Core Workflows

Workflow 1: Container Image Security Assessment

Progress:

[ ] 1. Identify target container image (repository:tag)

[ ] 2. Run comprehensive Trivy scan with trivy image <image-name>

[ ] 3. Analyze vulnerability findings by severity (CRITICAL, HIGH, MEDIUM, LOW)

[ ] 4. Map CVE findings to CWE categories and OWASP references

[ ] 5. Check for available patches and updated base images

[ ] 6. Generate prioritized remediation report with upgrade recommendations

Work through each step systematically. Check off completed items.

Workflow 2: Dependency Vulnerability Scanning

Scan project dependencies for known vulnerabilities:

# Scan filesystem for all dependencies
trivy fs --severity CRITICAL,HIGH .

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

# Generate JSON report for analysis
trivy fs --format json --output trivy-report.json .

# Generate SARIF for GitHub/GitLab integration
trivy fs --format sarif --output trivy.sarif .

For each vulnerability:

  1. Review CVE details and CVSS score
  2. Check if fixed version is available
  3. Consult references/remediation_guide.md for language-specific guidance
  4. Update dependency to patched version
  5. Re-scan to validate fix

Workflow 3: Infrastructure as Code Security

Detect misconfigurations in IaC files:

# Scan Terraform configurations
trivy config ./terraform --severity CRITICAL,HIGH

# Scan Kubernetes manifests
trivy config ./k8s --severity CRITICAL,HIGH

# Scan Dockerfile best practices
trivy config --file-patterns dockerfile:Dockerfile .

# Generate report with remediation guidance
trivy config --format json --output iac-findings.json .

Review findings by category:

Workflow 4: CI/CD Pipeline Integration

GitHub Actions
name: Trivy Security Scan
on: [push, pull_request]

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

      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          scan-type: 'fs'
          scan-ref: '.'
          format: 'sarif'
          output: 'trivy-results.sarif'
          severity: 'CRITICAL,HIGH'

      - name: Upload results to GitHub Security
        uses: github/codeql-action/upload-sarif@v2
        with:
          sarif_file: 'trivy-results.sarif'
GitLab CI
trivy-scan:
  stage: test
  image: aquasec/trivy:latest
  script:
    - trivy fs --exit-code 1 --severity CRITICAL,HIGH --format json --output trivy-report.json .
  artifacts:
    reports:
      dependency_scanning: trivy-report.json
    when: always
  allow_failure: false

Use bundled templates from assets/ci_integration/ for additional platforms.

Workflow 5: SBOM Generation

Generate Software Bill of Materials for supply chain transparency:

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

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

# SBOM for filesystem/project
trivy fs --format cyclonedx --output project-sbom.json .

SBOM use cases:

Security Considerations

Sensitive Data Handling

Access Control

Audit Logging

Log the following for compliance and incident response:

Compliance Requirements

Bundled Resources

Scripts (`scripts/`)

References (`references/`)

Assets (`assets/`)

Common Patterns

Pattern 1: Multi-Stage Security Scanning

Comprehensive security assessment combining multiple scan types:

# 1. Scan container image for vulnerabilities
trivy image --severity CRITICAL,HIGH myapp:latest

# 2. Scan IaC for misconfigurations
trivy config ./infrastructure --severity CRITICAL,HIGH

# 3. Scan filesystem for dependency vulnerabilities
trivy fs --severity CRITICAL,HIGH ./app

# 4. Scan for exposed secrets
trivy fs --scanners secret ./app

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

Pattern 2: Baseline Vulnerability Tracking

Implement baseline scanning to track only new vulnerabilities:

# Initial scan - create baseline
trivy image --format json --output baseline.json nginx:latest

# Subsequent scans - detect new vulnerabilities
trivy image --format json --output current.json nginx:latest
./scripts/baseline_manager.py --baseline baseline.json --current current.json

Pattern 3: License Compliance Scanning

Detect license compliance risks:

# Scan for license information
trivy image --scanners license --format json --output licenses.json myapp:latest

# Filter by license type
trivy image --scanners license --severity HIGH,CRITICAL myapp:latest

Review findings:

Pattern 4: Custom Policy Enforcement

Apply custom security policies with OPA:

# Create Rego policy in assets/policy_template.rego
# Deny images with CRITICAL vulnerabilities or outdated packages

# Run scan with policy enforcement
trivy image --format json --output scan.json myapp:latest
trivy image --ignore-policy assets/policy_template.rego myapp:latest

Integration Points

CI/CD Integration

Container Platforms

Security Tools Ecosystem

Troubleshooting

Issue: High False Positive Rate

Symptoms: Many vulnerabilities reported that don't apply to your use case

Solution:

  1. Use .trivyignore file to suppress specific CVEs with justification
  2. Filter by exploitability: trivy image --ignore-unfixed myapp:latest
  3. Apply severity filtering: --severity CRITICAL,HIGH
  4. Review vendor-specific security advisories for false positive validation
  5. See references/false_positives.md for common patterns

Issue: Performance Issues on Large Images

Symptoms: Scans taking excessive time or high memory usage

Solution:

  1. Use cached DB: trivy image --cache-dir /path/to/cache myapp:latest
  2. Skip unnecessary scanners: --scanners vuln (exclude config, secret)
  3. Use offline mode after initial DB download: --offline-scan
  4. Increase timeout: --timeout 30m
  5. Scan specific layers: --removed-pkgs to exclude removed packages

Issue: Missing Vulnerabilities for Specific Languages

Symptoms: Expected CVEs not detected in application dependencies

Solution:

  1. Verify language support: Check supported languages and file patterns
  2. Ensure dependency manifests are present (package.json, go.mod, requirements.txt)
  3. Include lock files for accurate version detection
  4. For compiled binaries, scan source code separately
  5. Consult references/scanner_types.md for language-specific requirements

Issue: Registry Authentication Failures

Symptoms: Unable to scan private container images

Solution:

# Use Docker credential helper
docker login registry.example.com
trivy image registry.example.com/private/image:tag

# Or use environment variables
export TRIVY_USERNAME=user
export TRIVY_PASSWORD=pass
trivy image registry.example.com/private/image:tag

# Or use credential file
trivy image --username user --password pass registry.example.com/private/image:tag

Advanced Configuration

Custom Trivy Configuration

Create trivy.yaml configuration file:

# trivy.yaml
vulnerability:
  type: os,library
severity: CRITICAL,HIGH,MEDIUM
ignorefile: .trivyignore
ignore-unfixed: false
skip-files:
  - "test/**"
  - "**/node_modules/**"

cache:
  dir: /tmp/trivy-cache

db:
  repository: ghcr.io/aquasecurity/trivy-db:latest

output:
  format: json
  severity-sort: true

Use with: trivy image --config trivy.yaml myapp:latest

Trivy Ignore File

Create .trivyignore to suppress specific CVEs:

# .trivyignore
# False positive - patched in vendor fork
CVE-0000-12345

# Risk accepted by security team - JIRA-1234
CVE-0000-67890

# No fix available, compensating controls in place
CVE-0000-11111

Offline Air-Gapped Scanning

For air-gapped environments:

# On internet-connected machine:
trivy image --download-db-only --cache-dir /path/to/db

# Transfer cache to air-gapped environment

# On air-gapped machine:
trivy image --skip-db-update --cache-dir /path/to/db --offline-scan myapp:latest

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.