Skip to content

Commit

Permalink
use iptables-wrappers to switch between legacy and nft
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed May 9, 2024
1 parent 78dc866 commit 43edd6f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
ARG FAIL2BAN_VERSION=1.1.0
ARG ALPINE_VERSION=3.19

# https://github.com/kubernetes-sigs/iptables-wrappers
ARG IPTABLES_WRAPPER_VERSION=f6ef44b2c449cca8f005b32dea9a4b497202dbef
ARG GO_VERSION=1.21
ARG XX_VERSION=1.4.0

FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS iw-builder
RUN apk --update --no-cache add file
COPY --from=xx / /
WORKDIR /src
ARG IPTABLES_WRAPPER_VERSION
ADD "https://github.com/kubernetes-sigs/iptables-wrappers.git#${IPTABLES_WRAPPER_VERSION}" .
ARG TARGETPLATFORM
ENV CGO_ENABLED=0
RUN xx-go build -v -trimpath -o /bin/iptables-wrapper -ldflags='-s -w -extldflags="-static" -buildid=""' . \
&& xx-verify --static /bin/iptables-wrapper

FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS fail2ban-src
RUN apk add --no-cache git
WORKDIR /src/fail2ban
Expand All @@ -16,6 +33,7 @@ RUN --mount=from=fail2ban-src,source=/src/fail2ban,target=/tmp/fail2ban,rw \
bash \
curl \
grep \
iproute2 \
ipset \
iptables \
iptables-legacy \
Expand All @@ -40,6 +58,10 @@ RUN --mount=from=fail2ban-src,source=/src/fail2ban,target=/tmp/fail2ban,rw \
&& apk del build-dependencies \
&& rm -rf /etc/fail2ban/jail.d /root/.cache

COPY --from=iw-builder /src/iptables-wrapper-installer.sh /
COPY --from=iw-builder /bin/iptables-wrapper /
RUN /iptables-wrapper-installer.sh

COPY entrypoint.sh /entrypoint.sh

ENV TZ="UTC"
Expand Down

0 comments on commit 43edd6f

Please sign in to comment.