只需一条命令,即可在构建或部署任何内容之前,找出会暴露受 *sshole (CVE-2026-123158) 影响的 sshd 的 Dockerfile。
uvx check-sshole
这会扫描当前文件夹下的每个 Dockerfile。无需安装、无需 Docker、无需网络访问:它只读取文件。(pipx run check-sshole 或 pip install check-sshole 也可以。)
.devcontainer/Dockerfile:2: sshd from 'openssh' on 'python:3.12-alpine3.15' accepts password logins: exposed to *sshole (CVE-2026-123158)
why: Alpine 3.15 never got a fixed openssh build
fix: turn password logins off: RUN echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
(or start sshd with -o PasswordAuthentication=no)
or: move to Alpine 3.16 or newer and require its fixed openssh build
more: https://sshhole.com/ (to silence, put '# check-sshole: ignore' above line 2)
services/sftp/Dockerfile:2: sshd from 'openssh-server' on 'alpine:3.22' accepts password logins: exposed to *sshole (CVE-2026-123158)
why: a fresh build may pull the fixed package, but nothing here requires it; older or cached builds have the bug
fix: turn password logins off: RUN echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
(or start sshd with -o PasswordAuthentication=no)
or: if you need password logins, require a fixed build: apk add 'openssh-server>=10.0_p1-r11'
more: https://sshhole.com/ (to silence, put '# check-sshole: ignore' above line 2)
check-sshole: 2 findings in 3 Dockerfiles
*sshole 是 OpenSSH 的 sshd 在 10.6p2 之前版本中的一个密码认证绕过漏洞,前提是 sshd 在未启用 PAM 的情况下针对 musl libc 构建。Alpine 正是这样构建其默认的 openssh-server,因此,通过 apk 安装 sshd 并保留密码登录(OpenSSH 的默认设置)的容器会受到影响。密码字段为 * 的账户(仅使用密钥的用户,以及 Alpine 上的 root)是存在风险的账户。Debian、Ubuntu、RHEL 及其他 glibc 镜像不受影响。
当以下所有条件均成立时,check-sshole 会标记 Dockerfile 阶段:
| 条件 | check-sshole 检查的内容 |
|---|---|
| 已安装 sshd | apk add openssh、openssh-server、openssh-server-pam 或 openssh-server-krb5,包括 shell 形式、exec 形式、sh -c 和 heredoc;会跟踪 apk del |
| 基础镜像是 musl | 该阶段使用 apk,且不是 Wolfi/Chainguard(这些是 glibc) |
| 密码登录已开启 | 在 RUN、CMD/ENTRYPOINT(sshd -o …)、从仓库 COPY 的 sshd 配置文件或 COPY heredoc 中,没有任何内容设置 PasswordAuthentication no 或不含密码的 AuthenticationMethods;使用 openssh-server-pam 时设置 UsePAM yes 也算作关闭 |
| 不要求修复后的构建 | 该软件包未固定(=、>=、~)到修复后的构建版本 |
会跟踪多阶段构建:一个阶段会继承其 FROM <stage> 父阶段所安装和配置的内容,并且只检查没有其他阶段在其之上构建的阶段。
check-sshole # every Dockerfile under the current folder
check-sshole services/ Dockerfile # some folders and files
check-sshole --format json . # machine-readable
它会匹配 Dockerfile、Containerfile、Dockerfile.<anything> 和
<anything>.Dockerfile,并跳过 .git、node_modules 以及 virtualenv。
你指定的文件无论叫什么名字都会被检查。
| 退出状态 | 含义 |
|---|---|
| 0 | 未发现任何问题 |
| 1 | 至少发现一个问题 |
| 2 | 路径不存在或无法读取 |
repos:
- repo: https://github.com/shenxianpeng/check-sshole
rev: v0.1.0
hooks:
- id: check-sshole
要一次性检查所有 Dockerfile,而不仅仅是某次提交涉及的 Dockerfile:
pre-commit run check-sshole --all-files。
jobs:
check-sshole:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: shenxianpeng/[email protected]
# with:
# path: services/ Dockerfile # default: the whole repository
检查结果会以注解形式显示在拉取请求上,并出现在作业摘要中,同时使作业失败。该 action 使用运行器自带的 Python 运行,不安装任何内容。
| 输入 | 默认值 | 含义 |
|---|---|---|
path | . | 要扫描的文件或文件夹,以空格分隔 |
format | github | github(注解和作业摘要)、text 或 json |
| Alpine | 首个修复构建 |
|---|---|
| edge | 10.6_p2-r0 |
| 3.24 | 10.3_p1-r2 |
| 3.23 | 10.2_p1-r1 |
| 3.22 | 10.0_p1-r11 |
| 3.21 | 9.9_p2-r1 |
| 3.20 | 9.7_p1-r6 |
| 3.19 | 9.6_p1-r3 |
| 3.18 | 9.3_p2-r4 |
| 3.17 | 9.1_p1-r7 |
| 3.16 | 9.0_p1-r6 |
| 3.15 及更早版本 | 无:请关闭密码登录或迁移到更新的分支 |
来源:各 *-stable 分支上的 aports 提交 "main/openssh: fix password authentication"(2026-11-05)。
check-sshole 读取的是 Dockerfile,因此无法看到现有镜像实际包含的内容。要检查某个镜像,请读取其已安装的构建版本,并与下表进行比对:
docker run --rm --entrypoint apk IMAGE list --installed openssh-server
# openssh-server-10.0_p1-r11 aarch64 {openssh} (SSH-OpenSSH) [installed]
sshd -V 和 ssh -V 不会显示 Alpine 修订版本(-r11),而
apk info -v 不会打印版本号,因此请使用 apk list --installed。
在没有 --no-cache 的情况下重新构建镜像,可能会保留旧的、存在漏洞的层。
将 # check-sshole: ignore 放在安装 sshd 的 RUN 的上一行,
或放在 FROM 上方以跳过整个阶段(以及基于该阶段构建的后续阶段):
FROM alpine:3.22
# check-sshole: ignore (sshd only listens on the internal network)
RUN apk add --no-cache openssh-server
FROM linuxserver/openssh-server),也无法看到入口点脚本在运行时修改的 sshd 配置。请使用上述命令检查这些镜像。pip install -e '.[test]'
pytest --cov # fails below 100% coverage
发布流程通过发布一个标记为 vX.Y.Z 的 GitHub release 来完成;发布工作流会构建软件包并将其上传至 PyPI。