Initial implementation of the OPEN-2 epic: a .NET 10 YARP edge that decides from what the upstream answered. Design (docs/ARCHITECTURE.md, tracker authority 4c9de3f6): - one short-circuit point, ordered: always-pass prefixes -> allowlist -> operator block (301) -> engine ban (403 + Retry-After) -> geo (451) - a post-response observer feeds a consecutive-refusal streak; N refusals in M minutes ban for BanDuration; 5xx alerts and never bans - provenance on the block row, so clearing engine bans cannot touch an operator's entries; the toggle is Off/Observe/Enforce and changes no rows - inherited protections from the reference deployment: one durable write per source per 30s, LRU-bounded streak map, no DB on the request path Verification: 36 unit + 14 integration tests, plus scripts/smoke.sh (19 assertions against a running edge and a real upstream, including the distroless --healthcheck mode). Findings worth keeping (documented in docs/ARCHITECTURE.md): - ctx.RequestAborted silently cancelled the ban write, because the observer runs after the response is written - SQLite cannot translate DateTimeOffset comparisons; timestamps are stored as integers there and stay timestamptz on PostgreSQL - CIDR masking order silently widened prefixes (198.51.100.24/19 -> /16) - an empty string in appsettings.json defeats the env fallback (?? on "") - concurrent ban writes raced into the unique index and lost evidence Also moves the unrelated 2026-09-30 inference benchmarks out of the project root into research/.
84 lines
3.6 KiB
Docker
84 lines
3.6 KiB
Docker
# syntax=docker/dockerfile:1.7
|
||
#
|
||
# openwaf edge — framework-dependent publish on a chiseled distroless runtime.
|
||
#
|
||
# Why not NativeAOT: the reference deployment (~/work/neemle/landing) tried it
|
||
# and recorded the reason in its Dockerfile — EF Core under AOT needs every LINQ
|
||
# query precompiled and every request/response shape annotated, and the size win
|
||
# washes out against the chiseled runtime base. Not relitigated here.
|
||
#
|
||
# Stages:
|
||
# 1. restore – NuGet layer, cached independently of source changes
|
||
# 2. build – framework-dependent publish, debug artefacts stripped
|
||
# 3. runtime – mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled, no shell
|
||
#
|
||
# HEALTHCHECK re-executes the binary in --healthcheck mode: a chiseled base has
|
||
# no shell, no wget and no curl, so the binary is the only probe available.
|
||
|
||
ARG DOTNET_VERSION=10.0
|
||
|
||
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS restore
|
||
WORKDIR /src
|
||
COPY dotnet/global.json dotnet/Directory.Build.props dotnet/NuGet.Config dotnet/OpenWaf.slnx ./
|
||
COPY dotnet/OpenWaf.Domain/OpenWaf.Domain.csproj OpenWaf.Domain/
|
||
COPY dotnet/OpenWaf.Infrastructure/OpenWaf.Infrastructure.csproj OpenWaf.Infrastructure/
|
||
COPY dotnet/OpenWaf.Edge/OpenWaf.Edge.csproj OpenWaf.Edge/
|
||
COPY dotnet/OpenWaf.Tests.Unit/OpenWaf.Tests.Unit.csproj OpenWaf.Tests.Unit/
|
||
COPY dotnet/OpenWaf.Tests.Integration/OpenWaf.Tests.Integration.csproj OpenWaf.Tests.Integration/
|
||
RUN dotnet restore OpenWaf.Edge/OpenWaf.Edge.csproj
|
||
|
||
FROM restore AS build
|
||
COPY dotnet/ ./
|
||
RUN dotnet publish OpenWaf.Edge/OpenWaf.Edge.csproj \
|
||
-c Release \
|
||
-p:DebugType=none \
|
||
-p:DebugSymbols=false \
|
||
-o /publish/api \
|
||
&& cd /publish/api \
|
||
&& rm -f *.pdb \
|
||
&& rm -rf BuildHost-net472 BuildHost-netcore
|
||
|
||
# Stage the volume mount points with app:app ownership — a chiseled image has
|
||
# no shell, so there is no mkdir at runtime.
|
||
RUN mkdir -p /publish/data /publish/geoip
|
||
|
||
# GeoIP: dbip-city-lite, free and redistributable, same MMDB binary format as
|
||
# MaxMind. Kept under the legacy GeoLite2-Country.mmdb name so one env var
|
||
# covers both, and the reader sniffs Metadata.DatabaseType rather than trusting
|
||
# the filename — a city database stored under a country name is exactly the
|
||
# trap the reference repo documented.
|
||
#
|
||
# DBIP_VERSION is pinned, which means the database ages with the image. /healthz
|
||
# reports the loaded database's build date so a stale one is visible at runtime,
|
||
# not only at build time; bump this argument in CI on a schedule.
|
||
ARG DBIP_VERSION=2026-04
|
||
RUN apt-get update -qq && apt-get install -qq -y curl gzip > /dev/null && \
|
||
mkdir -p /publish/geoip && \
|
||
curl -fsSL "https://download.db-ip.com/free/dbip-city-lite-${DBIP_VERSION}.mmdb.gz" \
|
||
| gunzip > /publish/geoip/GeoLite2-Country.mmdb && \
|
||
ls -la /publish/geoip/GeoLite2-Country.mmdb
|
||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-noble-chiseled AS runtime
|
||
|
||
# Chiseled ships a non-root `app` user (UID 1654) and no shell.
|
||
WORKDIR /app/api
|
||
COPY --from=build --chown=app:app /publish/api /app/api
|
||
COPY --from=build --chown=app:app /publish/data /app/data
|
||
COPY --from=build --chown=app:app /publish/geoip /app/geoip
|
||
|
||
USER app:app
|
||
|
||
ENV ASPNETCORE_URLS=http://+:8080 \
|
||
ASPNETCORE_FORWARDEDHEADERS_ENABLED=false \
|
||
ConnectionStrings__OpenWaf="Data Source=/app/data/openwaf.db" \
|
||
Database__Provider=sqlite \
|
||
GEOIP_MAXMIND_DB_PATH=/app/geoip/GeoLite2-Country.mmdb \
|
||
HEALTHCHECK_PORT=8080
|
||
|
||
EXPOSE 8080
|
||
|
||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
|
||
CMD ["dotnet", "/app/api/OpenWaf.Edge.dll", "--healthcheck"]
|
||
|
||
ENTRYPOINT ["dotnet", "/app/api/OpenWaf.Edge.dll"]
|