Skip to content

Commit 2e60f87

Browse files
authored
Merge pull request coreruleset#218 from fzipi/build-apache-pcre2
feat(apache): switch to pcre2
2 parents df7a97a + 60f2816 commit 2e60f87

File tree

7 files changed

+50
-26
lines changed

7 files changed

+50
-26
lines changed

.github/workflows/configure-rules-for-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ while read -r line; do
2222
test_value="$(cut -d'|' -f5 <<< "${line}")"
2323

2424
if ! grep -q "${var_name}" "${readme_file}"; then
25-
echo "Failed to find environment variable `${var_name}` in README."
25+
echo "Failed to find environment variable '${var_name}' in README."
2626
exit 1
2727
fi
2828

.github/workflows/verifyimage.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ jobs:
128128
's#image: owasp/modsecurity-crs:${{ contains(matrix.target, 'apache') && 'apache' || 'nginx' }}.*#image: ${{ matrix.target }}-verification#' \
129129
crs/tests/docker-compose.yml
130130
- name: Run CRS tests for ${{ matrix.target }}
131+
# Log flushing isn't reliable enough for go-ftw (https://github.com/coreruleset/go-ftw/issues/473)
132+
if: ${{!contains(matrix.target, 'nginx-alpine')}}
131133
run: |
132134
cd crs
133135
modsec_version="${{ contains(matrix.target, 'apache') && 'modsec2-apache' || 'modsec3-nginx' }}"
134136
backend="${{ contains(matrix.target, 'apache') && 'httpd' || 'nginx' }}"
135137
mkdir -p "tests/logs/${modsec_version}/{nginx,apache2}"
136138
docker compose -f ./tests/docker-compose.yml up -d "${modsec_version}"
139+
sleep 10
137140
docker compose -f ./tests/docker-compose.yml logs
138141
if ! [ "$(docker inspect ${modsec_version} --format='{{.State.Running}}')" = "true" ]; then
139142
echo "Web server failed to start. Aborting."
@@ -146,3 +149,12 @@ jobs:
146149
--log-file "tests/logs/${modsec_version}/error.log" \
147150
--overrides "tests/regression/${backend}-overrides.yaml" \
148151
--show-failures-only
152+
153+
- name: Upload logs
154+
uses: actions/upload-artifact@v4
155+
if: always()
156+
with:
157+
name: ${{ matrix.target }}-error.log
158+
path: "crs/tests/logs/${{ contains(matrix.target, 'apache') && 'modsec2-apache' || 'modsec3-nginx' }}/error.log"
159+
retention-days: 7
160+
overwrite: true

apache/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG HTTPD_VERSION="n/a"
33
FROM image AS build
44

55
ARG MODSEC2_VERSION="n/a"
6+
ARG MODSEC2_FLAGS="n/a"
67
ARG LUA_VERSION="n/a"
78

89
RUN set -eux; \
@@ -17,7 +18,7 @@ RUN set -eux; \
1718
libaprutil1-dev \
1819
libcurl4-gnutls-dev \
1920
libfuzzy-dev \
20-
libpcre3-dev \
21+
libpcre2-dev \
2122
libtool \
2223
libxml2-dev \
2324
libyajl-dev \
@@ -31,7 +32,7 @@ RUN set -eux; \
3132
tar -zxvf v${MODSEC2_VERSION}.tar.gz; \
3233
cd ModSecurity-${MODSEC2_VERSION}; \
3334
./autogen.sh; \
34-
./configure --with-yajl --with-ssdeep; \
35+
./configure ${MODSEC2_FLAGS}; \
3536
make; \
3637
make install; \
3738
make clean
@@ -173,6 +174,7 @@ RUN set -eux; \
173174
libfuzzy2 \
174175
liblua${LUA_VERSION} \
175176
${LUA_MODULES} \
177+
libpcre2-8-0 \
176178
libxml2 \
177179
libyajl2; \
178180
update-ca-certificates -f; \

apache/Dockerfile-alpine

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG HTTPD_VERSION="n/a"
33
FROM image AS build
44

55
ARG MODSEC2_VERSION="n/a"
6+
ARG MODSEC2_FLAGS="n/a"
67
ARG LUA_VERSION="n/a"
78

89
# see https://httpd.apache.org/docs/2.4/install.html#requirements
@@ -33,15 +34,15 @@ RUN set -eux; \
3334
make \
3435
openssl \
3536
openssl-dev \
36-
pcre-dev \
37+
pcre2-dev \
3738
zlib-dev
3839

3940
RUN set -eux; \
4041
wget --quiet https://github.com/owasp-modsecurity/ModSecurity/archive/refs/tags/v${MODSEC2_VERSION}.tar.gz; \
4142
tar -zxvf v${MODSEC2_VERSION}.tar.gz; \
4243
cd ModSecurity-${MODSEC2_VERSION}; \
4344
./autogen.sh; \
44-
./configure --with-yajl --with-ssdeep --with-lmdb; \
45+
./configure ${MODSEC2_FLAGS}; \
4546
make; \
4647
make install; \
4748
make clean
@@ -184,6 +185,7 @@ RUN set -eux; \
184185
${LUA_MODULES} \
185186
moreutils \
186187
openssl \
188+
pcre2 \
187189
sed \
188190
tzdata \
189191
yajl; \

docker-bake.hcl

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ variable "modsec3-version" {
44
default = "3.0.14"
55
}
66

7+
variable "modsec3-flags" {
8+
default = "--with-yajl --with-ssdeep --with-lmdb --with-pcre2 --with-maxmind --enable-silent-rules"
9+
}
10+
711
variable "modsec2-version" {
812
# renovate: depName=ModSecurity2 packageName=owasp-modsecurity/ModSecurity datasource=github-releases
913
default = "2.9.8"
1014
}
1115

16+
variable "modsec2-flags" {
17+
default = "--with-yajl --with-ssdeep --with-pcre2"
18+
}
19+
1220
variable "crs-version" {
1321
# renovate: depName=coreruleset/coreruleset datasource=github-releases
1422
default = "4.12.0"
@@ -109,7 +117,9 @@ target "platforms-base" {
109117
args = {
110118
CRS_RELEASE = "${crs-version}"
111119
MODSEC2_VERSION = "${modsec2-version}"
120+
MODSEC2_FLAGS = modsec2-flags
112121
MODSEC3_VERSION = "${modsec3-version}"
122+
MODSEC3_FLAGS = modsec3-flags
113123
LUA_VERSION = "${lua-version}"
114124
LMDB_VERSION = "${lmdb-version}"
115125
}
@@ -125,13 +135,13 @@ target "apache" {
125135
lua_modules = join(" ", lua-modules-debian)
126136
tag_base = "apache"
127137
},
128-
# {
129-
# name = "alpine"
130-
# dockerfile = "apache/Dockerfile-alpine"
131-
# image = "docker-image://httpd:${httpd-version}-alpine"
132-
# lua_modules = join(" ", lua-modules-alpine)
133-
# tag_base = "apache-alpine"
134-
# }
138+
{
139+
name = "alpine"
140+
dockerfile = "apache/Dockerfile-alpine"
141+
image = "docker-image://httpd:${httpd-version}-alpine"
142+
lua_modules = join(" ", lua-modules-alpine)
143+
tag_base = "apache-alpine"
144+
}
135145
]
136146
}
137147

@@ -159,13 +169,13 @@ target "nginx" {
159169
lua_modules = join(" ", lua-modules-debian)
160170
tag_base = "nginx"
161171
},
162-
# {
163-
# name = "alpine"
164-
# dockerfile = "nginx/Dockerfile-alpine"
165-
# image = "docker-image://nginxinc/nginx-unprivileged:${nginx-version}-alpine"
166-
# lua_modules = join(" ", lua-modules-alpine)
167-
# tag_base = "nginx-alpine"
168-
# }
172+
{
173+
name = "alpine"
174+
dockerfile = "nginx/Dockerfile-alpine"
175+
image = "docker-image://nginxinc/nginx-unprivileged:${nginx-version}-alpine"
176+
lua_modules = join(" ", lua-modules-alpine)
177+
tag_base = "nginx-alpine"
178+
}
169179
],
170180
read-only-fs = [
171181
{

nginx/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM image AS build
22

33
ARG NGINX_VERSION="n/a"
44
ARG MODSEC3_VERSION="n/a"
5+
ARG MODSEC3_FLAGS="n/a"
56
ARG LMDB_VERSION="n/a"
67
ARG LUA_VERSION="n/a"
78
ARG NGINX_DYNAMIC_MODULES="n/a"
@@ -10,8 +11,6 @@ ARG READ_ONLY_FS="false"
1011

1112
USER root
1213

13-
# Note: libpcre3-dev (PCRE 1) is required by the build description,
14-
# even though the build will use PCRE2.
1514
RUN set -eux; \
1615
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \
1716
apt-get update -qq; \
@@ -24,7 +23,6 @@ RUN set -eux; \
2423
libcurl4-gnutls-dev \
2524
libfuzzy-dev \
2625
liblua${LUA_VERSION}-dev \
27-
libpcre3-dev \
2826
libpcre2-dev \
2927
libtool \
3028
libxml2-dev \
@@ -53,7 +51,7 @@ RUN set -eux; \
5351
sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \
5452
sed -ie "s/i386-linux-gnu/${ARCH}/g" build/pcre2.m4; \
5553
./build.sh; \
56-
./configure --with-yajl --with-ssdeep --with-pcre2 --with-maxmind --enable-silent-rules; \
54+
./configure ${MODSEC3_FLAGS}; \
5755
make -j$(nproc) install; \
5856
strip /usr/local/modsecurity/lib/lib*.so*
5957

@@ -243,6 +241,7 @@ RUN set -eux; \
243241
libfuzzy2 \
244242
liblua${LUA_VERSION} \
245243
${LUA_MODULES} \
244+
libpcre2-8-0 \
246245
libxml2 \
247246
libyajl2 \
248247
libmaxminddb-dev \

nginx/Dockerfile-alpine

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM image AS build
22

33
ARG NGINX_VERSION="n/a"
44
ARG MODSEC3_VERSION="n/a"
5+
ARG MODSEC3_FLAGS="n/a"
56
ARG LUA_VERSION="n/a"
67
ARG NGINX_DYNAMIC_MODULES="n/a"
78
ARG NGINX_HOME="n/a"
@@ -35,7 +36,6 @@ RUN set -eux; \
3536
openssl-dev \
3637
patch \
3738
pkgconfig \
38-
pcre-dev \
3939
pcre2-dev \
4040
yajl-dev \
4141
zlib-dev
@@ -49,7 +49,7 @@ RUN set -eux; \
4949
sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \
5050
sed -ie "s/i386-linux-gnu/${ARCH}/g" build/pcre2.m4; \
5151
./build.sh; \
52-
./configure --with-yajl --with-ssdeep --with-lmdb --with-pcre2 --with-maxmind --enable-silent-rules; \
52+
./configure ${MODSEC3_FLAGS}; \
5353
make -j$(nproc) install; \
5454
strip /usr/local/modsecurity/lib/lib*.so*
5555

@@ -240,7 +240,6 @@ RUN set -eux; \
240240
moreutils \
241241
openssl \
242242
tzdata \
243-
pcre \
244243
pcre2 \
245244
# Alpine needs GNU 'sed' because the 'sed' program shipped with busybox does not support 'z' parameter for separating lines with a 'NUL' character.
246245
sed \

0 commit comments

Comments
 (0)