เครื่องมือ Self-Hosted - Open Source

Docker Bench

อัตโนมัติการตรวจสอบความปลอดภัย Container ตามมาตรฐาน CIS Benchmarks 2025

Docker Bench for Security เป็นเครื่องมืออัตโนมัติที่ตรวจสอบการตั้งค่า Docker Engine และ Container ว่าสอดคล้องกับ CIS Docker Benchmark ซึ่งเป็นมาตรฐานความปลอดภัยระดับสากล

Docker
ความปลอดภัย
CIS
Automation

บทนำ

Docker Bench for Security เป็นเครื่องมืออัตโนมัติที่ถูกพัฒนาขึ้นโดยทีมผู้พัฒนา Docker เพื่อตรวจสอบการตั้งค่า Docker Engine และ Container ว่าสอดคล้องกับ CIS Docker Benchmark ซึ่งเป็นมาตรฐานความปลอดภัยระดับสากลที่ได้รับการยอมรับจากองค์กรต่างๆ

ในปี 2025 ด้วยความก้าวหน้าของ Container Technology และการใช้งาน Docker ใน Production การตรวจสอบความปลอดภัยอย่างสม่ำเสมอจึงเป็นสิ่งจำเป็นอย่างยิ่ง โดย Docker Bench จะช่วยคุณระบุช่องโหว่และจุดอ่อนในการตั้งค่าระบบ

100% เครื่องมือ Open Source
เผยแพร่ภายใต้ GNU General Public License และสามารถใช้งานได้ฟรี
การตรวจสอบแบบเรียลไทม์
ตรวจสอบการตั้งค่า Docker ได้ทันทีโดยไม่ต้อง restart บริการ
ผลลัพธ์แบบรายละเอียด
ส่งออกผลการตรวจสอบในรูปแบบ JSON และ Text พร้อมคำแนะนำการแก้ไข

โครงสร้างระบบ (Architecture)

Docker Bench ทำงานโดยการตรวจสอบไฟล์ configuration และ service files ของ Docker Engine และ Container ที่กำลังทำงานอยู่ โดยตรวจสอบเปรียบเทียบกับรูปแบบที่กำหนดไว้ใน CIS Benchmark

Input Docker Files /etc/docker/ daemon.json docker.service Read Config Rule Engine CIS Docker Benchmark v1.7 107 Rules Script Bash Shell bash docker-bench.sh Execute Analysis PASS / FAIL / WARN 107 Checks Result Terminal Summary Report PASS / FAIL D Docker C CIS B Benchmark S Security

สิ่งที่ต้องเตรียม (Prerequisites)

Docker Engine

ติดตั้ง Docker Engine เวอร์ชันล่าสุด (24.x หรือสูงกว่า)

bash
# Check Docker version
docker --version
docker info | grep 'Server Version'

ตรวจสอบให้แน่ใจว่า Docker Service กำลังทำงานอยู่ (Running)

ระบบปฏิบัติการ (Linux)

Docker Bench Security รองรับระบบปฏิบัติการ Linux ต่อไปนี้:

Ubuntu
20.04, 22.04, 24.04
Debian
11, 12
CentOS
8, 9

สิทธิ์การเข้าถึง (Root Access)

Docker Bench ต้องการสิทธิ์ Root หรือ root privileges เนื่องจากต้องอ่านไฟล์ configuration ของ Docker ที่อยู่ใน /etc/docker/

bash
sudo ./docker-bench-security.sh
# หรือ
sudo bash docker-bench-security.sh

ขั้นตอนการติดตั้ง (Installation)

คุณสามารถติดตั้ง Docker Bench Security ได้ 3 วิธี ขึ้นอยู่กับความต้องการและสภาพแวดล้อมของคุณ

1 วิธีที่ 1: Download Binary Package

วิธีที่รวดเร็วที่สุด สำหรับผู้ใช้ทั่วไปและผู้เริ่มต้น

ขั้นตอน:

bash
wget https://raw.githubusercontent.com/docker/docker-bench-security/main/docker-bench-security.sh
chmod +x docker-bench-security.sh

หรือใช้ curl แทน:

bash
curl -o docker-bench-security.sh https://raw.githubusercontent.com/docker/docker-bench-security/main/docker-bench-security.sh
chmod +x docker-bench-security.sh
./docker-bench-security.sh

2 วิธีที่ 2: Clone จาก GitHub

วิธีนี้เหมาะสำหรับนักพัฒนาที่ต้องการแก้ไขหรือดูซอร์สโค้ด

bash
git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
./docker-bench-security.sh

เพื่ออัปเดตเป็นเวอร์ชันล่าสุด:

bash
cd docker-bench-security
git pull

3 วิธีที่ 3: ใช้ Docker Container

วิธีที่ cleaner ไม่ต้องติดตั้ง script บน host system

Docker Bench Security มี Docker image ที่สามารถรันได้โดยตรง:

bash
docker run -it --net host --pid host --cap-add audit_control \
  -e DOCKER_VERSION=$(docker version -f '{{.Server.Version}}' 2>/dev/null || echo 'unknown') \
  -e DISABLE_TESTS=$DISABLE_TESTS \
  -v /var/lib:/var/lib \
  -v /var/run:/var/run:ro \
  -v /etc:/etc:ro \
  -v /usr:/usr:ro \
  docker/docker-bench-security
bash
docker run --rm -t docker/docker-bench-security 2>1 | tee docker-bench-results.txt

คำอธิบาย flag:

  • --net host - ใช้ network namespace ของ host
  • --pid host - ใช้ PID namespace ของ host
  • --cap-add audit_control - เพิ่ม capability สำหรับ audit
  • -v /etc:/etc:ro - Mount /etc ในโหมด read-only
  • -v /var/run:/var/run:ro - Mount /var/run ในโหมด read-only

ตรวจสอบว่าติดตั้งเรียบร้อย

bash
./docker-bench-security.sh --help

หากเห็น output ที่แสดง help message และ available options แสดงว่าติดตั้งเรียบร้อยแล้ว

ขั้นตอนการใช้งาน (Usage)

1 รันการตรวจสอบแบบครบถ้วน (Full Checks)

รันการตรวจสอบทุกรULE ทั้งหมด 107 rules ของ CIS Docker Benchmark

bash
sudo ./docker-bench-security.sh

2 รันการตรวจสอบเฉพาะส่วน (Selective Checks)

คุณสามารถเลือกรันเฉพาะ section ที่สนใจได้ โดยใช้ flag -i (ignore pattern)

ตัวอย่าง 1: ตรวจสอบเฉพาะ Docker Daemon Configuration

bash
sudo ./docker-bench-security.sh -c docker_daemon

ตัวอย่าง 2: ตรวจสอบเฉพาะ Container Image ที่ใช้งานอยู่

bash
sudo ./docker-bench-security.sh -c docker_container

ตัวอย่าง 3: ตรวจสอบเฉพาะ Docker Security ทั่วไป

bash
sudo ./docker-bench-security.sh -c docker_ce
Section Description
docker_daemon Docker Daemon Configuration
docker_container Container Runtime Security
docker_ce Docker Community Edition
docker_cis_benchmark CIS Docker Benchmark controls
docker_images Container Images security

3 การใช้งานด้วย Custom Configuration

คุณสามารถปรับแต่ง behavior ของ Docker Bench ได้ด้วย environment variables

Variable Description Default
DISABLE_TESTS Disable specific tests by name None
ENABLE_TESTS Enable only specific tests by name All
SKIP_DOCKER_VERSION_CHECK Skip Docker version check false
OUTPUT_FORMAT Output format (text, json) text

ตัวอย่างการใช้งาน:

bash
DISABLE_TESTS=\"test_1_1 test_1_2\" ./docker-bench-security.sh

การส่งออกผลลัพธ์ (Output Formats)

Docker Bench รองรับการส่งออกผลลัพธ์ในหลายรูปแบบ

bash
# Output as JSON
./docker-bench-security.sh --output json

# Output as JSON with timestamps
./docker-bench-security.sh --output json --timestamps

# Save to file
./docker-bench-security.sh --output json > results.json

การอ่านผลลัพธ์ (Interpret Results)

หลังจากการตรวจสอบ ผลลัพธ์จะแสดงในรูปแบบสีและสัญลักษณ์ที่ช่วยให้คุณเข้าใจสถานะความปลอดภัยได้ทันที

PASS

ตรวจสอบผ่าน

Configuration ตรงตามมาตรฐาน CIS Benchmark

FAIL

ตรวจสอบไม่ผ่าน

มีปัญหาความปลอดภัย ต้องแก้ไขทันที

WARN

คำเตือน

ควรพิจารณาปรับปรุง

ตัวอย่าง Output Format

output
===========================================================
Docker Bench Security v1.7.0
===========================================================

Checking Docker security configuration...

-- Section 1: Docker Daemon Configuration --

[INFO] 1.1 - Ensure AIDE is installed
[PASS] 1.1 - AIDE is installed

[INFO] 1.2 - Ensure SELinux security options are set
[WARN] 1.2 - SELinux is not enabled

[INFO] 1.3 - Ensure AppArmor profile is enabled
[PASS] 1.3 - AppArmor is enabled

-- Summary --
Total: 107 checks
PASS: 89
FAIL: 8
WARN: 10
INFO: 0

-- Score: 83.2% (89/107) --

อธิบายสัญลักษณ์สถานะ

Indicator Meaning Action
PASS ผ่านเกณฑ์การตรวจสอบ ไม่ต้องทำอะไร - Configuration ถูกต้อง
FAIL ไม่ผ่านเกณฑ์ - มีปัญหาความปลอดภัย จำเป็นต้องแก้ไข - ซ่อมแซมทันที
WARN คำเตือน - ควรพิจารณาปรับปรุง ควรพิจารณา - อาจมีความเสี่ยงในอนาคต
INFO ข้อมูลเพิ่มเติม อ่านข้อมูล - ไม่ต้องทำอะไร

ตัวอย่างจริง (Real Examples)

มาดูตัวอย่างผลลัพธ์จริงจาก Docker Bench Security และวิธีการวิเคราะห์

1 กรณีที่ 1: Docker Daemon Configuration (FAIL)

ปัญหาที่พบ: Docker Daemon ไม่มีการจำกัด resource ที่ container สามารถใช้ได้

result
[WARN] 2.2 - Ensure Docker is allowed to make changes to iptables rules
[FAIL] 2.2 - Docker is allowed to make changes to iptables rules

[WARN] 2.3 - Ensure iptables is enabled for Docker
[WARN] 2.3 - iptables is not enabled for Docker

[FAIL] 2.6 - Ensure Docker cgroup driver is configured to "cgroupfs"

วิธีแก้ไข:

bash
# Edit /etc/docker/daemon.json
sudo nano /etc/docker/daemon.json

# Add these settings:
{
  "iptables": true,
  "live-restore": true,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

# Restart Docker daemon
sudo systemctl daemon-reexec
sudo systemctl restart docker

2 กรณีที่ 2: Container Security (PASS)

ปัญหาที่พบ: Container ถูกตั้งค่าตามมาตรฐานความปลอดภัยแล้ว

result
[PASS] 5.1 - Ensure Docker is installed (not just Docker CLI)
[PASS] 5.2 - Ensure a user for the container is created
[PASS] 5.3 - Ensure HTTP headers are set in containers
[PASS] 5.4 - Ensure Linux kernel capabilities are configured
[PASS] 5.5 - Ensure privileged containers are not used
[PASS] 5.6 - Ensure sensitive host system directories are not mounted on containers
[PASS] 5.7 - Ensure sshd is not run inside containers

ข้อสรุป:

Container ถูกตั้งค่าตามมาตรฐานความปลอดภัยแล้ว สิ่งที่ต้องทำต่อคือบันทึก configuration และตรวจสอบให้แน่ใจว่าทุก container ใหม่จะใช้ configuration เดียวกัน

3 กรณีที่ 3: Image Security (WARN)

ปัญหาที่พบ: บาง image ยังไม่ได้รับการอัปเดต security patches

result
[WARN] 6.1 - Ensure Docker images are based on images with latest security patches
[WARN] 6.2 - Ensure unnecessary packages are removed from images
[WARN] 6.3 - Ensure Docker files do not contain secrets
[WARN] 6.4 - Ensure Docker files do not contain unnecessary tools

วิธีแก้ไข:

ใช้ Trivy หรือ Snyk สำหรับ scan images:

bash
# Install Trivy
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin

# Scan image
trivy image --severity HIGH,CRITICAL myapp:latest

# Scan for secrets
trivy config --severity HIGH,CRITICAL .

Best Practices

การใช้งาน Docker Bench Security อย่างมีประสิทธิภาพต้องมีการวางแผนและจัดการอย่างต่อเนื่อง

1 กำหนด Schedule อัตโนมัติ (Cron Job)

ตั้งค่าให้ Docker Bench รันอัตโนมัติทุกช่วงเวลา เพื่อตรวจสอบสภาพความปลอดภัยอย่างสม่ำเสมอ

ตัวอย่าง: รันทุกสัปดาห์ในวันอาทิตย์เวลา 02:00

bash
# 1. Create docker bench weekly script
cat > /usr/local/bin/docker-bench-weekly.sh << 'EOF'
#!/bin/bash
# Docker Bench Weekly Scan
DATE=\$(date +%Y%m%d_%H%M%S)
OUTPUT_DIR="/var/log/docker-bench"
REPORT="\${OUTPUT_DIR}/bench_report_\${DATE}.json"

mkdir -p \$OUTPUT_DIR
cd /opt/docker-bench-security
sudo ./docker-bench-security.sh --output json > \$REPORT 2>/dev/null

# Send report via email (optional)
# mail -s "Docker Bench Report \${DATE}" admin@company.com < \$REPORT
EOF

chmod +x /usr/local/bin/docker-bench-weekly.sh

# 2. Add to crontab
echo '0 2 * * 0 /usr/local/bin/docker-bench-weekly.sh >> /var/log/docker-bench/cron.log 2>&1' | sudo crontab -

วิธีนี้จะสร้าง JSON report ทุกสัปดาห์ และสามารถส่ง report ไปยัง email หรือ system อื่นๆ ได้

2 การเชื่อมต่อกับ SIEM

ส่งผลลัพธ์การตรวจสอบไปยัง SIEM สำหรับการวิเคราะห์และ alert

ตัวอย่าง: บันทึกไปยัง ELK Stack หรือ Splunk

bash
# ส่ง JSON data ไป Splunk HEC
curl -k https://splunk-server:8088/services/collector \
  -H "Authorization: Splunk YOUR_TOKEN_HERE" \
  -d "@docker-bench-report.json"

# หรือใช้ filebeat สำหรับส่งไป ELK
# /etc/filebeat/filebeat.yml
- type: filestream
  paths:
    - /var/log/docker-bench/*.json
  fields:
    type: docker-bench
    environment: production

3 Integration กับ CI/CD Pipeline

ผสาน Docker Bench เข้ากับ CI/CD เพื่อตรวจสอบความปลอดภัยก่อน deployment

ตัวอย่าง: GitHub Actions Workflow

yaml
name: Docker Security Scan

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  security-scan:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Clone Docker Bench
      run: |
        git clone https://github.com/docker/docker-bench-security.git
        cd docker-bench-security

    - name: Run Docker Bench Security
      run: |
        sudo chmod +x docker-bench-security.sh
        sudo ./docker-bench-security.sh --output json > ../security-report.json

    - name: Parse Results
      run: |
        # Check for FAIL results
        FAIL_COUNT=\$(grep -c '"'"'\"status\": \"fail\"'"'"' ../security-report.json)
        if [ \"\$FAIL_COUNT\" -gt 0 ]; then
          echo "Found \$FAIL_COUNT security issues!"
          exit 1
        fi
        echo "No critical security issues found."

    - name: Upload Report
      uses: actions/upload-artifact@v3
      with:
        name: security-report
        path: security-report.json

4 การวิเคราะห์ trend ความปลอดภัย

เก็บ history ผลลัพธ์เพื่อวิเคราะห์ trend และดูว่าความปลอดภัยดีขึ้นหรือแย่ลงตามเวลา

bash
# ตัวอย่าง script สำหรับสร้าง security trend report
#!/bin/bash

# สรุปผลรายสัปดาห์
echo "Docker Security Trend Report"
echo "=============================="
echo "Date: $(date)"
echo ""

# รวมผลจากทุก file
for file in /var/log/docker-bench/*.json; do
  if [ -f "$file" ]; then
    date=$(echo "$file" | grep -oP '\d{8}_\d{6}')
    total=$(grep -c '"'"'\"check\":'\"'"' "$file") || 0
    pass=$(grep -c '"'"'\"status\": \"pass\"'"'"' "$file") || 0
    fail=$(grep -c '"'"'\"status\": \"fail\"'"'"' "$file") || 0
    
    echo "Date: $date | Total: $total | PASS: $pass | FAIL: $fail"
  fi
done

# สร้าง summary
echo "=============================="
echo "Security Score Trend: [Chart would be generated here]"

Troubleshooting

แก้ไขปัญหาที่อาจเกิดขึ้นขณะใช้งาน Docker Bench Security

1 ปัญหา: "permission denied" หรือ "command not found"

สาเหตุ: Script ไม่มีสิทธิ์การ execute หรือ path ผิด

วิธีแก้ไข:

bash
# ตรวจสอบสิทธิ์
ls -la docker-bench-security.sh

# ให้สิทธิ์ execute
chmod +x docker-bench-security.sh

# เรียกใช้ด้วย sudo
sudo ./docker-bench-security.sh

# หรือเรียกใช้โดยตรงกับ bash
sudo bash docker-bench-security.sh

2 ปัญหา: Docker daemon is not running

สาเหตุ: Docker service ไม่ได้ทำงานอยู่

วิธีแก้ไข:

bash
# ตรวจสอบสถานะ Docker
sudo systemctl status docker

# เริ่ม Docker service
sudo systemctl start docker

# รัน Docker Bench ใหม่
sudo ./docker-bench-security.sh

3 ปัญหา: Out of memory หรือ Timeout

สาเหตุ: ระบบมี memory ไม่เพียงพอหรือตรวจสอบหลาย files พร้อมกัน

วิธีแก้ไข:

bash
# ใช้ memory limit สำหรับการรัน Docker container
docker run -m 512m docker/docker-bench-security

# หรือรันเฉพาะบาง section แทนที่จะตรวจสอบทั้งหมด
sudo ./docker-bench-security.sh -c docker_daemon
sudo ./docker-bench-security.sh -c docker_container

4 ปัญหา: ผลลัพธ์มีแต่ FAIL ทั้งหมด

สาเหตุ: นี่อาจเป็นเรื่องปกติสำหรับ environment ที่ยังไม่ได้รับการ secure หรือมี configuration ที่ไม่ผ่านมาตรฐาน

วิธีแก้ไข:

1. ไม่ต้องกังวล - นี่คือจุดเริ่มต้น:

  • Docker Bench เป็นเครื่องมือช่วยวิเคราะห์ ไม่ใช่เครื่องมือบังคับ
  • บาง test อาจไม่เกี่ยวข้องกับ environment ของคุณ
  • ควรโฟกัสที่ FAIL items ที่สำคัญก่อน

2. อ่านคำอธิบายแต่ละ test:

คุณสามารถดูรายละเอียดเกี่ยวกับ test แต่ละตัวได้จาก:

bash
# เข้าไปดู source code
cat /opt/docker-bench-security/bench.sh | head -100

สรุป (Summary)

สิ่งที่เรียนรู้

  • Docker Bench for Security เป็นเครื่องมืออัตโนมัติที่ตรวจสอบการตั้งค่า Docker ตามมาตรฐาน CIS Docker Benchmark
  • มีวิธีการติดตั้ง 3 แบบ: Download Binary, Clone GitHub, ใช้ Docker Container
  • ผลลัพธ์มี 4 สถานะ: PASS, FAIL, WARN, INFO พร้อมคำแนะนำการแก้ไข
  • ควรผสาน Docker Bench เข้ากับ CI/CD และตั้ง schedule อัตโนมัติ
  • การใช้งานอย่างมีประสิทธิภาพต้องมีการวางแผนและจัดการอย่างต่อเนื่อง

Next Steps

  • อัปเดต Docker Bench เป็นเวอร์ชันล่าสุดทุกเดือน
  • ผสานกับ SIEM สำหรับ monitoring และ alerting
  • สร้าง dashboard สำหรับติดตาม security score ของระบบ
  • เรียนรู้เพิ่มเติมเกี่ยวกับ Docker Security Best Practices
  • สมัครเข้าร่วม community และติดตาม security advisory

Quick Reference

คำสั่งติดตั้ง

bash
wget https://raw.githubusercontent.com/docker/docker-bench-security/main/docker-bench-security.sh
chmod +x docker-bench-security.sh

คำสั่งรันการตรวจสอบ

bash
sudo ./docker-bench-security.sh
bash
sudo ./docker-bench-security.sh -c docker_daemon

ความหมายของสถานะผลลัพธ์

PASS
ผ่านเกณฑ์
Configuration ถูกต้อง
FAIL
ไม่ผ่านเกณฑ์
ต้องแก้ไขทันที
WARN
คำเตือน
ควรพิจารณาปรับปรุง
INFO
ข้อมูล
สำหรับอ่านดู

References & Resources

Official Repository

Docker Bench Security GitHub Repository - ซอร์สโค้ดหลัก ไดอารี่การเปลี่ยนแปลง และ documentation

https://github.com/docker/docker-bench-security

CIS Docker Benchmark

CIS (Center for Internet Security) Docker Benchmark v1.7.0 - Standard ความปลอดภัยระดับสากลสำหรับ Docker

https://www.cisecurity.org/benchmark/docker

Related Security Tools

Trivy: Security scanner for container and filesystem
Snyk: Developer-first security scanning
Aqua Security: Kubernetes and container security

Community Support

ชุมชนที่ช่วยเหลือและแลกเปลี่ยนความรู้เกี่ยวกับ Docker Security
Reddit: r/Docker, r/DevSecOps
Slack: Docker Community, Kubernetes Security

FAQ - คำถามที่พบบ่อย

Q Docker Bench Security สามารถรันบน Windows ได้หรือไม่?

A: Docker Bench Security ออกแบบมาสำหรับ Linux เท่านั้น แต่คุณสามารถรันผ่าน Docker Desktop บน Windows โดย mount ไฟล์เข้าไปใน container ได้

Q การตรวจสอบ FAIL ทำให้ Docker ไม่สามารถใช้งานได้หรือไม่?

A: ไม่จำเป็นค่ะ Docker Bench เป็นเพียงเครื่องมือตรวจสอบ ไม่ได้บังคับการตั้งค่าใดๆ แต่ FAIL บางรายการอาจทำให้ระบบมีความเสี่ยงสูง

Q ต้องรัน Docker Bench บ่อยแค่ไหน?

A: แนะนำให้รันอย่างน้อยสัปดาห์ละครั้งสำหรับ production environment หรือหลังการตั้งค่าใดๆ เปลี่ยนแปลง

Q ผลการตรวจสอบสามารถส่งออกเป็นไฟล์ PDF ได้หรือไม่?

A: Docker Bench รองรับ JSON และ Text output คุณสามารถใช้ tool อื่นแปลง JSON เป็น PDF ได้ หรือสร้าง script สำหรับสร้าง report PDF เอง