Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
dockle — 容器镜像安全Linter,帮助构建最佳实践的Docker镜像,易于上手。 | Kitploit
工具/GitHubGitHub/goodwithtech/dockle
漏洞扫描器容器安全配置审计DevSecOps
GitHubgoodwithtech/dockle

dockle

容器镜像安全Linter,帮助构建最佳实践的Docker镜像,易于上手。

查看仓库网站
3.3k16662个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

Financial Contributors on Open Collective GitHub release CircleCI Go Report Card License: AGPL v3

Dockle - 用于安全的容器镜像检查工具,帮助构建最佳实践的Docker镜像,易于上手

Dockle 帮助你:

  1. 构建最佳实践的Docker镜像
  2. 构建安全的Docker镜像
    • 检查点包括CIS基准```bash $ brew untap goodwithtech/dockle # who use 0.1.16 or older version $ brew install goodwithtech/r/dockle $ dockle [YOUR_IMAGE_NAME]
root@kitploit:~
参见 [安装](#installation) 和 [常见示例](#common-examples)

<img src="https://assets.kitploit.com/production/public/readmes/4137/343598bd4d53296c6d6d23acde8c2917d5727f03e7b3a34c1ff0865c435bb974.png" width="800">

# 检查点对比

<img src="https://assets.kitploit.com/production/public/readmes/4137/4f4835c3a5fd70f436d9d8ea656fd8a521112fece4e35977288064d3f6f4510a.png" width="800">
<img src="https://assets.kitploit.com/production/public/readmes/4137/7bee9da0b061957af6a175a3b975dca82813c27f72ab6921dfe8ab2d6747322b.png" width="800">

# 目录

- [特性](#features)
- [对比](#comparison)
- [安装](#installation)
  - [Homebrew (Mac OS X / Linux 和 WSL)](#homebrew-mac-os-x--linux-and-wsl)
  - [RHEL/CentOS](#rhelcentos)
  - [Debian/Ubuntu](#debianubuntu)
  - [Arch Linux](#arch-linux)
  - [Windows](#windows)
  - [Microsoft PowerShell 7](#microsoft-powershell-7)
  - [二进制](#binary)
  - [asdf](#asdf)
  - [mise](#mise)
  - [源码编译](#from-source)
  - [使用 Docker](#use-docker)
- [快速开始](#quick-start)
  - [基础](#basic)
  - [Docker](#docker)
- [检查点概述](#checkpoint-summary)
- [常见示例](#common-examples)
  - [扫描镜像](#scan-an-image)
  - [扫描镜像文件](#scan-an-image-file)
  - [以 JSON 格式获取或保存结果](#get-or-save-the-results-as-json)
  - [以 SARIF 格式获取或保存结果](#get-or-save-the-results-as-sarif)
  - [指定退出码](#specify-exit-code)
  - [指定退出级别](#specify-exit-level)
  - [忽略指定的检查点](#ignore-the-specified-checkpoints)
  - [接受可疑的环境变量 / 文件 / 文件扩展名](#accept-suspicious-environment-variables--files--file-extensions)
  - [拒绝可疑的环境变量 / 文件 / 文件扩展名](#reject-suspicious-environment-variables--files--file-extensions)
- [持续集成 (CI)](#continuous-integration-ci)
  - [GitHub Action](#github-action)
  - [Travis CI](#travis-ci)
  - [CircleCI](#circleci)
  - [GitLab CI](#gitlab-ci)
  - [私有 Docker 仓库的认证](#authorization-for-private-docker-registry)
    - [Docker Hub](#docker-hub)
    - [Amazon ECR (Elastic Container Registry)](#amazon-ecr-elastic-container-registry)
    - [GCR (Google Container Registry)](#gcr-google-container-registry)
    - [自托管仓库 (BasicAuth)](#self-hosted-registry-basicauth)
- [贡献者](#contributors)
  - [代码贡献者](#code-contributors)
  - [财务贡献者](#financial-contributors)
    - [个人](#individuals)
    - [组织](#organizations)
- [许可证](#license)
- [作者](#author)

# 特性

- 检测容器漏洞
- 帮助构建最佳实践的 Dockerfile
- 使用简单
  - 仅需指定镜像名称
  - 参见 [快速开始](#quick-start) 和 [常见示例](#common-examples)
- 支持 CIS 基准
  - 高准确度
- DevSecOps
  - 适用于 CI,如 Travis CI、CircleCI、Jenkins 等
  - 参见 [CI 示例](#continuous-integration-ci)

# 对比

|  | [Dockle](https://github.com/goodwithtech/dockle) | [Hadolint](https://github.com/hadolint/hadolint) | [Docker Bench for Security](https://github.com/docker/docker-bench-security) | [Clair](https://github.com/coreos/clair) |
|--- |---:|---:|---:|---:|
| 目标 | 镜像 | Dockerfile | 主机<br/>Docker 守护进程<br/>镜像<br/>容器运行时 | 镜像 |
| 运行方式 | 二进制 | 二进制 | Shell 脚本 | 二进制 |
| 依赖 | 无 | 无 | 一些依赖 | 无 |
| CI 适用性 | ✓ | ✓ | x | x | 
| 目的 | 安全审计<br/>Dockerfile 检查 | Dockerfile 检查 | 安全审计<br/>Dockerfile 检查 | 漏洞扫描 |

# 安装

## Homebrew (Mac OS X / Linux 和 WSL)

你可以在 [Mac OS X](https://brew.sh/) 或 [Linux 和 WSL(Windows Subsystem for Linux)](https://docs.brew.sh/Homebrew-on-Linux) 上使用 Homebrew。```bash
$ brew install goodwithtech/r/dockle

RHEL/CentOS```bash

VERSION=$( curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" |
grep '"tag_name":' |
sed -E 's/."v([^"]+)"./\1/'
) && rpm -ivh https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.rpm

root@kitploit:~
## Debian/Ubuntu```bash
VERSION=$(
 curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | \
 grep '"tag_name":' | \
 sed -E 's/.*"v([^"]+)".*/\1/' \
) && curl -L -o dockle.deb https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.deb
$ sudo dpkg -i dockle.deb && rm dockle.deb

Arch Linux

可以通过Arch用户软件仓库使用dockle或dockle-bin包来安装dockle。``` git clone https://aur.archlinux.org/dockle-bin.git cd dockle-bin makepkg -sri

root@kitploit:~
## Windows```bash
VERSION=$(
 curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | \
 grep '"tag_name":' | \
 sed -E 's/.*"v([^"]+)".*/\1/' \
) && curl -L -o dockle.zip https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Windows-64bit.zip
$ unzip dockle.zip && rm dockle.zip
$ ./dockle.exe [IMAGE_NAME]

Microsoft PowerShell 7```bash

if (((Invoke-WebRequest "https://api.github.com/repos/goodwithtech/dockle/releases/latest").Content) -match '"tag_name":"v(?[^"]+)"') { $VERSION=$Matches.ver && Invoke-WebRequest "https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Windows-64bit.zip" -OutFile dockle.zip && Expand-Archive dockle.zip && Remove-Item dockle.zip }

root@kitploit:~
## Binary

你可以从 [releases 页面](https://github.com/goodwithtech/dockle/releases/latest) 获取最新版本的二进制文件。

下载适用于你操作系统/架构的归档文件。解压归档,并将二进制文件放到你的 `$PATH` 中的某个位置(在类 UNIX 系统上,通常是 `/usr/local/bin` 或类似路径)。

- 注意:确保其可执行位已开启。(`chmod +x dockle`)

## asdf

你可以通过 [asdf 版本管理器](https://asdf-vm.com/) 和这个 [插件](https://github.com/mathew-fleisch/asdf-dockle) 来安装 dockle,该插件自动化了安装(以及切换)各种版本 GitHub 发布二进制文件的过程。在已安装 asdf 的情况下,运行以下命令来安装 dockle:```bash
# Add dockle plugin
asdf plugin add dockle

# Show all installable versions
asdf list-all dockle

# Install specific version
asdf install dockle latest

# Set a version globally (on your ~/.tool-versions file)
asdf global dockle latest

# Now dockle commands are available
dockle --version

mise

你可以使用 mise(多语言工具版本管理器)来安装 dockle。在已安装 mise 的情况下,运行以下命令来安装 dockle:```bash

Show all installable versions

mise ls-remote dockle

Install specific version

mise install dockle@latest

Set a version globally

mise use -g dockle@latest

Now dockle commands are available

dockle --version

root@kitploit:~
## 从源码```bash
$ GO111MODULE=off go get github.com/goodwithtech/dockle/cmd/dockle
$ cd $GOPATH/src/github.com/goodwithtech/dockle && GO111MODULE=on go build -o $GOPATH/bin/dockle cmd/dockle/main.go

使用 Docker

Docker Hub 上也有一个 Dockle 镜像。你可以在安装命令之前试用 dockle。``` $ VERSION=$( curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" |
grep '"tag_name":' |
sed -E 's/."v([^"]+)"./\1/'
) && docker run --rm -v /var/run/docker.sock:/var/run/docker.sock
goodwithtech/dockle:v${VERSION} [YOUR_IMAGE_NAME]

root@kitploit:~
当你想要扫描主机上的镜像时,你只需要 `-v /var/run/docker.sock:/var/run/docker.sock`。

# 快速开始

## 基础

只需指定一个镜像名称(及标签)。```bash
$ dockle [YOUR_IMAGE_NAME]
结果``` FATAL - CIS-DI-0009: Use COPY instead of ADD in Dockerfile * Use COPY : /bin/sh -c #(nop) ADD file:81c0a803075715d1a6b4f75a29f8a01b21cc170cfc1bff6702317d1be2fe71a3 in /app/credentials.json FATAL - CIS-DI-0010: Do not store credential in ENVIRONMENT vars/files * Suspicious filename found : app/credentials.json FATAL - DKL-DI-0005: Clear apt-get caches * Use 'rm -rf /var/lib/apt/lists' after 'apt-get install' : /bin/sh -c apt-get update && apt-get install -y git FATAL - DKL-LI-0001: Avoid empty password * No password user found! username : nopasswd WARN - CIS-DI-0001: Create a user for the container * Last user should not be root INFO - CIS-DI-0005: Enable Content trust for Docker * export DOCKER_CONTENT_TRUST=1 before docker pull/build INFO - CIS-DI-0008: Confirm safety of setuid/setgid files * setuid file: app/suid.txt urw-r--r-- * setgid file: app/gid.txt grw-r--r-- * setuid file: usr/bin/gpasswd urwxr-xr-x * setgid file: usr/bin/wall grwxr-xr-x * setuid file: bin/su urwxr-xr-x * setuid file: bin/umount urwxr-xr-x * setuid file: bin/mount urwxr-xr-x * setgid file: usr/bin/ssh-agent grwxr-xr-x * setuid file: etc/shadow urw-r----- * setuid file: usr/bin/chsh urwxr-xr-x * setuid file: usr/bin/chfn urwxr-xr-x * setuid file: usr/lib/openssh/ssh-keysign urwxr-xr-x * setgid file: etc/passwd grw-r--r-- * setgid file: sbin/unix_chkpwd grwxr-xr-x * setgid file: usr/bin/chage grwxr-xr-x * setuid file: usr/bin/passwd urwxr-xr-x * setgid file: usr/bin/expiry grwxr-xr-x * setuid file: usr/bin/newgrp urwxr-xr-x IGNORE - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
root@kitploit:~
</details>

## Docker

此外,您也可以使用 Docker 运行 `dockle` 命令,如下所示。```bash
$ export DOCKLE_LATEST=$(
 curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | \
 grep '"tag_name":' | \
 sed -E 's/.*"v([^"]+)".*/\1/' \
)
$ docker run --rm goodwithtech/dockle:v${DOCKLE_LATEST} [YOUR_IMAGE_NAME]
  • 如果您想扫描宿主机上的镜像,您需要挂载 docker.sock。

    root@kitploit:~
    $ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ...
    

扫描图像文件```bash

$ docker save alpine:latest -o alpine.tar $ dockle --input alpine.tar

root@kitploit:~
### 获取或保存结果为JSON```bash
$ dockle -f json goodwithtech/test-image:v1
$ dockle -f json -o results.json goodwithtech/test-image:v1
结果```json { "summary": { "fatal": 6, "warn": 2, "info": 2, "pass": 7 }, "details": [ { "code": "CIS-DI-0001", "title": "Create a user for the container", "level": "WARN", "alerts": [ "Last user should not be root" ] }, { "code": "CIS-DI-0005", "title": "Enable Content trust for Docker", "level": "INFO", "alerts": [ "export DOCKER_CONTENT_TRUST=1 before docker pull/build" ] }, { "code": "CIS-DI-0006", "title": "Add HEALTHCHECK instruction to the container image", "level": "WARN", "alerts": [ "not found HEALTHCHECK statement" ] }, { "code": "CIS-DI-0008", "title": "Remove setuid and setgid permissions in the images", "level": "INFO", "alerts": [ "Found setuid file: usr/lib/openssh/ssh-keysign urwxr-xr-x" ] }, { "code": "CIS-DI-0009", "title": "Use COPY instead of ADD in Dockerfile", "level": "FATAL", "alerts": [ "Use COPY : /bin/sh -c #(nop) ADD file:81c0a803075715d1a6b4f75a29f8a01b21cc170cfc1bff6702317d1be2fe71a3 in /app/credentials.json " ] }, { "code": "CIS-DI-0010", "title": "Do not store secrets in ENVIRONMENT variables", "level": "FATAL", "alerts": [ "Suspicious ENV key found : MYSQL_PASSWD" ] }, { "code": "CIS-DI-0010", "title": "Do not store secret files", "level": "FATAL", "alerts": [ "Suspicious filename found : app/credentials.json " ] }, { "code": "DKL-DI-0002", "title": "Avoid sensitive directory mounting", "level": "FATAL", "alerts": [ "Avoid mounting sensitive dirs : /usr" ] }, { "code": "DKL-DI-0005", "title": "Clear apt-get caches", "level": "FATAL", "alerts": [ "Use 'rm -rf /var/lib/apt/lists' after 'apt-get install' : /bin/sh -c apt-get update \u0026\u0026 apt-get install -y git" ] }, { "code": "DKL-LI-0001", "title": "Avoid empty password", "level": "FATAL", "alerts": [ "No password user found! username : nopasswd" ] } ] } ```

获取或保存结果为 SARIF```bash

$ dockle -f sarif goodwithtech/test-image:v1 $ dockle -f sarif -o results.json goodwithtech/test-image:v1

root@kitploit:~
<details>
<summary>结果</summary>```json
{
  "version": "2.1.0",
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "Dockle",
          "informationUri": "https://github.com/goodwithtech/dockle",
          "rules": [
            {
              "id": "CIS-DI-0009",
              "shortDescription": {
                "text": "Use COPY instead of ADD in Dockerfile"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0009"
              }
            },
            {
              "id": "CIS-DI-0010",
              "shortDescription": {
                "text": "Do not store credential in ENVIRONMENT vars/files"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0010"
              }
            },
            {
              "id": "DKL-DI-0005",
              "shortDescription": {
                "text": "Clear apt-get caches"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#DKL-DI-0005"
              }
            },
            {
              "id": "DKL-LI-0001",
              "shortDescription": {
                "text": "Avoid empty password"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#DKL-LI-0001"
              }
            },
            {
              "id": "CIS-DI-0005",
              "shortDescription": {
                "text": "Enable Content trust for Docker"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0005"
              }
            },
            {
              "id": "CIS-DI-0008",
              "shortDescription": {
                "text": "Confirm safety of setuid/setgid files"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0008"
              }
            },
            {
              "id": "CIS-DI-0001",
              "shortDescription": {
                "text": "Create a user for the container"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0001"
              }
            },
            {
              "id": "CIS-DI-0006",
              "shortDescription": {
                "text": "Add HEALTHCHECK instruction to the container image"
              },
              "help": {
                "text": "https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#CIS-DI-0006"
              }
            }
          ]
        }
      },
      "results": [
        {
          "ruleId": "CIS-DI-0009",
          "level": "error",
          "message": {
            "text": "Use COPY : /bin/sh -c #(nop) ADD file:81c0a803075715d1a6b4f75a29f8a01b21cc170cfc1bff6702317d1be2fe71a3 in /app/credentials.json "
          }
        },
        {
          "ruleId": "CIS-DI-0010",
          "level": "error",
          "message": {
            "text": "Suspicious filename found : app/credentials.json , Suspicious ENV key found : MYSQL_PASSWD"
          }
        },
        {
          "ruleId": "DKL-DI-0005",
          "level": "error",
          "message": {
            "text": "Use 'rm -rf /var/lib/apt/lists' after 'apt-get install' : /bin/sh -c apt-get update \u0026\u0026 apt-get install -y git"
          }
        },
        {
          "ruleId": "DKL-LI-0001",
          "level": "error",
          "message": {
            "text": "No password user found! username : nopasswd"
          }
        },
        {
          "ruleId": "CIS-DI-0005",
          "level": "note",
          "message": {
            "text": "export DOCKER_CONTENT_TRUST=1 before docker pull/build"
          }
        },
        {
          "ruleId": "CIS-DI-0008",
          "level": "note",
          "message": {
            "text": "setuid file: urwxr-xr-x usr/bin/newgrp, setgid file: grwxr-xr-x usr/bin/ssh-agent, setgid file: grwxr-xr-x usr/bin/expiry, setuid file: urwxr-xr-x usr/lib/openssh/ssh-keysign, setuid file: urwxr-xr-x bin/umount, setgid file: grwxr-xr-x usr/bin/chage, setuid file: urwxr-xr-x usr/bin/passwd, setgid file: grwxr-xr-x sbin/unix_chkpwd, setuid file: urwxr-xr-x usr/bin/chsh, setgid file: grwxr-xr-x usr/bin/wall, setuid file: urwxr-xr-x bin/ping, setuid file: urwxr-xr-x bin/su, setuid file: urwxr-xr-x usr/bin/chfn, setuid file: urwxr-xr-x usr/bin/gpasswd, setuid file: urwxr-xr-x bin/mount"
          }
        },
        {
          "ruleId": "CIS-DI-0001",
          "level": "none",
          "message": {
            "text": "Last user should not be root"
          }
        },
        {
          "ruleId": "CIS-DI-0006",
          "level": "none",
          "message": {
            "text": "not found HEALTHCHECK statement"
          }
        }
      ]
    }
  ]
}

指定退出码

默认情况下,即使存在一些问题,Dockle 也会以退出码 0 退出。

使用 --exit-code, -c 选项,如果发现 WARN 或 FATAL 警报,则以非零退出码退出。```bash $ dockle --exit-code 1 [IMAGE_NAME]

root@kitploit:~
### Specify exit level

默认情况下,当存在 `WARN` 或 `FATAL` 级别的警报时,`--exit-code` 会运行。

使用 `--exit-level, -l` 选项更改警报级别。可以设置为 `info`、`warn` 或 `fatal`。```bash
$ dockle --exit-code 1 --exit-level info [IMAGE_NAME]
$ dockle --exit-code 1 --exit-level fatal [IMAGE_NAME]

忽略指定的检查点

--ignore, -i 选项可以忽略指定的检查点。```bash $ dockle -i CIS-DI-0001 -i DKL-DI-0006 [IMAGE_NAME]

root@kitploit:~
或者,使用 `DOCKLE_IGNORES`:```
export DOCKLE_IGNORES=CIS-DI-0001,DKL-DI-0006
dockle [IMAGE_NAME]

或者,使用 .dockleignore 文件:```bash $ cat .dockleignore

set root to default user because we want to run nginx

CIS-DI-0001

Use latest tag because to check the image inside only

DKL-DI-0006

root@kitploit:~
### 接受可疑的 `environment variables` / `files` / `file extensions````bash
# --accept-key value, --ak value             You can add acceptable keywords.
dockle -ak GPG_KEY -ak KEYCLOAK_VERSION [IMAGE_NAME]
or DOCKLE_ACCEPT_KEYS=GPG_KEY,KEYCLOAK_VERSION dockle [IMAGE_NAME]

# --accept-file value, --af value            You can add acceptable file names.
dockle -af id_rsa -af id_dsa [IMAGE_NAME]
or DOCKLE_ACCEPT_FILES=id_rsa,id_dsa dockle [IMAGE_NAME]

# --accept-file-extension value, --ae value  You can add acceptable file extensions.
dockle -ae pem -ae log [IMAGE_NAME]
or DOCKLE_ACCEPT_FILE_EXTENSIONS=pem,log dockle [IMAGE_NAME]

拒绝可疑的 environment variables / files / `file extensions````bash

--sensitive-word value, --sw value You can add acceptable keywords.

dockle -sw PRIVATE [IMAGE_NAME] or DOCKLE_ACCEPT_KEYS=GPG_KEY,KEYCLOAK_VERSION dockle [IMAGE_NAME]

--sensitive-file value, --sf value You can add acceptable file names.

dockle -sf .env [IMAGE_NAME] or DOCKLE_REJECT_FILES=.env dockle [IMAGE_NAME]

--sensitive-file-extension value, --se value You can add acceptable file extensions.

dockle -se pfx [IMAGE_NAME] or DOCKLE_REJECT_FILE_EXTENSIONS=pfx dockle [IMAGE_NAME]

root@kitploit:~
## 持续集成 (CI)

你可以在 Travis CI/CircleCI 中使用 `Dockle` 扫描构建的镜像。

在这些示例中,如果发现任何警告,测试将会失败。

不过,你可以通过使用 `.dockleignore` 文件忽略指定的检查点。

或者,如果你只想显示结果而不让测试因此失败,可以在 `dockle` 命令中指定 `--exit-code` 为 `0`。

### GitHub Action

我们提供了 [goodwithtech/dockle-action](https://github.com/goodwithtech/dockle-action)。```yaml
- uses: goodwithtech/dockle-action@main
  with:
    image: 'target'
    format: 'list'
    exit-code: '1'
    exit-level: 'warn'
    ignore: 'CIS-DI-0001,DKL-DI-0006'

Travis CI

.travis.yml```yaml services: - docker

env: global: - COMMIT=${TRAVIS_COMMIT::8}

before_install:

  • docker build -t dockle-ci-test:${COMMIT} .
  • export VERSION=$(curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | grep '"tag_name":' | sed -E 's/."v([^"]+)"./\1/')
  • wget https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.tar.gz
  • tar zxvf dockle_${VERSION}_Linux-64bit.tar.gz script:
  • ./dockle dockle-ci-test:${COMMIT}
  • ./dockle --exit-code 1 dockle-ci-test:${COMMIT}
root@kitploit:~
</details>

- 示例: https://travis-ci.org/goodwithtech/dockle-ci-test
- 仓库: https://github.com/goodwithtech/dockle-ci-test

### CircleCI

<details>
<summary>.circleci/config.yml</summary>```yaml
jobs:
  build:
    docker:
      - image: docker:18.09-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Build image
          command: docker build -t dockle-ci-test:${CIRCLE_SHA1} .
      - run:
          name: Install dockle
          command: |
            apk add --update curl
            VERSION=$(
                curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | \
                grep '"tag_name":' | \
                sed -E 's/.*"v([^"]+)".*/\1/'
            )
            wget https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.tar.gz
            tar zxvf dockle_${VERSION}_Linux-64bit.tar.gz
            mv dockle /usr/local/bin
      - run:
          name: Scan the local image with dockle
          command: dockle --exit-code 1 dockle-ci-test:${CIRCLE_SHA1}
workflows:
  version: 2
  release:
    jobs:
      - build
  • 示例: https://circleci.com/gh/goodwithtech/dockle-ci-test
  • 仓库: https://github.com/goodwithtech/dockle-ci-test

GitLab CI

.gitlab-ci.yml```yaml image: docker:stable stages: - test

variables: DOCKER_HOST: tcp://docker:2375/ DOCKER_DRIVER: overlay2 services:

  • docker:dind

unit_test: stage: test before_script: - apk -Uuv add bash git curl tar sed grep script: - docker build -t dockle-ci-test:${CI_COMMIT_SHORT_SHA} . - | VERSION=$( curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" |
grep '"tag_name":' |
sed -E 's/."v([^"]+)"./\1/'
) && curl -L -o dockle.tar.gz https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.tar.gz &&
tar zxvf dockle.tar.gz - ./dockle --exit-code 1 dockle-ci-test:${CI_COMMIT_SHORT_SHA}

root@kitploit:~
</details>

- 示例:https://gitlab.com/tomoyamachi/dockle-ci-test/-/jobs/238215077
- 仓库:https://github.com/goodwithtech/dockle-ci-test

## 私有 Docker 仓库的认证

`Dockle` 可以下载来自私有仓库的镜像,无需安装 `Docker` 或任何其他第三方工具。其设计目的是为了在 CI 流程中易于使用。

您只需执行:安装 `Dockle` 并设置环境变量。

- 注意:我不建议在本地机器上使用环境变量。

### Docker Hub

要从 Docker Hub 下载私有仓库,您需要设置 `DOCKLE_AUTH_URL`、`DOCKLE_USERNAME` 和 `DOCKLE_PASSWORD` 环境变量。```bash
export DOCKLE_AUTH_URL=https://registry.hub.docker.com
export DOCKLE_USERNAME={DOCKERHUB_USERNAME}
export DOCKLE_PASSWORD={DOCKERHUB_PASSWORD}
  • 注意:从公共仓库下载时,无需设置环境变量。

Amazon ECR(弹性容器注册表)

Dockle 使用 AWS SDK。你无需安装 aws CLI 工具。

请使用 。```bash export AWS_ACCESS_KEY_ID={AWS ACCESS KEY} export AWS_SECRET_ACCESS_KEY={SECRET KEY} export AWS_DEFAULT_REGION={AWS REGION}

下载工具

检查点摘要

  • 每个检查点的详细信息见 CHECKPOINT.md
CODE描述LEVEL※
CIS 的 Docker 镜像检查点
CIS-DI-0001为容器创建一个用户WARN
CIS-DI-0002使用受信任的基础镜像FATAL
CIS-DI-0003不要在容器中安装不必要的包FATAL
CIS-DI-0004扫描并重建镜像以包含安全补丁FATAL
CIS-DI-0005为 Docker 启用内容信任INFO
CIS-DI-0006在容器镜像中添加 HEALTHCHECK 指令INFO
CIS-DI-0007不要在 Dockerfile 中单独使用 update 指令FATAL
CIS-DI-0008确认 setuid 和 setgid 文件的安全性INFO
CIS-DI-0009在 Dockerfile 中使用 COPY 而不是 ADDFATAL
CIS-DI-0010不要在 Dockerfile 中存储机密FATAL
CIS-DI-0011

级别

Dockle 有 5 个检查级别。

级别描述
FATAL需实际且谨慎
WARN需实际且谨慎,但用途受限(即使是官方镜像)
INFO可能会负面影响实用性或性能
SKIP未找到目标文件
PASS未发现任何问题

常见示例

扫描镜像

只需指定镜像名称(和标签)。```bash $ dockle goodwithtech/test-image:v1

root@kitploit:~
<details>
<summary>结果</summary>```
FATAL   - CIS-DI-0001: Create a user for the container
        * Last user should not be root
WARN    - CIS-DI-0005: Enable Content trust for Docker
        * export DOCKER_CONTENT_TRUST=1 before docker pull/build
FATAL   - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
        * not found HEALTHCHECK statement
FATAL   - CIS-DI-0007: Do not use update instructions alone in the Dockerfile
        * Use 'Always combine RUN 'apt-get update' with 'apt-get install' : /bin/sh -c apt-get update && apt-get install -y git
FATAL   - CIS-DI-0008: Remove setuid and setgid permissions in the images
        * Found setuid file: etc/passwd grw-r--r--
        * Found setuid file: usr/lib/openssh/ssh-keysign urwxr-xr-x
        * Found setuid file: app/hoge.txt ugrw-r--r--
        * Found setuid file: app/hoge.txt ugrw-r--r--
        * Found setuid file: etc/shadow urw-r-----
FATAL   - CIS-DI-0009: Use COPY instead of ADD in Dockerfile
        * Use COPY : /bin/sh -c #(nop) ADD file:81c0a803075715d1a6b4f75a29f8a01b21cc170cfc1bff6702317d1be2fe71a3 in /app/credentials.json
FATAL   - CIS-DI-0010: Do not store secrets in ENVIRONMENT variables
        * Suspicious ENV key found : MYSQL_PASSWD
FATAL   - CIS-DI-0010: Do not store secret files
        * Suspicious filename found : app/credentials.json
PASS    - DKL-DI-0001: Avoid sudo command
FATAL   - DKL-DI-0002: Avoid sensitive directory mounting
        * Avoid mounting sensitive dirs : /usr
PASS    - DKL-DI-0003: Avoid apt-get/apk/dist-upgrade
PASS    - DKL-DI-0004: Use apk add with --no-cache
FATAL   - DKL-DI-0005: Clear apt-get caches
        * Use 'apt-get clean && rm -rf /var/lib/apt/lists/*' : /bin/sh -c apt-get update && apt-get install -y git
PASS    - DKL-DI-0006: Avoid latest tag
FATAL   - DKL-LI-0001: Avoid empty password
        * No password user found! username : nopasswd
PASS    - DKL-LI-0002: Be unique UID
PASS    - DKL-LI-0002: Be unique GROUP
AWS CLI 的环境变量
root@kitploit:~
### GCR (Google Container Registry)

`Dockle` 使用 Google Cloud SDK。因此,您无需安装 `gcloud` 命令。

如果您想使用目标项目的仓库,可以通过 `GOOGLE_APPLICATION_CREDENTIAL` 进行设置。```bash
# must set DOCKLE_USERNAME empty char
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credential.json

自托管注册表 (BasicAuth)

BasicAuth服务器需要 DOCKLE_USERNAME 和 DOCKLE_PASSWORD。```bash export DOCKLE_USERNAME={USERNAME} export DOCKLE_PASSWORD={PASSWORD}

if you'd like to use 80 port, use NonSSL

export DOCKLE_NON_SSL=true

root@kitploit:~
## 贡献者

### 代码贡献者

这个项目感谢所有贡献者。[[贡献](https://github.com/goodwithtech/dockle/blob/master/CONTRIBUTING.md)]。
<a href="https://github.com/goodwithtech/dockle/graphs/contributors"><img src="https://opencollective.com/dockle/contributors.svg?width=890&amp;button=false" /></a>

### 财务贡献者

成为财务贡献者,帮助我们维持社区发展。[[贡献](https://opencollective.com/dockle/contribute)]

#### 个人

<a href="https://opencollective.com/dockle"><img src="https://opencollective.com/dockle/individuals.svg?width=890"></a>

#### 组织

用您的组织支持这个项目。您的Logo将显示在这里,并附带您的网站链接。[[贡献](https://opencollective.com/dockle/contribute)]

<a href="https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=dockle"><img src="https://assets.kitploit.com/production/public/readmes/4137/e063c5948228b346da42565b27ee62f2dd85648c0de86a2b184c7f111319d275.png"></a>
<a href="https://opencollective.com/dockle/organization/1/website"><img src="https://opencollective.com/dockle/organization/1/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/2/website"><img src="https://opencollective.com/dockle/organization/2/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/3/website"><img src="https://opencollective.com/dockle/organization/3/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/4/website"><img src="https://opencollective.com/dockle/organization/4/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/5/website"><img src="https://opencollective.com/dockle/organization/5/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/6/website"><img src="https://opencollective.com/dockle/organization/6/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/7/website"><img src="https://opencollective.com/dockle/organization/7/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/8/website"><img src="https://opencollective.com/dockle/organization/8/avatar.svg"></a>
<a href="https://opencollective.com/dockle/organization/9/website"><img src="https://opencollective.com/dockle/organization/9/avatar.svg"></a>

### 开源项目支持者

本项目使用了以下开源项目提供的服务。

<a href="https://flatt.tech/oss/gmo/trampoline" target="_blank"><img src="https://flatt.tech/assets/images/badges/gmo-oss.svg" height="24px"/></a>
<a href="https://github.com/1Password/for-open-source" target="_blank"><img src="https://img.shields.io/badge/1Password-OSS%20Program-0094F5?logo=1password&amp;logoColor=white" height="24px"/></a>

# 许可证

- Apache许可证 2.0

# 作者

[@tomoyamachi](https://github.com/tomoyamachi) (Tomoya Amachi)

特别感谢 [@knqyf263](https://github.com/knqyf263) (Teppei Fukuda) 和 [Trivy](https://github.com/knqyf263/trivy)
仅安装已验证的包
INFO
Dockle 针对 Docker 的检查点
DKL-DI-0001避免使用 sudo 命令FATAL
DKL-DI-0002避免挂载敏感目录FATAL
DKL-DI-0003避免使用 apt-get dist-upgradeWARN
DKL-DI-0004使用 apk add 搭配 --no-cacheFATAL
DKL-DI-0005清除 apt-get 缓存FATAL
DKL-DI-0006避免使用 latest 标签WARN
Dockle 针对 Linux 的检查点
DKL-LI-0001避免空密码FATAL
DKL-LI-0002确保 UID/GROUP 唯一FATAL
DKL-LI-0003仅放置必要的文件INFO