securing-container-registry-images
Securing container registry images by implementing vulnerability scanning with Trivy and Grype, enforcing image signing with Cosign and Sigstore, configuring registry access controls, and building CI/CD pipelines that prevent deploying unscanned or unsigned images.
What this skill does
# Securing Container Registry Images ## When to Use - When establishing security controls for container image registries (ECR, ACR, GCR, Docker Hub) - When building CI/CD pipelines that enforce vulnerability scanning before image promotion - When implementing image signing and verification to prevent supply chain attacks - When auditing existing registries for vulnerable, unscanned, or unsigned images - When compliance requires software bill of materials (SBOM) for deployed container images **Do not use** for runtime container security (use Falco or Sysdig), for Kubernetes admission control (use OPA Gatekeeper or Kyverno after establishing registry controls), or for host-level vulnerability scanning (use Amazon Inspector or Qualys). ## Prerequisites - Trivy installed (`brew install trivy` or `apt install trivy`) - Grype installed (`curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh`) - Cosign installed for image signing (`go install github.com/sigstore/cosign/v2/cmd/cosign@latest`) - Syft installed for SBOM generation (`curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh`) - Container registry access (ECR, ACR, GCR, or private registry) ## Workflow ### Step 1: Scan Images for Vulnerabilities with Trivy Run comprehensive vulnerability scans against container images before and after pushing to the registry. ```bash # Scan a local image for vulnerabilities trivy image --severity HIGH,CRITICAL myapp:latest # Scan a remote registry image trivy image --severity HIGH,CRITICAL 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Scan with JSON output for CI/CD processing trivy image --format json --output trivy-results.json myapp:latest # Scan for vulnerabilities AND misconfigurations trivy image --scanners vuln,misconfig,secret myapp:latest # Scan a specific image with SBOM output trivy image --format spdx-json --output sbom.json myapp:latest # Fail CI/CD if critical vulnerabilities found trivy image --exit-code 1 --severity CRITICAL myapp:latest ``` ### Step 2: Scan with Grype for Additional Coverage Use Grype as a complementary scanner for broader vulnerability database coverage. ```bash # Scan image with Grype grype myapp:latest # Scan with severity threshold grype myapp:latest --fail-on critical # Output in JSON for processing grype myapp:latest -o json > grype-results.json # Scan an SBOM instead of the image directly syft myapp:latest -o spdx-json > sbom.json grype sbom:sbom.json # Scan a directory-based image export grype dir:/path/to/image-rootfs ``` ### Step 3: Generate Software Bill of Materials (SBOM) Create SBOMs for all images to maintain an inventory of software components and dependencies. ```bash # Generate SBOM with Syft in SPDX format syft myapp:latest -o spdx-json > sbom-spdx.json # Generate SBOM in CycloneDX format syft myapp:latest -o cyclonedx-json > sbom-cyclonedx.json # Attach SBOM to the image as an OCI artifact cosign attach sbom --sbom sbom-spdx.json \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Verify SBOM contents syft myapp:latest -o table | head -50 ``` ### Step 4: Sign Images with Cosign and Sigstore Implement image signing to ensure image integrity and authenticity in the supply chain. ```bash # Generate a key pair for signing cosign generate-key-pair # Sign an image in the registry cosign sign --key cosign.key \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Sign using keyless signing with Sigstore (OIDC-based) cosign sign --yes \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Verify image signature cosign verify --key cosign.pub \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Verify keyless signature cosign verify \ --certificate-identity [email protected] \ --certificate-oidc-issuer https://accounts.google.com \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest # Add attestation with scan results cosign attest --predicate trivy-results.json \ --key cosign.key \ 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest ``` ### Step 5: Configure Registry-Level Security Controls Set up registry-specific security features for ECR, ACR, and GCR. ```bash # AWS ECR: Enable image scanning on push aws ecr put-image-scanning-configuration \ --repository-name myapp \ --image-scanning-configuration scanOnPush=true # ECR: Set image tag immutability (prevent tag overwrites) aws ecr put-image-tag-mutability \ --repository-name myapp \ --image-tag-mutability IMMUTABLE # ECR: Set lifecycle policy to clean up untagged images aws ecr put-lifecycle-policy \ --repository-name myapp \ --lifecycle-policy-text '{ "rules": [{ "rulePriority": 1, "description": "Remove untagged images after 7 days", "selection": {"tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 7}, "action": {"type": "expire"} }] }' # ECR: Get scan findings for an image aws ecr describe-image-scan-findings \ --repository-name myapp \ --image-id imageTag=latest \ --query 'imageScanFindings.findingSeverityCounts' # Azure ACR: Enable Defender for container registries az security pricing create --name ContainerRegistry --tier standard # GCR: Enable Container Analysis gcloud services enable containeranalysis.googleapis.com gcloud artifacts docker images list-vulnerabilities \ LOCATION-docker.pkg.dev/PROJECT/REPO/IMAGE@sha256:DIGEST ``` ### Step 6: Build CI/CD Pipeline with Security Gates Integrate scanning and signing into the CI/CD pipeline as mandatory gates. ```yaml # GitHub Actions: Scan, sign, and push image name: Container Security Pipeline on: push jobs: build-scan-sign: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build image run: docker build -t myapp:${{ github.sha }} . - name: Trivy vulnerability scan uses: aquasecurity/trivy-action@master with: image-ref: myapp:${{ github.sha }} format: json output: trivy-results.json severity: CRITICAL,HIGH exit-code: 1 - name: Generate SBOM run: syft myapp:${{ github.sha }} -o spdx-json > sbom.json - name: Push to ECR run: | aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REGISTRY docker tag myapp:${{ github.sha }} $ECR_REGISTRY/myapp:${{ github.sha }} docker push $ECR_REGISTRY/myapp:${{ github.sha }} - name: Sign image with Cosign run: | cosign sign --key env://COSIGN_PRIVATE_KEY \ $ECR_REGISTRY/myapp:${{ github.sha }} - name: Attach SBOM run: | cosign attach sbom --sbom sbom.json \ $ECR_REGISTRY/myapp:${{ github.sha }} ``` ## Key Concepts | Term | Definition | |------|------------| | Container Image Scanning | Automated analysis of container image layers to identify known vulnerabilities in OS packages and application dependencies | | Image Signing | Cryptographic attestation that verifies the authenticity and integrity of a container image using Cosign or Notation | | SBOM | Software Bill of Materials, a comprehensive inventory of software components, libraries, and dependencies in a container image | | Tag Immutability | Registry setting that prevents overwriting existing image tags, ensuring that a tag always refers to the same image digest | | Sigstore | Open-source project providing keyless signing, transparency logs, and verification tooling for software supply chain security | | Image Attestation | Cryptographically signed metadata attached to an image (scan results, SBOM, build provenance) that can be verified before deployment | ## Tools & Systems - **Trivy**: Comprehensive vulnerability scanner for container images, filesystems, git repos, and Kubernetes resources - **Grype**: Anchore's vulnerability scanner with broad vulnerability database covera
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.