Skip to content

A flexible, security-focused framework for scanning containers in Kubernetes environments with multiple scanning engines and comprehensive security controls.

License

Notifications You must be signed in to change notification settings

mitre/kube-secure-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Kube Secure Scanner

A flexible, security-focused framework for scanning containers in Kubernetes environments with multiple scanning engines. Built initially with CINC Auditor (open source InSpec), the platform provides secure RBAC configurations, multiple scanning approaches, and comprehensive CI/CD integration for validating container compliance in both standard and distroless containers.

Project Overview

Our solution offers three distinct technical approaches for container scanning:

  1. Kubernetes API Approach (Recommended): Direct API-based scanning through the Kubernetes API using the train-k8s-container plugin. This is our recommended enterprise solution with future distroless support in development, offering the most scalable and seamless integration. Once distroless support is implemented, this will be a universal solution for all container types.
  2. Debug Container Approach: Ephemeral debug container with chroot-based scanning for distroless containers, ideal for environments with ephemeral container support.
  3. Sidecar Container Approach: CINC Auditor sidecar container with shared process namespace for any container type, offering universal compatibility across Kubernetes versions.

These approaches can be deployed via:

  • Self-contained shell scripts for direct management and testing
  • Modular Helm charts for declarative, enterprise deployment
  • CI/CD integration with GitHub Actions and GitLab CI for both minikube-based and existing Kubernetes clusters

The platform works in both local minikube environments and existing production Kubernetes clusters, with specialized security controls that address the fundamental challenges of privileged container scanning:

  1. Least Privilege Access - Restrict scanning to specific containers only
  2. Dynamic Access Control - Create temporary, targeted access for scanning
  3. CI/CD Integration - Ready-to-use scripts and templates for pipeline integration
  4. Threshold Validation - Integration with MITRE SAF CLI for compliance validation
  5. Distroless Support - Specialized approach for scanning distroless containers
  6. Modular Deployment - Supporting both script-based and Helm-based approaches

Current Status (March 2025)

The project currently offers two complete deployment methods with flexible scanner engine support:

  1. Shell Script Approach - Simple, self-contained scripts for setup and scanning
  2. Helm Chart Approach - Modular Helm charts for more complex deployments

Both approaches support:

  • Standard container scanning with pluggable scanner engines
  • Threshold validation with MITRE SAF CLI
  • CI/CD pipeline integration
  • Dynamic RBAC with least privilege
  • Token-based authentication
  • Extensible architecture for adding new scanning engines

Distroless Container Support Status

We now provide three distinct approaches for scanning distroless containers:

  1. Kubernetes API Approach (Enterprise Recommended) - Enhanced train-k8s-container plugin for direct, API-based scanning:

    • Implementation: Currently being developed as our strategic enterprise solution
    • Advantage: No additional containers required, most efficient and scalable approach
    • Advantage: Seamless integration with existing CINC Auditor/InSpec workflows
    • Advantage: Transparent to users - same commands for both standard and distroless containers
    • Key Advantage: Will become a universal solution for all container types once distroless support is implemented
    • Status: In active development with high priority for enterprise environments
  2. Debug Container Approach - Uses kubectl debug to attach a debug container and scan via chroot:

    • Implementation: The scan-distroless-container.sh script demonstrates this approach
    • Limitation: Requires Kubernetes clusters with ephemeral container support enabled
    • Use Case: Best for testing and development environments with ephemeral container support
  3. Sidecar Container Approach - Deploys a scanner sidecar in the same pod with shared process namespace:

    • Implementation: Fully implemented in scan-with-sidecar.sh and integrated with CI/CD examples
    • Advantage: Works with any Kubernetes cluster, requires no special features
    • Advantage: Can scan any container type, including distroless containers
    • Limitation: Must be deployed alongside the target container (can't scan existing containers)
    • Use Case: Ideal for environments without ephemeral container support or for universal compatibility

Directory Structure

.
β”œβ”€β”€ docs/                                # Comprehensive documentation
β”‚   β”œβ”€β”€ approaches/                      # Scanning approach documentation
β”‚   β”‚   β”œβ”€β”€ comparison.md                # Comparison of scanning approaches
β”‚   β”‚   β”œβ”€β”€ decision-matrix.md           # Decision matrix for approach selection
β”‚   β”‚   β”œβ”€β”€ direct-commands.md           # Direct command usage documentation
β”‚   β”‚   β”œβ”€β”€ index.md                     # Approaches overview
β”‚   β”‚   β”œβ”€β”€ inventory.md                 # Directory contents
β”‚   β”‚   β”œβ”€β”€ debug-container/             # Debug container approach
β”‚   β”‚   β”œβ”€β”€ kubernetes-api/              # Kubernetes API approach
β”‚   β”‚   β”œβ”€β”€ sidecar-container/           # Sidecar container approach
β”‚   β”‚   └── helper-scripts/              # Helper scripts documentation
β”‚   β”œβ”€β”€ architecture/                    # Architecture documentation
β”‚   β”‚   β”œβ”€β”€ components/                  # Core and security components
β”‚   β”‚   β”œβ”€β”€ deployment/                  # Deployment methods
β”‚   β”‚   β”œβ”€β”€ diagrams/                    # Visual diagrams for workflows
β”‚   β”‚   β”œβ”€β”€ integrations/                # Integration architecture
β”‚   β”‚   └── workflows/                   # Workflow process documentation
β”‚   β”œβ”€β”€ configuration/                   # Configuration documentation
β”‚   β”‚   β”œβ”€β”€ advanced/                    # Advanced configuration
β”‚   β”‚   β”œβ”€β”€ integration/                 # Integration configuration
β”‚   β”‚   β”œβ”€β”€ kubeconfig/                  # Kubeconfig management
β”‚   β”‚   β”œβ”€β”€ plugins/                     # Plugins configuration
β”‚   β”‚   β”œβ”€β”€ security/                    # Security configuration
β”‚   β”‚   └── thresholds/                  # Threshold configuration
β”‚   β”œβ”€β”€ learning-paths/                  # Guided learning paths
β”‚   β”‚   β”œβ”€β”€ new-users.md                 # For new users
β”‚   β”‚   β”œβ”€β”€ security-first.md            # Security-focused implementation
β”‚   β”‚   β”œβ”€β”€ core-concepts.md             # Core concepts
β”‚   β”‚   β”œβ”€β”€ implementation.md            # Implementation guide
β”‚   β”‚   └── advanced-features.md         # Advanced features
β”‚   β”œβ”€β”€ tasks/                           # Task-oriented guides
β”‚   β”‚   β”œβ”€β”€ standard-container-scan.md   # Standard container scanning
β”‚   β”‚   β”œβ”€β”€ distroless-container-scan.md # Distroless container scanning
β”‚   β”‚   β”œβ”€β”€ sidecar-container-scan.md    # Sidecar container scanning
β”‚   β”‚   β”œβ”€β”€ github-integration.md        # GitHub integration
β”‚   β”‚   β”œβ”€β”€ gitlab-integration.md        # GitLab integration
β”‚   β”‚   └── kubernetes-setup.md          # Kubernetes setup
β”‚   β”œβ”€β”€ security/                        # Security documentation
β”‚   β”‚   β”œβ”€β”€ compliance/                  # Compliance documentation
β”‚   β”‚   β”‚   └── nsa-cisa-hardening.md    # NSA/CISA Kubernetes Hardening Guide
β”‚   β”‚   β”œβ”€β”€ principles/                  # Security principles
β”‚   β”‚   β”œβ”€β”€ recommendations/             # Security recommendations
β”‚   β”‚   β”œβ”€β”€ risk/                        # Risk analysis
β”‚   β”‚   └── threat-model/                # Threat modeling
β”‚   β”œβ”€β”€ helm-charts/                     # Helm chart documentation
β”‚   β”‚   β”œβ”€β”€ infrastructure/              # Infrastructure components
β”‚   β”‚   β”œβ”€β”€ operations/                  # Operations guidance
β”‚   β”‚   β”œβ”€β”€ overview/                    # Architecture overview
β”‚   β”‚   β”œβ”€β”€ scanner-infrastructure/      # Scanner infrastructure
β”‚   β”‚   β”œβ”€β”€ scanner-types/               # Scanner implementations
β”‚   β”‚   β”œβ”€β”€ security/                    # Security considerations
β”‚   β”‚   └── usage/                       # Usage guides
β”‚   β”œβ”€β”€ integration/                     # CI/CD integration guides
β”‚   β”‚   β”œβ”€β”€ configuration/               # Integration configuration
β”‚   β”‚   β”œβ”€β”€ examples/                    # Integration examples
β”‚   β”‚   β”œβ”€β”€ platforms/                   # Platform-specific guides
β”‚   β”‚   └── workflows/                   # Integration workflows
β”‚   β”œβ”€β”€ kubernetes-scripts/              # Kubernetes script documentation
β”‚   β”œβ”€β”€ kubernetes-setup/                # Kubernetes setup documentation
β”‚   β”‚   β”œβ”€β”€ best-practices.md            # Kubernetes best practices
β”‚   β”‚   β”œβ”€β”€ existing-cluster-requirements.md # Existing cluster setup
β”‚   β”‚   └── minikube-setup.md            # Minikube setup guide
β”‚   β”œβ”€β”€ project/                         # Project documentation
β”‚   β”‚   β”œβ”€β”€ changelog.md                 # Detailed changelog
β”‚   β”‚   β”œβ”€β”€ roadmap.md                   # Project roadmap
β”‚   β”‚   β”œβ”€β”€ tasks.md                     # Task tracking
β”‚   β”‚   └── documentation-structure-progress.md # Documentation progress
β”‚   β”œβ”€β”€ site-index.md                    # Site index with navigation aids
β”‚   β”œβ”€β”€ common-abbreviations.md          # Common abbreviations reference
β”‚   β”œβ”€β”€ rbac/                            # RBAC configuration guides
β”‚   β”œβ”€β”€ service-accounts/                # Service account setup
β”‚   └── tokens/                          # Token management
β”œβ”€β”€ scripts/                             # Automation scripts
β”‚   β”œβ”€β”€ doc-tools/                       # Documentation tools
β”‚   β”‚   β”œβ”€β”€ extract-doc-warnings.sh      # Extract documentation warnings
β”‚   β”‚   β”œβ”€β”€ fix-links.sh                 # Fix documentation links
β”‚   β”‚   └── track-warning-progress.sh    # Track warning resolution
β”‚   β”œβ”€β”€ kubernetes/                      # Kubernetes scripts
β”‚   β”‚   β”œβ”€β”€ generate-kubeconfig.sh       # Generate restricted kubeconfig
β”‚   β”‚   β”œβ”€β”€ scan-container.sh            # End-to-end container scanning
β”‚   β”‚   β”œβ”€β”€ scan-distroless-container.sh # Distroless container scanning
β”‚   β”‚   β”œβ”€β”€ scan-with-sidecar.sh         # Sidecar container scanning
β”‚   β”‚   └── setup-minikube.sh            # Multi-node minikube setup
β”‚   └── project-maintenance/             # Project maintenance scripts
β”œβ”€β”€ kubernetes/                          # Kubernetes manifests
β”‚   └── templates/                       # Template YAML files
β”œβ”€β”€ helm-charts/                         # Modular Helm charts for deployment
β”‚   β”œβ”€β”€ scanner-infrastructure/          # Core RBAC, service accounts
β”‚   β”œβ”€β”€ common-scanner/                  # Common scanning components 
β”‚   β”œβ”€β”€ standard-scanner/                # Standard container scanning
β”‚   β”œβ”€β”€ distroless-scanner/              # Distroless container scanning
β”‚   └── sidecar-scanner/                 # Sidecar approach for container scanning
β”œβ”€β”€ github-workflow-examples/            # GitHub Actions workflow examples
β”‚   β”œβ”€β”€ setup-and-scan.yml               # Basic setup and scan workflow
β”‚   β”œβ”€β”€ dynamic-rbac-scanning.yml        # Dynamic pod scanning with RBAC
β”‚   β”œβ”€β”€ ci-cd-pipeline.yml               # Complete CI/CD pipeline with scanning
β”‚   └── sidecar-scanner.yml              # Sidecar container scanning workflow
β”œβ”€β”€ gitlab-pipeline-examples/            # GitLab CI examples
β”‚   β”œβ”€β”€ gitlab-ci.yml                    # Standard GitLab CI configuration
β”‚   β”œβ”€β”€ gitlab-ci-with-services.yml      # GitLab CI with services
β”‚   β”œβ”€β”€ gitlab-ci-sidecar.yml            # GitLab CI with sidecar approach
β”‚   └── gitlab-ci-sidecar-with-services.yml # GitLab CI sidecar with services
└── examples/                            # Example resources
    β”œβ”€β”€ cinc-profiles/                   # Example CINC Auditor profiles
    β”œβ”€β”€ cinc-auditor-scanner/            # Dockerfile for scanner sidecar container
    └── sidecar-scanner-pod.yaml         # Example sidecar container pod

Quick Start

Option 1: Automated Minikube Setup (Shell Script Approach)

The quickest way to set up a test environment is using our automated setup script:

# Set up a 3-node minikube cluster with standard containers
./scripts/setup-minikube.sh

# For distroless container scanning support (experimental)
./scripts/setup-minikube.sh --with-distroless

# For a customized setup
./scripts/setup-minikube.sh --nodes=2 --driver=virtualbox --install-deps

The script will:

  1. Check and optionally install dependencies
  2. Create a multi-node minikube cluster
  3. Deploy the necessary RBAC and service accounts using kubectl directly (not Helm)
  4. Set up test pods
  5. Generate a kubeconfig file
  6. Provide instructions for running scans

Option 2: Manual Deployment

  1. Set up the Kubernetes resources:
kubectl apply -f kubernetes/templates/namespace.yaml
kubectl apply -f kubernetes/templates/service-account.yaml
kubectl apply -f kubernetes/templates/rbac.yaml
kubectl apply -f kubernetes/templates/test-pod.yaml
  1. Generate a kubeconfig file:
./scripts/generate-kubeconfig.sh inspec-test inspec-scanner ./kubeconfig.yaml
  1. Run a CINC Auditor scan:
KUBECONFIG=./kubeconfig.yaml cinc-auditor exec ./examples/cinc-profiles/container-baseline \
  -t k8s-container://inspec-test/inspec-target/busybox
  1. Process results with SAF CLI (optional):
# Generate a summary report
saf summary --input inspec-results.json --output-md summary.md

# Validate against threshold requirements
saf threshold -i inspec-results.json -t threshold.yml

Option 3: Modular Helm Charts (Helm Approach)

We provide specialized Helm charts as an alternative deployment method:

Standard Container Scanning

# Install the standard-scanner chart
helm install standard-scanner ./helm-charts/standard-scanner \
  --set common-scanner.scanner-infrastructure.targetNamespace=inspec-test \
  --set testPod.deploy=true

# Generate a kubeconfig and run a scan
./scripts/generate-kubeconfig.sh inspec-test inspec-scanner ./kubeconfig.yaml
KUBECONFIG=./kubeconfig.yaml cinc-auditor exec ./examples/cinc-profiles/container-baseline \
  -t k8s-container://inspec-test/inspec-target/busybox

Distroless Container Scanning

We provide three approaches for scanning distroless containers:

Approach 1: Ephemeral Debug Container (Requires Kubernetes 1.18+)
# Install the distroless-scanner chart
helm install distroless-scanner ./helm-charts/distroless-scanner \
  --set common-scanner.scanner-infrastructure.targetNamespace=inspec-test \
  --set testPod.deploy=true

# Generate a kubeconfig and run a specialized scan
./scripts/generate-kubeconfig.sh inspec-test inspec-scanner ./kubeconfig.yaml
./scripts/scan-distroless-container.sh inspec-test distroless-target distroless ./examples/cinc-profiles/container-baseline
Approach 2: Sidecar Container (Recommended, works with any Kubernetes cluster)
# Deploy a pod with sidecar container for scanning
kubectl apply -f examples/sidecar-scanner-pod.yaml

# Wait for the pod to be ready
kubectl wait --for=condition=ready pod/app-scanner -n inspec-test --timeout=300s

# Check scan results directly from the sidecar
kubectl exec -it app-scanner -n inspec-test -c scanner -- cat /results/scan-summary.md
Approach 3: Sidecar Container with CI/CD Integration

We provide ready-to-use CI/CD examples for the sidecar approach:

  • GitLab CI: gitlab-examples/gitlab-ci-sidecar.yml
  • GitLab CI with Services: gitlab-examples/gitlab-ci-sidecar-with-services.yml
  • GitHub Actions: github-workflows/sidecar-scanner.yml

These examples automatically deploy, scan, and retrieve results from a scanner sidecar container.

See the Distroless Container Documentation and Sidecar Container Approach for more details.

Option 4: CI/CD Pipeline Integration

GitHub Actions

  1. Copy the workflow files to your repository's .github/workflows directory:
mkdir -p .github/workflows
cp github-workflows/* .github/workflows/
  1. Commit and push the changes
  2. Run the workflows from the GitHub Actions tab in your repository

GitLab CI

  1. Copy the .gitlab-ci.yml file to your repository root:
cp gitlab-examples/gitlab-ci.yml .gitlab-ci.yml
  1. Customize the file for your environment
  2. Commit and push the changes

CI/CD Integration

For CI/CD pipelines, this project provides:

  1. GitLab CI/CD example configurations in gitlab-examples/
  2. GitHub Actions workflows in github-workflows/
  3. Dynamic access creation scripts
  4. Cleanup procedures to avoid resource leaks
  5. SAF CLI integration for threshold validation

Key Features

Security-Focused Design

  • No permanent elevated privileges
  • No shared access between scans
  • Time-limited token generation (default: 15 minutes)
  • Fine-grained RBAC controls
  • Namespace isolation

Flexibility

  • Support for label-based scanning
  • Support for named resource restrictions
  • Multiple deployment methods (scripts or Helm)
  • Configurable threshold validation
  • Modular Helm chart structure

Ease of Use

  • Comprehensive documentation
  • Ready-to-use scripts
  • Helm chart deployment
  • Example profiles and configurations
  • GitHub Actions and GitLab CI integration

SAF CLI Integration

The project integrates with MITRE Security Automation Framework (SAF) CLI for:

  1. Results processing and summary generation
  2. Threshold validation for compliance requirements
  3. JSON, Markdown, and HTML report generation

Example threshold configuration:

# threshold.yml
compliance:
  min: 80  # Minimum 80% compliance required
failed:
  critical:
    max: 0  # No critical failures allowed
  high:
    max: 2  # Maximum 2 high failures allowed

Documentation

Online Documentation

Visit our comprehensive documentation at:

Documentation Management

We provide a comprehensive documentation system with tools for previewing, validating, and improving documentation quality:

# Use the documentation tools script from the project root
./docs-tools.sh preview     # Preview documentation (background server)
./docs-tools.sh status      # Check server status
./docs-tools.sh restart     # Restart server
./docs-tools.sh stop        # Stop server
./docs-tools.sh setup       # Install all documentation dependencies
./docs-tools.sh lint        # Check Markdown style
./docs-tools.sh fix         # Fix common Markdown issues
./docs-tools.sh check-all   # Run comprehensive quality checks
./docs-tools.sh help        # See all available commands

Documentation Tools and CI/CD Scripts

This project provides a comprehensive set of documentation management tools:

  1. docs-tools.sh - Interactive documentation management tool for developers:

    • Located at: Available both in project root (symlinked) and in docs/docs-tools.sh (original)
    • Purpose: Day-to-day documentation development and testing
    • Features: Preview server, linting, spell checking, link validation, and more
    • Usage: Run from either location with ./docs-tools.sh [command]
    • Note: The script automatically adapts to being run from either location
  2. docs-ci.sh - Automated documentation validation for CI/CD pipelines:

    • Located at: Project root
    • Purpose: Verify documentation quality in automated builds
    • Features: Non-interactive validation for continuous integration
    • Usage: Used by CI/CD pipelines or run with ./docs-ci.sh [--help] to validate locally
    • Supports: --help flag for usage information and --verbose flag for detailed output
  3. Documentation Fix Utilities - Specialized tools for documentation maintenance:

    • Located at: scripts/doc-tools/
    • Purpose: Fix and track documentation issues
    • Key utilities:
      • extract-doc-warnings.sh: Generate comprehensive issue reports
      • fix-links.sh: Fix broken links using mappings file
      • track-warning-progress.sh: Monitor documentation improvements
      • fix-cross-references.sh: Fix cross-references between files
      • generate-doc-mappings.sh: Generate file mappings for documentation

The documentation system includes:

  • MkDocs with Material theme for beautiful documentation
  • Markdown style checking with markdownlint
  • Spell checking with pyspelling
  • Link validation with linkchecker
  • Comprehensive quality validation tools

For more details, see Documentation Management

Documentation Structure

Our documentation covers the following areas:

Getting Started

Learning Paths

Common Tasks

Approach-Specific Documentation

Security Documentation

Technical Implementation

CI/CD Integration

Helm Charts Documentation

Development and Testing

Requirements

  • Kubernetes 1.24+ (for token creation API)
  • kubectl
  • CINC Auditor with train-k8s-container plugin
  • MITRE SAF CLI (for threshold validation)
  • Helm 3.2.0+ (for Helm deployment)

Current Status and Future Work

Project Status (March 2025)

  • Overall Project Completion: ~90%
  • Documentation Completion: 95%
  • Core Functionality: 100%
  • Testing Coverage: 70%
  • Scanner Engine Support:
    • CINC Auditor (InSpec): 100%
    • Additional engines: Planned for post-v1.0 releases
  • Next Major Milestone: Complete API-based approach and v1.0.0 release
  • Target Release Date: May 2025

Implementation Status

  1. Multi-Approach Container Scanning:

    • βœ… Implemented three distinct approaches:
      • βœ… Ephemeral debug container (requires special cluster feature)
      • βœ… Sidecar container with shared process namespace (works universally)
      • πŸ”„ API-based direct scanning approach (20% complete, in progress)
    • βœ… Integrated all approaches with CI/CD examples
    • βœ… Created comprehensive documentation for all approaches
    • βœ… Completed approach comparison and decision matrix
    • πŸ”„ Future work will focus on completing the API-based approach
  2. Scanner Engine Support:

    • βœ… CINC Auditor (InSpec) integration complete
    • πŸ”„ Extensible architecture for additional scanning engines
    • πŸ”„ Plugin interface for scanner integration (planned)
    • πŸ”„ Scanner results normalization layer (planned)
    • πŸ”„ Support for additional scanners post-v1.0
  3. Documentation and Resources:

    • βœ… Implemented comprehensive MkDocs documentation system
    • βœ… Created workflow diagrams for all scanning approaches
    • βœ… Developed security analysis and risk documentation
    • βœ… Added enterprise integration analysis documentation
    • βœ… Reorganized documentation into logical structure
    • βœ… Identified documentation gaps for contribution
    • βœ… Implemented dark/light mode support for diagrams
    • πŸ”„ Addressing high-priority documentation gaps before v1.0.0 release
  4. CI/CD Integration:

    • βœ… GitLab CI standard pipeline
    • βœ… GitLab CI with services
    • βœ… GitLab CI for sidecar approach
    • βœ… GitLab CI with services for sidecar approach
    • βœ… GitHub Actions for standard approach
    • βœ… GitHub Actions for sidecar approach
    • βœ… Comprehensive integration documentation
    • πŸ”„ Future work will include examples for other CI/CD platforms
  5. Performance and Container Images:

    • βœ… Implemented services-based approach for GitLab CI
    • βœ… Created optimized sidecar container implementations
    • πŸ”„ Future work will include building and publishing dedicated scanner containers
    • πŸ”„ Creating specialized debug containers with scanners pre-installed
    • πŸ”„ Creating sidecar container images with optimized configurations
    • πŸ”„ Performance optimization with large-scale scanning

Development Roadmap

For a detailed view of our roadmap and project status, see:


Kube Secure Scanner - Developed by the project collaborators with experimental collaboration from Claude Code

About

A flexible, security-focused framework for scanning containers in Kubernetes environments with multiple scanning engines and comprehensive security controls.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages