Skip to content

Commit 64ca575

Browse files
committed
fix: patch zlib and remove vulnerable runtime tools
1 parent 4befaee commit 64ca575

3 files changed

Lines changed: 98 additions & 5 deletions

File tree

‎Dockerfile‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
# Java and Node are build tools only; the published image contains a jlink runtime.
33
FROM node:26.10.0-alpine@sha256:0b36e8c136b94cd4fcf02188228e76c31ad5872eef3fec8cbd2eee500cfd9e80 AS node-toolchain
44

5+
FROM alpine:3.24.2@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 AS zlib-build
6+
RUN apk add --no-cache alpine-sdk ca-certificates dash=0.5.13.1-r2 && \
7+
adduser -D builder && addgroup builder abuild && \
8+
mkdir -p /build/zlib /build/dash /packages /out && chown -R builder:builder /build /packages /out
9+
COPY --chown=builder:builder docker/zlib/APKBUILD /build/zlib/APKBUILD
10+
COPY --chown=builder:builder docker/dash/APKBUILD /build/dash/APKBUILD
11+
USER builder
12+
WORKDIR /build/zlib
13+
RUN abuild-keygen -an && REPODEST=/packages abuild -r && \
14+
cp /packages/*/*/zlib-*.apk /out/zlib.apk && \
15+
cd /build/dash && REPODEST=/packages abuild -r && \
16+
cp /packages/*/*/dash-*.apk /out/dash.apk
17+
518
FROM eclipse-temurin:25.0.4.1_1-jdk-alpine-3.24@sha256:3fd2d245c4e0eba615fe366a71b8bd25f5db7104f53e4026b24bf508b880bd2a AS backend-build
619
RUN apk add --no-cache libstdc++ libatomic
720
COPY --from=node-toolchain /usr/local/ /usr/local/
@@ -27,10 +40,14 @@ RUN mkdir /app/unpacked && cd /app/unpacked && \
2740
--output /opt/java-runtime
2841

2942
FROM alpine:3.24.2@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 AS runtime-base
43+
COPY --from=zlib-build /out/zlib.apk /tmp/zlib.apk
44+
COPY --from=zlib-build /out/dash.apk /tmp/dash.apk
3045
RUN apk upgrade --no-cache && \
31-
apk add --no-cache ca-certificates libstdc++ zlib fontconfig font-dejavu && \
46+
apk add --no-cache --allow-untrusted /tmp/zlib.apk /tmp/dash.apk && rm /tmp/zlib.apk /tmp/dash.apk && \
47+
apk add --no-cache ca-certificates libstdc++ fontconfig font-dejavu curl && \
3248
addgroup -g 1001 -S spring && \
33-
adduser -u 1001 -S spring -G spring
49+
adduser -u 1001 -S spring -G spring && \
50+
apk del --no-cache busybox busybox-binsh ssl_client
3451
ENV JAVA_HOME=/opt/java
3552
ENV PATH="$JAVA_HOME/bin:$PATH" \
3653
JAVA_OPTS="-Xms256m -Xmx512m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Djava.awt.headless=true"
@@ -40,19 +57,25 @@ COPY --from=backend-build --chmod=0444 /app/target/website-0.0.1-SNAPSHOT.jar /a
4057
USER 1001:1001
4158
EXPOSE 8080
4259
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
43-
CMD wget -q -T 2 -O /dev/null http://127.0.0.1:8080/actuator/health || exit 1
60+
CMD ["/usr/bin/dash", "-ec", "test \"$(curl --fail --silent --max-time 2 --output /dev/null --write-out '%{http_code}' http://127.0.0.1:8080/actuator/health)\" = 200"]
4461
ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar /app/app.jar"]
4562

4663
# Run the packaged app as the production UID to verify the linked Java modules,
4764
# PDF extraction, content parsing, and the actual generated web assets.
4865
FROM runtime-base AS smoke-test
49-
RUN set -eu; \
66+
RUN --mount=type=bind,from=node-toolchain,source=/bin/busybox,target=/tmp/smoke-busybox \
67+
set -eu; \
68+
/tmp/smoke-busybox mkdir /tmp/website-smoke-tools; \
69+
/tmp/smoke-busybox --install -s /tmp/website-smoke-tools; \
70+
export PATH="/tmp/website-smoke-tools:$PATH"; \
5071
test "$(id -u)" = 1001; \
72+
test ! -e /bin/busybox; \
73+
test ! -e /usr/bin/ssl_client; \
5174
test ! -e /opt/java/bin/javac; \
5275
java -version; \
5376
java $JAVA_OPTS -jar /app/app.jar > /tmp/website-smoke.log 2>&1 & \
5477
app_pid=$!; \
55-
cleanup() { kill "$app_pid" 2>/dev/null || true; wait "$app_pid" 2>/dev/null || true; }; \
78+
cleanup() { kill "$app_pid" 2>/dev/null || true; wait "$app_pid" 2>/dev/null || true; /tmp/smoke-busybox rm -rf /tmp/website-smoke-tools; }; \
5679
trap cleanup EXIT; \
5780
attempt=0; \
5881
while [ "$attempt" -lt 60 ]; do \
@@ -63,6 +86,9 @@ RUN set -eu; \
6386
done; \
6487
if [ "$attempt" -ge 60 ]; then cat /tmp/website-smoke.log; exit 1; fi; \
6588
grep -Eq '"status"[[:space:]]*:[[:space:]]*"UP"' /tmp/website-health.json; \
89+
health_status="$(curl --fail --silent --max-time 5 --output /tmp/website-curl-health.json --write-out '%{http_code}' http://127.0.0.1:8080/actuator/health)"; \
90+
test "$health_status" = 200; \
91+
grep -Eq '"status"[[:space:]]*:[[:space:]]*"UP"' /tmp/website-curl-health.json; \
6692
wget -T 5 -qO /tmp/website-client-info.json http://127.0.0.1:8080/api/client/info; \
6793
grep -Eq '"hostname"[[:space:]]*:[[:space:]]*"javadevjt[.]tech"' /tmp/website-client-info.json; \
6894
grep -Eq '"username"[[:space:]]*:[[:space:]]*"visitor"' /tmp/website-client-info.json; \

‎docker/dash/APKBUILD‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Keep Alpine's signed, pinned shell binary; omit interactive-shell hooks whose
2+
# BusyBox dependency is unnecessary in this application container.
3+
pkgname=dash
4+
pkgver=0.5.13.1
5+
pkgrel=3
6+
pkgdesc="POSIX shell for containers without interactive shell registration"
7+
url="http://gondor.apana.org.au/~herbert/dash/"
8+
arch="x86_64"
9+
license="BSD-3-Clause"
10+
replaces="busybox-binsh"
11+
provides="cmd:sh=$pkgver"
12+
options="!dbg"
13+
14+
build() {
15+
test "$(apk info -v dash)" = "dash-$pkgver-r2"
16+
}
17+
18+
check() {
19+
test "$(/usr/bin/dash -c 'printf "%s" "$((2 + 2))"')" = 4
20+
}
21+
22+
package() {
23+
install -Dm755 /usr/bin/dash "$pkgdir/usr/bin/dash"
24+
mkdir -p "$pkgdir/bin"
25+
ln -s /usr/bin/dash "$pkgdir/bin/sh"
26+
}

‎docker/zlib/APKBUILD‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Maintainer: Joshua Terk
2+
pkgname=zlib
3+
# Upstream zlib.h reports 1.3.2.1-motley. Encode the pinned Git snapshot using
4+
# the official commit date and Alpine's recognized _gitYYYYMMDD suffix.
5+
pkgver=1.3.2.1_git20260715
6+
pkgrel=0
7+
pkgdesc="Compression and decompression library"
8+
url="https://zlib.net/"
9+
arch="x86_64"
10+
license="Zlib"
11+
makedepends="build-base"
12+
options="!dbg"
13+
14+
_source_commit=bf3364d56678ae12892168d1ee22ac4e13ef80a3
15+
source="zlib-$_source_commit.tar.gz::https://codeload.github.com/madler/zlib/tar.gz/$_source_commit"
16+
builddir="$srcdir/zlib-$_source_commit"
17+
18+
build() {
19+
# Match Alpine's zlib build flags: optimize for speed and use its hardening.
20+
export CFLAGS="$CFLAGS -O2"
21+
CHOST="$CHOST" ./configure \
22+
--prefix=/usr \
23+
--shared \
24+
--disable-crcvx
25+
make
26+
}
27+
28+
check() {
29+
make check
30+
}
31+
32+
package() {
33+
make install DESTDIR="$pkgdir"
34+
# Keep only the runtime shared library and its soname link.
35+
rm -f "$pkgdir"/usr/lib/libz.a "$pkgdir"/usr/lib/libz.so
36+
rm -rf "$pkgdir"/usr/include "$pkgdir"/usr/share "$pkgdir"/usr/lib/pkgconfig
37+
}
38+
39+
sha512sums="
40+
482b344b482bd34f1ff9775e8da085918e6998ffd86e010ddc8667ee4c0c23f6a10f795c9d8d6f6169ab28cc4f175d401dbfcdc794dbd01c22ac4b5bdd5f9a95 zlib-bf3364d56678ae12892168d1ee22ac4e13ef80a3.tar.gz
41+
"

0 commit comments

Comments
 (0)