diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index c64263eb..c7b6bea7 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -8,6 +8,8 @@ on: env: REPO: "owasp/modsecurity-crs" + # sha256sum format: + MODSECURITY_RECOMMENDED: "d9e164c508218202eba13d37cf661baacb8600706e618ce93ccc91c74c51449e modsecurity.conf-recommended" jobs: prepare: @@ -20,6 +22,11 @@ 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 + echo '${{ env.MODSECURITY_RECOMMENDED }}' > sha256sum.txt + sha256sum -c sha256sum.txt build: runs-on: ubuntu-latest diff --git a/README-containers.md b/README-containers.md index a92b1070..0ff2b199 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 diff --git a/README.md b/README.md index ab7f87dc..28b8b4bc 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` 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`) | @@ -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 6827d984..ef0d39fc 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 736538c6..469c0391 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/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 0fb665fe..01dc372c 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/sh -e /usr/local/bin/generate-certificate /usr/local/apache2 +/usr/local/bin/check-low-port . /opt/modsecurity/activate-plugins.sh . /opt/modsecurity/activate-rules.sh diff --git a/docker-bake.hcl b/docker-bake.hcl index 9bd2c2e9..7d04c205 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" { + # 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/docker-compose.yaml b/docker-compose.yaml index ae523057..e1bd73ee 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 diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 5745d98d..cc801318 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}; \ @@ -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 f30e249b..83749f07 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,18 +54,15 @@ RUN set -eux; \ # We use master RUN set -eux; \ - git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ - wget --quiet http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz; \ - tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ + git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ + 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/nginx/docker-entrypoint.d/01-check-low-port.sh b/nginx/docker-entrypoint.d/01-check-low-port.sh new file mode 100755 index 00000000..527e508f --- /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/openresty/Dockerfile-alpine b/openresty/Dockerfile-alpine index 3eb21402..e7e969b5 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,9 +61,8 @@ 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; \ - wget --quiet https://openresty.org/download/openresty-"${OPENRESTY_VERSION}".tar.gz; \ - tar -xzf openresty-"${OPENRESTY_VERSION}".tar.gz; \ + git clone -b master --depth 1 https://github.com/owasp-modsecurity/ModSecurity-nginx.git; \ + 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/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh b/openresty/docker-entrypoint.d/93-update-proxy-ssl-config.sh index 496d8fdc..0d2c29ad 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 diff --git a/openresty/templates/includes/location_common.conf.template b/openresty/templates/includes/location_common.conf.template new file mode 100644 index 00000000..db02c20a --- /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; +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..7d28d1b5 --- /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" + } + ] +} diff --git a/src/bin/check-low-port b/src/bin/check-low-port new file mode 100755 index 00000000..62eb3ba4 --- /dev/null +++ b/src/bin/check-low-port @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then + echo<