CVE 2022 0778

Feb 20, 2023 22:48 · 268 words · 2 minute read

[作業メモ] CVE 2022 0778 対応 🔗

使っていたコンテナイメージが、イメージスキャンで CVE 2022 0778 に引っかかったので対応する。

A flaw was found in OpenSSL. It is possible to trigger an infinite loop by crafting a certificate that has invalid elliptic curve parameters. Since certificate parsing happens before verification of the certificate signature, any process that parses an externally supplied certificate may be subject to a denial of service attack.

Fixed in OpenSSL 3.0.2 (Affected 3.0.0,3.0.1). Fixed in OpenSSL 1.1.1n (Affected 1.1.1-1.1.1m). Fixed in OpenSSL 1.0.2zd (Affected 1.0.2-1.0.2zc).

実行コンテナでは golang で実装したサーバーが動いているだけ。

ベースイメージが ubuntu:20.04 で openssl は 1.1.1f。

root@62392a644ca5:/app# openssl version
OpenSSL 1.1.1f  31 Mar 2020

openssl を更新するだけでもいいが、attack surface の少ない distroless にするのがなおよさそう。
https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md

FROM ubuntu:20.04

FROM gcr.io/distroless/gcr.io/distroless/base-debian11:nonroot

ca-cert は distroless 側でメンテしてくれていそう。
chmod は distroless だと入ってないので builder 側でやってからコピーする。

これでコンテナスキャンの指摘は解消した。

ファイルサイズの比較 🔗

❯ docker image ls
REPOSITORY                                 TAG       IMAGE ID       CREATED             SIZE
new-image				                           latest    ef18dc61d52b   4 minutes ago       67.5MB
old-image																   v0.32.0   c5c1c701c54c   7 hours ago         178MB
ubuntu                                     20.04     61c45d0e9798   29 hours ago        72.8MB
gcr.io/distroless/static-debian11          latest    329ba29cac3c   7 days ago          2.43MB
gcr.io/distroless/base-debian11            latest    9f2d5b5c220e   7 days ago          20.4MB

distroless/static 🔗

distroless/static にすると、glibc や openssl も含まれていないので、アプリケーションサーバーが立ち上がらない。

❯ docker run --rm -it new-image /app/bin/app
standard_init_linux.go:228: exec user process caused: no such file or directory

CGO_ENABLED=0 でビルドすれば、実行環境で動的リンクしなくなるので distroless/static でも動くのでは?

app:
		CGO_ENABLED=0 go build -ldflags="-s -w -extldflags \"-static\"" cmd/server/main.go

実際これで行けて、イメージサイズも小さくなった。

❯ docker image ls
REPOSITORY                                 TAG       IMAGE ID       CREATED             SIZE
new-image                                  latest    7716f30212f8   21 minutes ago      49.5MB
old-image																   v0.32.0   c5c1c701c54c   8 hours ago         178MB
gcr.io/distroless/static-debian11          nonroot   36f7012c4853   7 days ago          2.43MB
gcr.io/distroless/base-debian11            latest    9f2d5b5c220e   7 days ago          20.4MB
gcr.io/distroless/base                     latest    9f2d5b5c220e   7 days ago          20.4MB
gcr.io/distroless/static-debian11          latest    329ba29cac3c   7 days ago          2.43MB
gcr.io/distroless/base                     debug     f288d0ab47e8   7 days ago          21.6MB

ただ、distroless/base でも本来の目的は達成できたのと、結局のところビルダーコンテナなかで openssl は使っている。
コンテナ診断から見えにくくなっただけなので、採用は見送った。

references 🔗