diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9e54a2..3d9c8fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,6 +56,12 @@ jobs: fi echo "push=$push" >>"$GITHUB_OUTPUT" - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 + - if: steps.meta.outputs.push == 'true' + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc with: context: . @@ -64,15 +70,9 @@ jobs: provenance: false load: true tags: edge:smoke - cache-from: type=gha,scope=${{ matrix.arch }} - cache-to: type=gha,mode=max,scope=${{ matrix.arch }} + cache-from: type=registry,ref=${{ env.IMAGE }}:cache-${{ matrix.arch }} + cache-to: ${{ steps.meta.outputs.push == 'true' && format('type=registry,ref={0}:cache-{1},mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE, matrix.arch) || '' }} - run: sh test/smoke.sh edge:smoke - - if: steps.meta.outputs.push == 'true' - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - if: steps.meta.outputs.push == 'true' id: push uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc @@ -82,7 +82,6 @@ jobs: platforms: linux/${{ matrix.arch }} provenance: false outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true - cache-from: type=gha,scope=${{ matrix.arch }} - if: steps.meta.outputs.push == 'true' env: DIGEST: ${{ steps.push.outputs.digest }} diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml index 0b67716..e04f766 100644 --- a/.github/workflows/scan.yml +++ b/.github/workflows/scan.yml @@ -41,6 +41,9 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git switch -c "$branch" date -u +%Y-%m-%dT%H:%M:%SZ >REFRESH + base=gcr.io/distroless/cc-debian13:latest + digest=$(docker buildx imagetools inspect "$base" --format '{{json .Manifest}}' | jq -r .digest) + case "$digest" in sha256:*) sed -i "s#^FROM $base@sha256:[0-9a-f]*#FROM $base@$digest#" Dockerfile ;; esac git commit -am "build(debian): refresh packages" git push origin "$branch" gh pr create --base main --head "$branch" --title "build(debian): refresh packages" --label security --body-file body.md diff --git a/Dockerfile b/Dockerfile index 4bd0695..b95630a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG VERSION ARG LUAJIT=2769af8852a4b32687dfdfc55040c4cb4e6a8417 ARG NDK=3bd7c5619312ca562c5fd5dda238cb8d73bf2a1d ARG LUA=43c620962d8d23e534208165ab3f1c68c8fe887b -ARG STREAM_LUA=eefc17dee2b4033b92fc6c664c114b1892b26270 +ARG STREAM_LUA=5b74db0dcb2aa8b54f130f91bc47c9fa53fc2372 ARG RESTY_CORE=8c8091a829fc5209980821c3845f936851d5c5e5 ARG RESTY_LRUCACHE=20869bd34742fa20344c29fe31d4d6506d6827bf ARG RESTY_STRING=be19d0f70548a2deb73f5b426af51541be0d7ef9 @@ -74,7 +74,27 @@ RUN apt-get update \ COPY build.sh /build.sh RUN sh /build.sh "${VERSION}" -FROM debian:trixie-20261104-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 +FROM gcr.io/distroless/cc-debian13:latest@sha256:e8343d4a7da8bb210df0c3ea29de38bbadbba6c773bed0cd8bde506fca3a5c44 AS base + +FROM debian:trixie-20261104-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 AS runtime + +RUN --mount=type=bind,source=REFRESH,target=/tmp/refresh \ + --mount=type=bind,from=base,source=/var/lib/dpkg/status.d,target=/tmp/base \ + apt-get update \ + && mkdir -p /debs /ctrl /rootfs/var/lib/dpkg/status.d \ + && cd /debs \ + && apt-get download $({ ls /tmp/base | grep -v '\.md5sums$'; echo libcrypt1 libmaxminddb0 libpcre2-8-0 libyajl2 | tr ' ' '\n'; } | grep -vx ca-certificates | sort -u) \ + && for deb in *.deb; do \ + name=$(dpkg-deb --field "$deb" Package) \ + && rm -rf /ctrl/* && dpkg-deb --control "$deb" /ctrl \ + && cp /ctrl/control "/rootfs/var/lib/dpkg/status.d/$name" \ + && { [ ! -f /ctrl/md5sums ] || cp /ctrl/md5sums "/rootfs/var/lib/dpkg/status.d/$name.md5sums"; } \ + && dpkg-deb --extract "$deb" /rootfs || exit 1; \ + done \ + && find /rootfs/usr/share/doc -type f ! -name copyright -delete \ + && rm -rf /rootfs/usr/share/man /rootfs/usr/share/lintian /var/lib/apt/lists/* + +FROM base ARG VERSION LABEL dev.ingrest.image=edge \ @@ -83,15 +103,12 @@ LABEL dev.ingrest.image=edge \ org.opencontainers.image.licenses=AGPL-3.0-only \ org.opencontainers.image.version="${VERSION}" -RUN --mount=type=bind,source=REFRESH,target=/tmp/refresh apt-get update \ - && apt-get upgrade -y --no-install-recommends \ - && apt-get install -y --no-install-recommends ca-certificates curl \ - libssl3t64 libpcre2-8-0 zlib1g libmaxminddb0 libzstd1 libyajl2 libstdc++6 \ - && rm -rf /var/lib/apt/lists/* - +COPY --from=runtime /rootfs / COPY --from=build /usr/local/nginx /usr/local/nginx -COPY --from=build /usr/local/luajit /usr/local/luajit +COPY --from=build /usr/local/luajit/lib /usr/local/luajit/lib +COPY --from=build /usr/local/luajit/share /usr/local/luajit/share COPY --from=build /usr/local/modsecurity/lib /usr/local/modsecurity/lib COPY --from=directives /directives.json /usr/local/nginx/directives.json -ENV PATH=/usr/local/nginx/sbin:$PATH +ENV PATH=/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin STOPSIGNAL SIGQUIT +CMD ["nginx", "-g", "daemon off;"] diff --git a/MIN_PANEL b/MIN_PANEL index 6e8bf73..17e51c3 100644 --- a/MIN_PANEL +++ b/MIN_PANEL @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/README.md b/README.md index f2c4910..9575ca0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # edge -Web server image for the [Ingrest](https://github.com/ingrest-dev) panel: nginx mainline with the Lua module stack, HTTP/3, brotli, zstd, GeoIP2 and ModSecurity on Debian 13, plus the directive table the panel validates configs against. +Web server image for the [Ingrest](https://github.com/ingrest-dev) panel: nginx mainline with the Lua module stack, HTTP/3, brotli, zstd, GeoIP2 and ModSecurity on distroless Debian 13, plus the directive table the panel validates configs against. ## Contents +- Runtime on `gcr.io/distroless/cc-debian13`: no shell or package manager; binaries built with stack protector, FORTIFY, full RELRO, PIE and control-flow protection flags. - nginx from nginx.org, verified against the signing keys in `keys/nginx.gpg`. - Static modules: `lua-nginx-module`, `stream-lua-nginx-module`, `ngx_devel_kit`; LuaJIT 2.1. - Dynamic modules: brotli, zstd (`GetPageSpeed/zstd-nginx-module`), GeoIP2 (HTTP), ModSecurity. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..699c05a --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,30 @@ +# Security policy + +This image is part of Ingrest. Report vulnerabilities privately and keep the details private until a fix is out. + +## How to report + +- **GitHub:** a [private vulnerability report](https://github.com/ingrest-dev/edge/security/advisories/new) in this + repository. +- **Email:** security@ingrest.com, if GitHub does not work for you. + +Do not open public issues about vulnerabilities. Write in English or Russian. Include the image version (`nginx -v`) +or digest, steps to reproduce and what the vulnerability allows. + +## Scope + +- In scope: our build of `ghcr.io/ingrest-dev/edge` (Dockerfile, build flags, patches, bundled configs), the release + workflows and the signed manifest `stable.json`. +- Flaws in nginx itself, its modules, LuaJIT, libmodsecurity or Debian packages go to their projects. Tell us too if + the image is affected: we pin or patch the fix. +- Scanner reports without proof that the vulnerability affects this image are out of scope. + +## Supported versions + +Only the newest image in `stable.json` gets fixes. Panels with automatic security updates install a release labelled +`security` at once. + +## Timeline + +We acknowledge a report within 3 business days, tell you our decision within 7 days and publish the details once a +fix is released, or 90 days after the report unless we agree otherwise. diff --git a/VERSION b/VERSION index 2a3b381..4f559c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.31.10.3 +1.31.10.4 diff --git a/build.sh b/build.sh index 0a1da41..882cf8d 100755 --- a/build.sh +++ b/build.sh @@ -6,14 +6,22 @@ LJ=/usr/local/luajit LIB=$P/lualib cd /src -cmake -S brotli/deps/brotli -B brotli/deps/brotli/out -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBROTLI_DISABLE_TESTS=ON >/dev/null +case $(uname -m) in +x86_64) CF=-fcf-protection=full ;; +aarch64) CF=-mbranch-protection=standard ;; +*) CF= ;; +esac +HARDEN="-D_FORTIFY_SOURCE=3 -fstack-protector-strong -fstack-clash-protection $CF" +HARDEN_LD="-Wl,-z,relro,-z,now" + +cmake -S brotli/deps/brotli -B brotli/deps/brotli/out -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBROTLI_DISABLE_TESTS=ON -DCMAKE_C_FLAGS="-O2 $HARDEN" >/dev/null cmake --build brotli/deps/brotli/out --target brotlienc -j"$(nproc)" >/dev/null MS=/usr/local/modsecurity ( cd libmodsecurity sh build.sh >/dev/null - ./configure --prefix=$MS --disable-static --disable-examples --disable-doxygen-doc \ + CFLAGS="-O2 $HARDEN" CXXFLAGS="-O2 $HARDEN" LDFLAGS="$HARDEN_LD" ./configure --prefix=$MS --disable-static --disable-examples --disable-doxygen-doc \ --with-yajl --with-pcre2 --without-libxml --without-curl --without-lua --without-lmdb \ --without-ssdeep --without-geoip --without-maxmind >/dev/null make -j"$(nproc)" >/dev/null @@ -22,7 +30,7 @@ MS=/usr/local/modsecurity rm -rf $MS/lib/*.la $MS/lib/pkgconfig export MODSECURITY_INC=$MS/include MODSECURITY_LIB=$MS/lib -make -C luajit -j"$(nproc)" PREFIX=$LJ >/dev/null +make -C luajit -j"$(nproc)" PREFIX=$LJ TARGET_CFLAGS="$HARDEN" TARGET_LDFLAGS="$HARDEN_LD" TARGET_SHLDFLAGS="$HARDEN_LD" >/dev/null make -C luajit install PREFIX=$LJ >/dev/null export LUAJIT_LIB=$LJ/lib LUAJIT_INC=$LJ/include/luajit-2.1 @@ -41,8 +49,8 @@ EOF done cd nginx -./configure --prefix=$P --build="ingrest-${version##*.}" \ - --with-cc-opt="-O2 -DNGX_LUA_ABORT_AT_PANIC" --with-ld-opt="-Wl,-rpath,$LJ/lib" \ +./configure --prefix=$P --build="ingrest-${version##*.}" --user=nobody --group=nobody \ + --with-cc-opt="-O2 $HARDEN -DNGX_LUA_ABORT_AT_PANIC" --with-ld-opt="-Wl,-rpath,$LJ/lib $HARDEN_LD" \ --error-log-path=stderr --http-log-path=/tmp/access.log --pid-path=/tmp/nginx.pid --lock-path=/tmp/nginx.lock \ --http-client-body-temp-path=/tmp/client_body --http-proxy-temp-path=/tmp/proxy \ --http-fastcgi-temp-path=/tmp/fastcgi --http-uwsgi-temp-path=/tmp/uwsgi --http-scgi-temp-path=/tmp/scgi \ @@ -64,7 +72,7 @@ rm -rf $P/html $P/logs $P/modules/ngx_stream_geoip2_module.so for lib in resty-core resty-lrucache resty-string; do make -C "$lib" install PREFIX=$P LUA_LIB_DIR=$LIB >/dev/null done -make -C cjson LUA_INCLUDE_DIR="$LUAJIT_INC" >/dev/null +make -C cjson LUA_INCLUDE_DIR="$LUAJIT_INC" CFLAGS="-O3 -Wall -pedantic -DNDEBUG $HARDEN" LDFLAGS="$HARDEN_LD" >/dev/null install -m755 cjson/cjson.so $LIB/cjson.so for d in nginx luajit ndk lua stream-lua resty-core resty-lrucache resty-string cjson brotli zstd geoip2 modsecurity libmodsecurity; do diff --git a/test/smoke.sh b/test/smoke.sh index f68461f..c5e9c5c 100755 --- a/test/smoke.sh +++ b/test/smoke.sh @@ -4,15 +4,24 @@ image=$1 name=edge-smoke-$$ here=$(cd "$(dirname "$0")" && pwd) work=$(mktemp -d) -trap 'docker rm -f "$name" >/dev/null 2>&1 || true; rm -rf "$work"' EXIT +files=$(docker create "$image") +trap 'docker rm -f "$name" "$files" >/dev/null 2>&1 || true; rm -rf "$work"' EXIT fail() { echo "$*"; docker logs "$name" 2>&1 | tail -20 || true; exit 1; } build="ingrest-$(sed 's/.*\.//' "$here/../VERSION")" docker run --rm "$image" nginx -V 2>&1 | grep -q -- "--with-http_v3_module" || fail "nginx -V lacks http_v3" docker run --rm "$image" nginx -v 2>&1 | grep -qF "($build)" || fail "nginx -v lacks $build" -n=$(docker run --rm "$image" sh -c 'grep -c "\"ctx\"" /usr/local/nginx/directives.json') +docker cp -q "$files:/usr/local/nginx/directives.json" "$work/directives.json" +n=$(grep -c '"ctx"' "$work/directives.json") [ "$n" -gt 500 ] || fail "directives.json has $n forms" -docker run --rm "$image" sh -c '! ls /usr/local/nginx/modules/ngx_stream_geoip2_module.so 2>/dev/null' || fail "stream geoip2 module is shipped" +for f in /usr/local/nginx/modules/ngx_stream_geoip2_module.so /bin/sh /bin/bash /usr/bin/curl /usr/bin/perl /usr/local/luajit/bin; do + ! docker cp -q "$files:$f" "$work/shipped" 2>/dev/null || fail "$f is shipped" +done +client=edge-smoke-client +from=$(sed -n 's/^FROM \(debian:[^ ]*\) AS sources$/\1/p' "$here/../Dockerfile") +printf 'FROM %s\nRUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && rm -rf /var/lib/apt/lists/*\n' "$from" | + docker buildx build --load -q -t "$client" - >/dev/null +h3() { docker run --rm --network "container:$name" "$client" curl -sk --http3-only "$@"; } for c in fallback lua; do openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 -subj "/CN=$c.test" \ @@ -55,11 +64,11 @@ upload() { } got=$(upload 'filename="ok.txt"')/$(upload "filename=\"ok.txt\"; filename*=UTF-8''shell.php") [ "$got" = 200/403 ] || fail "modsecurity multipart filename*: got '$got'" -got=$(docker exec "$name" curl -sk --http3-only -o /dev/null -w '%{http_version} %{http_code}' https://127.0.0.1:8443/) +got=$(h3 -o /dev/null -w '%{http_version} %{http_code}' https://127.0.0.1:8443/) [ "$got" = "3 200" ] || fail "HTTP/3: got '$got'" got=$(curl -sk --http2 https://127.0.0.1:18443/hello https://127.0.0.1:18443/hello | tr '\n' ' ') [ "$got" = "tcp ok tcp ok " ] || fail "ssl_client_hello_by_lua, clienthello API or ngx.ctx to requests: got '$got'" -got=$(docker exec "$name" curl -sk --http3-only https://127.0.0.1:8443/hello https://127.0.0.1:8443/hello | tr '\n' ' ') +got=$(h3 https://127.0.0.1:8443/hello https://127.0.0.1:8443/hello | tr '\n' ' ') [ "$got" = "quic ok quic ok " ] || fail "ssl_client_hello_by_lua over QUIC: got '$got'" got=$(curl -fs http://127.0.0.1:19000/) [ "$got" = backend ] || fail "stream balancer_by_lua: got '$got'" diff --git a/tools/watch/scan.sh b/tools/watch/scan.sh index 36b4acb..7e21cc6 100755 --- a/tools/watch/scan.sh +++ b/tools/watch/scan.sh @@ -23,5 +23,5 @@ The published image \`$image\` has fixable HIGH or CRITICAL vulnerabilities in D | --- | --- | --- | --- | --- | $rows -This pull request changes \`REFRESH\`, so the runtime stage installs current packages instead of its cached layer. +This pull request changes \`REFRESH\`, so the runtime stage downloads current packages instead of its cached layer, and moves the distroless base to its newest digest. EOF diff --git a/tools/watch/unfixed.sh b/tools/watch/unfixed.sh index 68b80b4..28a34fa 100755 --- a/tools/watch/unfixed.sh +++ b/tools/watch/unfixed.sh @@ -6,14 +6,26 @@ repo=${GITHUB_REPOSITORY:-ingrest-dev/edge} image=${1:-$(gh release download channels -R "$repo" -p stable.json -O - | jq -r '.images[0].image')} case "$image" in ghcr.io/ingrest-dev/edge@sha256:*) ;; *) echo "unexpected image '$image'" >&2; exit 1 ;; esac -work=$(mktemp -d) +work=$(cd "$(mktemp -d)" && pwd -P) trap 'rm -rf "$work"' EXIT -docker run --rm --entrypoint sh "$image" -c ' - for f in /usr/local/nginx/sbin/nginx /usr/local/nginx/modules/*.so /usr/local/modsecurity/lib/*.so.* /usr/local/luajit/lib/*.so.*; do - [ -e "$f" ] && ldd "$f" - done | awk "\$2 == \"=>\" && \$3 ~ /^\// {print \$3}" | sort -u | while read -r lib; do - dpkg -S "$lib" 2>/dev/null || dpkg -S "$(readlink -f "$lib")" 2>/dev/null || true - done | cut -d: -f1 | sort -u' >"$work/linked.txt" +files=$(docker create "$image") +trap 'docker rm -f "$files" >/dev/null 2>&1 || true; rm -rf "$work"' EXIT +mkdir "$work/root" +docker export "$files" | tar -x -C "$work/root" +case $(docker image inspect -f '{{.Architecture}}' "$image") in +amd64) ld=/lib64/ld-linux-x86-64.so.2 ;; +arm64) ld=/lib/ld-linux-aarch64.so.1 ;; +*) echo "unknown architecture of $image" >&2; exit 1 ;; +esac +(cd "$work/root" && ls -d usr/local/nginx/sbin/nginx usr/local/nginx/modules/*.so usr/local/nginx/lualib/*.so usr/local/modsecurity/lib/*.so.* usr/local/luajit/lib/*.so.* 2>/dev/null || true) | + while read -r f; do + docker run --rm --network none --entrypoint "$ld" "$image" --list "/$f" || exit 1 + done | awk '$2 == "=>" && $3 ~ /^\// && $3 !~ /^\/usr\/local\// {print $3}' | sort -u | while read -r lib; do + real=$(readlink -f "$work/root$lib") || real= + pkg=$(grep -l " ${real#"$work/root/"}\$" "$work/root/var/lib/dpkg/status.d/"*.md5sums 2>/dev/null | head -n 1) || true + [ -n "$pkg" ] || echo "no package owns $lib" >&2 + echo "$pkg" + done | sed '/^$/d; s#.*/##; s#\.md5sums$##' | sort -u >"$work/linked.txt" [ -s "$work/linked.txt" ] || { echo "no linked Debian packages found in $image" >&2; exit 1; } docker run --rm --network host -e HTTPS_PROXY -e https_proxy -e TRIVY_DISABLE_TELEMETRY=true -e TRIVY_SKIP_VERSION_CHECK=true -v "$work:/out" "$trivy" image --quiet \