Skip to content

Commit cea5a14

Browse files
committed
Add WAF dockerfile and make targets
1 parent 0bbb602 commit cea5a14

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ CHART_DIR = $(SELF_DIR)charts/nginx-gateway-fabric
55
NGINX_CONF_DIR = internal/controller/nginx/conf
66
NJS_DIR = internal/controller/nginx/modules/src
77
KIND_CONFIG_FILE = $(SELF_DIR)config/cluster/kind-cluster.yaml
8+
NAP_WAF_ALPINE_VERSION = 3.19
89
NGINX_DOCKER_BUILD_PLUS_ARGS = --secret id=nginx-repo.crt,src=$(SELF_DIR)nginx-repo.crt --secret id=nginx-repo.key,src=$(SELF_DIR)nginx-repo.key
10+
NGINX_DOCKER_BUILD_NAP_WAF_ARGS = --build-arg ALPINE_VERSION=$(NAP_WAF_ALPINE_VERSION) --build-arg INCLUDE_NAP_WAF=true
911
BUILD_AGENT = local
1012

1113
PROD_TELEMETRY_ENDPOINT = oss.edge.df.f5.com:443
@@ -43,6 +45,7 @@ HELM_SCHEMA_VERSION = 0.18.1
4345
PREFIX ?= nginx-gateway-fabric## The name of the NGF image. For example, nginx-gateway-fabric
4446
NGINX_PREFIX ?= $(PREFIX)/nginx## The name of the nginx image. For example: nginx-gateway-fabric/nginx
4547
NGINX_PLUS_PREFIX ?= $(PREFIX)/nginx-plus## The name of the nginx plus image. For example: nginx-gateway-fabric/nginx-plus
48+
NGINX_PLUS_WAF_PREFIX ?= $(PREFIX)/nginx-plus-waf## The name of the nginx plus image with NAP WAF. For example: nginx-gateway-fabric/nginx-plus-waf
4649
TAG ?= $(VERSION:v%=%)## The tag of the image. For example, 1.1.0
4750
TARGET ?= local## The target of the build. Possible values: local and container
4851
OUT_DIR ?= build/out## The folder where the binary will be stored
@@ -77,6 +80,9 @@ build-images: build-ngf-image build-nginx-image ## Build the NGF and nginx docke
7780
.PHONY: build-images-with-plus
7881
build-images-with-plus: build-ngf-image build-nginx-plus-image ## Build the NGF and NGINX Plus docker images
7982

83+
.PHONY: build-images-nap-waf
84+
build-images-with-nap-waf: build-ngf-image build-nginx-plus-image-with-nap-waf ## Build the NGF and NGINX Plus with WAF docker images
85+
8086
.PHONY: build-prod-ngf-image
8187
build-prod-ngf-image: TELEMETRY_ENDPOINT=$(PROD_TELEMETRY_ENDPOINT)
8288
build-prod-ngf-image: build-ngf-image ## Build the NGF docker image for production
@@ -99,6 +105,13 @@ build-prod-nginx-plus-image: build-nginx-plus-image ## Build the custom nginx pl
99105
build-nginx-plus-image: check-for-docker ## Build the custom nginx plus image
100106
docker build --platform linux/$(GOARCH) $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) $(strip $(NGINX_DOCKER_BUILD_PLUS_ARGS)) -f $(SELF_DIR)build/Dockerfile.nginxplus -t $(strip $(NGINX_PLUS_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))
101107

108+
.PHONY: build-nginx-plus-image-with-nap-waf
109+
build-nginx-plus-image-with-nap-waf: check-for-docker ## Build the custom nginx plus image with NAP WAF. Note that arm is NOT supported.
110+
@if [ $(GOARCH) = "arm64" ]; then \
111+
echo "\033[0;31mIMPORTANT:\033[0m The nginx-plus-waf image cannot be built for arm64 architecture and will be built for amd64."; \
112+
fi
113+
docker build --platform linux/amd64 $(strip $(NGINX_DOCKER_BUILD_OPTIONS)) $(strip $(NGINX_DOCKER_BUILD_PLUS_ARGS)) $(strip $(NGINX_DOCKER_BUILD_NAP_WAF_ARGS)) -f $(SELF_DIR)build/Dockerfile.nginxplus -t $(strip $(NGINX_PLUS_WAF_PREFIX)):$(strip $(TAG)) $(strip $(SELF_DIR))
114+
102115
.PHONY: check-for-docker
103116
check-for-docker: ## Check if Docker is installed
104117
@docker -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with Docker\n"; exit $$code)

build/Dockerfile.nginxplus

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# syntax=docker/dockerfile:1.16
2+
3+
# renovate: datasource=docker depName=alpine
4+
ARG ALPINE_VERSION=3.21
5+
26
FROM scratch AS nginx-files
37

48
# the following links can be replaced with local files if needed, i.e. ADD --chown=101:1001 <local_file> <container_file>
59
ADD --link --chown=101:1001 https://cs.nginx.com/static/keys/nginx_signing.rsa.pub nginx_signing.rsa.pub
610

7-
FROM alpine:3.21
11+
FROM alpine:${ALPINE_VERSION}
812

913
ARG NGINX_PLUS_VERSION=R34
1014
# renovate: datasource=github-tags depName=nginx/agent extractVersion=^v?(?<version>.*)$
1115
ARG NGINX_AGENT_VERSION=3.0.0
16+
ARG APP_PROTECT_VERSION=34.5.342
17+
ARG INCLUDE_NAP_WAF=false
1218
ARG NJS_DIR
1319
ARG NGINX_CONF_DIR
1420
ARG BUILD_AGENT
@@ -20,6 +26,10 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/apk/cert.pem,mode=0644 \
2026
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
2127
&& printf "%s\n" "https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION}/alpine/v$(grep -E -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
2228
&& printf "%s\n" "https://pkgs.nginx.com/nginx-agent/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
29+
&& if [ "${INCLUDE_NAP_WAF}" = "true" ]; then \
30+
printf "%s\n" "https://pkgs.nginx.com/app-protect-x-plus/alpine/v$(grep -E -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
31+
&& apk add --no-cache app-protect-module-plus~=${APP_PROTECT_VERSION}; \
32+
fi \
2333
&& apk add --no-cache nginx-plus nginx-plus-module-njs nginx-plus-module-otel nginx-agent=${NGINX_AGENT_VERSION}
2434

2535
RUN apk add --no-cache libcap bash \
@@ -45,4 +55,5 @@ USER 101:1001
4555

4656
LABEL org.nginx.ngf.image.build.agent="${BUILD_AGENT}"
4757

58+
ENV USE_NAP_WAF=${INCLUDE_NAP_WAF}
4859
ENTRYPOINT ["/agent/entrypoint.sh"]

build/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ trap 'handle_quit' QUIT
2727

2828
rm -rf /var/run/nginx/*.sock
2929

30+
# Bootstrap the necessary app protect files
31+
if [ "${USE_NAP_WAF:-false}" = "true" ]; then
32+
touch /opt/app_protect/bd_config/policy_path.map
33+
fi
34+
3035
# Launch nginx
3136
echo "starting nginx ..."
3237

0 commit comments

Comments
 (0)