meles 是一款用于容器镜像的恶意软件扫描器:只需一条命令即可扫描镜像引用,无需 Docker 守护进程,并提供适合 CI 的退出码。在 Kubernetes 中,它还会扫描你的 Pod 所运行的每一个镜像,并且如果你愿意,它还能暂缓新 Pod 的启动,直到其镜像完成扫描。
meles 会在镜像运行之前检查其内容。它是对漏洞扫描器和 Falco 等运行时检测的补充,而非替代。
这个名字来自 Meles meles,即欧洲獾——它会挖掘镜像的各个层。
meles image <ref> 发现恶意软件时,会让流水线失败。输出支持表格、JSON 或 SARIF 格式,并可通过忽略规则处理误报。MalwareReport,可选配 Prometheus 告警。在你的机器上试用(Linux amd64、Docker、bash):
curl -fsSL https://github.com/movray/meles/releases/download/v0.5.0/meles_0.5.0_linux_amd64.tar.gz | tar -xz meles
docker run -d --name clamd -p 127.0.0.1:3310:3310 clamav/clamav:1.4
export MELES_CLAMD=tcp://127.0.0.1:3310
until (exec 3<>/dev/tcp/127.0.0.1/3310 && printf 'zPING\0' >&3 && head -c4 <&3 | grep -q PONG) 2>/dev/null; do sleep 5; done
./meles selftest
./meles image alpine:3.20
或在集群中(集群管理员、默认 StorageClass、节点上约 2 GB 可用内存):
kubectl create namespace meles
kubectl label namespace meles pod-security.kubernetes.io/enforce=baseline
helm install meles oci://ghcr.io/movray/charts/meles --version 0.5.0 -n meles --set operator.enabled=true
kubectl -n meles rollout status deploy/meles-clamd --timeout=15m
kubectl get malwarereports -A # every image running in your cluster
kubectl -n meles port-forward svc/meles-server 8080:80 # http://localhost:8080/
操作员现在会拉取并扫描每个 Pod 的镜像,这会占用你镜像仓库的拉取限额;它只报告,不会触碰你的 Pod。报告会在几分钟内出现。非常大的二进制文件可能最终显示为 Incomplete,这绝不算干净:参见
读取结果。
端口转发只是查看结果的最快方式。若要长期使用,请通过 server.ingress 或 server.httpRoute 暴露 UI,并通过 server.oauth2Proxy 在其前面加上登录,这些都在 chart 的 values 中配置:
Web UI 的登录。meles 自身没有登录功能,因此不要在没有登录的情况下暴露 UI。
从被后续层隐藏的文件到 Kubernetes 中的扫描门禁,逐步导览:docs/getting-started.md。
clamd 通过其 socket 协议完成。meles 不链接 libclamav,并保持 Apache-2.0 许可。默认情况下 meles 只报告,且从不删除任何内容。它不能替代镜像签名、SBOM 或运行时检测。
每个 release 都附带适用于 Linux 和 macOS 的二进制文件(amd64、arm64)、多架构镜像和 Helm chart:
VERSION=0.5.0
# Binary
curl -fsSLO https://github.com/movray/meles/releases/download/v$VERSION/meles_${VERSION}_linux_amd64.tar.gz
tar -xzf meles_${VERSION}_linux_amd64.tar.gz meles
# Image (linux/amd64, linux/arm64; no shell, runs as non-root)
docker run --rm ghcr.io/movray/meles:$VERSION version
# Helm chart (see Kubernetes below)
helm install meles oci://ghcr.io/movray/charts/meles --version $VERSION -n meles -f my-values.yaml
# From source
go install github.com/movray/meles/cmd/meles@v$VERSION
二进制文件、镜像和图表由 release workflow 构建,并带有签名的构建 来源信息。镜像在发布前会使用 meles 和 Trivy 进行扫描。 使用 GitHub CLI 检查来源信息:
gh attestation verify meles_${VERSION}_linux_amd64.tar.gz -R movray/meles
gh attestation verify oci://ghcr.io/movray/meles:$VERSION -R movray/meles
gh attestation verify oci://ghcr.io/movray/charts/meles:$VERSION -R movray/meles
从 0.4.1 起的发布版本还会以 meles_$VERSION.intoto.jsonl 的形式附带二进制文件的来源信息,以便在不使用 GitHub API 的情况下进行校验:
gh attestation verify meles_${VERSION}_linux_amd64.tar.gz -R movray/meles \
--bundle meles_$VERSION.intoto.jsonl
镜像和图表也使用 cosign(无密钥)进行签名,因此 Kyverno 或 Sigstore policy-controller 等准入策略可以对其进行检查。签名是以 OCI 引用形式存储的 Sigstore 捆绑包:使用 cosign 3 进行验证(cosign 2 需要 --new-bundle-format):
cosign verify ghcr.io/movray/meles:$VERSION \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp '^https://github.com/movray/meles/\.github/workflows/release\.yml@refs/tags/v'
二进制文件由发布版本中的 checksums.txt 及其签名 checksums.txt.sigstore.json 覆盖(自 0.4.1 起):
cosign verify-blob checksums.txt --bundle checksums.txt.sigstore.json \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp '^https://github.com/movray/meles/\.github/workflows/release\.yml@refs/tags/v'
sha256sum --ignore-missing -c checksums.txt
你需要一个正在运行的 clamd。使用 apt install clamav-daemon 时,meles 会自动找到它的
socket(/run/clamav/clamd.ctl);clamav/clamav 镜像同样可用
(参见 TL;DR;加载签名需要一两分钟)。
meles selftest # checks the whole chain with EICAR test images
# (--yara: also the default YARA rules, if loaded)
meles image alpine:3.20
meles image --format json --platform linux/amd64 ghcr.io/org/app:1.2
alpine:3.20 (d9e853e87e55)
engine: ClamAV 1.4.3, signatures 28159, scanned in 2.6s
PLATFORM LAYERS FILES FINDINGS SKIPPED
linux/amd64 1 87 0 0
linux/arm64/v8 1 87 0 0
No malware found.
| 代码 | 含义 |
|---|---|
0 | 干净(或在 --exit-code 0 下发现结果,仅报告模式) |
1 | 发现恶意软件,或文件未被扫描(可通过 --exit-code 和 --skipped-exit-code 更改) |
2 | 错误:拉取、引擎或配置。绝不报告为干净。 |
meles 默认在发现结果时使流水线失败,因此无需额外标志即可作为门禁使用。
未被扫描的文件(超过 --max-file-size,或超过 clamd 的某个限制)会被列为已跳过,并且报告被标记为不完整:表格显示“Scan INCOMPLETE”而不是“No malware found.”,JSON 报告包含 "complete": false,并且 meles 像发现结果时一样以 1 退出。任何大小限制都可以通过使文件大于该限制来规避,因此未扫描的文件绝不能通过安全门禁。使用 --skipped-exit-code 0 仅报告跳过的文件,或使用 2 将其视为错误。