Skip to content

mtyiska/scanrunner-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ScanRunner: A Modular CLI for File Validation, Compliance, and AI-Powered Insights

Overview

ScanRunner is a flexible and extensible command-line tool designed to simplify file scanning, compliance checks, and AI-driven insights. Built with the powerful Cobra CLI framework, it enables users to process YAML/JSON files, enforce compliance rules, and leverage lightweight AI models to generate actionable suggestions.


Key Features

✨ File Scanning and Validation

  • Scan directories for YAML/JSON files.
  • Validate files for structural correctness and required fields.

πŸ“‹ Compliance Enforcement

  • Apply customizable rules for mock compliance checks.
  • Analyze Kubernetes manifests for missing labels, RBAC misconfigurations, and more.

πŸ€– AI-Powered Suggestions

  • Leverage pre-trained lightweight AI models (ONNX) for context-aware recommendations.
  • Prioritize findings and suggest resolutions dynamically.

πŸ“ˆ Reporting and Summarization

  • Aggregate results into clean JSON/Markdown reports.
  • Generate summary statistics for compliance results and AI insights.

βš™οΈ Concurrency and Scalability

  • Process files in parallel using a worker pool.
  • Efficient resource management for large-scale tasks.

Architecture

graph TD
    A[User] -->|Inputs commands| B[CLI Tool]
    B --> C{Command Handler}
    C -->|Scan Command| D[File Parser]
    C -->|Validate Command| E[Compliance Engine]
    C -->|Report Command| F[Report Generator]
    C -->|AI Integration| G[AI Engine]
    
    D --> H[File Scanner]
    D --> I[File Parser - YAML/JSON]
    D --> J[File Validator]

    E --> K[Rule Engine]
    E --> L[Compliance Evaluator]
    E --> M[Policy Checker]

    G --> N[Model Loader]
    G --> O[Inference Engine]
    G --> P[Suggestion Generator]

    F --> Q[Results Aggregator]
    F --> R[Summary Formatter]
    F --> S[Report Formatter - JSON/Markdown]

    subgraph Internal Components
        D
        E
        G
        F
    end

    subgraph Core CLI Logic
        C
    end

    subgraph Output
        Q
        R
        S
    end

Loading

Setup Instructions

Prerequisites

  • Go (1.20 or later) installed.
  • Familiarity with command-line tools and YAML/JSON files.

Install ScanRunner

  1. Clone the repository:

    git clone https://github.com/your_username/scanrunner.git
    cd scanrunner
  2. Run Setup script:

    bash setup.sh
  3. Build the tool:

    go build -o scanrunner main.go

Basic Commands

  1. Build the CLI Tool

    • Compile the tool before running commands:
      go build -o scanrunner main.go
  2. Root Command

    • Display help for the root command:
      ./scanrunner --help
  3. Scan Command

    • Run the scan command with default settings:
      ./scanrunner scan
    • Specify a custom directory to scan:
      ./scanrunner scan --config=/path/to/config.yaml
  4. Validate Command

    • Run the validate command with default compliance rules:
      ./scanrunner validate
    • Specify a custom rules file:
      ./scanrunner validate --rules=/path/to/custom-rules.yaml
    • Specify a custom configuration file:
      ./scanrunner validate --config=/path/to/config.yaml
    • Enable strict mode:
      ./scanrunner validate --strict
  5. Report Command

    • Generate a report in the default format (JSON):
      ./scanrunner report
    • Specify a custom output format (e.g., Markdown):
      ./scanrunner report --format=markdown
    • Save the report to a specific path:
      ./scanrunner report --output=/path/to/report.md
  6. Version Command

    • Display the version of the CLI tool:
      ./scanrunner version

Folder Structure

Yes, the folder structure you provided is a great choice for your project, and the descriptions can be slightly refined for better clarity. Here's the updated explanation for your scanRunner folder structure:


Folder Structure Description

scanrunner/
β”œβ”€β”€ bin/                      # Compiled binaries (optional for pre-built releases)
β”œβ”€β”€ cmd/                      # CLI commands
β”‚   β”œβ”€β”€ root.go               # Base command setup
β”‚   β”œβ”€β”€ scan.go               # Scan command implementation
β”‚   β”œβ”€β”€ validate.go           # Validate command implementation
β”‚   β”œβ”€β”€ report.go             # Report command implementation
β”‚   β”œβ”€β”€ scan_secrets.go       # Secret scanning command (Phase 5)
β”‚   β”œβ”€β”€ scan_dependencies.go  # Dependency scanning command (Phase 6)
β”‚   β”œβ”€β”€ scan_iac.go           # IaC scanning command (Phase 6)
β”‚   β”œβ”€β”€ scan_images.go        # Image scanning command (Phase 6)
β”‚   β”œβ”€β”€ scan_code.go          # Static code analysis command (Post-MVP)
β”‚   β”œβ”€β”€ validate_policy.go    # Kubernetes policy validation command (Post-MVP)
β”‚   β”œβ”€β”€ scan_audit.go         # Audit log scanning command (Post-MVP)
β”‚   β”œβ”€β”€ version.go            # Version command implementation
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ cli/                  # CLI utilities for argument parsing and validation
β”‚   β”‚   β”œβ”€β”€ parser.go         # CLI argument and flag parser
β”‚   β”‚   β”œβ”€β”€ validator.go      # Input validation logic
β”‚   β”œβ”€β”€ model/                # CLI utilities for argument parsing and validation
β”‚   β”‚   β”œβ”€β”€ rules.go          # Validation Rules Model
β”‚   β”œβ”€β”€ compliance/           # Compliance logic and rule engine
β”‚   β”‚   β”œβ”€β”€ rules.go          # Compliance rules logic and handling
β”‚   β”‚   β”œβ”€β”€ evaluator.go      # Compliance evaluation engine
β”‚   β”‚   β”œβ”€β”€ report.go         # Report generation logic for compliance checks
β”‚   β”œβ”€β”€ fileparser/           # File handling logic
β”‚   β”‚   β”œβ”€β”€ yaml_parser.go    # YAML file parsing and validation
β”‚   β”‚   β”œβ”€β”€ json_parser.go    # JSON file parsing and validation
β”‚   β”‚   β”œβ”€β”€ scanner.go        # File system scanner and directory walker
β”‚   β”‚   β”œβ”€β”€ writer.go         # File content writer for output or modifications
β”‚   β”œβ”€β”€ concurrency/          # Concurrency utilities for parallel processing
β”‚   β”‚   β”œβ”€β”€ worker_pool.go    # Goroutines and worker pool utilities
β”‚   β”‚   β”œβ”€β”€ task_manager.go   # Task distribution and synchronization
β”‚   β”‚   β”œβ”€β”€ aggregator.go     # Result aggregation logic from multiple workers
β”‚   β”œβ”€β”€ ai/                   # AI-related components
β”‚   β”‚   β”œβ”€β”€ inference.go      # AI model inference logic
β”‚   β”‚   β”œβ”€β”€ ai_model.onnx     # Pre-trained lightweight ONNX model
β”‚   β”‚   β”œβ”€β”€ model_loader.go   # ONNX model loading and initialization
β”‚   β”‚   β”œβ”€β”€ suggestion.go     # AI-based suggestion generation based on results
β”‚   β”œβ”€β”€ security/             # Security scanning integrations
β”‚   β”‚   β”œβ”€β”€ trivy.go          # Trivy integration for secret and dependency scanning
β”‚   β”‚   β”œβ”€β”€ checkov.go        # Checkov integration for IaC scanning (Post-MVP)
β”‚   β”œβ”€β”€ kubernetes/           # Kubernetes runtime compliance (Post-MVP)
β”‚   β”‚   β”œβ”€β”€ operator.go       # Operator implementation using Kubebuilder
β”‚   β”‚   β”œβ”€β”€ policy_validator.go # Policy validation logic
β”‚   β”‚   β”œβ”€β”€ audit_log.go      # Kubernetes audit log processing
β”‚   β”‚   β”œβ”€β”€ pod_security.go   # Pod security compliance checks
β”œβ”€β”€ pkg/                      # Shared utilities and reusable components
β”‚   β”œβ”€β”€ logger.go             # Logging utilities for consistent output
β”‚   β”œβ”€β”€ config_loader.go      # Configuration loading and management
β”‚   β”œβ”€β”€ error_handler.go      # Centralized error handling utilities
β”‚   β”œβ”€β”€ rules_loader.go       # Centralized rules handling utilities
β”‚   β”œβ”€β”€ report_formatter.go   # Formatting logic for reports (e.g., JSON/Markdown)
β”‚   β”œβ”€β”€ stats_generator.go    # Summary statistics generator for results
β”œβ”€β”€ config/                   # Configuration files
β”‚   β”œβ”€β”€ custom-rules.yaml     # Default rules file for compliance checks
β”‚   β”œβ”€β”€ default-config.yaml   # Default configuration shipped with the tool
β”œβ”€β”€ assets/                   # Static assets and templates
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   β”œβ”€β”€ report_template.txt  # Report template for terminal output
β”‚   β”‚   β”œβ”€β”€ report_template.json # Report template for JSON output
β”œβ”€β”€ docs/                     # Documentation files
β”‚   β”œβ”€β”€ usage.md              # Detailed CLI usage guide
β”‚   β”œβ”€β”€ architecture.md       # High-level architecture design document
β”‚   β”œβ”€β”€ faq.md                # Frequently asked questions
β”œβ”€β”€ test/                     # Test suite for the project
β”‚   β”œβ”€β”€ cli_test.go           # End-to-end CLI tests
β”‚   β”œβ”€β”€ compliance_test.go    # Tests for compliance rules and engine
β”‚   β”œβ”€β”€ fileparser_test.go    # Tests for file parsing and validation
β”‚   β”œβ”€β”€ concurrency_test.go   # Tests for concurrency and parallel processing
β”‚   β”œβ”€β”€ ai_test.go            # Tests for AI model inference and suggestions
β”‚   β”œβ”€β”€ security_test.go      # Tests for security scanning integrations
β”‚   β”œβ”€β”€ integration/          # Integration tests for workflow validation
β”œβ”€β”€ CONTRIBUTING.md           # Contribution guidelines for open-source contributors
β”œβ”€β”€ LICENSE                   # Licensing terms for the project
β”œβ”€β”€ go.mod                    # Go module file for dependency management
β”œβ”€β”€ Makefile                  # Build and automation commands for the project
β”œβ”€β”€ main.go                   # Entry point for the CLI tool
└── README.md                 # Project overview and basic usage instructions


Folder Descriptions

  1. bin/:

    • Stores pre-built binaries for distribution (optional).
  2. cmd/:

    • Contains all CLI-related commands implemented with Cobra, including:
      • root.go: Base setup for the CLI and parent command.
      • scan.go, validate.go, report.go: Implementations of individual commands.
      • version.go: Outputs the tool’s version.
  3. internal/:

    • Core internal logic split into focused modules:
      • cli/: Argument parsing (parser.go) and input validation (validator.go).
      • compliance/: Compliance rules (rules.go), evaluation logic (evaluator.go), and report generation (report.go).
      • fileparser/: File handling logic for YAML/JSON parsing, scanning directories, and writing files.
      • concurrency/: Worker pool, task management, and result aggregation for parallel processing.
      • ai/: AI model loading (model_loader.go), inference logic (inference.go), and suggestion generation (suggestion.go).
  4. pkg/:

    • Shared utility functions used across modules, including logging, configuration, error handling, and report formatting.
  5. config/:

    • Default and example configuration files for users to customize.
  6. assets/:

    • Templates for report output and static assets like the AI model.
  7. docs/:

    • Comprehensive documentation for usage, architecture, and FAQs.
  8. test/:

    • Unit, integration, and end-to-end tests to ensure the tool’s functionality.
  9. CONTRIBUTING.md:

    • Guidelines for contributing to the open-source project.
  10. LICENSE:

    • Defines the licensing terms for the tool (e.g., MIT).
  11. Makefile:

    • Simplifies build, test, and run commands for developers.
  12. README.md:

    • Serves as the primary project overview and usage guide.

Contributing

We welcome contributions! To get started:

  1. Fork this repository.
  2. Clone your fork and create a feature branch.
  3. Submit a pull request with your changes.

For detailed guidelines, see CONTRIBUTING.md.


Future Features

  • Advanced compliance rule definitions.
  • Real-time drift detection.
  • Integration with cloud storage providers (e.g., AWS S3).
  • Interactive CLI wizard for setup.

License

This project is licensed under the MIT License. See LICENSE for details.


Contact

Have questions or feedback? Reach out via GitHub Issues.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published