A little bash script for converting CIS benchmarks to Fleet-compatible policy files.
Convert Center for Internet Security (CIS) benchmark policies from the Fleet repository into clean, Fleet-ready YAML files for streamlined security compliance management.
# 1. Download and make executable
curl -O https://raw.githubusercontent.com/tux234/cis-to-fleet/canonical/bash-implementation/cis-to-fleet.sh
chmod +x cis-to-fleet.sh
# 2. Install dependencies (if needed)
brew install curl jq yq # macOS with Homebrew
# 3. Generate Fleet policies
./cis-to-fleet.sh list # Show available platforms
./cis-to-fleet.sh generate macos-15 gitops # GitOps YAML array
./cis-to-fleet.sh generate win-11 fleetctl split # Individual fleetctl filesThis script requires three system tools:
| Tool | Purpose | Installation |
|---|---|---|
curl |
HTTP requests to GitHub API | Usually pre-installed |
jq |
JSON processing and filtering | brew install jq |
yq |
YAML processing and generation | brew install yq |
macOS (Homebrew):
brew install curl jq yqUbuntu/Debian:
sudo apt update && sudo apt install curl jq
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yqRHEL/CentOS/Fedora:
sudo yum install curl jq # or dnf install
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq./cis-to-fleet.sh <command> [options] [arguments]
./cis-to-fleet.sh list [--verbose] [--help]Examples:
./cis-to-fleet.sh list # Show all platforms
./cis-to-fleet.sh list --verbose # Show with debug info./cis-to-fleet.sh generate [platforms...] <format> [split] [options]Arguments:
platforms- One or more platform names (or--allfor all platforms)format- Output format:gitopsorfleetctlsplit- Optional modifier to create individual files per policy
Options:
-a, --all- Process all available platforms-l, --level <level>- CIS compliance level:1,2, orall(default:all)-o, --output <dir>- Output directory (default:./output)-f, --force- Overwrite existing files without prompting-v, --verbose- Enable detailed logging-h, --help- Show command help
Basic Operations:
# List available CIS benchmark platforms
./cis-to-fleet.sh list
# Generate GitOps format for macOS 15
./cis-to-fleet.sh generate macos-15 gitops
# Generate Fleetctl format for Windows 11
./cis-to-fleet.sh generate win-11 fleetctlIndividual Policy Files:
# Create individual GitOps files (one per policy)
./cis-to-fleet.sh generate macos-15 gitops split
# Create individual Fleetctl files for multiple platforms
./cis-to-fleet.sh generate win-10 win-11 fleetctl splitAdvanced Usage:
# All platforms, Level 1 policies only, custom output
./cis-to-fleet.sh generate --all gitops --level 1 --output /tmp/policies
# Multiple platforms, Level 2, force overwrite, verbose logging
./cis-to-fleet.sh generate macos-14 macos-15 fleetctl --level 2 --force --verbosePurpose: Optimized for GitOps workflows and Fleet's "separate file" configuration.
Structure: YAML array with field ordering optimized for readability
- name: Policy Name
platform: darwin
description: |
Multi-line policy description
with proper formatting
resolution: |
Step-by-step resolution
instructions
query: SELECT * FROM table WHERE condition;File Output:
- Combined:
output/cis-benchmark-macos15-gitops.yml - Split:
output/macos-15-gitops/Policy_Name.yml(each wrapped in array)
Purpose: Ready for direct deployment with fleetctl apply command.
Structure: Kubernetes-style YAML documents with proper Fleet schema
apiVersion: v1
kind: policy
spec:
name: Policy Name
query: SELECT * FROM table WHERE condition;
critical: false
description: |
Multi-line policy description
resolution: |
Step-by-step resolution
platform: darwin
---
apiVersion: v1
kind: policy
spec:
# Next policy...File Output:
- Combined:
output/cis-benchmark-macos15-fleetctl.yml(multi-document YAML) - Split:
output/macos-15-fleetctl/Policy_Name.yml(individual Kubernetes documents)
| Platform | Description | CIS Benchmark |
|---|---|---|
macos-13 |
macOS 13 Ventura | CIS macOS 13.0 Benchmark |
macos-14 |
macOS 14 Sonoma | CIS macOS 14.0 Benchmark |
macos-15 |
macOS 15 Sequoia | CIS macOS 15.0 Benchmark |
win-10 |
Windows 10 | CIS Windows 10 Benchmark |
win-11 |
Windows 11 | CIS Windows 11 Benchmark |
Run ./cis-to-fleet.sh list for the most current platform list.
The script supports filtering by CIS compliance levels:
| Level | Description | Use Case |
|---|---|---|
| Level 1 | Essential security measures | All organizations, minimal impact |
| Level 2 | Advanced security measures | High-security environments |
| All | Both Level 1 and Level 2 | Complete coverage (default) |
Examples:
# Essential security policies only
./cis-to-fleet.sh generate macos-15 gitops --level 1
# Advanced security policies only
./cis-to-fleet.sh generate win-11 fleetctl --level 2
# All policies (default behavior)
./cis-to-fleet.sh generate macos-15 gitops --level allThe script follows a systematic process to ensure reliable, accurate policy conversion:
- π Discovery - Queries GitHub API to find available CIS benchmark platforms
- π₯ Fetching - Downloads raw policy YAML files using GitHub's content API
- π§ Parsing - Processes Kubernetes-style YAML documents, handles multi-document files
- π·οΈ Filtering - Applies CIS level filtering based on policy tags (
CIS_Level1,CIS_Level2) - π§Ή Sanitization - Extracts essential fields, removes metadata, handles null values
- π Transformation - Converts to target format with proper field ordering and structure
- πΎ Output - Generates clean YAML files with proper formatting and Fleet compatibility
Missing Dependencies:
β Missing required dependencies: yq
You can install them with: brew install yq
Solution: Install missing tools using your package manager.
Network Issues:
β Failed to fetch platform list from GitHub API
Solution: Check internet connection and GitHub availability.
Invalid CIS Level:
β No policies found for macos-15 at CIS level 3
Solution: Use valid levels: 1, 2, or all.
File Conflicts:
β File exists: ./output/cis-benchmark-macos15-gitops.yml (use --force to overwrite)
Solution: Use --force flag or remove existing files.
Enable verbose logging for detailed troubleshooting:
./cis-to-fleet.sh generate macos-15 gitops --verboseThis shows:
- API requests and responses
- YAML parsing steps
- File operations
- Temporary file locations
The bash implementation is optimized for speed and efficiency:
| Metric | Performance |
|---|---|
| Startup Time | ~50ms (vs 200ms TypeScript) |
| Memory Usage | ~5MB (vs 50MB TypeScript) |
| Dependencies | 3 system tools (vs Node.js ecosystem) |
| Distribution | Single file (vs npm modules) |
Optimization Features:
- β‘ Smart Caching - Temporary files prevent re-downloading
- π Streaming Processing - Minimal memory usage for large datasets
- π§Ή Auto Cleanup - Temporary files removed on exit
- π Batch Processing - Multiple platforms processed efficiently
name: Generate CIS Policies
on: [push]
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt install jq
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Generate policies
run: |
chmod +x cis-to-fleet.sh
./cis-to-fleet.sh generate --all gitops --output policies/
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: cis-policies
path: policies/FROM alpine:latest
RUN apk add --no-cache bash curl jq
RUN wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
RUN chmod +x /usr/local/bin/yq
COPY cis-to-fleet.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/cis-to-fleet.sh
ENTRYPOINT ["cis-to-fleet.sh"].PHONY: policies clean
policies:
./cis-to-fleet.sh generate --all gitops --output policies/
clean:
rm -rf policies/ output/
install-deps:
brew install curl jq yqThe script follows these conventions:
- Functions:
snake_casewith descriptive names - Variables:
snake_casewith clear, descriptive names - Constants:
UPPER_CASEfor configuration values - Error Messages: Consistent color coding and format
- Comments: Explain the "why", not just the "what"
# Test basic functionality
./cis-to-fleet.sh list
./cis-to-fleet.sh generate macos-15 gitops --output /tmp/test
# Test error handling
./cis-to-fleet.sh generate invalid-platform gitops
./cis-to-fleet.sh generate macos-15 invalid-format
# Test edge cases
./cis-to-fleet.sh generate macos-15 gitops --level 3- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Test your changes thoroughly
- Document any new functionality
- Submit a Pull Request with clear description
MIT License - see LICENSE file for details.
- π Documentation: This README and inline script comments
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Contact: Open an issue for questions or support
Made with β€οΈ for the Fleet community