跳到主内容
智客 ZICQ

技能库 智客分类:安全测试 docker-security-guide

Docker Security Guide

综合多克安全准则和减轻威胁。 积极激活:(1) 集装箱安全审查,(2) 作为非终端用户运行,(3) 仅读取根文件系统和tmpfs挂载,(4) 能力下降(-cap-drop All),(5) 分包和AppArmor剖面,(6) 图像脆弱性扫描(Docker Scout, Trivy, Grype),(7) 供应链安全(签名图像,SBOM,出处),(8) 秘密管理(Docker secret,BuildKit -- secret,外部金库),(9) 网络分块(用户定义的网络,无 -- net=host),(10) 独联体多克基准遵守. 提供:硬化核对表,扫描工具集成配方,独联体基准绘图,秘密处理模式,以及能力投放参考.

625 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

综合多克安全准则和减轻威胁。 积极激活:(1) 集装箱安全审查,(2) 作为非终端用户运行,(3) 仅读取根文件系统和tmpfs挂载,(4) 能力下降(-cap-drop All),(5) 分包和AppArmor剖面,(6) 图像脆弱性扫描(Docker Scout, Trivy, Grype),(7) 供应链安全(签名图像,SBOM,出处),(8) 秘密管理(Docker secret,BuildKit -- secret,外部金库),(9) 网络分块(用户定义的网络,无 -- net=host),(10) 独联体多克基准遵守. 提供:硬化核对表,扫描工具集成配方,独联体基准绘图,秘密处理模式,以及能力投放参考.

何时用

页:1 安全关键应用程序、合规要求(SOC2、HIPAA、PCI-DSS)、零信任环境、供应链安全重点

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:🚨 CRITICAL GUIDELINES、Windows File Path Requirements、Documentation Guidelines、Docker Security Guide、Security Principles、Defense in Depth。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/build-runtime-security.md,属于带资源的技能包,这些文件按需再读。 正文约 548 行,超过规范建议的 500 行,激活时仍会整份载入。

官方 description(原文)

Comprehensive Docker security guidelines and threat mitigation. PROACTIVELY activate for: (1) container security review, (2) running as non-root user, (3) read-only root filesystems and tmpfs mounts, (4) capability dropping (--cap-drop ALL), (5) seccomp and AppArmor profiles, (6) image vulnerability scanning (Docker Scout, Trivy, Grype), (7) supply-chain security (signed images, SBOM, provenance), (8) secrets management (Docker secrets, BuildKit --secret, external vaults), (9) network segmentation (user-defined networks, no --net=host), (10) CIS Docker Benchmark compliance. Provides: hardening checklist, scan-tool integration recipes, CIS benchmark mapping, secret handling patterns, and capability-drop reference.

🚨 CRITICAL GUIDELINESWindows File Path RequirementsDocumentation GuidelinesDocker Security GuideSecurity PrinciplesDefense in DepthLeast PrivilegeImage SecurityBase Image SelectionUse official images onlyNOTVerify image source

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
docker-security-guide
description
Comprehensive Docker security guidelines and threat mitigation. PROACTIVELY activate for: (1) container security review, (2) running as non-root user, (3) read-only root filesystems and tmpfs mounts, (4) capability dropping (--cap-drop ALL), (5) seccomp and AppArmor profiles, (6) image vulnerability scanning (Docker Scout, Trivy, Grype), (7) supply-chain security (signed images, SBOM, provenance), (8) secrets management (Docker secrets, BuildKit --secret, external vaults), (9) network segmentation (user-defined networks, no --net=host), (10) CIS Docker Benchmark compliance. Provides: hardening checklist, scan-tool integration recipes, CIS benchmark mapping, secret handling patterns, and capability-drop reference.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 1
  • references/build-runtime-security.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「docker-security-guide」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-e876dcefc5602c43-Docker-Security-Guide.html
请存为 .cursor/skills/docker-security-guide/SKILL.md 或 .claude/skills/docker-security-guide/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/josiahsiegel/claude-plugin-marketplace 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/josiahsiegel/claude-plugin-marketplace' --list

npx skills add 'https://github.com/josiahsiegel/claude-plugin-marketplace' --skill 'docker-security-guide'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: docker-security-guide description: | Comprehensive Docker security guidelines and threat mitigation. PROACTIVELY activate for: (1) container security review, (2) running as non-root user, (3) read-only root filesystems and tmpfs mounts, (4) capability dropping (--cap-drop ALL), (5) seccomp and AppArmor profiles, (6) image vulnerability scanning (Docker Scout, Trivy, Grype), (7) supply-chain security (signed images, SBOM, provenance), (8) secrets management (Docker secrets, BuildKit --secret, external vaults), (9) network segmentation (user-defined networks, no --net=host), (10) CIS Docker Benchmark compliance. Provides: hardening checklist, scan-tool integration recipes, CIS benchmark mapping, secret handling patterns, and capability-drop reference.

🚨 CRITICAL GUIDELINES

Windows File Path Requirements

MANDATORY: Always Use Backslashes on Windows for File Paths

When using Edit or Write tools on Windows, you MUST use backslashes (\) in file paths, NOT forward slashes (/).

Examples:

  • ❌ WRONG: D:/repos/project/file.tsx
  • ✅ CORRECT: D:\repos\project\file.tsx

This applies to:

  • Edit tool file_path parameter
  • Write tool file_path parameter
  • All file operations on Windows systems

Documentation Guidelines

NEVER create new documentation files unless explicitly requested by the user.

  • Priority: Update existing README.md files rather than creating new documentation
  • Repository cleanliness: Keep repository root clean - only README.md unless user requests otherwise
  • Style: Documentation should be concise, direct, and professional - avoid AI-generated tone
  • User preference: Only create additional .md files when user specifically asks for documentation

Docker Security Guide

This skill provides comprehensive security guidelines for Docker across all platforms, covering threats, mitigations, and compliance requirements.

Security Principles

Defense in Depth

Apply security at multiple layers:

  1. Image security: Minimal, scanned, signed images
  2. Build security: Secure build process, no secrets in layers
  3. Runtime security: Restricted capabilities, resource limits
  4. Network security: Isolation, least privilege
  5. Host security: Hardened host OS, updated Docker daemon
  6. Orchestration security: Secure configuration, RBAC
  7. Monitoring: Detection, logging, alerting

Least Privilege

Grant only the minimum permissions necessary:

  • Non-root users
  • Dropped capabilities
  • Read-only filesystems
  • Minimal network exposure
  • Restricted syscalls (seccomp)
  • Limited resources

Image Security

Base Image Selection

Threat: Vulnerable or malicious base images

Mitigation:

# Use official images only
FROM node:20.11.0-alpine3.19  # Official, specific version

# NOT
FROM randomuser/node  # Unverified source
FROM node:latest      # Unpredictable, can break

Verification:

# Verify image source
docker image inspect node:20-alpine | grep -A 5 "Author"

# Enable Docker Content Trust (image signing)
export DOCKER_CONTENT_TRUST=1
docker pull node:20-alpine

Minimal Images

Threat: Larger attack surface, more vulnerabilities

Mitigation:

# Prefer minimal distributions
FROM alpine:3.19           # ~7MB
FROM gcr.io/distroless/static  # ~2MB
FROM scratch               # 0MB (for static binaries)

# vs
FROM ubuntu:22.04          # ~77MB with more packages

Benefits:

  • Fewer packages = fewer vulnerabilities
  • Smaller attack surface
  • Faster downloads and starts
  • Less disk space

Micro-Distros for Security-Critical Applications (2025)

Wolfi/Chainguard Images:

  • Zero-CVE goal, SBOM included by default
  • Nightly security patches, signed with provenance
  • Available for: Node, Python, Go, Java, .NET, etc.

Usage:

# Development stage (includes build tools)
FROM cgr.dev/chainguard/node:latest-dev AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

# Production stage (minimal, zero-CVE goal)
FROM cgr.dev/chainguard/node:latest
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER node
ENTRYPOINT ["node", "server.js"]

When to use: Security-critical apps, compliance requirements (SOC2, HIPAA, PCI-DSS), zero-trust environments, supply chain security emphasis.

See docker-best-practices skill for full image comparison table.

Vulnerability Scanning

Tools:

  • Docker Scout (built-in)
  • Trivy
  • Grype
  • Snyk
  • Clair

Process:

# Scan with Docker Scout
docker scout cves IMAGE_NAME
docker scout recommendations IMAGE_NAME

# Scan with Trivy
trivy image IMAGE_NAME
trivy image --severity HIGH,CRITICAL IMAGE_NAME

# Scan Dockerfile
trivy config Dockerfile

# Scan for secrets
trivy fs --scanners secret .

CI/CD Integration:

# GitHub Actions example
- name: Scan image
  run: |
    docker scout cves my-image:${{ github.sha }}
    trivy image --exit-code 1 --severity CRITICAL my-image:${{ github.sha }}

Multi-Stage Builds for Security

Threat: Build tools and secrets in final image

Mitigation:

# Build stage with build tools
FROM golang:1.21 AS builder
WORKDIR /app
COPY . .
RUN go build -o app

# Final stage - minimal, no build tools
FROM gcr.io/distroless/base-debian11
COPY --from=builder /app/app /
USER nonroot:nonroot
ENTRYPOINT ["/app"]

Benefits:

  • No compiler/build tools in production image
  • Secrets used in build don't persist
  • Smaller, more secure final image

Build-Time & Runtime Security

Complete recipes for build secrets (--mount=type=secret, BuildKit), multi-stage hardening, capability drops (--cap-drop=ALL), seccomp / AppArmor profiles, read-only root, user namespaces, resource limits, and rootless runtime live in references/build-runtime-security.md. Core principles:

  • Build secrets: use --mount=type=secret and --mount=type=ssh; never ARG/ENV for sensitive values.
  • Runtime: drop all capabilities and add back what is needed; run read-only root; non-root user; resource limits; pinned image digests.
  • Profiles: apply seccomp, AppArmor, and SELinux; combine with user namespaces.

See references/build-runtime-security.md for all commands and recipes.

Network Security

Network Isolation

Threat: Lateral movement between containers

Mitigation:

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge
    internal: true  # No external access

services:
  web:
    networks:
      - frontend

  api:
    networks:
      - frontend
      - backend

  database:
    networks:
      - backend  # Isolated from frontend

Port Exposure

Threat: Unnecessary network exposure

Mitigation:

# Bind to localhost only
docker run -p 127.0.0.1:8080:8080 my-image

# NOT (binds to all interfaces)
docker run -p 8080:8080 my-image

In Compose:

services:
  app:
    ports:
      - "127.0.0.1:8080:8080"  # Localhost only

Inter-Container Communication

# Disable default inter-container communication
# /etc/docker/daemon.json
{
  "icc": false
}

Then explicitly allow via networks:

services:
  app1:
    networks:
      - app-network
  app2:
    networks:
      - app-network  # Can communicate with app1

networks:
  app-network:
    driver: bridge

Secrets Management

Docker Secrets (Swarm Mode)

# Create secret
echo "mypassword" | docker secret create db_password -

# Use in service
docker service create \
  --name my-service \
  --secret db_password \
  my-image

# Access in container at /run/secrets/db_password

In stack file:

version: '3.8'

services:
  app:
    image: my-image
    secrets:
      - db_password

secrets:
  db_password:
    external: true

Secrets Best Practices

  1. Never in environment variables (visible in docker inspect)
  2. Never in images (in layer history)
  3. Never in version control (Git history)
  4. Mount as files with restricted permissions
  5. Use secret management systems (Vault, AWS Secrets Manager, etc.)
  6. Rotate regularly

Alternative: Mounted secrets:

docker run -v /secure/secrets:/run/secrets:ro my-image

Compliance & Benchmarking

CIS Docker Benchmark

Automated checking:

# Clone docker-bench-security
git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
sudo sh docker-bench-security.sh

# Or run as container
docker run --rm --net host --pid host --userns host \
  --cap-add audit_control \
  -v /var/lib:/var/lib:ro \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /usr/lib/systemd:/usr/lib/systemd:ro \
  -v /etc:/etc:ro \
  docker/docker-bench-security

Key CIS Recommendations

  1. Host Configuration

    • Keep Docker up to date
    • Restrict network traffic between containers
    • Set logging level to 'info'
    • Enable Docker Content Trust
  2. Docker Daemon

    • Use TLS for Docker daemon socket
    • Don't expose daemon on TCP without TLS
    • Enable user namespace support
  3. Docker Files

    • Verify Docker files ownership and permissions
    • Audit Docker files and directories
  4. Container Images

    • Create user for container
    • Use trusted base images
    • Don't install unnecessary packages
  5. Container Runtime

    • Run containers with limited privileges
    • Set resource limits
    • Don't share host network namespace

Monitoring & Detection

Logging

services:
  app:
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
        labels: "service,env"
        env: "ENV,VERSION"

Centralized logging:

services:
  app:
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://log-server:514"
        tag: "{{.Name}}/{{.ID}}"

Runtime Monitoring

Tools:

  • Falco: Runtime security monitoring
  • Sysdig: Container visibility
  • Prometheus + cAdvisor: Metrics
  • Docker events: Real-time events

Monitor for:

  • Unexpected processes
  • File modifications
  • Network connections
  • Resource spikes
  • Failed authentication
  • Privilege escalation attempts
# Monitor Docker events
docker events --filter 'type=container' --filter 'event=start'

# Watch specific container
docker events --filter "container=my-container"

# Runtime security with Falco
docker run --rm -it \
  --privileged \
  -v /var/run/docker.sock:/host/var/run/docker.sock \
  -v /dev:/host/dev \
  -v /proc:/host/proc:ro \
  falcosecurity/falco

Platform-Specific Security

Linux

User namespace remapping:

// /etc/docker/daemon.json
{
  "userns-remap": "default"
}

Benefits: Root in container → unprivileged on host

SELinux:

# Enable SELinux for Docker
setenforce 1

# Run with SELinux labels
docker run --security-opt label=type:svirt_sandbox_file_t my-image

# Volumes with SELinux
docker run -v /host/path:/container/path:z my-image

AppArmor:

# Check AppArmor status
aa-status

# Run with AppArmor profile
docker run --security-opt apparmor=docker-default my-image

Windows

Hyper-V isolation:

# More isolated than process isolation
docker run --isolation=hyperv my-image

Windows Defender:

  • Ensure real-time protection enabled
  • Configure exclusions carefully
  • Scan images regularly

macOS

Docker Desktop security:

  • Keep Docker Desktop updated
  • Enable "Use gRPC FUSE for file sharing"
  • Limit file sharing to necessary paths
  • Review resource allocation

Security Checklist

Image:

  • [ ] Based on official, minimal image
  • [ ] Specific version tag (not latest)
  • [ ] Scanned for vulnerabilities
  • [ ] No secrets in layers
  • [ ] Runs as non-root user
  • [ ] Signed (Content Trust)

Build:

  • [ ] .dockerignore configured
  • [ ] Multi-stage build (if applicable)
  • [ ] Build secrets handled properly
  • [ ] Build from trusted sources only

Runtime:

  • [ ] Non-root user
  • [ ] Capabilities dropped
  • [ ] Read-only filesystem (where possible)
  • [ ] Security options set
  • [ ] Resource limits configured
  • [ ] Isolated network
  • [ ] Minimal port exposure
  • [ ] Secrets mounted securely

Operations:

  • [ ] CIS benchmark compliance
  • [ ] Logging configured
  • [ ] Monitoring in place
  • [ ] Regular vulnerability scans
  • [ ] Incident response plan
  • [ ] Regular updates
  • [ ] Audit logs enabled

Common Security Mistakes

❌ NEVER:

  • Run as root
  • Use --privileged
  • Mount Docker socket (/var/run/docker.sock)
  • Hardcode secrets
  • Use latest tag
  • Skip vulnerability scanning
  • Expose unnecessary ports
  • Disable security features
  • Ignore security updates
  • Trust unverified images

✅ ALWAYS:

  • Run as non-root
  • Drop capabilities
  • Scan for vulnerabilities
  • Use secrets management
  • Tag with specific versions
  • Enable security options
  • Apply least privilege
  • Keep systems updated
  • Monitor runtime behavior
  • Use official images

This security guide represents current best practices. Security threats evolve constantly—always check the latest Docker security documentation and CVE databases.

相关技能

安全测试

Skill Vetter

人工智能特工的安全第一技能审查。 在安装来自 ClawdHub, GitHub 或其他来源的任何技能之前使用 。 检查红旗,许可范围,可疑图案.

安全测试

Moltguard

MoltGuard——由OpenGuardrails担任OpenClaw保安. 安装 MoltGuard 以保护你和你的人类免受迅速注射、数据过滤和恶意命令的影响。 资料来源:https://github.com/openguardrails/openguardrails/tre…

安全测试

Security Auditor

用于审查安全漏洞代码,实施认证流,审计OWASP Top 10,配置CORS/CSP头,处理秘密,输入验证,SQL注射预防,XSS保护,或任何与安全相关的代码审查.

安全测试

Skill Vetter

安装任何AI代理技能前的安全审查协议. 红旗侦取入证盗取,疏通密码,放出. 风险分类:低/中/高/高。 编制结构化审查报告。 不先运行此功能, 绝不安装不信任的技能 .