Skillpedia
الوكلاء35k · #8357

scanning-containers-with-trivy-in-cicd

ما الذي تفعله

يؤتمت هذا النظام فحوص الأمان لصور الحاويات. يبحث عن الثغرات الأمنية المعروفة في البرمجيات والأنظمة، وكذلك الأخطاء في الإعدادات داخل شيفرتك، قبل أن تصل إلى بيئة الإنتاج.

متى تستخدمها

  • ✓عندما تبني صور الحاويات في عمليات التطوير الآلية.
  • ✓عندما تحتاج إلى التأكد من أن الصور التي بها مشكلات خطيرة لا تصل إلى البيئة النهائية.
  • ✓عندما تتحقق من أن ملفات الإعداد، مثل Dockerfile وملفات manifests الخاصة بـ Kubernetes، آمنة.

رابط المهارة

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/scanning-containers-with-trivy-in-cicd/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/scanning-containers-with-trivy-in-cicd/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“ساعدني في فحص صورة الحاوية الخاصة بي بحثاً عن الثغرات الحرجة والإعدادات الخاطئة قبل رفعها إلى السجل.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يستخدم هذا النظام أداة Trivy لتحليل صورة الحاوية. يبحث عن المشكلات المعروفة ويتحقق من أن الإعدادات تتبع أفضل ممارسات الأمان.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Scanning Containers with Trivy in CI/CD

When to Use

  • When building Docker container images in CI/CD and needing automated vulnerability scanning before registry push
  • When establishing quality gates that prevent images with critical or high CVEs from reaching production
  • When compliance requirements mandate vulnerability scanning of all container images before deployment
  • When scanning IaC files (Dockerfiles, Kubernetes manifests) alongside container image scanning
  • When needing a single tool to scan OS packages, language-specific dependencies, and misconfigurations

Do not use for runtime container security monitoring (use Falco), for scanning running containers in production (use runtime agents), or when only scanning application source code without containerization (use SAST tools).

Prerequisites

  • Trivy CLI installed (v0.50+) or access to aquasecurity/trivy-action GitHub Action
  • Docker daemon available in CI/CD for building and scanning images
  • Container registry credentials for pulling base images and pushing scanned images
  • Trivy vulnerability database accessible (downloaded automatically or cached)

Workflow

Step 1: Configure Trivy Scanning in GitHub Actions

Set up a GitHub Actions workflow that builds a Docker image and scans it with Trivy before pushing to a container registry.

# .github/workflows/container-security.yml
name: Container Security Scan

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
    paths:
      - 'Dockerfile'
      - 'docker-compose*.yml'
      - 'src/**'
      - 'requirements*.txt'
      - 'package*.json'

jobs:
  build-and-scan:
    runs-on: ubuntu-latest
    permissions:
      security-events: write
      contents: read

    steps:
      - uses: actions/checkout@v4

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

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

      - name: Upload Trivy scan results
        uses: github/codeql-action/upload-sarif@v3
        if: always()
        with:
          sarif_file: 'trivy-results.sarif'
          category: 'trivy-container'

      - name: Run Trivy misconfiguration scanner
        uses: aquasecurity/trivy-action@0.28.0
        with:
          scan-type: 'config'
          scan-ref: '.'
          format: 'table'
          exit-code: '1'
          severity: 'CRITICAL,HIGH'

Step 2: Scan Dockerfiles for Misconfigurations

Trivy detects common Dockerfile security issues such as running as root, using latest tags, and exposing unnecessary ports.

# Scan Dockerfile for misconfigurations
trivy config --severity HIGH,CRITICAL ./Dockerfile

# Scan with custom policy directory
trivy config --policy ./security-policies --severity MEDIUM,HIGH,CRITICAL .

# Example secure Dockerfile practices Trivy checks for:
# - USER instruction present (not running as root)
# - HEALTHCHECK instruction defined
# - Base image uses specific tag, not :latest
# - No secrets in ENV or ARG instructions
# - COPY preferred over ADD

Step 3: Integrate with GitLab CI/CD

# .gitlab-ci.yml
stages:
  - build
  - scan
  - push

variables:
  TRIVY_CACHE_DIR: .trivycache/

build:
  stage: build
  script:
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
    - docker save $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -o image.tar
  artifacts:
    paths:
      - image.tar

trivy-scan:
  stage: scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  cache:
    paths:
      - .trivycache/
  script:
    - trivy image
        --input image.tar
        --exit-code 1
        --severity CRITICAL,HIGH
        --ignore-unfixed
        --format json
        --output trivy-report.json
    - trivy image
        --input image.tar
        --severity CRITICAL,HIGH,MEDIUM
        --format table
  artifacts:
    reports:
      container_scanning: trivy-report.json
    paths:
      - trivy-report.json
  allow_failure: false

push:
  stage: push
  needs: [trivy-scan]
  script:
    - docker load -i image.tar
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

Step 4: Configure Trivy Ignore and Exception Handling

Manage false positives and accepted risks through Trivy's ignore file and VEX statements.

…

الأسئلة الشائعة

ما هي CVEs؟

CVEs معرّفات فريدة للثغرات الأمنية المعروفة في البرمجيات.

ما هي « بوابات الجودة »؟

هي حواجز أمنية تمنع انتقال شيء ما (مثل صورة حاوية) إلى المرحلة التالية إذا لم يستوفِ معايير الجودة أو الأمان.

هل يمكنني تجاهل بعض الثغرات؟

نعم، يمكنك ضبط النظام لتجاهل ثغرات محددة إذا كان لديك سبب وجيه وتوثّقه.

التفاصيل

الوصف الأصلي من المؤلف

Integrates Aqua Security''s Trivy scanner into CI/CD pipelines to detect OS package and application dependency CVEs, Dockerfile misconfigurations, and issues in filesystems or git repositories, and to enforce severity-based quality gates that block vulnerable images from being deployed. Use when building Docker images in CI/CD and needing automated vulnerability scanning and pass/fail gates before

repo: mukul975/Anthropic-Cybersecurity-Skills

الشعبية

نجوم GitHub
35k
الترتيب
#8357
الترخيص
Apache-2.0
آخر تحديث
31‏/8‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة