diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc89a508..e637f0e5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,8 +1,8 @@ name: Build and publish images for container registries + on: - push: - branches: - - master + release: + types: [published] jobs: prepare: diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index c64263eb..2abe4c04 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -3,11 +3,11 @@ name: Verify Images on: pull_request: branches: - - master - - develop - + - main env: REPO: "owasp/modsecurity-crs" + # sha256sum format: + MODSECURITY_RECOMMENDED: "d9e164c508218202eba13d37cf661baacb8600706e618ce93ccc91c74c51449e modsecurity.conf-recommended" jobs: prepare: @@ -20,6 +20,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 b7691984..0ff2b199 100644 --- a/README-containers.md +++ b/README-containers.md @@ -1,15 +1,12 @@ -# OWASP CRS Docker Image +# OWASP CRS Container Image [![dockeri.co](http://dockeri.co/image/owasp/modsecurity-crs)](https://hub.docker.com/r/owasp/modsecurity-crs/) -[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fcoreruleset%2Fmodsecurity-crs-docker%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/coreruleset/modsecurity-crs-docker/goto?ref=master -) [![GitHub issues](https://img.shields.io/github/issues-raw/coreruleset/modsecurity-crs-docker.svg)](https://github.com/coreruleset/modsecurity-crs-docker/issues -) [![GitHub PRs](https://img.shields.io/github/issues-pr-raw/coreruleset/modsecurity-crs-docker.svg)](https://github.com/coreruleset/modsecurity-crs-docker/pulls -) [![License](https://img.shields.io/github/license/coreruleset/modsecurity-crs-docker.svg)](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/LICENSE) +[![License](https://img.shields.io/github/license/coreruleset/modsecurity-crs-docker.svg)](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/LICENSE) -## Full documentation -⚠️ We are limited to 25000 chars in the Docker Hub documentation. The full documentation is hosted 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 @@ -40,180 +37,3 @@ Examples: * `nginx` * `apache-alpine` * `openresty-alpine-fat` - -## OS Variants - -* nginx – *latest stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable OWASP CRS 4.0.0* - * [nginx](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile) - * [nginx-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile-alpine) -* Openresty - *last stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable OWASP CRS 4.0.0* - * [openresty-alpine-fat](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/openresty/Dockerfile-alpine) -* Apache httpd – *last stable ModSecurity v2 on Apache 2.4.58 official stable base image, and latest stable OWASP CRS 4.0.0* - * [apache](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile) - * [apache-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile-alpine) - -### Notes regarding Openresty version of this image - -We currently only provide a version of the Openresty image based on **Alpine Linux**. The Dockerfile for Openresty resides in the [docker-openresty repository](https://github.com/openresty/docker-openresty/blob/master/alpine/Dockerfile.fat). - -## Supported architectures - -* linux/amd64 -* linux/arm/v7 -* linux/arm64/v8 -* linux/i386 - -### Notes regarding Openresty version of the image - -Openresty image builds currently support only these architectures: - -* linux/amd64 -* linux/arm64 - -### Common ENV Variables - -These variables are common to image variants and will set defaults based on the image name. -| Name | Description | httpd default | nginx / Openresty default (if different) | -| -- | -- | -- | -- | -| ACCESSLOG | Location of the custom log file | `/var/log/apache2/access.log` | `/var/log/nginx/access.log` | -| BACKEND | Partial URL for the remote server of the `ProxyPass` (httpd) and `proxy_pass` (nginx) directives | `http://localhost:80` | - | -| ERRORLOG | Location of the error log file | `/proc/self/fd/2` | - | -| LOGLEVEL | Minimum level for log messages to be logged to the error log | `warn` | - | -| METRICS_ALLOW_FROM | A single range of IP adresses that can access the metrics | `127.0.0.0/255.0.0.0 ::1/128` | `127.0.0.0/24` | -| METRICS_DENY_FROM | A range of IP adresses that cannot access the metrics | `All` | `all` | -| METRICSLOG | Location of metrics log file | `/dev/null` | - | -| PROXY_SSL_CERT | A string indicating the path to the PEM-encoded X.509 certificate data file or token identifier of the proxied server | `/usr/local/apache2/conf/proxy.crt` | `/etc/nginx/conf/proxy.crt` / `/usr/local/openresty/nginx/conf/proxy.crt` | -| PROXY_SSL_CERT_KEY | A string indicating the path to the PEM-encoded private key file of the proxied server | `/usr/local/apache2/conf/proxy.key` | `/etc/nginx/conf/proxy.key` / `/usr/local/openresty/nginx/conf/proxy.key` | -| PROXY_SSL_CIPHERS| A string indicating the cipher suite to connect to the backend via TLS | `"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"` | - | -| PROXY_SSL_PROTOCOLS | TLS protocols to enable for the connection to the backend | `"all -SSLv3 -TLSv1 -TLSv1.1"` | `TTLSv1.2 TLSv1.3` | -| PROXY_SSL | SSL Proxy Engine Operation Switch | `off` | - | -| PROXY_SSL_VERIFY | A string value indicating the type of proxy server Certificate verification | `none` | `off` | -| PROXY_TIMEOUT | Number of seconds for proxied requests to time out | `60` | `60s` | -| SERVER_NAME | The server name | `localhost` | - | -| SSL_CERT | A string indicating the path to the PEM-encoded X.509 certificate data file or token identifier of the proxied server | `/usr/local/apache2/conf/server.crt` | `/etc/nginx/conf/server.crt` / `/usr/local/openresty/nginx/conf/server.crt` | -| SSL_CERT_KEY | A string indicating the path to the PEM-encoded private key file of the proxied server | `/usr/local/apache2/conf/server.key` | `/etc/nginx/conf/server.key` / `/usr/local/openresty/nginx/conf/server.key` | -| SSL_CIPHERS| A string indicating the cipher suite for incoming TLS connections | `"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"` | - | -| SSL_OCSP_STAPLING | Enable / disable OCSP stapling | `On` | `on` | -| SSL_PROTOCOLS | TLS protocols to enable for the connection to the backend | `"all -SSLv3 -TLSv1 -TLSv1.1"` | `TTLSv1.2 TLSv1.3` | - -### Apache ENV Variables - -| Name | Description| -| -------- | ------------------------------------------------------------------- | -| APACHE_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | -| APACHE_ERRORLOG_FORMAT | A string value indicating the `ErrorLogFormat` that Apache should use. (Default: `'"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"'` | -| APACHE_LOGFORMAT | A string value indicating the LogFormat that apache should use. (Default: `'"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""'` (combined). Tip: use single quotes outside your double quoted format string.) ⚠️ Do not add a `|` as part of the log format. It is used internally. | -| APACHE_METRICS_LOGFORMAT | A string value indicating the LogFormat that the additional log apache metrics should use. (Default:'"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' (combined). Tip: use single quotes outside your double quoted format string.) ⚠️ Do not add a `|` as part of the log format. It is used internally. | -| BACKEND_WS | A string indicating the IP/URL of the WebSocket service (Default: `ws://localhost:8080`) | -| H2_PROTOCOLS | A string value indicating the protocols supported by the HTTP2 module (Default: `h2 http/1.1`) | -| MUTEX | Configure mutex and lock file directory for all specified mutexes (see [Mutex](https://httpd.apache.org/docs/2.4/mod/core.html#mutex)) (Default: `default`) | -| PORT | An int value indicating the port where the webserver is listening to | `80` | - | -| PROXY_ERROR_OVERRIDE | A string indicating that errors from the backend services should be overridden by this proxy server (see [ProxyErrorOverride](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyerroroverride) directive). (Allowed values: `on`, `off`. Default: `on`) | -| PROXY_PRESERVE_HOST | A string indicating the use of incoming Host HTTP request header for proxy request (Default: `on`) | -| PROXY_SSL_CA_CERT | A string indicating the path to the PEM-encoded list of accepted CA certificates for the proxied server (Default: `/etc/ssl/certs/ca-certificates.ca`) | -| PROXY_SSL_CHECK_PEER_NAME | A string indicating if the host name checking for remote server certificates is to be enabled (Default: `on`) | -| REMOTEIP_INT_PROXY | A string indicating the client intranet IP addresses trusted to present the RemoteIPHeader value (Default: `10.1.0.0/16`) | -| REQ_HEADER_FORWARDED_PROTO | A string indicating the transfer protocol of the initial request (Default: `https`) | -| SERVER_ADMIN | A string value indicating the address where problems with the server should be e-mailed (Default: `root@localhost`) | -| SERVER_SIGNATURE | A string value configuring the footer on server-generated documents (Allowed values: `On`, `Off`, `EMail`. Default: `Off`) | -| SERVER_TOKENS | Option defining the server information presented to clients in the `Server` HTTP response header. Also see `MODSEC_SERVER_SIGNATURE`. (Allowed values: `Full`, `Prod[uctOnly]`, `Major`, `Minor`, `Min[imal]`, `OS`. Default: `Full`). | -| SSL_ENGINE | A string indicating the SSL Engine Operation Switch (Default: `on`) | -| SSL_HONOR_CIPHER_ORDER | A string indicating if the server should [honor the cipher list provided by the client](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslhonorcipherorder) (Allowed values: `on`, `off`. Default: `off`) | -| SSL_PORT | Port number where the SSL enabled webserver is listening | `443` | - | -| SSL_SESSION_TICKETS | A string to enable or disable the use of [TLS session tickets](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslsessiontickets) (RFC 5077). (Default: `off`) | -| TIMEOUT | Number of seconds before receiving and sending timeout (Default: `60`) | -| WORKER_CONNECTIONS | Maximum number of MPM request worker processes (Default: `400`) | - -> [!NOTE] -> Apache access and metric logs can be disabled by exporting the `nologging=1` environment variable, or using `ACCESSLOG=/dev/null` and `METRICSLOG=/dev/null`. - -### Nginx ENV Variables - -| Name | Description| -| -------- | ------------------------------------------------------------------- | -| DNS_SERVER | A string indicating the name servers used to resolve names of upstream servers into addresses. For localhost backend this value should not be defined (Default: _not defined_) | -| KEEPALIVE_TIMEOUT | Number of seconds for a keep-alive client connection to stay open on the server side (Default: `60s`) | -| NGINX_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | -| PORT | An int value indicating the port where the webserver is listening to | `8080` | We run as unprivileged user. | -| PROXY_SSL_VERIFY_DEPTH | An integer value indicating the verification depth for the client certificate chain (Default: `1`) | -| REAL_IP_HEADER | Name of the header containing the real IP value(s) (Default: `X-REAL-IP`). See [real_ip_header](http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header) | -| REAL_IP_PROXY_HEADER | Name of the header containing `$remote_addr` to be passed to proxy (Default: `X-REAL-IP`). See [proxy_set_header](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header) | -| REAL_IP_RECURSIVE | A string value indicating whether to use recursive reaplacement on addresses in `REAL_IP_HEADER` (Allowed values: `on`, `off`. Default: `on`). See [real_ip_recursive](http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_recursive) | -| SERVER_TOKENS | A boolean value for enabling / disabling emission of server identifying information in the `Server` HTTP response header and on error pages. (Allowed values: `on`, `off`, `build`. Default: `off`). | -| SET_REAL_IP_FROM | A string of comma separated IP, CIDR, or UNIX domain socket addresses that are trusted to replace addresses in `REAL_IP_HEADER` (Default: `127.0.0.1`). See [set_real_ip_from](http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from) | -| SSL_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | -| SSL_PORT | Port number where the SSL enabled webserver is listening | `8443` | We run as unprivileged user. | -| SSL_PREFER_CIPHERS | A string value indicating if the server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols (Allowed values: `on`, `off`. Default: `off`)| -| SSL_VERIFY | A string value indicating if the client certificates should be verified (Allowed values: `on`, `off`. Default: `off`) | -| SSL_VERIFY_DEPTH | An integer value indicating the verification depth for the client certificate chain (Default: `1`) | -| WORKER_CONNECTIONS | Maximum number of simultaneous connections that can be opened by a worker process (Default: `1024`) | - -### Openresty ENV Variables - -Openresty uses the same environment variables as the nginx version. - -### ModSecurity ENV Variables - -All these variables impact in configuration directives in the modsecurity engine running inside the container. The [reference manual](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)) has the extended documentation, and for your reference we list the specific directive we change when you modify the ENV variables for the container. - -| Name | Description| -| -------- | ------------------------------------------------------------------- | -| 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_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_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`) | -| MODSEC_DEBUG_LOGLEVEL | An integer indicating the verboseness of the debug log data (Default: `0`). Accepted values: `0` - `9`. See [SecDebugLogLevel](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secdebugloglevel). | -| MODSEC_DEFAULT_PHASE1_ACTION | ModSecurity string with the contents for the default action in phase 1 (Default: `'phase:1,log,auditlog,pass,tag:\'\${MODSEC_TAG}\''`) | -| MODSEC_DEFAULT_PHASE2_ACTION | ModSecurity string with the contents for the default action in phase 2 (Default: `'phase:2,log,auditlog,pass,tag:\'\${MODSEC_TAG}\''`) | -| MODSEC_DISABLE_BACKEND_COMPRESSION | A string indicating whether or not to disable backend compression (Default: `On`). Allowed values: `On`, `Off`. See [SecDisableBackendCompression](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secdisablebackendcompression) for more. Only supported in ModSecurity 2.x, will have not effect on 3.x | -| MODSEC_PCRE_MATCH_LIMIT | An integer value indicating the limit for the number of internal executions in the PCRE function (Default: `100000`) (Only valid for Apache - v2). See [SecPcreMatchLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#SecPcreMatchLimit) | -| MODSEC_PCRE_MATCH_LIMIT_RECURSION | An integer value indicating the limit for the depth of recursion when calling PCRE function (Default: `100000`) | -| MODSEC_REQ_BODY_ACCESS | A string value allowing ModSecurity to access request bodies (Default: `On`). Allowed values: `On`, `Off`. See [SecRequestBodyAccess](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodyaccess) for more information. | -| MODSEC_REQ_BODY_JSON_DEPTH_LIMIT | An integer value indicating the maximun JSON request depth (Default: `512`). See [SecRequestBodyJsonDepthLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecRequestBodyJsonDepthLimit) for additional information. | -| MODSEC_REQ_BODY_LIMIT_ACTION | A string value for the action when `SecRequestBodyLimit` is reached (Default: `Reject`). Accepted values: `Reject`, `ProcessPartial`. See [SecRequestBodyLimitAction](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimitaction) for additional information. | -| MODSEC_REQ_BODY_LIMIT | An integer value indicating the maximum request body size accepted for buffering (Default: `13107200`). See [SecRequestBodyLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimit) for additional information. | -| MODSEC_REQ_BODY_NOFILES_LIMIT | An integer indicating the maximum request body size ModSecurity will accept for buffering (Default: `131072`). See [SecRequestBodyNoFilesLimit](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodynofileslimit) for more information. | -| MODSEC_RESP_BODY_ACCESS | A string value allowing ModSecurity to access response bodies (Default: `On`). Allowed values: `On`, `Off`. See [SecResponseBodyAccess](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secresponsebodyaccess) for more information. | -| MODSEC_RESP_BODY_LIMIT_ACTION | A string value for the action when `SecResponseBodyLimit` is reached (Default: `ProcessPartial`). Accepted values: `Reject`, `ProcessPartial`. See [SecResponseBodyLimitAction](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secresponsebodylimitaction) for additional information. | -| MODSEC_RESP_BODY_LIMIT | An integer value indicating the maximum response body size accepted for buffering (Default: `1048576`) | -| MODSEC_RESP_BODY_MIMETYPE | A string with the list of mime types that will be analyzed in the response (Default: `'text/plain text/html text/xml'`). You might consider adding `application/json` documented [here](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-\(v2.x\)#secresponsebodymimetype). | -| MODSEC_RULE_ENGINE | A string value enabling ModSecurity itself (Default: `On`). Accepted values: `On`, `Off`, `DetectionOnly`. See [SecRuleEngine](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secruleengine) for additional information. | -| MODSEC_SERVER_SIGNATURE | Sets the directive [SecServerSignature](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secserversignature) and instructs ModSecurity to change the data presented in the "Server:" response header token when Apache `ServerTokens` directive is set to `Full`. Also see Apache `SERVER_TOKENS`. Only supported in ModSecurity 2.x, will have not effect on 3.x. (Default: `Apache`). | -| MODSEC_STATUS_ENGINE | A string used to configure the status engine, which sends statistical information (Default: `Off`). Accepted values: `On`, `Off`. See [SecStatusEngine](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecStatusEngine) for additional information. | -| 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_UPLOAD_DIR | A string indicating the path where intercepted files will be stored (Default: `/tmp/modsecurity/upload`) | - -### CRS specific - -| Name | Description| -| -------- | ------------------------------------------------------------------- | -| ALLOWED_HTTP_VERSIONS | A string indicating the allowed_http_versions (Default: `HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/2.0`) | -| ALLOWED_METHODS | A string indicating the allowed_methods (Default: `GET HEAD POST OPTIONS`) | -| ALLOWED_REQUEST_CONTENT_TYPE | A string indicating the allowed_request_content_type (Default: `\|application/x-www-form-urlencoded\| \|multipart/form-data\| \|multipart/related\| \|text/xml\| \|application/xml\| \|application/soap+xml\| \|application/json\| \|application/cloudevents+json\| \|application/cloudevents-batch+json\|`) | -| ALLOWED_REQUEST_CONTENT_TYPE_CHARSET | A string indicating the allowed_request_content_type_charset (Default: `utf-8\|iso-8859-1\|iso-8859-15\|windows-1252`) | -| ANOMALY_INBOUND | An integer indicating the inbound_anomaly_score_threshold (Default: `5`) | -| ANOMALY_OUTBOUND | An integer indicating the outbound_anomaly_score_threshold (Default: `4`) | -| ARG_LENGTH | An integer indicating the arg_length (Default: `unlimited`) | -| ARG_NAME_LENGTH | An integer indicating the arg_name_length (Default: `unlimited`) | -| BLOCKING_PARANOIA | (:new: Replaces `PARANOIA` in CRSv4) An integer indicating the paranoia level (Default: `1`) | -| COMBINED_FILE_SIZES | An integer indicating the combined_file_sizes (Default: `unlimited`) | -| CRS_DISABLE_PLUGINS | A boolean indicating whether plugins will be **disabled** (Only from v4 and up. Default: `0`) | -| CRS_ENABLE_TEST_MARKER | A boolean indicating whether to write test markers to the log file (Used for running the CRS test suite. Default: `0`) | -| DETECTION_PARANOIA | (:new: Replaces `EXECUTING_PARANOIA` in CRSv4) An integer indicating the detection_paranoia_level (Default: `BLOCKING_PARANOIA`) | -| ENFORCE_BODYPROC_URLENCODED | A boolean indicating the enforce_bodyproc_urlencoded (Default: `0`) | -| EXECUTING_PARANOIA | An integer indicating the executing_paranoia_level (Default: `PARANOIA`) | -| MANUAL_MODE | A boolean indicating that you are providing your own `crs-setup.conf` file mounted as volume. (Default: `0`). ⚠️ None of the following variables are used if you set it to `1`. | -| MAX_FILE_SIZE | An integer indicating the max_file_size (Default: `unlimited`) | -| MAX_NUM_ARGS | An integer indicating the max_num_args (Default: `unlimited`) | -| PARANOIA | An integer indicating the paranoia level (Default: `1`) | -| RESTRICTED_EXTENSIONS | A string indicating the restricted_extensions (Default: `.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .rdb/ .resources/ .resx/ .sql/ .swp/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/`) | -| RESTRICTED_HEADERS | A string indicating the restricted_headers (Default: `/accept-charset/ /content-encoding/ /proxy/ /lock-token/ /content-range/ /if/`) | -| STATIC_EXTENSIONS | A string indicating the static_extensions (Default: `/.jpg/ /.jpeg/ /.png/ /.gif/ /.js/ /.css/ /.ico/ /.svg/ /.webp/`) | -| TOTAL_ARG_LENGTH | An integer indicating the total_arg_length (Default: `unlimited`) | -| VALIDATE_UTF8_ENCODING | A boolean indicating the crs_validate_utf8_encoding (Default: `0`) | diff --git a/README.md b/README.md index a7e1dbd4..3f18db36 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ Examples: ## OS Variants -* nginx – *latest stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable OWASP CRS 4.0.0* +* nginx – *latest stable ModSecurity v3 on Nginx 1.27.0 official stable base image, and latest stable OWASP CRS 4.4.0* * [nginx](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile) * [nginx-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile-alpine) -* Openresty - *last stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable OWASP CRS 4.0.0* +* Openresty - *last stable ModSecurity v3 on OpenResty 1.25.3.1 official stable base image, and latest stable OWASP CRS 4.4.0* * [openresty-alpine-fat](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/openresty/Dockerfile-alpine) -* Apache httpd – *last stable ModSecurity v2 on Apache 2.4.58 official stable base image, and latest stable OWASP CRS 4.0.0* +* Apache httpd – *last stable ModSecurity v2 on Apache 2.4.62 official stable base image, and latest stable OWASP CRS 4.4.0* * [apache](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile) * [apache-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile-alpine) @@ -117,7 +117,7 @@ You can achieve the same results just by getting any version you want, and using git clone https://github.com/coreruleset/coreruleset.git myrules cd myrules git checkout ac2a0d1 -docker run -p 80:80 -ti -e PARANOIA=4 -v rules:/opt/owasp-crs/rules:ro --rm owasp/modsecurity-crs +docker run -p 8080:8080 -ti -e PARANOIA=4 -v rules:/opt/owasp-crs/rules:ro --rm owasp/modsecurity-crs ``` ## Quick reference @@ -145,7 +145,7 @@ An example can be seen in the [docker-compose](https://github.com/coreruleset/mo > 💬 What happens if I want to make changes in a different file, like `/etc/nginx/conf.d/default.conf`? > You mount your local file, e.g. `nginx/default.conf` as the new template: `/etc/nginx/templates/conf.d/default.conf.template`. You can do this similarly with other files. Files in the templates directory will be copied and subdirectories will be preserved. -nginx is 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 nginx are `8080` and `8443`. +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`. ### Common ENV Variables @@ -181,10 +181,10 @@ These variables are common to image variants and will set defaults based on the | APACHE_ERRORLOG_FORMAT | A string value indicating the `ErrorLogFormat` that Apache should use. (Default: `'"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"'` | | APACHE_LOGFORMAT | A string value indicating the LogFormat that apache should use. (Default: `'"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""'` (combined). Tip: use single quotes outside your double quoted format string.) ⚠️ Do not add a `|` as part of the log format. It is used internally. | | APACHE_METRICS_LOGFORMAT | A string value indicating the LogFormat that the additional log apache metrics should use. (Default:'"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' (combined). Tip: use single quotes outside your double quoted format string.) ⚠️ Do not add a `|` as part of the log format. It is used internally. | -| BACKEND_WS | A string indicating the IP/URL of the WebSocket service (Default: `ws://localhost:8080`) | +| BACKEND_WS | A string indicating the IP/URL of the WebSocket service (Default: `ws://localhost:8081`) | | H2_PROTOCOLS | A string value indicating the protocols supported by the HTTP2 module (Default: `h2 http/1.1`) | | MUTEX | Configure mutex and lock file directory for all specified mutexes (see [Mutex](https://httpd.apache.org/docs/2.4/mod/core.html#mutex)) (Default: `default`) | -| PORT | An int value indicating the port where the webserver is listening to | `80` | - | +| PORT | An int value indicating the port where the webserver is listening to | `8080` | - | | PROXY_ERROR_OVERRIDE | A string indicating that errors from the backend services should be overridden by this proxy server (see [ProxyErrorOverride](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyerroroverride) directive). (Allowed values: `on`, `off`. Default: `on`) | | PROXY_PRESERVE_HOST | A string indicating the use of incoming Host HTTP request header for proxy request (Default: `on`) | | PROXY_SSL_CA_CERT | A string indicating the path to the PEM-encoded list of accepted CA certificates for the proxied server (Default: `/etc/ssl/certs/ca-certificates.ca`) | @@ -196,7 +196,7 @@ These variables are common to image variants and will set defaults based on the | SERVER_TOKENS | Option defining the server information presented to clients in the `Server` HTTP response header. Also see `MODSEC_SERVER_SIGNATURE`. (Allowed values: `Full`, `Prod[uctOnly]`, `Major`, `Minor`, `Min[imal]`, `OS`. Default: `Full`). | | SSL_ENGINE | A string indicating the SSL Engine Operation Switch (Default: `on`) | | SSL_HONOR_CIPHER_ORDER | A string indicating if the server should [honor the cipher list provided by the client](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslhonorcipherorder) (Allowed values: `on`, `off`. Default: `off`) | -| SSL_PORT | Port number where the SSL enabled webserver is listening | `443` | - | +| SSL_PORT | Port number where the SSL enabled webserver is listening | `8443` | - | | SSL_SESSION_TICKETS | A string to enable or disable the use of [TLS session tickets](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslsessiontickets) (RFC 5077). (Default: `off`) | | TIMEOUT | Number of seconds before receiving and sending timeout (Default: `60`) | | WORKER_CONNECTIONS | Maximum number of MPM request worker processes (Default: `400`) | @@ -235,12 +235,16 @@ 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_AUDIT_STORAGE | A string indicating the directory where concurrent audit log entries are to be stored (Default: `/var/log/modsecurity/audit/`) | +| 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_DIR | 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`) | | MODSEC_DEBUG_LOGLEVEL | An integer indicating the verboseness of the debug log data (Default: `0`). Accepted values: `0` - `9`. See [SecDebugLogLevel](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secdebugloglevel). | @@ -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` on Apache, `Off` on nginx) Accepted values: `On`, `Off`, `RelevantOnly` (only modsec2). See [SecUploadKeepFiles](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secuploadkeepfiles) and [libmodsecurity3](https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#secuploadkeepfiles) ### CRS specific @@ -290,7 +297,8 @@ All these variables impact in configuration directives in the modsecurity engine | MAX_NUM_ARGS | An integer indicating the max_num_args (Default: `unlimited`) | | PARANOIA | An integer indicating the paranoia level (Default: `1`) | | RESTRICTED_EXTENSIONS | A string indicating the restricted_extensions (Default: `.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .rdb/ .resources/ .resx/ .sql/ .swp/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/`) | -| RESTRICTED_HEADERS | A string indicating the restricted_headers (Default: `/accept-charset/ /content-encoding/ /proxy/ /lock-token/ /content-range/ /if/`) | +| RESTRICTED_HEADERS_BASIC | A string indicating the restricted_headers_basic (Default: `/content-encoding/ /proxy/ /lock-token/ /content-range/ /if/ /x-http-method-override/ /x-http-method/ /x-method-override/`) | +| RESTRICTED_HEADERS_EXTENDED | A string indicating the restricted_headers_extended (Default: `/accept-charset/`) | | STATIC_EXTENSIONS | A string indicating the static_extensions (Default: `/.jpg/ /.jpeg/ /.png/ /.gif/ /.js/ /.css/ /.ico/ /.svg/ /.webp/`) | | TOTAL_ARG_LENGTH | An integer indicating the total_arg_length (Default: `unlimited`) | | VALIDATE_UTF8_ENCODING | A boolean indicating the crs_validate_utf8_encoding (Default: `0`) | @@ -302,10 +310,10 @@ All these variables impact in configuration directives in the modsecurity engine > > ```bash > docker build -t my-modsec . -> docker run -p 8443:443 my-modsec +> docker run -p 8443:8443 my-modsec > ``` -TLS is configured on port `443` and enabled by default. +TLS is configured on port `8443` and enabled by default. We use sane intermediate defaults taken from the [Mozilla SSL config tool](https://ssl-config.mozilla.org/). Please review the defaults and choose the ones that best match your needs. @@ -327,11 +335,11 @@ ModSecurity is often used in a reverse proxy setup with the following porperties This allows one to use ModSecurity without modifying the webserver hosting the underlying application and also protects web servers that ModSecurity cannot currently be embedd into. Tips: -* the application web server (the one receiving traffic from the reverse proxy) should not listen on a public interface. Only the reverse proxy should be exposed to the public. With Docker, this could meain setting up a network for both containers and only exposing the reverse proxy with `-p 8080:80`, for example. `docker compose` takes care of this automatically. See the `docker-compose.yaml` for an example setup. +* the application web server (the one receiving traffic from the reverse proxy) should not listen on a public interface. Only the reverse proxy should be exposed to the public. With Docker, this could mean setting up a network for both containers and only exposing the reverse proxy with `-p 8080:8080`, for example. `docker compose` takes care of this automatically. See the `docker-compose.yaml` for an example setup. ```bash docker build -t my-modsec . -f -docker run -p 8080:80 -e BACKEND=http://example.com my-modsec +docker run -p 8080:8080 -e BACKEND=http://example.com my-modsec ``` ## ServerName @@ -340,7 +348,7 @@ It is often convenient to set your server name (set to `localhost` by defualt). ```bash docker build -t modsec . -docker run -p 8080:80 -e SERVER_NAME=myhost my-modsec +docker run -p 8080:8080 -e SERVER_NAME=myhost my-modsec ``` ## ModSecurity CRS Tuning @@ -354,7 +362,7 @@ There are two possible ways to pass ModSecurity CRS tuning rules to the containe ```bash docker run -dti --rm \ - -p 80:80 \ + -p 8080:8080 \ -v /path/to/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf:/etc/modsecurity.d/owasp-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf \ -v /path/to/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf:/etc/modsecurity.d/owasp-crs/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf \ owasp/modsecurity-crs:apache @@ -366,7 +374,7 @@ This example can be helpful when no volume mounts are possible (some CI pipeline ```bash docker create -ti --name modseccrs \ - -p 80:80 \ + -p 8080:8080 \ owasp/modsecurity-crs:apache docker cp /path/to/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf \ @@ -377,8 +385,26 @@ docker start modseccrs ## Full docker run example of possible setup +The following example illustrates how to use `docker run` with some of the variables. It's purpose is illustration only and it should not be used to run a container in production. + +Some important things to note: +- Error and audit logs are enabled and mapped to files on the host, so that their contents are accessible and don't pollute the container filesystem. Docker requires these files to exist, otherwise they would be created as directories, hence the use of the `touch ...` commands. +- For containers with read-only filesystems, the volumes might have to be specified differently, e.g., using `tmpfs`. Alternatively, if only one log output is required, the output could be redirected to `stdout` (`/proc/self/fd/2`). +- The example expects a backend web server to be running at `localhost:8081`. + ```bash -docker run -dti -p 80:80 --rm \ +touch /tmp/host-fs-auditlog.log +touch /tmp/host-fs-errorlog.log +docker run \ + -dti \ + -p 8080:8080 \ + --rm \ + -v /tmp/host-fs-auditlog.log:/var/log/modsec_audit.log \ + -v /tmp/host-fs-errorlog.log:/var/log/modsec_error.log \ + -e MODSEC_AUDIT_ENGINE=on \ + -e MODSEC_AUDIT_LOG=/var/log/modsec_audit.log + -e LOGLEVEL=warn \ + -e ERRORLOG=/var/log/modsec_error.log \ -e PARANOIA=1 \ -e EXECUTING_PARANOIA=2 \ -e ENFORCE_BODYPROC_URLENCODED=1 \ @@ -398,11 +424,9 @@ docker run -dti -p 80:80 --rm \ -e MAX_FILE_SIZE=100000 \ -e COMBINED_FILE_SIZES=1000000 \ -e TIMEOUT=60 \ - -e LOGLEVEL=warn \ - -e ERRORLOG='/proc/self/fd/2' \ -e SERVER_ADMIN=root@localhost \ -e SERVER_NAME=localhost \ - -e PORT=80 \ + -e PORT=8080 \ -e MODSEC_RULE_ENGINE=on \ -e MODSEC_REQ_BODY_ACCESS=on \ -e MODSEC_REQ_BODY_LIMIT=13107200 \ @@ -413,5 +437,6 @@ docker run -dti -p 80:80 --rm \ -e MODSEC_PCRE_MATCH_LIMIT_RECURSION=1000 \ -e VALIDATE_UTF8_ENCODING=1 \ -e CRS_ENABLE_TEST_MARKER=1 \ + -e BACKEND="http://localhost:8081" \ owasp/modsecurity-crs:apache ``` diff --git a/apache/Dockerfile b/apache/Dockerfile index 149f0765..bc73aac3 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,6 +1,6 @@ ARG HTTPD_VERSION="n/a" -FROM httpd:${HTTPD_VERSION} as build +FROM httpd:${HTTPD_VERSION} AS build ARG MODSEC2_VERSION="n/a" ARG LUA_VERSION="n/a" @@ -36,7 +36,7 @@ RUN set -eux; \ make install; \ make clean -FROM httpd:${HTTPD_VERSION} as crs_release +FROM httpd:${HTTPD_VERSION} AS crs_release ARG CRS_RELEASE @@ -70,20 +70,24 @@ ENV \ APACHE_ERRORLOG_FORMAT='"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"' \ APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ - BACKEND=http://localhost:80 \ - BACKEND_WS=ws://localhost:8080 \ + BACKEND=http://localhost:8080 \ + BACKEND_WS=ws://localhost:8081 \ ERRORLOG='/proc/self/fd/2' \ H2_PROTOCOLS='h2 http/1.1' \ LOGLEVEL=warn \ 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_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ + MODSEC_COOKIE_FORMAT=0 \ + MODSEC_AUDIT_STORAGE_DIR=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ MODSEC_DEBUG_LOGLEVEL=0 \ @@ -107,9 +111,12 @@ 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=80 \ + PORT=8080 \ PROXY_ERROR_OVERRIDE=on \ PROXY_PRESERVE_HOST=on \ PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ @@ -133,7 +140,7 @@ ENV \ SSL_ENGINE=on \ SSL_HONOR_CIPHER_ORDER=off \ SSL_OCSP_STAPLING=On \ - SSL_PORT=443 \ + SSL_PORT=8443 \ SSL_PROTOCOLS="all -SSLv3 -TLSv1 -TLSv1.1" \ SSL_SESSION_TICKETS=off \ TIMEOUT=60 \ @@ -144,9 +151,8 @@ ENV \ ANOMALY_OUTBOUND=4 \ 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=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so +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/ COPY src/bin/* /usr/local/bin/ @@ -174,12 +180,13 @@ RUN set -eux; \ apt-get clean; \ rm -rf /var/lib/apt/lists/* +RUN useradd --system httpd + RUN set -eux; \ mkdir -p /etc/modsecurity.d/; \ mkdir -p /tmp/modsecurity/data; \ mkdir -p /tmp/modsecurity/upload; \ mkdir -p /tmp/modsecurity/tmp; \ - chown -R $(awk '/^User/ { print $2;}' /usr/local/apache2/conf/httpd.conf) /tmp/modsecurity; \ mkdir -p /var/log/apache2/; \ ln -s /opt/owasp-crs /etc/modsecurity.d/; \ sed -i -E 's|(Listen) [0-9]+|\1 ${PORT}|' /usr/local/apache2/conf/httpd.conf; \ @@ -205,8 +212,14 @@ RUN set -eux; \ echo 'Include conf/extra/httpd-locations.conf' >> /usr/local/apache2/conf/httpd.conf; \ echo 'Include conf/extra/httpd-modsecurity.conf' >> /usr/local/apache2/conf/httpd.conf; \ sed -i -E 's|(MaxRequestWorkers[ ]*)[0-9]*|\1${WORKER_CONNECTIONS}|' /usr/local/apache2/conf/extra/httpd-mpm.conf; \ - chgrp -R 0 /var/log/ /usr/local/apache2/; \ - chmod -R g=u /var/log/ /usr/local/apache2/ + chown -R httpd:httpd \ + /var/log/ \ + /usr/local/apache2/ \ + /etc/modsecurity.d \ + /tmp/modsecurity \ + /opt/owasp-crs + +USER httpd ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/apache/Dockerfile-alpine b/apache/Dockerfile-alpine index 3888ce1c..b24d972b 100644 --- a/apache/Dockerfile-alpine +++ b/apache/Dockerfile-alpine @@ -1,6 +1,6 @@ ARG HTTPD_VERSION="n/a" -FROM httpd:${HTTPD_VERSION}-alpine as build +FROM httpd:${HTTPD_VERSION}-alpine AS build ARG MODSEC2_VERSION="n/a" ARG LUA_VERSION="n/a" @@ -46,7 +46,7 @@ RUN set -eux; \ make install; \ make clean -FROM httpd:${HTTPD_VERSION}-alpine as crs_release +FROM httpd:${HTTPD_VERSION}-alpine AS crs_release ARG CRS_RELEASE @@ -80,20 +80,24 @@ ENV \ APACHE_ERRORLOG_FORMAT='"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"' \ APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ - BACKEND=http://localhost:80 \ - BACKEND_WS=ws://localhost:8080 \ + BACKEND=http://localhost:8080 \ + BACKEND_WS=ws://localhost:8081 \ ERRORLOG='/proc/self/fd/2' \ H2_PROTOCOLS='h2 http/1.1' \ LOGLEVEL=warn \ 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_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ + MODSEC_COOKIE_FORMAT=0 \ + MODSEC_AUDIT_STORAGE_DIR=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ MODSEC_DEBUG_LOGLEVEL=0 \ @@ -117,9 +121,12 @@ 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=80 \ + PORT=8080 \ PROXY_ERROR_OVERRIDE=on \ PROXY_PRESERVE_HOST=on \ PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ @@ -143,7 +150,7 @@ ENV \ SSL_ENGINE=on \ SSL_HONOR_CIPHER_ORDER=off \ SSL_OCSP_STAPLING=On \ - SSL_PORT=443 \ + SSL_PORT=8443 \ SSL_PROTOCOLS="all -SSLv3 -TLSv1 -TLSv1.1" \ SSL_SESSION_TICKETS=off \ TIMEOUT=60 \ @@ -154,9 +161,8 @@ ENV \ ANOMALY_OUTBOUND=4 \ 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=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so +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/ COPY src/bin/* /usr/local/bin/ @@ -164,6 +170,8 @@ COPY src/opt/modsecurity/activate-*.sh /opt/modsecurity/ COPY apache/conf/extra/*.conf /usr/local/apache2/conf/extra/ COPY apache/docker-entrypoint.sh / +RUN addgroup -S httpd && adduser -SH httpd httpd + RUN set -eux; \ apk add --no-cache \ ca-certificates \ @@ -207,9 +215,14 @@ RUN set -eux; \ mkdir -p /tmp/modsecurity/data; \ mkdir -p /tmp/modsecurity/upload; \ mkdir -p /tmp/modsecurity/tmp; \ - chown -R $(awk '/^User/ { print $2;}' /usr/local/apache2/conf/httpd.conf) /tmp/modsecurity /var/log/apache2; \ - chgrp -R 0 /var/log/ /usr/local/apache2/; \ - chmod -R g=u /var/log/ /usr/local/apache2/ + chown -R httpd:httpd \ + /var/log/ \ + /usr/local/apache2/ \ + /etc/modsecurity.d \ + /tmp/modsecurity \ + /opt/owasp-crs + +USER httpd HEALTHCHECK CMD /usr/local/bin/healthcheck 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 e02792fb..17292247 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.0.0" + # renovate: depName=coreruleset/coreruleset datasource=github-releases + default = "4.4.0" } variable "nginx-version" { - default = "1.25.3" + # renovate: depName=nginxinc/nginx-unprivileged datasource=docker + default = "1.27.0" } variable "httpd-version" { - default = "2.4.58" + # renovate: depName=httpd datasource=docker + default = "2.4.62" } 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 = [ @@ -172,7 +179,7 @@ target "openresty-alpine-fat" { dockerfile="openresty/Dockerfile-alpine" args = { OPENRESTY_VERSION = "${openresty-version}" - NGINX_VERSION = "${nginx-version}" + NGINX_VERSION = patch(openresty-version) LUA_MODULES = join(" ", lua-modules-luarocks) } tags = concat(tag("openresty-alpine-fat"), diff --git a/docker-compose.yaml b/docker-compose.yaml index ae523057..26951aa8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -50,7 +50,8 @@ x-defaults: &default-settings # ALLOWED_REQUEST_CONTENT_TYPE_CHARSET: 'utf-8|iso-8859-1|iso-8859-15|windows-1252' # ALLOWED_HTTP_VERSIONS: HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/2.0 # RESTRICTED_EXTENSIONS: .asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .rdb/ .resources/ .resx/ .sql/ .swp/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/ - # RESTRICTED_HEADERS: /accept-charset/ /content-encoding/ /proxy/ /lock-token/ /content-range/ /if/ + # RESTRICTED_HEADERS_BASIC: /content-encoding/ /proxy/ /lock-token/ /content-range/ /if/ /x-http-method-override/ /x-http-method/ /x-method-override/ + # RESTRICTED_HEADERS_EXTENDED: /accept-charset/ # STATIC_EXTENSIONS: /.jpg/ /.jpeg/ /.png/ /.gif/ /.js/ /.css/ /.ico/ /.svg/ /.webp/ ####################################################### @@ -82,9 +83,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 +94,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 5480bf11..8d6e9e5c 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,6 +1,6 @@ ARG NGINX_VERSION="n/a" -FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} as build +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} AS build ARG MODSEC3_VERSION="n/a" ARG LMDB_VERSION="n/a" @@ -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 @@ -76,7 +74,7 @@ RUN set -eux; \ curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /usr/share/TLS/dhparam-2048.pem; \ curl -sSL https://ssl-config.mozilla.org/ffdhe4096.txt -o /usr/share/TLS/dhparam-4096.pem -FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} as crs_release +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} AS crs_release ARG CRS_RELEASE @@ -124,17 +122,22 @@ 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_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ + MODSEC_COOKIE_FORMAT=0 \ + MODSEC_AUDIT_STORAGE_DIR=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ MODSEC_DEBUG_LOGLEVEL=0 \ MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ + MODSEC_DISABLE_BACKEND_COMPRESSION="Off" \ MODSEC_PCRE_MATCH_LIMIT=100000 \ MODSEC_PCRE_MATCH_LIMIT_RECURSION=100000 \ MODSEC_REQ_BODY_ACCESS=on \ @@ -151,7 +154,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=Off \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ PORT=8080 \ @@ -191,8 +197,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 8f0a645b..b6549a82 100644 --- a/nginx/Dockerfile-alpine +++ b/nginx/Dockerfile-alpine @@ -1,6 +1,6 @@ ARG NGINX_VERSION="n/a" -FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine as build +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine AS build ARG MODSEC3_VERSION="n/a" ARG LUA_VERSION="n/a" @@ -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; \ @@ -73,7 +70,7 @@ RUN set -eux; \ curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /usr/share/TLS/dhparam-2048.pem; \ curl -sSL https://ssl-config.mozilla.org/ffdhe4096.txt -o /usr/share/TLS/dhparam-4096.pem -FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine as crs_release +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine AS crs_release ARG CRS_RELEASE @@ -119,17 +116,22 @@ 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_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ + MODSEC_COOKIE_FORMAT=0 \ + MODSEC_AUDIT_STORAGE_DIR=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ MODSEC_DEBUG_LOGLEVEL=0 \ MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ + MODSEC_DISABLE_BACKEND_COMPRESSION="Off" \ MODSEC_PCRE_MATCH_LIMIT=100000 \ MODSEC_PCRE_MATCH_LIMIT_RECURSION=100000 \ MODSEC_REQ_BODY_ACCESS=on \ @@ -146,7 +148,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=Off \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ PORT=8080 \ @@ -185,8 +190,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 6170b7e3..d56925e2 100644 --- a/openresty/Dockerfile-alpine +++ b/openresty/Dockerfile-alpine @@ -2,7 +2,7 @@ # Also specify the nginx core used. (Openresty, adds their own version numbers after the nginx one, so we can't use the same number for both Openresty and nginx) ARG OPENRESTY_VERSION="n/a" -FROM openresty/openresty:${OPENRESTY_VERSION}-alpine-fat as build +FROM openresty/openresty:${OPENRESTY_VERSION}-alpine-fat AS build ARG OPENRESTY_VERSION ARG MODSEC3_VERSION="n/a" @@ -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,10 +61,9 @@ 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; \ - cd ./openresty-"${OPENRESTY_VERSION}"/bundle/nginx-${NGINX_VERSION}; \ + 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"; \ COMPILEOPTIONS=$(openresty -V 2>&1| grep -i "arguments"|cut -d ":" -f2-); \ @@ -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) @@ -91,7 +88,7 @@ RUN /usr/local/openresty/openssl/bin/openssl dhparam -out /usr/share/TLS/dhparam RUN curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /usr/share/TLS/dhparam-2048.pem RUN curl -sSL https://ssl-config.mozilla.org/ffdhe4096.txt -o /usr/share/TLS/dhparam-4096.pem -FROM openresty/openresty:${OPENRESTY_VERSION}-alpine-fat as crs_release +FROM openresty/openresty:${OPENRESTY_VERSION}-alpine-fat AS crs_release ARG CRS_RELEASE @@ -129,17 +126,22 @@ 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_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ + MODSEC_COOKIE_FORMAT=0 \ + MODSEC_AUDIT_STORAGE_DIR=/var/log/modsecurity/audit/ \ MODSEC_DATA_DIR=/tmp/modsecurity/data \ MODSEC_DEBUG_LOG=/dev/null \ MODSEC_DEBUG_LOGLEVEL=0 \ MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ + MODSEC_DISABLE_BACKEND_COMPRESSION="Off" \ MODSEC_PCRE_MATCH_LIMIT=100000 \ MODSEC_PCRE_MATCH_LIMIT_RECURSION=100000 \ MODSEC_REQ_BODY_ACCESS=on \ @@ -156,7 +158,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=Off \ NGINX_ALWAYS_TLS_REDIRECT=off \ NGINX_ENVSUBST_OUTPUT_DIR=/usr/local/openresty/nginx/conf \ PORT=80 \ @@ -197,7 +202,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 +209,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..4cf0518e --- /dev/null +++ b/renovate.json @@ -0,0 +1,111 @@ +{ + "$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" + }, + { + "description": "Docs: OpenResty", + "customType": "regex", + "fileMatch": [ + "^README\\.md$" + ], + "matchStrings": [ + "OpenResty (?\\d+\\.\\d+\\.\\d+(\\.\\d+)?)" + ], + "depNameTemplate": "openresty/openresty", + "datasourceTemplate": "docker" + } + ] +} diff --git a/src/bin/check-low-port b/src/bin/check-low-port new file mode 100755 index 00000000..00ef61cd --- /dev/null +++ b/src/bin/check-low-port @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then + cat<&2 - exit 1 -fi - -# relases might be release candidates, which are named with '-rcX' -release="${target%-*}" -server="${target#*-}" -server_no_rc="${server#*-}" - -cd "$(dirname "$0")/.." -mkdir -p "${target}" - - -sed -e "s,%%RELEASE%%,${release},g" \ - "${server_no_rc}/Dockerfile" > "${target}/Dockerfile" -