From dd83b18992326b7a40909f665359fa15472b6e46 Mon Sep 17 00:00:00 2001 From: Max Leske Date: Wed, 10 Apr 2024 21:54:50 +0200 Subject: [PATCH 01/14] docs: fix notice in container readme --- README-containers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README-containers.md b/README-containers.md index a92b107..0ff2b19 100644 --- a/README-containers.md +++ b/README-containers.md @@ -4,8 +4,8 @@ [![License](https://img.shields.io/github/license/coreruleset/modsecurity-crs-docker.svg)](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/LICENSE) -> [!IMPORTANT] -> Please refer to the [documentation on GitHub](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/README.md). + +⚠️ Please refer to the [documentation on GitHub](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/README.md). ## Supported Tags From a0bb71f9103292e0aecd6920415612680d79afcf Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Sun, 14 Apr 2024 19:54:28 -0300 Subject: [PATCH 02/14] fix: update compose port for apache Signed-off-by: Felipe Zipitria --- docker-compose.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index ae52305..e1bd73e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -82,9 +82,9 @@ services: crs-apache: image: owasp/modsecurity-crs:apache ports: - - "80:80" + - "80:8080" # only available if SETTLS was enabled: - - "443:443" + - "443:8443" <<: *default-settings crs-nginx: @@ -93,4 +93,4 @@ services: - "80:8080" # only available if SETTLS was enabled: - "443:8443" - <<: *default-settings \ No newline at end of file + <<: *default-settings From 23e6d024bdd8cfae08d03192457774592b03c64e Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 22 Apr 2024 11:08:12 -0300 Subject: [PATCH 03/14] fix: use new upstream sources Signed-off-by: Felipe Zipitria --- nginx/Dockerfile | 4 ++-- nginx/Dockerfile-alpine | 4 ++-- openresty/Dockerfile-alpine | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 5745d98..aa19535 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -44,7 +44,7 @@ RUN set -eux; \ strip /usr/local/lib/liblmdb*.so* RUN set -eux; \ - git clone https://github.com/SpiderLabs/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ + git clone https://github.com/owasp-modsecurity/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ cd ModSecurity; \ ARCH=$(gcc -print-multiarch); \ sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \ @@ -56,7 +56,7 @@ RUN set -eux; \ # We use master RUN set -eux; \ - git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ + git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ curl -sSL https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -o nginx-${NGINX_VERSION}.tar.gz; \ tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ cd ./nginx-${NGINX_VERSION}; \ diff --git a/nginx/Dockerfile-alpine b/nginx/Dockerfile-alpine index f30e249..404ef12 100644 --- a/nginx/Dockerfile-alpine +++ b/nginx/Dockerfile-alpine @@ -42,7 +42,7 @@ RUN set -eux; \ WORKDIR /sources RUN set -eux; \ - git clone https://github.com/SpiderLabs/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ + git clone https://github.com/owasp-modsecurity/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ cd ModSecurity; \ ARCH=$(gcc -print-multiarch); \ sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \ @@ -54,7 +54,7 @@ RUN set -eux; \ # We use master RUN set -eux; \ - git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ + git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ wget --quiet http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz; \ tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ cd ./nginx-${NGINX_VERSION}; \ diff --git a/openresty/Dockerfile-alpine b/openresty/Dockerfile-alpine index 3eb2140..b456731 100644 --- a/openresty/Dockerfile-alpine +++ b/openresty/Dockerfile-alpine @@ -47,7 +47,7 @@ WORKDIR /sources # Download ModSecurity and compile it. RUN set -eux; \ - git clone https://github.com/SpiderLabs/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ + git clone https://github.com/owasp-modsecurity/ModSecurity --branch "v${MODSEC3_VERSION}" --depth 1 --recursive; \ cd ModSecurity; \ ARCH=$(gcc -print-multiarch); \ sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \ @@ -61,7 +61,7 @@ RUN set -eux; \ # Download Openresty bundle for the specific version. We can then get the compilation options for nginx from the installed Openresty in the docker image to be used with the 'configure' script inside the openresty bundle to configure the ModSecurity-nginx module and then build it. I did not find the configure script inside the Openresty Docker image. # Specify the LUAJIT_LIB and LUAJIT_INC that are already installed in the base image. RUN set -eux; \ - git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ + git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ wget --quiet https://openresty.org/download/openresty-"${OPENRESTY_VERSION}".tar.gz; \ tar -xzf openresty-"${OPENRESTY_VERSION}".tar.gz; \ cd ./openresty-"${OPENRESTY_VERSION}"/bundle/nginx-${NGINX_VERSION}; \ From aa33d2b313d2c838d1db4b17556ec60b7f9f970d Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 22 Apr 2024 11:11:49 -0300 Subject: [PATCH 04/14] fix(openresty): add healthz endpoint Signed-off-by: Felipe Zipitria --- .../includes/location_common.conf.template | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 openresty/templates/includes/location_common.conf.template diff --git a/openresty/templates/includes/location_common.conf.template b/openresty/templates/includes/location_common.conf.template new file mode 100644 index 0000000..db02c20 --- /dev/null +++ b/openresty/templates/includes/location_common.conf.template @@ -0,0 +1,19 @@ + +location /healthz { + access_log off; + add_header Content-Type text/plain; + return 200 "OK"; +} + +location /metrics/nginx { + access_log off; + allow ${METRICS_ALLOW_FROM}; + deny ${METRICS_DENY_FROM}; + proxy_store off; + stub_status; +} + +error_page 500 502 503 504 /50x.html; +location = /50x.html { + root /usr/share/nginx/html; +} From e388f493b9a6ee15b50390722819e4b7e344d0a6 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 22 Apr 2024 15:53:10 -0300 Subject: [PATCH 05/14] fix: update path in proxy ssl config Signed-off-by: Felipe Zipitria --- openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh b/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh index 496d8fd..0d2c29a 100755 --- a/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh +++ b/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh @@ -11,4 +11,4 @@ if [ "${PROXY_SSL}" = "on" ]; then PROXY_SSL_CONFIG="include includes/proxy_backend_ssl.conf;" fi -sed -i.bak -r 's#PROXY_SSL_CONFIG#'"${PROXY_SSL_CONFIG}"'#' /usr/local/openresty/nginx/conf.d/default.conf +sed -i.bak -r 's#PROXY_SSL_CONFIG#'"${PROXY_SSL_CONFIG}"'#' /usr/local/openresty/nginx/conf/conf.d/default.conf From 955b9afd7744e493049c636f675de84a0ad9ee00 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Wed, 24 Apr 2024 00:06:43 -0300 Subject: [PATCH 06/14] chore: error if port or ssl_port are lower than 1024 Signed-off-by: Felipe Zipitria --- apache/docker-entrypoint.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 0fb665f..27521e7 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -2,6 +2,20 @@ /usr/local/bin/generate-certificate /usr/local/apache2 +if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then + echo "ERROR: you are using PORT=${PORT} and SSL_PORT=${SSL_PORT}" + echo "Both nginx and httpd containers now run with an unprivileged user. This means that we cannot bind to ports below 1024, so you might need to correct your PORT and SSL_PORT settings. Now the defaults for both nginx and httpd are 8080 and 8443." + echo "FIX:" + echo "if you have a port mapping like" + echo "ports:" + echo " - \"80:80\"" + echo "then update it to use a port higher than 1024. Example:" + echo " - \"80:8080\"" + echo "The same should be done for the SSL ports." + + exit 1 +fi + . /opt/modsecurity/activate-plugins.sh . /opt/modsecurity/activate-rules.sh From 3a11ef0b458ebf8909cd0addfb791443c1892514 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Wed, 24 Apr 2024 09:47:01 -0300 Subject: [PATCH 07/14] feat: call new check-low-port script Signed-off-by: Felipe Zipitria --- apache/docker-entrypoint.sh | 15 +---------- .../docker-entrypoint.d/01-check-low-port.sh | 12 +++++++++ src/bin/check-low-port | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100755 nginx/docker-entrypoint.d/01-check-low-port.sh create mode 100755 src/bin/check-low-port diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 27521e7..01dc372 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -1,20 +1,7 @@ #!/bin/sh -e /usr/local/bin/generate-certificate /usr/local/apache2 - -if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then - echo "ERROR: you are using PORT=${PORT} and SSL_PORT=${SSL_PORT}" - echo "Both nginx and httpd containers now run with an unprivileged user. This means that we cannot bind to ports below 1024, so you might need to correct your PORT and SSL_PORT settings. Now the defaults for both nginx and httpd are 8080 and 8443." - echo "FIX:" - echo "if you have a port mapping like" - echo "ports:" - echo " - \"80:80\"" - echo "then update it to use a port higher than 1024. Example:" - echo " - \"80:8080\"" - echo "The same should be done for the SSL ports." - - exit 1 -fi +/usr/local/bin/check-low-port . /opt/modsecurity/activate-plugins.sh . /opt/modsecurity/activate-rules.sh diff --git a/nginx/docker-entrypoint.d/01-check-low-port.sh b/nginx/docker-entrypoint.d/01-check-low-port.sh new file mode 100755 index 0000000..527e508 --- /dev/null +++ b/nginx/docker-entrypoint.d/01-check-low-port.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# vim:sw=2:ts=2:sts=2:et + +set -eu + +LC_ALL=C +ME=$( basename "$0" ) +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +/usr/local/bin/check-low-port + +exit 0 diff --git a/src/bin/check-low-port b/src/bin/check-low-port new file mode 100755 index 0000000..62eb3ba --- /dev/null +++ b/src/bin/check-low-port @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then + echo< Date: Wed, 24 Apr 2024 16:38:43 -0300 Subject: [PATCH 08/14] chore: update crs to 4.2.0 Signed-off-by: Felipe Zipitria --- docker-bake.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-bake.hcl b/docker-bake.hcl index 9bd2c2e..67a659a 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -8,7 +8,7 @@ variable "modsec2-version" { } variable "crs-version" { - default = "4.1.0" + default = "4.2.0" } variable "nginx-version" { From a99fdd72d8b9c0cf37d5740d9666d8011acea8fd Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Fri, 26 Apr 2024 17:13:51 -0300 Subject: [PATCH 09/14] chore: check modsecurity.conf-recommended has not changed Signed-off-by: Felipe Zipitria --- .github/workflows/verifyimage.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index c64263e..477cdc9 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -8,6 +8,7 @@ on: env: REPO: "owasp/modsecurity-crs" + MODSECURITY_RECOMMENDED: "d9e164c508218202eba13d37cf661baacb8600706e618ce93ccc91c74c51449e" jobs: prepare: @@ -20,6 +21,10 @@ jobs: - name: List targets id: generate uses: docker/bake-action/subaction/list-targets@v4 + - name: Check modsecurity recommended + run: | + curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended -o modsecurity.conf-recommended + sha256sum -c "${{ env.MODSECURITY_RECOMMENDED }} modsecurity.conf-recommended" modsecurity.conf-recommended build: runs-on: ubuntu-latest From 032914e5201948956b15c53217ef1005309b0ead Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Fri, 26 Apr 2024 18:07:27 -0300 Subject: [PATCH 10/14] feat: override full modsecurity.conf file Signed-off-by: Felipe Zipitria --- README.md | 7 ++ apache/Dockerfile | 8 ++- apache/Dockerfile-alpine | 8 ++- nginx/Dockerfile | 11 +++- nginx/Dockerfile-alpine | 18 +++-- openresty/Dockerfile-alpine | 18 +++-- .../modsecurity.d/modsecurity-override.conf | 35 +--------- src/etc/modsecurity.d/modsecurity.conf | 65 +++++++++++++++++++ 8 files changed, 117 insertions(+), 53 deletions(-) create mode 100644 src/etc/modsecurity.d/modsecurity.conf diff --git a/README.md b/README.md index ab7f87d..e1d2bbb 100644 --- a/README.md +++ b/README.md @@ -235,11 +235,15 @@ All these variables impact in configuration directives in the modsecurity engine | Name | Description| | -------- | ------------------------------------------------------------------- | +| MODSEC_ARGUMENT_SEPARATOR | A character to use as the separator for `application/x-www-form-urlencoded` content. (Default: `&`). :warning: Do not touch unless you really know what you are doing. See [SecArgumentSeparator](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secargumentseparator) | +| MODSEC_ARGUMENTS_LIMIT | An integer indicating the maximum number of arguments that can be processed before setting the `REQBODY_ERROR` variable (Default `1000`). See [SecArgumentsLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secargumentslimit)| | MODSEC_AUDIT_ENGINE | A string used to configure the audit engine, which logs complete transactions (Default: `RelevantOnly`). Accepted values: `On`, `Off`, `RelevantOnly`. See [SecAuditEngine](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditEngine) for additional information. | | MODSEC_AUDIT_LOG | A string indicating the path to the main audit log file or the concurrent logging index file (Default: `/dev/stdout`) | | MODSEC_AUDIT_LOG_FORMAT | A string indicating the output format of the AuditLogs (Default: `JSON`). Accepted values: `JSON`, `Native`. See [SecAuditLogFormat](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditLogFormat) for additional information. | | MODSEC_AUDIT_LOG_PARTS | A string that defines which parts of each transaction are going to be recorded in the audit log (Default: `'ABIJDEFHZ'`). See [SecAuditLogParts](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secauditlogparts) for the accepted values. | +| MODSEC_AUDIT_LOG_RELEVANT_STATUS | A regular expression string that defines the http error codes that are relevant for audit logging (Default: `"^(?:5|4(?!04))"`). See [SecAuditLogRelevantStatus](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogrelevantstatus) | | MODSEC_AUDIT_LOG_TYPE | A string indicating the type of audit logging mechanism to be used (Default: `Serial`). Accepted values: `Serial`, `Concurrent` (`HTTPS` works only on Nginx - v3). See [SecAuditLogType](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogtype) for additional information. | +| MODSEC_COOKIE_FORMAT | The cookie format used (Default: `0`) :warning: Do not touch unless you really know what you are doing. | | MODSEC_AUDIT_STORAGE | A string indicating the directory where concurrent audit log entries are to be stored (Default: `/var/log/modsecurity/audit/`) | | MODSEC_DATA_DIR | A string indicating the path where persistent data (e.g., IP address data, session data, and so on) is to be stored (Default: `/tmp/modsecurity/data`) | | MODSEC_DEBUG_LOG | A string indicating the path to the ModSecurity debug log file (Default: `/dev/null`) | @@ -264,7 +268,10 @@ All these variables impact in configuration directives in the modsecurity engine | MODSEC_TAG | A string indicating the default tag action, which will be inherited by the rules in the same configuration context (Default: `modsecurity`) | | MODSEC_TMP_DIR | A string indicating the path where temporary files will be created (Default: `/tmp/modsecurity/tmp`) | | MODSEC_TMP_SAVE_UPLOADED_FILES | A string indicating if temporary uploaded files are saved (Default: `On`) (only relevant in Apache - ModSecurity v2) | +| MODSEC_UNICODE_MAPPING | The unicode Code Point to use form the default file(Default: `20127`). See [SecUnicodeMapFile](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secunicodemapfile) | | MODSEC_UPLOAD_DIR | A string indicating the path where intercepted files will be stored (Default: `/tmp/modsecurity/upload`) | +| MODSEC_UPLOAD_FILE_MODE | (Default: `0600`) | +| MODSEC_UPLOAD_KEEP_FILES | Configures whether or not the intercepted files will be kept after transaction is processed. (Default: `RelevantOnly`) Accepted values: `On`, `Off`, `RelevantOnly`. See [SecUploadKeepFiles](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secuploadkeepfiles) ### CRS specific diff --git a/apache/Dockerfile b/apache/Dockerfile index 6827d98..ef0d39f 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -78,11 +78,15 @@ ENV \ METRICS_ALLOW_FROM='127.0.0.0/255.0.0.0 ::1/128' \ METRICS_DENY_FROM='All' \ METRICSLOG='/dev/null' \ + MODSEC_ARGUMENT_SEPARATOR="&" \ + MODSEC_ARGUMENTS_LIMIT=1000 \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG=/dev/stdout \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_LOG_RELEVANT_STATUS="^(?:5|4(?!04))" \ MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_COOKIE_FORMAT=0 \ MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ @@ -107,7 +111,10 @@ ENV \ MODSEC_TAG=modsecurity \ MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UNICODE_MAPPING=20127 \ MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + MODSEC_UPLOAD_FILE_MODE=0600 \ + MODSEC_UPLOAD_KEEP_FILES=RelevantOnly \ MUTEX='default' \ PORT=8080 \ PROXY_ERROR_OVERRIDE=on \ @@ -145,7 +152,6 @@ ENV \ BLOCKING_PARANOIA=1 COPY --from=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so -COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC2_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC2_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping COPY --from=crs_release /opt/owasp-crs /opt/owasp-crs COPY src/etc/modsecurity.d/*.conf /etc/modsecurity.d/ diff --git a/apache/Dockerfile-alpine b/apache/Dockerfile-alpine index 736538c..469c039 100644 --- a/apache/Dockerfile-alpine +++ b/apache/Dockerfile-alpine @@ -88,11 +88,15 @@ ENV \ METRICS_ALLOW_FROM='127.0.0.0/255.0.0.0 ::1/128' \ METRICS_DENY_FROM='All' \ METRICSLOG='/dev/null' \ + MODSEC_ARGUMENT_SEPARATOR="&" \ + MODSEC_ARGUMENTS_LIMIT=1000 \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG=/dev/stdout \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_LOG_RELEVANT_STATUS="^(?:5|4(?!04))" \ MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_COOKIE_FORMAT=0 \ MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ @@ -117,7 +121,10 @@ ENV \ MODSEC_TAG=modsecurity \ MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UNICODE_MAPPING=20127 \ MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + MODSEC_UPLOAD_FILE_MODE=0600 \ + MODSEC_UPLOAD_KEEP_FILES=RelevantOnly \ MUTEX='default' \ PORT=8080 \ PROXY_ERROR_OVERRIDE=on \ @@ -155,7 +162,6 @@ ENV \ BLOCKING_PARANOIA=1 COPY --from=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so -COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC2_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC2_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping COPY --from=crs_release /opt/owasp-crs /opt/owasp-crs COPY src/etc/modsecurity.d/*.conf /etc/modsecurity.d/ diff --git a/nginx/Dockerfile b/nginx/Dockerfile index aa19535..cc80131 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -65,8 +65,6 @@ RUN set -eux; \ strip objs/ngx_http_modsecurity_module.so; \ cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/; \ mkdir /etc/modsecurity.d; \ - curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended \ - -o /etc/modsecurity.d/modsecurity.conf; \ curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ -o /etc/modsecurity.d/unicode.mapping @@ -124,11 +122,15 @@ ENV \ METRICS_ALLOW_FROM='127.0.0.0/24' \ METRICS_DENY_FROM='all' \ METRICSLOG=/dev/null \ + MODSEC_ARGUMENT_SEPARATOR="&" \ + MODSEC_ARGUMENTS_LIMIT=1000 \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG=/dev/stdout \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_LOG_RELEVANT_STATUS="^(?:5|4(?!04))" \ MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_COOKIE_FORMAT=0 \ MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ @@ -151,7 +153,10 @@ ENV \ MODSEC_TAG=modsecurity \ MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UNICODE_MAPPING=20127 \ MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + MODSEC_UPLOAD_FILE_MODE=0600 \ + MODSEC_UPLOAD_KEEP_FILES=RelevantOnly \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ PORT=8080 \ @@ -191,8 +196,8 @@ COPY --from=build /etc/nginx/modules/ngx_http_modsecurity_module.so /etc/nginx/m COPY --from=build /usr/local/lib/liblmdb.so /usr/local/lib/ COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ COPY --from=build /etc/modsecurity.d/unicode.mapping /etc/modsecurity.d/unicode.mapping -COPY --from=build /etc/modsecurity.d/modsecurity.conf /etc/modsecurity.d/modsecurity.conf COPY --from=crs_release /opt/owasp-crs /opt/owasp-crs +COPY src/etc/modsecurity.d/modsecurity.conf /etc/nginx/templates/modsecurity.d/modsecurity.conf.template COPY src/etc/modsecurity.d/modsecurity-override.conf /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template COPY src/etc/modsecurity.d/setup.conf /etc/nginx/templates/modsecurity.d/setup.conf.template COPY nginx/docker-entrypoint.d/*.sh /docker-entrypoint.d/ diff --git a/nginx/Dockerfile-alpine b/nginx/Dockerfile-alpine index 404ef12..83749f0 100644 --- a/nginx/Dockerfile-alpine +++ b/nginx/Dockerfile-alpine @@ -55,17 +55,14 @@ RUN set -eux; \ # We use master RUN set -eux; \ git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ - wget --quiet http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz; \ - tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ + curl -sSL http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar -xzf -; \ cd ./nginx-${NGINX_VERSION}; \ ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx; \ make modules; \ cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/; \ mkdir /etc/modsecurity.d; \ - wget --quiet https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended \ - -O /etc/modsecurity.d/modsecurity.conf; \ - wget --quiet https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ - -O /etc/modsecurity.d/unicode.mapping + curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ + -o /etc/modsecurity.d/unicode.mapping # Generate/Download Diffie-Hellman parameter files RUN set -eux; \ @@ -119,11 +116,15 @@ ENV \ METRICS_ALLOW_FROM='127.0.0.0/24' \ METRICS_DENY_FROM='all' \ METRICSLOG=/dev/null \ + MODSEC_ARGUMENT_SEPARATOR="&" \ + MODSEC_ARGUMENTS_LIMIT=1000 \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG=/dev/stdout \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_LOG_RELEVANT_STATUS="^(?:5|4(?!04))" \ MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_COOKIE_FORMAT=0 \ MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ @@ -146,7 +147,10 @@ ENV \ MODSEC_TAG=modsecurity \ MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UNICODE_MAPPING=20127 \ MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + MODSEC_UPLOAD_FILE_MODE=0600 \ + MODSEC_UPLOAD_KEEP_FILES=RelevantOnly \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ PORT=8080 \ @@ -185,8 +189,8 @@ COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION COPY --from=build /etc/nginx/modules/ngx_http_modsecurity_module.so /etc/nginx/modules/ngx_http_modsecurity_module.so COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ COPY --from=build /etc/modsecurity.d/unicode.mapping /etc/modsecurity.d/unicode.mapping -COPY --from=build /etc/modsecurity.d/modsecurity.conf /etc/modsecurity.d/modsecurity.conf COPY --from=crs_release /opt/owasp-crs /opt/owasp-crs +COPY src/etc/modsecurity.d/modsecurity.conf /etc/nginx/templates/modsecurity.d/modsecurity.conf.template COPY src/etc/modsecurity.d/modsecurity-override.conf /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template COPY src/etc/modsecurity.d/setup.conf /etc/nginx/templates/modsecurity.d/setup.conf.template COPY nginx/docker-entrypoint.d/*.sh /docker-entrypoint.d/ diff --git a/openresty/Dockerfile-alpine b/openresty/Dockerfile-alpine index b456731..e7e969b 100644 --- a/openresty/Dockerfile-alpine +++ b/openresty/Dockerfile-alpine @@ -62,8 +62,7 @@ RUN set -eux; \ # Specify the LUAJIT_LIB and LUAJIT_INC that are already installed in the base image. RUN set -eux; \ git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ - wget --quiet https://openresty.org/download/openresty-"${OPENRESTY_VERSION}".tar.gz; \ - tar -xzf openresty-"${OPENRESTY_VERSION}".tar.gz; \ + curl -sSL https://openresty.org/download/openresty-"${OPENRESTY_VERSION}".tar.gz | tar -xzf -; \ cd ./openresty-"${OPENRESTY_VERSION}"/bundle/nginx-${NGINX_VERSION}; \ export LUAJIT_LIB="/usr/local/openresty/luajit/lib"; \ export LUAJIT_INC="/usr/local/openresty/luajit/include/luajit-2.1"; \ @@ -72,10 +71,8 @@ RUN set -eux; \ make modules; \ cp objs/ngx_http_modsecurity_module.so /usr/local/openresty/nginx/modules/; \ mkdir /etc/modsecurity.d; \ - wget --quiet https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended \ - -O /etc/modsecurity.d/modsecurity.conf; \ - wget --quiet https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ - -O /etc/modsecurity.d/unicode.mapping + curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ + -o /etc/modsecurity.d/unicode.mapping # Generate self-signed certificates (if needed) @@ -129,11 +126,15 @@ ENV \ METRICS_ALLOW_FROM='127.0.0.0/24' \ METRICS_DENY_FROM='all' \ METRICSLOG=/dev/null \ + MODSEC_ARGUMENT_SEPARATOR="&" \ + MODSEC_ARGUMENTS_LIMIT=1000 \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG=/dev/stdout \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_LOG_RELEVANT_STATUS="^(?:5|4(?!04))" \ MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_COOKIE_FORMAT=0 \ MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ @@ -156,7 +157,10 @@ ENV \ MODSEC_TAG=modsecurity \ MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UNICODE_MAPPING=20127 \ MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + MODSEC_UPLOAD_FILE_MODE=0600 \ + MODSEC_UPLOAD_KEEP_FILES=RelevantOnly \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/usr/local/openresty/nginx/conf \ PORT=80 \ @@ -197,7 +201,6 @@ COPY --from=build /usr/share/TLS/server.key /usr/local/openresty/nginx/conf/serv COPY --from=build /usr/share/TLS/server.crt /usr/local/openresty/nginx/conf/server.crt COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ COPY --from=build /etc/modsecurity.d/unicode.mapping /etc/modsecurity.d/unicode.mapping -COPY --from=build /etc/modsecurity.d/modsecurity.conf /etc/modsecurity.d/modsecurity.conf COPY --from=crs_release /opt/owasp-crs /opt/owasp-crs # We use the templating mechanism from the nginx image here. # Everything from templates except the nginx configuration, is the same for Openresty. @@ -205,6 +208,7 @@ COPY nginx/templates/conf.d /usr/local/openresty/nginx/templates/conf.d COPY nginx/templates/includes /usr/local/openresty/nginx/templates/includes COPY nginx/templates/modsecurity.d /usr/local/openresty/nginx/templates/modsecurity.d # Copy the nginx configuration separately +COPY src/etc/modsecurity.d/modsecurity.conf /usr/local/openresty/nginx/templates/modsecurity.d/modsecurity.conf.template COPY src/etc/modsecurity.d/modsecurity-override.conf /usr/local/openresty/nginx/templates/modsecurity.d/modsecurity-override.conf.template COPY src/etc/modsecurity.d/setup.conf /usr/local/openresty/nginx/templates/modsecurity.d/setup.conf.template COPY src/bin/healthcheck /usr/local/bin/healthcheck diff --git a/src/etc/modsecurity.d/modsecurity-override.conf b/src/etc/modsecurity.d/modsecurity-override.conf index 461c667..ffdff97 100644 --- a/src/etc/modsecurity.d/modsecurity-override.conf +++ b/src/etc/modsecurity.d/modsecurity-override.conf @@ -1,34 +1 @@ -# Original of the latest recommended version: -# https://github.com/owasp-modsecurity/ModSecurity/blob/v3/master/modsecurity.conf-recommended - -SecArgumentSeparator & -SecAuditEngine ${MODSEC_AUDIT_ENGINE} -SecAuditLog ${MODSEC_AUDIT_LOG} -SecAuditLogFormat ${MODSEC_AUDIT_LOG_FORMAT} -SecAuditLogParts ${MODSEC_AUDIT_LOG_PARTS} -SecAuditLogRelevantStatus "^(?:5|4(?!04))" -SecAuditLogStorageDir ${MODSEC_AUDIT_STORAGE} -SecAuditLogType ${MODSEC_AUDIT_LOG_TYPE} -SecCookieFormat 0 -SecDataDir ${MODSEC_DATA_DIR} -SecDebugLog ${MODSEC_DEBUG_LOG} -SecDebugLogLevel ${MODSEC_DEBUG_LOGLEVEL} -SecDisableBackendCompression ${MODSEC_DISABLE_BACKEND_COMPRESSION} -SecPcreMatchLimit ${MODSEC_PCRE_MATCH_LIMIT} -SecPcreMatchLimitRecursion ${MODSEC_PCRE_MATCH_LIMIT_RECURSION} -SecRequestBodyAccess ${MODSEC_REQ_BODY_ACCESS} -SecRequestBodyLimit ${MODSEC_REQ_BODY_LIMIT} -SecRequestBodyJsonDepthLimit ${MODSEC_REQ_BODY_JSON_DEPTH_LIMIT} -SecRequestBodyLimitAction ${MODSEC_REQ_BODY_LIMIT_ACTION} -SecRequestBodyNoFilesLimit ${MODSEC_REQ_BODY_NOFILES_LIMIT} -SecResponseBodyAccess ${MODSEC_RESP_BODY_ACCESS} -SecResponseBodyLimit ${MODSEC_RESP_BODY_LIMIT} -SecResponseBodyLimitAction ${MODSEC_RESP_BODY_LIMIT_ACTION} -SecResponseBodyMimeType ${MODSEC_RESP_BODY_MIMETYPE} -SecRuleEngine ${MODSEC_RULE_ENGINE} -SecStatusEngine ${MODSEC_STATUS_ENGINE} -SecTmpDir ${MODSEC_TMP_DIR} -SecTmpSaveUploadedFiles ${MODSEC_TMP_SAVE_UPLOADED_FILES} -SecUnicodeMapFile unicode.mapping 20127 -SecUploadDir ${MODSEC_UPLOAD_DIR} -SecUploadFileMode 0644 +# Use this file if you need to override specific parts that are not in environment variables diff --git a/src/etc/modsecurity.d/modsecurity.conf b/src/etc/modsecurity.d/modsecurity.conf new file mode 100644 index 0000000..42de40c --- /dev/null +++ b/src/etc/modsecurity.d/modsecurity.conf @@ -0,0 +1,65 @@ +# Original of the latest recommended version: +# https://github.com/owasp-modsecurity/ModSecurity/blob/v3/master/modsecurity.conf-recommended + +SecArgumentSeparator ${MODSEC_ARGUMENT_SEPARATOR} +SecArgumentsLimit ${MODSEC_ARGUMENTS_LIMIT} +SecAuditEngine ${MODSEC_AUDIT_ENGINE} +SecAuditLog ${MODSEC_AUDIT_LOG} +SecAuditLogFormat ${MODSEC_AUDIT_LOG_FORMAT} +SecAuditLogParts ${MODSEC_AUDIT_LOG_PARTS} +SecAuditLogRelevantStatus "${MODSEC_AUDIT_LOG_RELEVANT_STATUS}" +SecAuditLogStorageDir ${MODSEC_AUDIT_STORAGE_DIR} +SecAuditLogType ${MODSEC_AUDIT_LOG_TYPE} +SecCookieFormat ${MODSEC_COOKIE_FORMAT} +SecDataDir ${MODSEC_DATA_DIR} +SecDebugLog ${MODSEC_DEBUG_LOG} +SecDebugLogLevel ${MODSEC_DEBUG_LOGLEVEL} +SecDisableBackendCompression ${MODSEC_DISABLE_BACKEND_COMPRESSION} +SecPcreMatchLimit ${MODSEC_PCRE_MATCH_LIMIT} +SecPcreMatchLimitRecursion ${MODSEC_PCRE_MATCH_LIMIT_RECURSION} +SecRequestBodyAccess ${MODSEC_REQ_BODY_ACCESS} +SecRequestBodyJsonDepthLimit ${MODSEC_REQ_BODY_JSON_DEPTH_LIMIT} +SecRequestBodyLimit ${MODSEC_REQ_BODY_LIMIT} +SecRequestBodyLimitAction ${MODSEC_REQ_BODY_LIMIT_ACTION} +SecRequestBodyNoFilesLimit ${MODSEC_REQ_BODY_NOFILES_LIMIT} +SecResponseBodyAccess ${MODSEC_RESP_BODY_ACCESS} +SecResponseBodyLimit ${MODSEC_RESP_BODY_LIMIT} +SecResponseBodyLimitAction ${MODSEC_RESP_BODY_LIMIT_ACTION} +SecResponseBodyMimeType ${MODSEC_RESP_BODY_MIMETYPE} +SecRuleEngine ${MODSEC_RULE_ENGINE} +SecStatusEngine ${MODSEC_STATUS_ENGINE} +SecTmpDir ${MODSEC_TMP_DIR} +SecTmpSaveUploadedFiles ${MODSEC_TMP_SAVE_UPLOADED_FILES} +SecUnicodeMapFile unicode.mapping ${MODSEC_UNICODE_MAPPING} +SecUploadDir ${MODSEC_UPLOAD_DIR} +SecUploadFileMode ${MODSEC_UPLOAD_FILE_MODE} +SecUploadKeepFiles ${MODSEC_UPLOAD_KEEP_FILES} + +# Base SecRule configs +SecRule &ARGS "@ge 1000" \ + "id:'200007', phase:2,t:none,log,deny,status:400,msg:'Failed to fully parse request body due to large argument count',severity:2" +SecRule MULTIPART_UNMATCHED_BOUNDARY "@eq 1" \ + "id:'200004',phase:2,t:none,log,deny,msg:'Multipart parser detected a possible unmatched boundary.'" +SecRule REQBODY_ERROR "!@eq 0" \ + "id:'200002', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2" +SecRule REQUEST_HEADERS:Content-Type "^(?:application(?:/soap\+|/)|text/)xml" \ + "id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML" +SecRule REQUEST_HEADERS:Content-Type "^application/[a-z0-9.-]+[+]json" \ + "id:'200006',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON" +SecRule TX:/^MSC_/ "!@streq 0" \ + "id:'200005',phase:2,t:none,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'" +SecRule MULTIPART_STRICT_ERROR "!@eq 0" \ + "id:'200003',phase:2,t:none,log,deny,status:400, \ + msg:'Multipart request body failed strict validation: \ + PE %{REQBODY_PROCESSOR_ERROR}, \ + BQ %{MULTIPART_BOUNDARY_QUOTED}, \ + BW %{MULTIPART_BOUNDARY_WHITESPACE}, \ + DB %{MULTIPART_DATA_BEFORE}, \ + DA %{MULTIPART_DATA_AFTER}, \ + HF %{MULTIPART_HEADER_FOLDING}, \ + LF %{MULTIPART_LF_LINE}, \ + SM %{MULTIPART_MISSING_SEMICOLON}, \ + IQ %{MULTIPART_INVALID_QUOTING}, \ + IP %{MULTIPART_INVALID_PART}, \ + IH %{MULTIPART_INVALID_HEADER_FOLDING}, \ + FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'" From b10b8db912894854ce2551862dba63f0b86b0446 Mon Sep 17 00:00:00 2001 From: Max Leske Date: Fri, 26 Apr 2024 08:56:56 +0200 Subject: [PATCH 11/14] feat: manage deps with renovate --- docker-bake.hcl | 17 ++++++--- renovate.json | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 renovate.json diff --git a/docker-bake.hcl b/docker-bake.hcl index 67a659a..7d04c20 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,25 +1,31 @@ # docker-bake.hcl variable "modsec3-version" { + # renovate: depName=ModSecurity3 packageName=owasp-modsecurity/ModSecurity datasource=github-releases default = "3.0.12" } variable "modsec2-version" { + # renovate: depName=ModSecurity2 packageName=owasp-modsecurity/ModSecurity datasource=github-releases default = "2.9.7" } variable "crs-version" { - default = "4.2.0" + # renovate: depName=coreruleset/coreruleset datasource=github-releases + default = "4.1.0" } variable "nginx-version" { + # renovate: depName=nginxinc/nginx-unprivileged datasource=docker default = "1.25.3" } variable "httpd-version" { + # renovate: depName=httpd datasource=docker default = "2.4.59" } variable "openresty-version" { + # renovate: depName=openresty/openresty datasource=docker default = "1.25.3.1" } @@ -27,6 +33,11 @@ variable "lua-version" { default = "5.3" } +variable "lmdb-version" { + default = "0.9.29" +} + + variable "lua-modules-alpine" { default = [ "lua-lzlib", @@ -49,10 +60,6 @@ variable "lua-modules-luarocks" { ] } -variable "lmdb-version" { - default = "0.9.29" -} - variable "REPOS" { # List of repositories to tag default = [ diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..7d28d1b --- /dev/null +++ b/renovate.json @@ -0,0 +1,99 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>coreruleset/renovate-config", + "schedule:weekly" + ], + "enabledManagers": [ + "custom.regex" + ], + "packageRules": [ + { + "groupName": "all non-major dependencies", + "groupSlug": "all-minor-patch", + "matchPackagePatterns": [ + "*" + ], + "matchUpdateTypes": [ + "minor", + "patch" + ], + "prBodyColumns": [ + "Package", + "Type", + "Update", + "Change", + "Pending" + ] + }, + { + "groupName": "all major dependencies", + "groupSlug": "all-major", + "matchPackagePatterns": [ + "*" + ], + "matchUpdateTypes": [ + "major" + ], + "prBodyColumns": [ + "Package", + "Type", + "Update", + "Change", + "Pending" + ] + }, + { + "matchDepNames": ["ModSecurity2"], + "allowedVersions": "/^v2.*/" + } + ], + "customManagers": [ + { + "description": "Bake file", + "customType": "regex", + "fileMatch": [ + "^docker-bake\\.hcl$" + ], + "matchStrings": [ + "depName=(?[^\\s]+)(?:\\s+packageName=(?[^\\s]+))?\\s+datasource=(?[^\\s]+)\\s+[^\"]+\"(?[^\"]+)\"" + ] + }, + { + "description": "Docs: nginx", + "customType": "regex", + "fileMatch": [ + "^README\\.md$" + ], + "matchStrings": [ + ".*on [Nn]ginx (?\\d+\\.\\d+\\.\\d+)" + ], + "depNameTemplate": "nginxinc/nginx-unprivileged", + "datasourceTemplate": "docker" + }, + { + "description": "Docs: httpd", + "customType": "regex", + "fileMatch": [ + "^README\\.md$" + ], + "matchStrings": [ + ".*on Apache (?\\d+\\.\\d+\\.\\d+)" + ], + "depNameTemplate": "httpd", + "datasourceTemplate": "docker" + }, + { + "description": "Docs: CRS", + "customType": "regex", + "fileMatch": [ + "^README\\.md$" + ], + "matchStrings": [ + "OWASP CRS (?\\d+\\.\\d+\\.\\d+)" + ], + "depNameTemplate": "coreruleset/coreruleset", + "datasourceTemplate": "github-releases" + } + ] +} From 7d4e9e555db8100b6696f39014fbd5eb69fd6ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Zipitr=C3=ADa?= <3012076+fzipi@users.noreply.github.com> Date: Sat, 27 Apr 2024 09:35:03 -0300 Subject: [PATCH 12/14] Apply suggestions from code review Co-authored-by: Max Leske --- .github/workflows/verifyimage.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index 477cdc9..deb1b3f 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -8,7 +8,8 @@ on: env: REPO: "owasp/modsecurity-crs" - MODSECURITY_RECOMMENDED: "d9e164c508218202eba13d37cf661baacb8600706e618ce93ccc91c74c51449e" + # sha256sum format: + MODSECURITY_RECOMMENDED: "d9e164c508218202eba13d37cf661baacb8600706e618ce93ccc91c74c51449e modsecurity.conf-recommended" jobs: prepare: @@ -24,7 +25,7 @@ jobs: - name: Check modsecurity recommended run: | curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended -o modsecurity.conf-recommended - sha256sum -c "${{ env.MODSECURITY_RECOMMENDED }} modsecurity.conf-recommended" modsecurity.conf-recommended + sha256sum -c "${{ env.MODSECURITY_RECOMMENDED }}" build: runs-on: ubuntu-latest From 8031ecfd8b90ecea27e7805560ed970295189dce Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Sat, 27 Apr 2024 09:38:19 -0300 Subject: [PATCH 13/14] fix: apply recommendations from code review Signed-off-by: Felipe Zipitria --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1d2bbb..28b8b4b 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ All these variables impact in configuration directives in the modsecurity engine | MODSEC_AUDIT_LOG_PARTS | A string that defines which parts of each transaction are going to be recorded in the audit log (Default: `'ABIJDEFHZ'`). See [SecAuditLogParts](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secauditlogparts) for the accepted values. | | MODSEC_AUDIT_LOG_RELEVANT_STATUS | A regular expression string that defines the http error codes that are relevant for audit logging (Default: `"^(?:5|4(?!04))"`). See [SecAuditLogRelevantStatus](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogrelevantstatus) | | MODSEC_AUDIT_LOG_TYPE | A string indicating the type of audit logging mechanism to be used (Default: `Serial`). Accepted values: `Serial`, `Concurrent` (`HTTPS` works only on Nginx - v3). See [SecAuditLogType](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogtype) for additional information. | -| MODSEC_COOKIE_FORMAT | The cookie format used (Default: `0`) :warning: Do not touch unless you really know what you are doing. | +| MODSEC_COOKIE_FORMAT | The cookie format used (Default: `0` use Netscape cookies) :warning: Do not touch unless you really know what you are doing. See [SecCookieFormat](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#seccookieformat). | | MODSEC_AUDIT_STORAGE | A string indicating the directory where concurrent audit log entries are to be stored (Default: `/var/log/modsecurity/audit/`) | | MODSEC_DATA_DIR | A string indicating the path where persistent data (e.g., IP address data, session data, and so on) is to be stored (Default: `/tmp/modsecurity/data`) | | MODSEC_DEBUG_LOG | A string indicating the path to the ModSecurity debug log file (Default: `/dev/null`) | From da186a9de71e3f9288e478aeda8b99624e1f5487 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 29 Apr 2024 10:44:56 -0300 Subject: [PATCH 14/14] fix: use intermediate file with sums Signed-off-by: Felipe Zipitria --- .github/workflows/verifyimage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index deb1b3f..c7b6bea 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -25,7 +25,8 @@ jobs: - name: Check modsecurity recommended run: | curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended -o modsecurity.conf-recommended - sha256sum -c "${{ env.MODSECURITY_RECOMMENDED }}" + echo '${{ env.MODSECURITY_RECOMMENDED }}' > sha256sum.txt + sha256sum -c sha256sum.txt build: runs-on: ubuntu-latest