diff --git a/.github/workflows/buildimage.yml b/.github/workflows/buildimage.yml deleted file mode 100644 index 8c880c4e..00000000 --- a/.github/workflows/buildimage.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Build images for Docker Hub -on: - push: - branches: - - master - repository_dispatch: - types: [base-container-updated] - -env: - REPO: "owasp/modsecurity-crs" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - crs_version: ["3.3.5"] - image: [apache, nginx] - variant: ["", "-alpine"] - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - # https://github.com/docker/setup-qemu-action - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - driver-opts: image=moby/buildkit:master - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.dockerhub_user }} - password: ${{ secrets.dockerhub_token }} - - - name: Docker meta ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REPO }} - flavor: | - latest=false - tags: | - type=raw,value=${{ matrix.image }}${{ matrix.variant }} - type=semver,pattern={{major}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - type=semver,pattern={{version}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - - - name: Build and push ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} - uses: docker/bake-action@v2.3.0 - with: - targets: ${{ matrix.image }}${{ matrix.variant }} - files: | - ./docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} - push: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..2f1d0b4a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,54 @@ +name: Build and publish images for container registries +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + repo: ["owasp/modsecurity-crs", "ghcr.io/coreruleset/modsecurity-crs"] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + # https://github.com/docker/setup-qemu-action + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + with: + driver-opts: image=moby/buildkit:master + + - name: Login to DockerHub + if: ${{ startsWith(matrix.repo, 'owasp')}} + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + username: ${{ secrets.dockerhub_user }} + password: ${{ secrets.dockerhub_token }} + + - name: Login to GitHub Container Registry + if: ${{ startsWith(matrix.repo, 'ghcr.io')}} + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/bake-action@v4.1.0 + with: + files: | + ./docker-bake.hcl + push: true + env: + REPO: ${{ matrix.repo }} diff --git a/.github/workflows/verifyimage.yml b/.github/workflows/verifyimage.yml index deb56c3b..c64263eb 100644 --- a/.github/workflows/verifyimage.yml +++ b/.github/workflows/verifyimage.yml @@ -10,14 +10,24 @@ env: REPO: "owasp/modsecurity-crs" jobs: + prepare: + runs-on: ubuntu-latest + outputs: + targets: ${{ steps.generate.outputs.targets }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: List targets + id: generate + uses: docker/bake-action/subaction/list-targets@v4 + build: runs-on: ubuntu-latest + needs: + - prepare strategy: matrix: - crs_version: ["3.3.5"] - image: [apache, nginx] - variant: ["", "-alpine"] - platform: [linux/amd64] + target: ${{ fromJson(needs.prepare.outputs.targets) }} steps: - name: Checkout uses: actions/checkout@v4 @@ -26,47 +36,31 @@ jobs: # https://github.com/docker/setup-qemu-action - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 with: driver-opts: image=moby/buildkit:master - - name: Docker meta ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REPO }} - flavor: | - latest=false - tags: | - type=raw,value=${{ matrix.image }}${{ matrix.variant }} - type=semver,pattern={{major}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - type=semver,pattern={{version}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}} - - - name: Build ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} - uses: docker/bake-action@v2.3.0 + - name: Build images + uses: docker/bake-action@v4.1.0 with: - targets: ${{ matrix.image }}${{ matrix.variant }} files: | ./docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} + targets: ${{ matrix.target }} set: | - "${{ matrix.image }}${{ matrix.variant }}.platform=${{ matrix.platform }}" + *.platform=linux/amd64 load: true push: false - - name: Run ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} + - name: Run ${{ matrix.target }} run: | - TAG=$(docker image inspect -f '{{ json .RepoTags }}' ${{ env.REPO }}:${{ matrix.image }}${{ matrix.variant }} | jq -r '.[0]') - echo "Starting container with TAG=$TAG" - docker run --pull "never" -d --name ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test "$TAG" - docker logs ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test + echo "Starting container ${{ matrix.target }}" + docker run --pull "never" -d --name ${{ matrix.target }}-test "${REPO}:${{ matrix.target }}" + docker logs ${{ matrix.target }}-test - - name: Verify ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }} + - name: Verify ${{ matrix.target }} run: | - [ $(docker inspect ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test --format='{{.State.Running}}') = 'true' ] + [ $(docker inspect ${{ matrix.target }}-test --format='{{.State.Running}}') = 'true' ] diff --git a/README-containers.md b/README-containers.md index 9e1ee282..fc32a860 100644 --- a/README-containers.md +++ b/README-containers.md @@ -11,27 +11,50 @@ ⚠️ 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). -## What is the Core Rule Set +## Supported Tags -The Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity or compatible web application firewalls. +### Stable Tags -## Supported tags and respective `Dockerfile` links +Stable Tags are composed of: + * CRS version, in the fromat `[.[.-[-]-`. +Examples: + * `3-nginx-202401121309` + * `3.3-apache-alpine-202401121309` + * `3.3.5-openresty-alpine-fat-202401121309` -🆕 We added healthchecks to the images. Containers already return HTTP status code 200 when accessing the `/healthz` URI. When a container has a healthcheck specified, it has a _health status_ in addition to its normal status. This status is initially `starting`. Whenever a health check passes, it becomes `healthy` (whatever state it was previously in). After a certain number of consecutive failures, it becomes `unhealthy`. See for more information. +### Rolling Tags -## Supported variants +Rolling tags are updated whenever a new stable tag release occurs. Rolling tags can be practical but should not be used in production. -We also build [alpine linux](https://www.alpinelinux.org/) variants of the base images, using the `-alpine` suffix. Examples: +Rolling Tags are composed of: + * web server variant + * OS variant (optional) -* `3-nginx-alpine-YYYYMMDDHHMM`, `3.3-nginx-alpine-YYYYMMDDHHMM`, `3.3.5-nginx-alpine-YYYYMMDDHHMM`, `nginx-alpine` ([master/nginx/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile-alpine) – *last stable ModSecurity v3 on Nginx 1.25.3 official alpine stable base image, and latest stable Core Rule Set 3.3.5* -* `3-apache-alpine-YYYYMMDDHHMM`, `3.3-apache-alpine-YYYYMMDDHHMM`, `3.3.5-apache-alpine-YYYYMMDDHHMM`, `apache-alpine` ([master/apache/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile-alpine)) – *last stable ModSecurity v2 on Apache 2.4.58 official alpine stable base image, and latest stable Core Rule Set 3.3.5* +The stable tag format is `[-]`. +Examples: + * `nginx` + * `apache-alpine` + * `openresty-alpine-fat` -## Production usage +## OS Variants -⚠️ We changed tags to [support production usage](https://github.com/coreruleset/modsecurity-crs-docker/issues/67). Now, if you want to use the "rolling version", use tags `owasp/modsecurity-crs:nginx` or `owasp/modsecurity-crs:apache`, or if you want the alpine variant use `owasp/modsecurity-crs:nginx-alpine` or `owasp/modsecurity-crs:apache-alpine`. If you need a stable long term image, use the one with the full CRS version, the variant used (if any), and the build date in `YYYYMMDDHHMM` format, example `owasp/modsecurity-crs:3.3.5-nginx-202209141209` or `owasp/modsecurity-crs:3.3.5-apache-alpine-202209141209` for example. You have been warned. +* nginx – *latest stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable Core Rule Set 3.3.5* + * [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 Core Rule Set 3.3.5* + * [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 Core Rule Set 3.3.5* + * [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 @@ -40,169 +63,155 @@ We also build [alpine linux](https://www.alpinelinux.org/) variants of the base * linux/arm64/v8 * linux/i386 -## Quick reference - -* **Where to get help**: the [Core Rule Set Slack Channel](https://owasp.org/slack/invite) (#coreruleset on owasp.slack.com), or [Stack Overflow](https://stackoverflow.com/questions/tagged/mod-security) - -* **Where to file issues**: the [Core Rule Set Docker Repo](https://github.com/coreruleset/modsecurity-crs-docker) - -* **Maintained By**: The Core Rule Set Project maintainers - -## What is ModSecurity - -See [ModSecurity](https://modsecurity.org). - -### Nginx based images breaking change - -| ⚠️ WARNING | -|:--| -| Nginx based images are now based on upstream nginx. This changed the way the config file for nginx is generated. | +### Notes regarding Openresty version of the image -If using the [Nginx environment variables](#nginx-env-variables) is not enough for your use case, you can mount your own `nginx.conf` file as the new template for generating the base config. +Openresty image builds currently support only these architectures: -An example can be seen in the [docker-compose](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/docker-compose.yml) file. - -> 💬 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. +* 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| -| -- | -- | -| ACCESSLOG | Location of the custom log file (Default: `/var/log/apache2/access.log` and `/var/log/nginx/access.log`) | -| BACKEND | Partial URL for the remote server of the `ProxyPass` and `proxy_pass` directive (Default: `http://localhost:80`) | -| ERRORLOG | Location of the error log file (Default: `/proc/self/fd/2`) | -| LOGLEVEL | Number of messages logged to the error_log (Default: `warn`) | -| METRICS_ALLOW_FROM | a single range of IP adresses that can access the metrics (Default: `127.0.0.0/24` and `127.0.0.0/255.0.0.0 ::1/128`) | -| METRICS_DENY_FROM | a range of IP adresses that cannot access the metrics (Default: `all` and `All`) | -| PORT | An int value indicating the port where the webserver is listening to (Default: `80`) | -| PROXY_SSL_CERT | Path to the server PEM-encoded X.509 certificate data file or token identifier (Default: `/usr/local/apache2/conf/server.crt` and `/etc/nginx/conf/server.crt`) | -| PROXY_SSL_CERT_KEY | Path to the server PEM-encoded private key file (Default: `/etc/nginx/conf/server.key` and `/usr/local/apache2/conf/server.key`) | -| PROXY_SSL_VERIFY | Type of remote server Certificate verification (Default: `none` and `off`) | -| SSL_PORT | Port number where the SSL enabled webserver is listening (Default: `443`) | -| TIMEOUT | Number of seconds before receiving and sending timeout (Default: `60`) | +| 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` | - | +| PORT | An int value indicating the port where the webserver is listening to | `80` | - | +| PROXY_SSL | SSL Proxy Engine Operation Switch | `off` | - | +| 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` | +| 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` | +| 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_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` | +| 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` | +| 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_PORT | Port number where the SSL enabled webserver is listening | `443` | - | +| 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 | if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | -| APACHE_LOGFORMAT | 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 | 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 | The IP/URL of the WebSocket service (Default: `ws://localhost:8080`) | -| H2_PROTOCOLS | Protocols supported by the HTTP2 module (Default: `h2 http/1.1`) | -| METRICSLOG | Path of the metrics log (Default: `/dev/null`) | +| Name | Description| +| -------- | ------------------------------------------------------------------- | +| APACHE_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | +| 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_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_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`) | -| PROXY_ERROR_OVERRIDE | 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 | Use of incoming Host HTTP request header for proxy request (Default: `on`) | -| PROXY_SSL_CHECK_PEER_NAME | if the host name checking for remote server certificates is to be enabled (Default: `on`) | -| PROXY_SSL | A string with SSL Proxy Engine Operation Switch (Default: `off`) | -| PROXY_TIMEOUT | Number of seconds for proxied requests to time out (Default: `60`) | -| REMOTEIP_INT_PROXY | Client intranet IP addresses trusted to present the RemoteIPHeader value (Default: `10.1.0.0/16`) | -| REQ_HEADER_FORWARDED_PROTO | Transfer protocol of the initial request (Default: `https`) | -| SERVER_ADMIN | Address where problems with the server should be e-mailed (Default: `root@localhost`) | -| SERVER_NAME | Server name (Default: `localhost`) | -| SSL_CIPHER_SUITE | Cipher suite to use. Uses OpenSSL [list of cipher suites](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_ciphersuites.html) (Default: `"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_ENGINE | The SSL Engine Operation Switch (Default: `on`) | -| SSL_HONOR_CIPHER_ORDER | 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_PROTOCOL | A string for configuring the [usable SSL/TLS protocol versions](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslprotocol) (Default: `"all -SSLv3 -TLSv1 -TLSv1.1"`) | -| SSL_PROXY_PROTOCOL | A string for configuring the [proxy client SSL/TLS protocol versions](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslproxyprotocol) (Default: `"all -SSLv3 -TLSv1 -TLSv1.1"`) | -| SSL_PROXY_CIPHER_SUITE | Cipher suite to connect to the backend via TLS. (Default `"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_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_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`) | -| SSL_USE_STAPLING | if [OSCP Stapling](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslusestapling) should be used (Allowed values: `on`, `off`. Default: `on`) | -| WORKER_CONNECTIONS | Maximum number of MPM request worker processes (Default: `400`) | +| 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`. +> [!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 | Name servers used to resolve names of upstream servers into addresses. For localhost backend this value should not be defined (Default: _not defined_) | -| METRICSLOG | Location of metrics log file (Default: `/dev/null`) | -| NGINX_ALWAYS_TLS_REDIRECT | if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | +| 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`) | | 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) | | 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 | 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) | -| PROXY_SSL_CIPHERS | A String value indicating the enabled ciphers. The ciphers are specified in the format understood by the OpenSSL library. (Default: `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_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | -| PROXY_SSL_OCSP_STAPLING | if ssl_stapling and ssl_stapling_verify should be enabled (Allowed values: `on`, `off`. Default: `off`) | -| PROXY_SSL_PREFER_CIPHERS | if the server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols (Allowed values: `on`, `off`. Default: `off`)| -| PROXY_SSL_PROTOCOLS | Ssl protocols to enable (default: `TTLSv1.2 TLSv1.3`)| -| PROXY_TIMEOUT | Number of seconds for proxied requests to time out connections (Default: `60s`) | -| WORKER_CONNECTIONS | Maximum number of simultaneous connections that can be opened by a worker process (Default: `1024`) | +| 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) | +| PROXY_SSL_VERIFY_DEPTH | An integer value indicating the verification depth for the client certificate chain (Default: `1`) | +| 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`). | +| SSL_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | +| 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. +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| +| 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditEngine) for additional information. | -| MODSEC_AUDIT_LOG | Path to the main audit log file or the concurrent logging index file (Default: `/dev/stdout`) | -| MODSEC_AUDIT_LOG_FORMAT | Output format of the AuditLogs (Default: `JSON`). Accepted values: `JSON`, `Native`. See [SecAuditLogFormat](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditLogFormat) for additional information. | -| MODSEC_AUDIT_LOG_TYPE | 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogtype) 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secauditlogparts) for the accepted values. | -| MODSEC_AUDIT_STORAGE | Directory where concurrent audit log entries are to be stored (Default: `/var/log/modsecurity/audit/`) | -| MODSEC_DATA_DIR | 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 | Path to the ModSecurity debug log file (Default: `/dev/null`) | -| MODSEC_DEBUG_LOGLEVEL | An int indicating the verboseness of the debug log data (Default: `0`). Accepted values: `0` - `9`. See [SecDebugLogLevel](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secdebugloglevel). | -| MODSEC_DISABLE_BACKEND_COMPRESSION | whether or not to disable backend compression (Default: `On`). Allowed values: `On`, `Off`. See [SecDisableBackendCompression](https://github.com/SpiderLabs/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 int 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#SecPcreMatchLimit) | -| MODSEC_PCRE_MATCH_LIMIT_RECURSION | An int value indicating the limit for the depth of recursion when calling PCRE function (Default: `100000`) | -| MODSEC_REQ_BODY_ACCESS | A string allowing ModSecurity to access request bodies (Default: `On`). Allowed values: `On`, `Off`. See [SecRequestBodyAccess](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodyaccess) for more information. | -| MODSEC_REQ_BODY_LIMIT | An int value indicating the maximum request body size accepted for buffering (Default: `13107200`). See [SecRequestBodyLimit](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimit) for additional information. | -| MODSEC_REQ_BODY_LIMIT_ACTION | A string for the action when `SecRequestBodyLimit` is reached (Default: `Reject`). Accepted values: `Reject`, `ProcessPartial`. See [SecRequestBodyLimitAction](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimitaction) for additional information. | -| MODSEC_REQ_BODY_JSON_DEPTH_LIMIT | An int value indicating the maximun JSON request depth (Default: `512`). See [SecRequestBodyJsonDepthLimit](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecRequestBodyJsonDepthLimit) for additional information. | -| MODSEC_REQ_BODY_NOFILES_LIMIT | An int indicating the maximum request body size ModSecurity will accept for buffering (Default: `131072`). See [SecRequestBodyNoFilesLimit](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodynofileslimit) for more information. | -| MODSEC_RESP_BODY_ACCESS | A string allowing ModSecurity to access response bodies (Default: `On`). Allowed values: `On`, `Off`. See [SecResponseBodyAccess](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secresponsebodyaccess) for more information. | -| MODSEC_RESP_BODY_LIMIT | An int value indicating the maximum response body size accepted for buffering (Default: `1048576`) | -| MODSEC_RESP_BODY_LIMIT_ACTION | A string for the action when `SecResponseBodyLimit` is reached (Default: `ProcessPartial`). Accepted values: `Reject`, `ProcessPartial`. See [SecResponseBodyLimitAction](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secresponsebodylimitaction) for additional information. | -| MODSEC_RESP_BODY_MIMETYPE | 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-\(v2.x\)#secresponsebodymimetype). | -| MODSEC_RULE_ENGINE | A string enabling ModSecurity itself (Default: `On`). Accepted values: `On`, `Off`, `DetectionOnly`. See [SecRuleEngine](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secruleengine) for additional information. | -| 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecStatusEngine) for additional information. | -| MODSEC_TAG | Default tag action, which will be inherited by the rules in the same configuration context (Default: `modsecurity`) | -| MODSEC_TMP_DIR | Path where temporary files will be created (Default: `/tmp/modsecurity/tmp`) | -| MODSEC_TMP_SAVE_UPLOADED_FILES | if temporary uploaded files are saved (Default: `On`) (only relevant in Apache - ModSecurity v2) | -| MODSEC_UPLOAD_DIR | Path where intercepted files will be stored (Default: `/tmp/modsecurity/upload`) | +| 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_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_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_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_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_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_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_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_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 | An integer value indicating the maximum response body size accepted for buffering (Default: `1048576`) | +| 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_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`) | | 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}\''`) | -### Overridden - -| Name | Description| -| -- | -- | -| USER | Name (or #number) of the user to run httpd or nginx as (Default: `www-data` (httpd), `nginx` (nginx)) | -| GROUP | Name (or #number) of the group to run httpd as (Default: `www-data`) | -| BACKEND | Backend address (and optional port) of the backend server. (Default: the container's default router, port 81) (Examples: 192.0.2.2, 192.0.2.2:80, ) | - ### CRS specific -| Name | Description| -| -- | -- | -| MANUAL_MODE | A bool 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`. | -| CRS_DISABLE_PLUGINS | A bool indicating whether plugins will be **disabled** (Only from v4 and up. Default: `0`) | -| PARANOIA | An int indicating the paranoia level (Default: `1`) | -| BLOCKING_PARANOIA | (:new: Replaces `PARANOIA` in CRSv4) An int indicating the paranoia level (Default: `1`) | -| EXECUTING_PARANOIA | An int indicating the executing_paranoia_level (Default: `PARANOIA`) | -| DETECTION_PARANOIA | (:new: Replaces `EXECUTING_PARANOIA` in CRSv4) An int indicating the detection_paranoia_level (Default: `BLOCKING_PARANOIA`) | -| ENFORCE_BODYPROC_URLENCODED | A bool indicating the enforce_bodyproc_urlencoded (Default: `0`) | -| VALIDATE_UTF8_ENCODING | A bool indicating the crs_validate_utf8_encoding (Default: `0`) | -| ANOMALY_INBOUND | An int indicating the inbound_anomaly_score_threshold (Default: `5`) | -| ANOMALY_OUTBOUND | An int indicating the outbound_anomaly_score_threshold (Default: `4`) | -| ALLOWED_METHODS | Allowed_methods (Default: `GET HEAD POST OPTIONS`) | -| ALLOWED_REQUEST_CONTENT_TYPE | 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 | Allowed_request_content_type_charset (Default: `utf-8\|iso-8859-1\|iso-8859-15\|windows-1252`) | -| ALLOWED_HTTP_VERSIONS | Allowed_http_versions (Default: `HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/2.0`) | -| RESTRICTED_EXTENSIONS | 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 | Restricted_headers (Default: `/accept-charset/ /content-encoding/ /proxy/ /lock-token/ /content-range/ /if/`) | -| STATIC_EXTENSIONS | Static_extensions (Default: `/.jpg/ /.jpeg/ /.png/ /.gif/ /.js/ /.css/ /.ico/ /.svg/ /.webp/`) | -| MAX_NUM_ARGS | An int indicating the max_num_args (Default: `unlimited`) | -| ARG_NAME_LENGTH | An int indicating the arg_name_length (Default: `unlimited`) | -| ARG_LENGTH | An int indicating the arg_length (Default: `unlimited`) | -| TOTAL_ARG_LENGTH | An int indicating the total_arg_length (Default: `unlimited`) | -| MAX_FILE_SIZE | An int indicating the max_file_size (Default: `unlimited`) | -| COMBINED_FILE_SIZES | An int indicating the combined_file_sizes (Default: `unlimited`) | -| CRS_ENABLE_TEST_MARKER | A bool indicating whether to write test markers to the log file (Used for running the CRS test suite. Default: `0`) | +| Name | Description| +| -------- | ------------------------------------------------------------------- | +| 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`. | +| CRS_DISABLE_PLUGINS | A boolean indicating whether plugins will be **disabled** (Only from v4 and up. Default: `0`) | +| PARANOIA | An integer indicating the paranoia level (Default: `1`) | +| BLOCKING_PARANOIA | (:new: Replaces `PARANOIA` in CRSv4) An integer indicating the paranoia level (Default: `1`) | +| EXECUTING_PARANOIA | An integer indicating the executing_paranoia_level (Default: `PARANOIA`) | +| 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`) | +| VALIDATE_UTF8_ENCODING | A boolean indicating the crs_validate_utf8_encoding (Default: `0`) | +| ANOMALY_INBOUND | An integer indicating the inbound_anomaly_score_threshold (Default: `5`) | +| ANOMALY_OUTBOUND | An integer indicating the outbound_anomaly_score_threshold (Default: `4`) | +| 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`) | +| ALLOWED_HTTP_VERSIONS | A string indicating the allowed_http_versions (Default: `HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/2.0`) | +| 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/`) | +| MAX_NUM_ARGS | An integer indicating the max_num_args (Default: `unlimited`) | +| ARG_NAME_LENGTH | An integer indicating the arg_name_length (Default: `unlimited`) | +| ARG_LENGTH | An integer indicating the arg_length (Default: `unlimited`) | +| TOTAL_ARG_LENGTH | An integer indicating the total_arg_length (Default: `unlimited`) | +| MAX_FILE_SIZE | An integer indicating the max_file_size (Default: `unlimited`) | +| COMBINED_FILE_SIZES | An integer indicating the combined_file_sizes (Default: `unlimited`) | +| 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`) | diff --git a/README.md b/README.md index 33d0ce7f..2a8fe170 100644 --- a/README.md +++ b/README.md @@ -12,36 +12,65 @@ The Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity or compatible web application firewalls. ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. -## Supported tags and respective `Dockerfile` links +## Supported Tags -* `3-nginx-YYYYMMDDHHMM`, `3.3-nginx-YYYYMMDDHHMM`, `3.3.5-nginx-YYYYMMDDHHMM`, `nginx` ([master/nginx/Dockerfile](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile)) – *last stable ModSecurity v3 on Nginx 1.25.3 official stable base image, and latest stable Core Rule Set 3.3.5* -* `3-apache-YYYYMMDDHHMM`, `3.3-apache-YYYYMMDDHHMM`, `3.3.5-apache-YYYYMMDDHHMM`, `apache` ([master/apache/Dockerfile](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile)) –*last stable ModSecurity v2 on Apache 2.4.58 official stable base image, and latest stable Core Rule Set 3.3.5* +### Stable Tags -⚠️ We changed tags to [support production usage](https://github.com/coreruleset/modsecurity-crs-docker/issues/67). Now, if you want to use the "rolling version", use the tag `owasp/modsecurity-crs:nginx` or `owasp/modsecurity-crs:apache`. If you need a stable long term image, use the one with the full CRS version, in addition to the build date in `YYYYMMDDHHMM` format, example `owasp/modsecurity-crs:3.3.5-nginx-202209141209` or `owasp/modsecurity-crs:3.3.5-apache-202209141209` for example. You have been warned. +Stable Tags are composed of: + * CRS version, in the fromat `[.[. for more information. +The stable tag format is `-[-]-`. +Examples: + * `3-nginx-202401121309` + * `3.3-apache-alpine-202401121309` + * `3.3.5-openresty-alpine-fat-202401121309` -## Supported variants +### Rolling Tags -We also build [alpine linux](https://www.alpinelinux.org/) variants of the base images, using the `-alpine` suffix. Examples: +Rolling tags are updated whenever a new stable tag release occurs. Rolling tags can be practical but should not be used in production. -* `3-nginx-alpine-YYYYMMDDHHMM`, `3.3-nginx-alpine-YYYYMMDDHHMM`, `3.3.5-nginx-alpine-YYYYMMDDHHMM`, `nginx-alpine` ([master/nginx/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/nginx/Dockerfile-alpine) – *last stable ModSecurity v3 on Nginx 1.25.3 official alpine stable base image, and latest stable Core Rule Set 3.3.5* -* `3-apache-alpine-YYYYMMDDHHMM`, `3.3-apache-alpine-YYYYMMDDHHMM`, `3.3.5-apache-alpine-YYYYMMDDHHMM`, `apache-alpine` ([master/apache/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-crs-docker/blob/master/apache/Dockerfile-alpine)) – *last stable ModSecurity v2 on Apache 2.4.58 official alpine stable base image, and latest stable Core Rule Set 3.3.5* +Rolling Tags are composed of: + * web server variant + * OS variant (optional) -⚠️ We changed tags to [support production usage](https://github.com/coreruleset/modsecurity-crs-docker/issues/67). Now, if you want to use the "rolling version", use the tag `owasp/modsecurity-crs:nginx-alpine` or `owasp/modsecurity-crs:apache-alpine`. If you need a stable long term image, use the one with the full CRS version, in addition to the build date in `YYYYMMDDHHMM` format, example `owasp/modsecurity-crs:3.3.5-nginx-alpine-202209141209` or `owasp/modsecurity-crs:3.3.5-apache-alpine-202209141209` for example. You have been warned. +The stable tag format is `[-]`. +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 Core Rule Set 3.3.5* + * [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 Core Rule Set 3.3.5* + * [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 Core Rule Set 3.3.5* + * [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 -We added the [docker buildx](https://github.com/docker/buildx) support to our docker builds so additional architectures are supported now. As we create our containers based on the official apache and nginx ones, we can only support the architectures they support. +Our builds are based on the official Apache httpd, nginx and Openresty images, which means we can only support the architectures they support. -There is a new file `docker-bake.hcl` used for this purpose. To build for new platforms, just use this example: +We currently provide images for the following architectures: -```bash -docker buildx create --use --platform linux/amd64,linux/i386,linux/arm64,linux/arm/v7 -docker buildx bake -f docker-bake.hcl -``` +* linux/amd64 +* linux/arm/v7 +* linux/arm64/v8 +* linux/i386 -We require a version of `buildx` >= v0.9.1. [Visit the official documentation](https://docs.docker.com/build/buildx/install/) for instructions on installing and upgrading `buildx`. You can check which version you have using: +### Building + +We require a version of `buildx` >= v0.9.1. [Visit the official documentation](https://docs.docker.com/build/architecture/#install-buildx) for instructions on installing and upgrading `buildx`. You can check which version you have using: ```bash docker buildx version @@ -54,15 +83,12 @@ If you want to see the targets of the build, use: docker buildx bake -f ./docker-bake.hcl --print ``` -We are building now for these architectures: - -* linux/amd64 -* linux/arm/v7 -* linux/arm64/v8 -* linux/i386 +To build for any platforms of your choosing, just use this example: -You can find additional examples on how to use `buildx` in this repository's GitHub act -We added the [docker buildx](https://github.com/docker/buildx) support to our docker builds so additional architectures are supported now. As we create our containers based on the official apache and nginx ones, we can only support the architectures they support. +```bash +docker buildx create --use --platform linux/amd64,linux/i386,linux/arm64,linux/arm/v7 +docker buildx bake -f docker-bake.hcl +``` To build a specific target for a single platform only (replace target and platform strings in the example with the your choices): @@ -70,6 +96,17 @@ To build a specific target for a single platform only (replace target and platfo docker buildx bake -f docker-bake.hcl --set "*.platform=linux/amd64" nginx-alpine ``` +### Notes regarding Openresty version of the image + +Openresty image builds currently support only these architectures: + +* linux/amd64 +* linux/arm64 + +## Container Health Checks + +🆕 We add healthchecks to the images, so that containers return HTTP status code 200 from the `/healthz` endpoint. When a container has a healthcheck specified, it has a _health status_ in addition to its normal status. This status is initially `starting`. Whenever a health check passes, it becomes `healthy` (whatever state it was previously in). After a certain number of consecutive failures, it becomes `unhealthy`. See for more information. + ## CRS Versions > Hey, I used some specific git version with the containers? What happened? @@ -108,146 +145,116 @@ 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. -### TLS/HTTPS - -TLS is configured by default on port 443. Note: The default configuration generates a self signed certificate on first run. To use your own certificates (recommended) `COPY` or mount (`-v`) your `server.crt` and `server.key` into `/usr/local/apache2/conf/` or `/etc/nginx/conf/`. Remember to publish the HTTPS port when running the image. - -```bash -docker build -t my-modsec . -docker run -p 8443:443 my-modsec -``` - -We use sane intermediate defaults taken from the [Mozilla SSL config tool](https://ssl-config.mozilla.org/). Please check it and choose the best that match your needs. - -You can use variables on nginx and apache to always redirect from http to https if needed (see APACHE_ALWAYS_TLS_REDIRECT and NGINX_ALWAYS_TLS_REDIRECT below). - -### Proxying - -ModSecurity is often used as a reverse proxy. This allows one to use ModSecurity without modifying the webserver hosting the underlying application (and also protect web servers that modsecurity cannot currently embedd into). The proxy is set by default to true and the location is defined by BACKEND environment variable. The SSL is enabled by default. - -```bash -docker build -t my-modsec . -f -docker run -p 8080:80 -e PROXY_SSL=on -e BACKEND=http://example.com my-modsec -``` - -### ServerName - -It is often convenient to set your servername. To do this simply use the `SERVER_NAME` environment variable passed to docker run. By default the servername provided is `localhost`. - -```bash -docker build -t modsec . -docker run -p 8080:80 -e SERVER_NAME=myhost my-modsec -``` +### 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` | - | +| PORT | An int value indicating the port where the webserver is listening to | `80` | - | +| PROXY_SSL | SSL Proxy Engine Operation Switch | `off` | - | +| 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` | +| 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` | +| 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_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` | +| 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` | +| 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_PORT | Port number where the SSL enabled webserver is listening | `443` | - | +| 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| | -------- | ------------------------------------------------------------------- | -| ACCESSLOG | A string value indicating the location of the custom log file (Default: `/var/log/apache2/access.log`) | | APACHE_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | | 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_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_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 | A string indicating the partial URL for the remote server of the `ProxyPass` directive (Default: `http://localhost:80`) | | BACKEND_WS | A string indicating the IP/URL of the WebSocket service (Default: `ws://localhost:8080`) | -| ERRORLOG | A string value indicating the location of the error log file (Default: `/var/log/apache2/error.log`) | | H2_PROTOCOLS | A string value indicating the protocols supported by the HTTP2 module (Default: `h2 http/1.1`) | -| LOGLEVEL | A string value controlling the number of messages logged to the error_log (Default: `warn`) | -| METRICS_ALLOW_FROM | A string indicating a range of IP adresses that can access the metrics (Default: `127.0.0.0/255.0.0.0 ::1/128`) | -| METRICS_DENY_FROM | A string indicating a range of IP adresses that cannot access the metrics (Default: `All`) | -| METRICSLOG | A string indicating the path of the metrics log (Default: `/dev/null`) | | 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 integer value indicating the port where the webserver is listening to (Default: `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_CERT_KEY | A string indicating the path to the server PEM-encoded private key file (Default: `/usr/local/apache2/conf/server.key`) | -| PROXY_SSL_CERT | A string indicating the path to the server PEM-encoded X.509 certificate data file or token identifier (Default: `/usr/local/apache2/conf/server.crt`) | +| 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`) | -| PROXY_SSL_VERIFY | A string value indicating the type of remote server Certificate verification (Default: `none`) | -| PROXY_SSL | A string indicating SSL Proxy Engine Operation Switch (Default: `off`) | -| PROXY_TIMEOUT | Number of seconds for proxied requests to time out (Default: `60`) | | 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_NAME | A string value indicating the server name (Default: `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_CIPHER_SUITE | A string indicating the cipher suite to use. Uses OpenSSL [list of cipher suites](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_ciphersuites.html) (Default: `"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"` | +| 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 (Default: `443`) | -| SSL_PROTOCOL | A string for configuring the [usable SSL/TLS protocol versions](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslprotocol) (Default: `"all -SSLv3 -TLSv1 -TLSv1.1"`) | -| SSL_PROXY_PROTOCOL | A string for configuring the [proxy client SSL/TLS protocol versions](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslproxyprotocol) (Default: `"all -SSLv3 -TLSv1 -TLSv1.1"`) | -| SSL_PROXY_CIPHER_SUITE | A string indicating the cipher suite to connect to the backend via TLS. (Default `"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_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`) | -| SSL_USE_STAPLING | A string indicating if [OSCP Stapling](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslusestapling) should be used (Allowed values: `on`, `off`. Default: `on`) | | 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`. +> [!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| | -------- | ------------------------------------------------------------------- | -| ACCESSLOG | A string value indicating the location of the access log file (Default: `/var/log/nginx/access.log`) | -| BACKEND | A string indicating the partial URL for the remote server of the `proxy_pass` directive (Default: `http://localhost:80`) | | 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_) | -| ERRORLOG | A string value indicating the location of the error log file (Default: `/proc/self/fd/2`) | -| LOGLEVEL | A string value controlling the number of messages logged to the error_log (Default: `warn`) | -| METRICS_ALLOW_FROM | A string indicating a single range of IP adresses that can access the metrics (Default: `127.0.0.0/24`) | -| METRICS_DENY_FROM | A string indicating a range of IP adresses that cannot access the metrics (Default: `all`) | -| METRICSLOG | A string value indicating the location of metrics log file (Default: `/dev/null`) | +| 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 integer value indicating the port where the webserver is listening to (Default: `80`) | | 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) | | 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) | -| PROXY_SSL_CERT | A string value indicating the path to the server PEM-encoded X.509 certificate data file or token value identifier (Default: `/etc/nginx/conf/server.crt`) | -| PROXY_SSL_CERT_KEY | A string value indicating the path to the server PEM-encoded private key file (Default: `/etc/nginx/conf/server.key`) | -| PROXY_SSL_CIPHERS | A String value indicating the enabled ciphers. The ciphers are specified in the format understood by the OpenSSL library. (Default: `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_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | -| PROXY_SSL_OCSP_STAPLING | A string value indicating if ssl_stapling and ssl_stapling_verify should be enabled (Allowed values: `on`, `off`. Default: `off`) | -| PROXY_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`)| -| PROXY_SSL_PROTOCOLS | A string value indicating the ssl protocols to enable (default: `TTLSv1.2 TLSv1.3`)| -| PROXY_SSL_VERIFY | A string value indicating if the client certificates should be verified (Allowed values: `on`, `off`. Default: `off`) | -| PROXY_TIMEOUT | Number of seconds for proxied requests to time out connections (Default: `60s`) | +| PROXY_SSL_VERIFY_DEPTH | An integer value indicating the verification depth for the client certificate chain (Default: `1`) | | 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`). | -| SSL_PORT | Port number where the SSL enabled webserver is listening (Default: `443`) | -| TIMEOUT | Number of seconds for a keep-alive client connection to stay open on the server side (Default: `60s`) | +| SSL_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | +| 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/SpiderLabs/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. +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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditEngine) for additional information. | +| 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecAuditLogFormat) for additional information. | -| 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secauditlogtype) 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secauditlogparts) for the accepted values. | +| 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_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_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_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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secdebugloglevel). | -| 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/SpiderLabs/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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#SecPcreMatchLimit) | +| 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_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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodyaccess) for more information. | -| MODSEC_REQ_BODY_LIMIT | An integer value indicating the maximum request body size accepted for buffering (Default: `13107200`). See [SecRequestBodyLimit](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimit) 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secrequestbodylimitaction) for additional information. | -| MODSEC_REQ_BODY_JSON_DEPTH_LIMIT | An integer value indicating the maximun JSON request depth (Default: `512`). See [SecRequestBodyJsonDepthLimit](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecRequestBodyJsonDepthLimit) 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/SpiderLabs/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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secresponsebodyaccess) for more information. | +| 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_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_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_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_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 | An integer value indicating the maximum response body size accepted for buffering (Default: `1048576`) | -| 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/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secresponsebodylimitaction) for additional information. | -| 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/SpiderLabs/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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#secruleengine) for additional information. | -| MODSEC_SERVER_SIGNATURE | Sets the directive [SecServerSignature](https://github.com/SpiderLabs/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/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#SecStatusEngine) for additional 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_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) | @@ -255,14 +262,6 @@ All these variables impact in configuration directives in the modsecurity engine | 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}\''`) | -### Overridden - -| Name | Description| -| -------- | ------------------------------------------------------------------- | -| USER | A string value indicating the name (or #number) of the user to run httpd or nginx as (Default: `www-data` (httpd), `nginx` (nginx)) | -| GROUP | A string value indicating the name (or #number) of the group to run httpd as (Default: `www-data`) | -| BACKEND | The backend address (and optional port) of the backend server. (Default: the container's default router, port 81) (Examples: 192.0.2.2, 192.0.2.2:80, ) | - ### CRS specific | Name | Description| @@ -292,14 +291,53 @@ All these variables impact in configuration directives in the modsecurity engine | COMBINED_FILE_SIZES | An integer indicating the combined_file_sizes (Default: `unlimited`) | | 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`) | -## Notes regarding reverse proxy +## TLS/HTTPS + +> [!IMPORTANT] +> The default configuration generates a self signed certificate on first run. To use your own certificates (recommended) `COPY` or mount (`-v`) your `server.crt` and `server.key` into `/usr/local/apache2/conf/` or `/etc/nginx/conf/`. Remember to publish the HTTPS port when running the image. +> +> ```bash +> docker build -t my-modsec . +> docker run -p 8443:443 my-modsec +> ``` -In order to more easily test drive the CRS ruleset, we include support for an technique called [Reverse Proxy](https://en.wikipedia.org/wiki/Reverse_proxy). Using this technique, you keep your pre-existing web server online at a non-standard host and port, and then configure the CRS container to accept public traffic. The CRS container then proxies the traffic to your pre-existing webserver. This way, you can test out CRS with any web server. Some notes: +TLS is configured on port `443` and enabled by default. -* Proxy is not enabled by default. You'll need to pass the `-e PROXY=1` environment variable to enable it. -* You'll want to configure your typical webserver to listen on your docker interface only (i.e. 172.17.0.1:81) so that public traffic doesn't reach it. -* Do not use 127.0.0.1 as an UPSTREAM address. The loopback interface inside the docker container is not the same interface as the one on docker host. -* Note that traffic coming through this proxy will look like it's coming from the wrong address. You may want to configure your pre-existing webserver to use the `X-Forwarded-For` HTTP header to populate the remote address field for traffic from the proxy. +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. + +You can set the `*_ALWAYS_TLS_REDIRECT` environment variables to always redirect from `http` to `https`. + +## Proxy Configuration + +The owasp/modsecurity-crs container images in their default configuration (i.e., without manual changes to / overrides of configuration files) act as reverse proxies and require a running backend at the address specified through the `BACKEND` environment variable. + +> [!IMPORTANT] +> Make sure to set the `BACKEND` variable to an address where a web server is listening. Otherwise nothing useful will happen when you send requests to the owasp/modsecurity-crs container (at least not with the default configurational). + +ModSecurity is often used in a reverse proxy setup with the following porperties: +- reverse proxy acts as public end point +- reverse proxy performs TLS termination (necessary for ModSecurity to inspect content) +- ModSecurity runs on the reverse proxy to filter traffic +- only benign traffic is passed to the backend + +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. + +```bash +docker build -t my-modsec . -f +docker run -p 8080:80 -e BACKEND=http://example.com my-modsec +``` + +## ServerName + +It is often convenient to set your server name (set to `localhost` by defualt). To do this simply use the `SERVER_NAME` environment variable. + +```bash +docker build -t modsec . +docker run -p 8080:80 -e SERVER_NAME=myhost my-modsec +``` ## ModSecurity CRS Tuning @@ -355,12 +393,9 @@ docker run -dti -p 80:80 --rm \ -e TOTAL_ARG_LENGTH=6400 \ -e MAX_FILE_SIZE=100000 \ -e COMBINED_FILE_SIZES=1000000 \ - -e PROXY=1 \ -e TIMEOUT=60 \ -e LOGLEVEL=warn \ -e ERRORLOG='/proc/self/fd/2' \ - -e USER=daemon \ - -e GROUP=daemon \ -e SERVER_ADMIN=root@localhost \ -e SERVER_NAME=localhost \ -e PORT=80 \ diff --git a/apache/Dockerfile b/apache/Dockerfile index 29c9ae78..4cf5be76 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,9 +1,9 @@ -ARG APACHE_VERSION=2.4.58 +ARG HTTPD_VERSION="n/a" -FROM httpd:${APACHE_VERSION} as build +FROM httpd:${HTTPD_VERSION} as build -ARG MODSEC_VERSION=2.9.7 \ - LUA_VERSION=5.3 +ARG MODSEC2_VERSION="n/a" +ARG LUA_VERSION="n/a" RUN set -eux; \ echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ @@ -27,16 +27,16 @@ RUN set -eux; \ wget RUN set -eux; \ - wget --quiet https://github.com/SpiderLabs/ModSecurity/archive/refs/tags/v${MODSEC_VERSION}.tar.gz; \ - tar -zxvf v${MODSEC_VERSION}.tar.gz; \ - cd ModSecurity-${MODSEC_VERSION}; \ + wget --quiet https://github.com/owasp-modsecurity/ModSecurity/archive/refs/tags/v${MODSEC2_VERSION}.tar.gz; \ + tar -zxvf v${MODSEC2_VERSION}.tar.gz; \ + cd ModSecurity-${MODSEC2_VERSION}; \ ./autogen.sh; \ ./configure --with-yajl --with-ssdeep; \ make; \ make install; \ make clean -FROM httpd:${APACHE_VERSION} as crs_release +FROM httpd:${HTTPD_VERSION} as crs_release ARG CRS_RELEASE @@ -56,27 +56,27 @@ RUN set -eux; \ rm -f v${CRS_RELEASE}.tar.gz coreruleset-${CRS_RELEASE}.tar.gz.asc; \ mv -v /opt/owasp-crs/crs-setup.conf.example /opt/owasp-crs/crs-setup.conf -FROM httpd:${APACHE_VERSION} +FROM httpd:${HTTPD_VERSION} -ARG MODSEC_VERSION=2.9.7 \ - LUA_VERSION=5.3 +ARG MODSEC2_VERSION +ARG LUA_VERSION LABEL maintainer="Felipe Zipitria " ENV APACHE_ALWAYS_TLS_REDIRECT=off \ + APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ + APACHE_ERRORLOG_FORMAT='"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"' \ + APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ ACCESSLOG=/var/log/apache2/access.log \ BACKEND=http://localhost:80 \ BACKEND_WS=ws://localhost:8080 \ ERRORLOG='/proc/self/fd/2' \ - APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ - APACHE_ERRORLOG_FORMAT='"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"' \ - APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ 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' \ MUTEX='default' \ + METRICSLOG='/dev/null' \ MODSEC_AUDIT_ENGINE="RelevantOnly" \ MODSEC_AUDIT_LOG_FORMAT=JSON \ MODSEC_AUDIT_LOG_TYPE=Serial \ @@ -110,12 +110,14 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ PORT=80 \ PROXY_ERROR_OVERRIDE=on \ PROXY_PRESERVE_HOST=on \ + PROXY_SSL=off \ PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ - PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ - PROXY_SSL_CERT=/usr/local/apache2/conf/server.crt \ + PROXY_SSL_CERT=/usr/local/apache2/conf/proxy.crt \ + PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/proxy.key \ PROXY_SSL_CHECK_PEER_NAME=off \ + PROXY_SSL_CIPHERS="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="all -SSLv3 -TLSv1 -TLSv1.1" \ PROXY_SSL_VERIFY=none \ - PROXY_SSL=on \ PROXY_TIMEOUT=60 \ REMOTEIP_INT_PROXY='10.1.0.0/16' \ REQ_HEADER_FORWARDED_PROTO='https' \ @@ -123,19 +125,17 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ SERVER_NAME=localhost \ SERVER_SIGNATURE=Off \ SERVER_TOKENS=Full \ - SSL_CIPHER_SUITE="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_CERT=/usr/local/apache2/conf/server.crt \ + SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ + SSL_CIPHERS="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_ENGINE=on \ SSL_HONOR_CIPHER_ORDER=off \ SSL_PORT=443 \ - SSL_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ - SSL_PROXY_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ - SSL_PROXY_CIPHER_SUITE="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_PROTOCOLS="all -SSLv3 -TLSv1 -TLSv1.1" \ SSL_SESSION_TICKETS=off \ - SSL_USE_STAPLING=On \ + SSL_OCSP_STAPLING=On \ TIMEOUT=60 \ WORKER_CONNECTIONS=400 \ - USER=www-data \ - GROUP=www-data \ # CRS specific variables PARANOIA=1 \ ANOMALY_INBOUND=5 \ @@ -143,8 +143,8 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ 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-${MODSEC_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf -COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping +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/ COPY src/bin/* /usr/local/bin/ diff --git a/apache/Dockerfile-alpine b/apache/Dockerfile-alpine index a0397d49..d67d0ba5 100644 --- a/apache/Dockerfile-alpine +++ b/apache/Dockerfile-alpine @@ -1,9 +1,9 @@ -ARG APACHE_VERSION=2.4.58 +ARG HTTPD_VERSION="n/a" -FROM httpd:${APACHE_VERSION}-alpine as build +FROM httpd:${HTTPD_VERSION}-alpine as build -ARG MODSEC_VERSION=2.9.7 \ - LUA_VERSION=5.3 +ARG MODSEC2_VERSION="n/a" +ARG LUA_VERSION="n/a" # see https://httpd.apache.org/docs/2.4/install.html#requirements RUN set -eux; \ @@ -37,16 +37,16 @@ RUN set -eux; \ zlib-dev RUN set -eux; \ - wget --quiet https://github.com/SpiderLabs/ModSecurity/archive/refs/tags/v${MODSEC_VERSION}.tar.gz; \ - tar -zxvf v${MODSEC_VERSION}.tar.gz; \ - cd ModSecurity-${MODSEC_VERSION}; \ + wget --quiet https://github.com/owasp-modsecurity/ModSecurity/archive/refs/tags/v${MODSEC2_VERSION}.tar.gz; \ + tar -zxvf v${MODSEC2_VERSION}.tar.gz; \ + cd ModSecurity-${MODSEC2_VERSION}; \ ./autogen.sh; \ ./configure --with-yajl --with-ssdeep --with-lmdb; \ make; \ make install; \ make clean -FROM httpd:${APACHE_VERSION}-alpine as crs_release +FROM httpd:${HTTPD_VERSION}-alpine as crs_release ARG CRS_RELEASE @@ -66,10 +66,10 @@ RUN set -eux; \ rm -f v${CRS_RELEASE}.tar.gz coreruleset-${CRS_RELEASE}.tar.gz.asc; \ mv -v /opt/owasp-crs/crs-setup.conf.example /opt/owasp-crs/crs-setup.conf -FROM httpd:${APACHE_VERSION}-alpine +FROM httpd:${HTTPD_VERSION}-alpine -ARG MODSEC_VERSION=2.9.7 \ - LUA_VERSION=5.3 +ARG MODSEC2_VERSION +ARG LUA_VERSION LABEL maintainer="Felipe Zipitria " @@ -120,12 +120,14 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ PORT=80 \ PROXY_ERROR_OVERRIDE=on \ PROXY_PRESERVE_HOST=on \ + PROXY_SSL=off \ PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ - PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ - PROXY_SSL_CERT=/usr/local/apache2/conf/server.crt \ + PROXY_SSL_CERT=/usr/local/apache2/conf/proxy.crt \ + PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/proxy.key \ PROXY_SSL_CHECK_PEER_NAME=off \ + PROXY_SSL_CIPHERS="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="all -SSLv3 -TLSv1 -TLSv1.1" \ PROXY_SSL_VERIFY=none \ - PROXY_SSL=on \ PROXY_TIMEOUT=60 \ REMOTEIP_INT_PROXY='10.1.0.0/16' \ REQ_HEADER_FORWARDED_PROTO='https' \ @@ -133,20 +135,17 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ SERVER_NAME=localhost \ SERVER_SIGNATURE=Off \ SERVER_TOKENS=Full \ - SSL_CIPHER_SUITE="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_CERT=/usr/local/apache2/conf/server.crt \ + SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ + SSL_CIPHERS="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_ENGINE=on \ SSL_HONOR_CIPHER_ORDER=off \ SSL_PORT=443 \ - SSL_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ - SSL_PROXY_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ - SSL_PROXY_CIPHER_SUITE="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_PROTOCOLS="all -SSLv3 -TLSv1 -TLSv1.1" \ SSL_SESSION_TICKETS=off \ - SSL_USE_STAPLING=On \ + SSL_OCSP_STAPLING=On \ TIMEOUT=60 \ WORKER_CONNECTIONS=400 \ - # overridden variables - USER=www-data \ - GROUP=www-data \ # CRS specific variables PARANOIA=1 \ ANOMALY_INBOUND=5 \ @@ -154,8 +153,8 @@ ENV APACHE_ALWAYS_TLS_REDIRECT=off \ 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-${MODSEC_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf -COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping +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/ COPY src/bin/* /usr/local/bin/ diff --git a/apache/conf/extra/httpd-logging-before-modsec.conf b/apache/conf/extra/httpd-logging-before-modsec.conf index b18eaf86..776ebc30 100644 --- a/apache/conf/extra/httpd-logging-before-modsec.conf +++ b/apache/conf/extra/httpd-logging-before-modsec.conf @@ -11,7 +11,7 @@ LoadModule logio_module /usr/local/apache2/modules/mod_logio.so LogFormat "%h %{GEOIP_COUNTRY_CODE}e %u [%{%Y-%m-%d %H:%M:%S}t.%{usec_frac}t] \"%r\" %>s %b \ \"%{Referer}i\" \"%{User-Agent}i\" \"%{Content-Type}i\" %{remote}p %v %A %p %R \ -%{BALANCER_WORKER_ROUTE}e %X \"%{cookie}n\" %{UNIQUE_ID}e %{SSL_PROTOCOL}x %{SSL_CIPHER}x \ +%{BALANCER_WORKER_ROUTE}e %X \"%{cookie}n\" %{UNIQUE_ID}e %{SSL_PROTOCOLS}x %{SSL_CIPHERS}x \ %I %O %{ratio}n%% %D %{ModSecTimeIn}e %{ApplicationTime}e %{ModSecTimeOut}e \ %{ModSecAnomalyScoreInPLs}e %{ModSecAnomalyScoreOutPLs}e \ %{ModSecAnomalyScoreIn}e %{ModSecAnomalyScoreOut}e" extended diff --git a/apache/conf/extra/httpd-modsecurity.conf b/apache/conf/extra/httpd-modsecurity.conf index d59e8887..41f2292a 100644 --- a/apache/conf/extra/httpd-modsecurity.conf +++ b/apache/conf/extra/httpd-modsecurity.conf @@ -4,14 +4,9 @@ Timeout ${TIMEOUT} LogLevel ${LOGLEVEL} ErrorLog ${ERRORLOG} -# https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#secserversignature +# https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#secserversignature SecServerSignature ${MODSEC_SERVER_SIGNATURE} - - User ${USER} - Group ${GROUP} - - RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500 diff --git a/apache/conf/extra/httpd-ssl.conf b/apache/conf/extra/httpd-ssl.conf index 182610a6..c488a9b3 100644 --- a/apache/conf/extra/httpd-ssl.conf +++ b/apache/conf/extra/httpd-ssl.conf @@ -1,16 +1,16 @@ Listen ${SSL_PORT} -SSLProxyProtocol ${SSL_PROXY_PROTOCOL} -SSLProxyCipherSuite ${SSL_PROXY_CIPHER_SUITE} +SSLProxyProtocol ${PROXY_SSL_PROTOCOLS} +SSLProxyCipherSuite ${PROXY_SSL_CIPHERS} SSLPassPhraseDialog builtin -SSLProtocol ${SSL_PROTOCOL} -SSLCipherSuite ${SSL_CIPHER_SUITE} +SSLProtocol ${SSL_PROTOCOLS} +SSLCipherSuite ${SSL_CIPHERS} SSLHonorCipherOrder ${SSL_HONOR_CIPHER_ORDER} SSLSessionTickets ${SSL_SESSION_TICKETS} -SSLUseStapling ${SSL_USE_STAPLING} +SSLUseStapling ${SSL_OCSP_STAPLING} SSLStaplingCache "shmcb:logs/ssl_stapling(32768)" SSLSessionCache "shmcb:logs/ssl_scache(512000)" diff --git a/apache/conf/extra/httpd-vhosts.conf b/apache/conf/extra/httpd-vhosts.conf index e0984a38..b943e05d 100644 --- a/apache/conf/extra/httpd-vhosts.conf +++ b/apache/conf/extra/httpd-vhosts.conf @@ -41,6 +41,6 @@ UseCanonicalName on Protocols ${H2_PROTOCOLS} SSLEngine ${SSL_ENGINE} - SSLCertificateFile ${PROXY_SSL_CERT} - SSLCertificateKeyFile ${PROXY_SSL_CERT_KEY} + SSLCertificateFile ${SSL_CERT} + SSLCertificateKeyFile ${SSL_CERT_KEY} diff --git a/docker-bake.hcl b/docker-bake.hcl index 64d06d6d..bd3e58fc 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,8 +1,36 @@ # docker-bake.hcl +variable "modsec3-version" { + default = "3.0.12" +} + +variable "modsec2-version" { + default = "2.9.7" +} + variable "crs-version" { default = "3.3.5" } +variable "nginx-version" { + default = "1.25.3" +} + +variable "httpd-version" { + default = "2.4.58" +} + +variable "openresty-version" { + default = "1.25.3.1" +} + +variable "lua-version" { + default = "5.3" +} + +variable "lmdb-version" { + default = "0.9.29" +} + variable "REPO" { default = "owasp/modsecurity-crs" } @@ -30,9 +58,9 @@ function "tag" { function "vtag" { params = [semver, variant] result = concat( - tag("${major(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), - tag("${minor(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), - tag("${patch(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}") + tag("${major(semver)}-${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), + tag("${minor(semver)}-${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), + tag("${patch(semver)}-${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}") ) } @@ -41,7 +69,8 @@ group "default" { "apache", "apache-alpine", "nginx", - "nginx-alpine" + "nginx-alpine", + "openresty-alpine-fat" ] } @@ -51,39 +80,71 @@ target "platforms-base" { inherits = ["docker-metadata-action"] context="." platforms = ["linux/amd64", "linux/arm64/v8", "linux/arm/v7", "linux/i386"] + labels = { + "org.opencontainers.image.source" = "https://github.com/coreruleset/modsecurity-crs-docker" + } args = { CRS_RELEASE = "${crs-version}" + MODSEC2_VERSION = "${modsec2-version}" + MODSEC3_VERSION = "${modsec3-version}" + LUA_VERSION = "${lua-version}" + LMDB_VERSION = "${lmdb-version}" } } target "apache" { inherits = ["platforms-base"] dockerfile="apache/Dockerfile" + args = { + HTTPD_VERSION = "${httpd-version}" + } tags = concat(tag("apache"), - vtag("${crs-version}", "-apache") + vtag("${crs-version}", "apache") ) } target "apache-alpine" { inherits = ["platforms-base"] dockerfile="apache/Dockerfile-alpine" + args = { + HTTPD_VERSION = "${httpd-version}" + } tags = concat(tag("apache-alpine"), - vtag("${crs-version}", "-apache-alpine") + vtag("${crs-version}", "apache-alpine") ) } target "nginx" { inherits = ["platforms-base"] dockerfile="nginx/Dockerfile" + args = { + NGINX_VERSION = "${nginx-version}" + } tags = concat(tag("nginx"), - vtag("${crs-version}", "-nginx") + vtag("${crs-version}", "nginx") ) } target "nginx-alpine" { inherits = ["platforms-base"] dockerfile="nginx/Dockerfile-alpine" + args = { + NGINX_VERSION = "${nginx-version}" + } tags = concat(tag("nginx-alpine"), - vtag("${crs-version}", "-nginx-alpine") + vtag("${crs-version}", "nginx-alpine") + ) +} + +target "openresty-alpine-fat" { + inherits = ["platforms-base"] + platforms = ["linux/amd64", "linux/arm64/v8"] + dockerfile="openresty/Dockerfile-alpine" + args = { + OPENRESTY_VERSION = "${openresty-version}" + NGINX_VERSION = "${nginx-version}" + } + tags = concat(tag("openresty-alpine-fat"), + vtag("${crs-version}", "openresty-alpine-fat") ) } diff --git a/nginx/Dockerfile b/nginx/Dockerfile index e1c2dbf0..5a7aec9f 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,10 +1,12 @@ -ARG NGINX_VERSION="1.25.3" +ARG NGINX_VERSION="n/a" -FROM nginx:${NGINX_VERSION} as build +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} as build -ARG MODSEC_VERSION=3.0.11 \ - LMDB_VERSION=0.9.29 \ - LUA_VERSION=5.3 +ARG MODSEC3_VERSION="n/a" +ARG LMDB_VERSION="n/a" +ARG LUA_VERSION="n/a" + +USER root # Note: libpcre3-dev (PCRE 1) is required by the build description, # even though the build will use PCRE2. @@ -42,7 +44,7 @@ RUN set -eux; \ strip /usr/local/lib/liblmdb*.so* RUN set -eux; \ - git clone https://github.com/SpiderLabs/ModSecurity --branch v"${MODSEC_VERSION}" --depth 1 --recursive; \ + git clone https://github.com/SpiderLabs/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; \ @@ -63,9 +65,9 @@ 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/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended \ + 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/SpiderLabs/ModSecurity/v3/master/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 @@ -74,10 +76,12 @@ 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 nginx:${NGINX_VERSION} as crs_release +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} as crs_release ARG CRS_RELEASE +USER root + # hadolint ignore=DL3008,SC2016 RUN set -eux; \ apt-get update; \ @@ -86,7 +90,13 @@ RUN set -eux; \ curl \ gnupg; \ mkdir /opt/owasp-crs; \ - curl -SL https://github.com/coreruleset/coreruleset/archive/v${CRS_RELEASE}.tar.gz -o v${CRS_RELEASE}.tar.gz; \ + chown nginx:nginx /opt/owasp-crs + +USER nginx + +WORKDIR /sources + +RUN curl -SL https://github.com/coreruleset/coreruleset/archive/v${CRS_RELEASE}.tar.gz -o v${CRS_RELEASE}.tar.gz; \ curl -SL https://github.com/coreruleset/coreruleset/releases/download/v${CRS_RELEASE}/coreruleset-${CRS_RELEASE}.tar.gz.asc -o coreruleset-${CRS_RELEASE}.tar.gz.asc; \ gpg --fetch-key https://coreruleset.org/security.asc; \ gpg --verify coreruleset-${CRS_RELEASE}.tar.gz.asc v${CRS_RELEASE}.tar.gz; \ @@ -94,11 +104,11 @@ RUN set -eux; \ rm -f v${CRS_RELEASE}.tar.gz coreruleset-${CRS_RELEASE}.tar.gz.asc; \ mv -v /opt/owasp-crs/crs-setup.conf.example /opt/owasp-crs/crs-setup.conf -FROM nginx:${NGINX_VERSION} +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} -ARG MODSEC_VERSION=3.0.11 \ - LMDB_VERSION=0.9.29 \ - LUA_VERSION=5.3 +ARG MODSEC3_VERSION +ARG LMDB_VERSION +ARG LUA_VERSION LABEL maintainer="Felipe Zipitria " @@ -106,6 +116,7 @@ ENV ACCESSLOG=/var/log/nginx/access.log \ BACKEND=http://localhost:80 \ DNS_SERVER= \ ERRORLOG=/var/log/nginx/error.log \ + KEEPALIVE_TIMEOUT=60s \ LOGLEVEL=warn \ METRICS_ALLOW_FROM='127.0.0.0/24' \ METRICS_DENY_FROM='all' \ @@ -144,31 +155,36 @@ ENV ACCESSLOG=/var/log/nginx/access.log \ REAL_IP_HEADER="X-REAL-IP" \ REAL_IP_PROXY_HEADER="X-REAL-IP" \ REAL_IP_RECURSIVE="on" \ - PROXY_TIMEOUT=60s \ - PROXY_SSL_CERT=/etc/nginx/conf/server.crt \ - PROXY_SSL_CERT_KEY=/etc/nginx/conf/server.key \ - PROXY_SSL_DH_BITS=2048 \ - PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ + PROXY_SSL=off \ + PROXY_SSL_CERT=/etc/nginx/conf/proxy.crt \ + PROXY_SSL_CERT_KEY=/etc/nginx/conf/proxy.key \ PROXY_SSL_CIPHERS="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_PREFER_CIPHERS=off \ + PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ PROXY_SSL_VERIFY=off \ - PROXY_SSL_OCSP_STAPLING=off \ + PROXY_SSL_VERIFY_DEPTH=1 \ + PROXY_TIMEOUT=60s \ SERVER_NAME=localhost \ SERVER_TOKENS=off \ + SSL_CERT=/etc/nginx/conf/server.crt \ + SSL_CERT_KEY=/etc/nginx/conf/server.key \ + SSL_CIPHERS="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_DH_BITS=2048 \ + SSL_OCSP_STAPLING=on \ SSL_PORT=443 \ - TIMEOUT=60s \ + SSL_PREFER_CIPHERS=off \ + SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ + SSL_VERIFY=off \ + SSL_VERIFY_DEPTH=1 \ WORKER_CONNECTIONS=1024 \ LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ - # overridden variables - USER=nginx \ # CRS specific variables PARANOIA=1 \ ANOMALY_INBOUND=5 \ ANOMALY_OUTBOUND=4 \ BLOCKING_PARANOIA=1 -COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/ +COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/ COPY --from=build /etc/nginx/modules/ngx_http_modsecurity_module.so /etc/nginx/modules/ngx_http_modsecurity_module.so COPY --from=build /usr/local/lib/liblmdb.so /usr/local/lib/ COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ @@ -184,6 +200,8 @@ COPY src/opt/modsecurity/activate-rules.sh /docker-entrypoint.d/95-activate-rule COPY nginx/templates /etc/nginx/templates/ COPY src/bin/* /usr/local/bin/ +USER root + RUN set -eux; \ echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ apt-get update -qq; \ @@ -199,18 +217,18 @@ RUN set -eux; \ rm -rf /var/lib/apt/lists/*; \ apt-get clean; \ mkdir /etc/nginx/ssl; \ - mkdir -p /tmp/modsecurity/data; \ - mkdir -p /tmp/modsecurity/upload; \ - mkdir -p /tmp/modsecurity/tmp; \ - mkdir -p /usr/local/modsecurity; \ - chown -R nginx:nginx /tmp/modsecurity; \ # Comment out the SecDisableBackendCompression option since it is not supported in V3 sed -i 's/^\(SecDisableBackendCompression .*\)/# \1/' /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ - chgrp -R 0 /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/; \ - chmod -R g=u /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/; \ - ln -sv /opt/owasp-crs /etc/modsecurity.d/ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ + ln -sv /opt/owasp-crs /etc/modsecurity.d/; \ + chown nginx:nginx /opt/owasp-crs /etc/modsecurity.d + +USER nginx + +RUN mkdir -p /tmp/modsecurity/data; \ + mkdir -p /tmp/modsecurity/upload; \ + mkdir -p /tmp/modsecurity/tmp HEALTHCHECK CMD /usr/local/bin/healthcheck diff --git a/nginx/Dockerfile-alpine b/nginx/Dockerfile-alpine index 8a1d5b31..b50fb626 100644 --- a/nginx/Dockerfile-alpine +++ b/nginx/Dockerfile-alpine @@ -1,9 +1,11 @@ -ARG NGINX_VERSION="1.25.3" +ARG NGINX_VERSION="n/a" -FROM nginx:${NGINX_VERSION}-alpine as build +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine as build -ARG MODSEC_VERSION=3.0.11 \ - LUA_VERSION=5.3 +ARG MODSEC3_VERSION="n/a" +ARG LUA_VERSION="n/a" + +USER root # Note: pcre-dev (PCRE 1) is required by the build description, # even though the build will use PCRE2. @@ -40,7 +42,7 @@ RUN set -eux; \ WORKDIR /sources RUN set -eux; \ - git clone https://github.com/SpiderLabs/ModSecurity --branch v"${MODSEC_VERSION}" --depth 1 --recursive; \ + git clone https://github.com/SpiderLabs/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; \ @@ -60,9 +62,9 @@ RUN set -eux; \ make modules; \ cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/; \ mkdir /etc/modsecurity.d; \ - wget --quiet https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended \ + 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/SpiderLabs/ModSecurity/v3/master/unicode.mapping \ + wget --quiet https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/unicode.mapping \ -O /etc/modsecurity.d/unicode.mapping # Generate/Download Diffie-Hellman parameter files @@ -71,10 +73,12 @@ 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 nginx:${NGINX_VERSION}-alpine as crs_release +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine as crs_release ARG CRS_RELEASE +USER root + # hadolint ignore=DL3008,SC2016 RUN set -eux; \ apk add --no-cache \ @@ -82,7 +86,13 @@ RUN set -eux; \ curl \ gnupg; \ mkdir /opt/owasp-crs; \ - curl -SL https://github.com/coreruleset/coreruleset/archive/v${CRS_RELEASE}.tar.gz -o v${CRS_RELEASE}.tar.gz; \ + chown nginx:nginx /opt/owasp-crs + +USER nginx + +WORKDIR /sources + +RUN curl -SL https://github.com/coreruleset/coreruleset/archive/v${CRS_RELEASE}.tar.gz -o v${CRS_RELEASE}.tar.gz; \ curl -SL https://github.com/coreruleset/coreruleset/releases/download/v${CRS_RELEASE}/coreruleset-${CRS_RELEASE}.tar.gz.asc -o coreruleset-${CRS_RELEASE}.tar.gz.asc; \ gpg --fetch-key https://coreruleset.org/security.asc; \ gpg --verify coreruleset-${CRS_RELEASE}.tar.gz.asc v${CRS_RELEASE}.tar.gz; \ @@ -90,10 +100,10 @@ RUN set -eux; \ rm -f v${CRS_RELEASE}.tar.gz coreruleset-${CRS_RELEASE}.tar.gz.asc; \ mv -v /opt/owasp-crs/crs-setup.conf.example /opt/owasp-crs/crs-setup.conf -FROM nginx:${NGINX_VERSION}-alpine +FROM nginxinc/nginx-unprivileged:${NGINX_VERSION}-alpine -ARG MODSEC_VERSION=3.0.11 \ - LUA_VERSION=5.3 +ARG MODSEC3_VERSION +ARG LUA_VERSION LABEL maintainer="Felipe Zipitria " @@ -139,45 +149,52 @@ ENV ACCESSLOG=/var/log/nginx/access.log \ REAL_IP_HEADER="X-REAL-IP" \ REAL_IP_PROXY_HEADER="X-REAL-IP" \ REAL_IP_RECURSIVE="on" \ - PROXY_TIMEOUT=60s \ - PROXY_SSL_CERT=/etc/nginx/conf/server.crt \ - PROXY_SSL_CERT_KEY=/etc/nginx/conf/server.key \ - PROXY_SSL_DH_BITS=2048 \ - PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ + PROXY_SSL=off \ + PROXY_SSL_CERT=/etc/nginx/conf/proxy.crt \ + PROXY_SSL_CERT_KEY=/etc/nginx/conf/proxy.key \ PROXY_SSL_CIPHERS="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_PREFER_CIPHERS=off \ + PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ PROXY_SSL_VERIFY=off \ - PROXY_SSL_OCSP_STAPLING=off \ + PROXY_SSL_VERIFY_DEPTH=1 \ + PROXY_TIMEOUT=60s \ SERVER_NAME=localhost \ SERVER_TOKENS=off \ + SSL_CERT=/etc/nginx/conf/server.crt \ + SSL_CERT_KEY=/etc/nginx/conf/server.key \ + SSL_CIPHERS="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_DH_BITS=2048 \ + SSL_OCSP_STAPLING=on \ SSL_PORT=443 \ - TIMEOUT=60s \ + SSL_PREFER_CIPHERS=off \ + SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ + SSL_VERIFY_DEPTH=1 \ + SSL_VERIFY=off \ + KEEPALIVE_TIMEOUT=60s \ WORKER_CONNECTIONS=1024 \ LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib \ NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \ - # overridden variables - USER=nginx \ # CRS specific variables PARANOIA=1 \ ANOMALY_INBOUND=5 \ ANOMALY_OUTBOUND=4 \ BLOCKING_PARANOIA=1 -COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/ +COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/ 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 -# We use the templating mechanism from the nginx image here. -COPY nginx/templates /etc/nginx/templates/ 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 src/bin/* /usr/local/bin/ COPY nginx/docker-entrypoint.d/*.sh /docker-entrypoint.d/ COPY src/opt/modsecurity/activate-plugins.sh /docker-entrypoint.d/94-activate-plugins.sh COPY src/opt/modsecurity/activate-rules.sh /docker-entrypoint.d/95-activate-rules.sh +# We use the templating mechanism from the nginx image here. +COPY nginx/templates /etc/nginx/templates/ +COPY src/bin/* /usr/local/bin/ +USER root RUN set -eux; \ apk add --no-cache \ @@ -197,19 +214,20 @@ RUN set -eux; \ # Alpine needs GNU 'sed' because the 'sed' program shipped with busybox does not support 'z' parameter for separating lines with a 'NUL' character. sed \ yajl; \ - mkdir /etc/nginx/ssl/; \ - mkdir -p /tmp/modsecurity/data; \ - mkdir -p /tmp/modsecurity/upload; \ - mkdir -p /tmp/modsecurity/tmp; \ - chown -R nginx:nginx /usr/share/nginx /tmp/modsecurity; \ + mkdir /etc/nginx/ssl; \ # Comment out the SecDisableBackendCompression option since it is not supported in V3 sed -i 's/^\(SecDisableBackendCompression .*\)/# \1/' /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ - ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ ln -sv /opt/owasp-crs /etc/modsecurity.d/; \ - chgrp -R 0 /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/; \ - chmod -R g=u /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/ + chown nginx:nginx /opt/owasp-crs /etc/modsecurity.d + +USER nginx + +RUN mkdir -p /tmp/modsecurity/data; \ + mkdir -p /tmp/modsecurity/upload; \ + mkdir -p /tmp/modsecurity/tmp WORKDIR /usr/share/nginx/html diff --git a/nginx/docker-entrypoint.d/91-update-resolver.sh b/nginx/docker-entrypoint.d/91-update-resolver.sh index 7846c1d0..2afca720 100755 --- a/nginx/docker-entrypoint.d/91-update-resolver.sh +++ b/nginx/docker-entrypoint.d/91-update-resolver.sh @@ -4,7 +4,6 @@ set -eu LC_ALL=C -ME=$( basename "$0" ) PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DNS_SERVER="${DNS_SERVER:-$(grep -i '^nameserver' /etc/resolv.conf | head -n1 | cut -d ' ' -f2)}" diff --git a/nginx/docker-entrypoint.d/92-update-real_ip.sh b/nginx/docker-entrypoint.d/92-update-real_ip.sh index fae02bfe..c4a7da95 100755 --- a/nginx/docker-entrypoint.d/92-update-real_ip.sh +++ b/nginx/docker-entrypoint.d/92-update-real_ip.sh @@ -4,7 +4,6 @@ set -eu LC_ALL=C -ME=$( basename "$0" ) PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # split comma separated IP addresses into multiple `set_real_ip xxx;` lines diff --git a/nginx/docker-entrypoint.d/93-update-proxy-ssl-config.sh b/nginx/docker-entrypoint.d/93-update-proxy-ssl-config.sh new file mode 100755 index 00000000..aca86ee3 --- /dev/null +++ b/nginx/docker-entrypoint.d/93-update-proxy-ssl-config.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# vim:sw=2:ts=2:sts=2:et + +set -eu + +LC_ALL=C +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +PROXY_SSL_CONFIG="" +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}"'#' /etc/nginx/conf.d/default.conf diff --git a/nginx/templates/conf.d/default.conf.template b/nginx/templates/conf.d/default.conf.template index c934208f..56e050d4 100644 --- a/nginx/templates/conf.d/default.conf.template +++ b/nginx/templates/conf.d/default.conf.template @@ -14,6 +14,8 @@ server { set $upstream ${BACKEND}; set $always_redirect ${NGINX_ALWAYS_TLS_REDIRECT}; + PROXY_SSL_CONFIG + location / { client_max_body_size 0; @@ -37,22 +39,25 @@ server { server_name ${SERVER_NAME}; set $upstream ${BACKEND}; - ssl_certificate ${PROXY_SSL_CERT}; - ssl_certificate_key ${PROXY_SSL_CERT_KEY}; + ssl_certificate ${SSL_CERT}; + ssl_certificate_key ${SSL_CERT_KEY}; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; - ssl_dhparam /etc/ssl/certs/dhparam-${PROXY_SSL_DH_BITS}.pem; + ssl_dhparam /etc/ssl/certs/dhparam-${SSL_DH_BITS}.pem; + + ssl_protocols ${SSL_PROTOCOLS}; + ssl_ciphers ${SSL_CIPHERS}; + ssl_prefer_server_ciphers ${SSL_PREFER_CIPHERS}; - ssl_protocols ${PROXY_SSL_PROTOCOLS}; - ssl_ciphers ${PROXY_SSL_CIPHERS}; - ssl_prefer_server_ciphers ${PROXY_SSL_PREFER_CIPHERS}; + ssl_stapling ${SSL_OCSP_STAPLING}; + ssl_stapling_verify ${SSL_OCSP_STAPLING}; - ssl_stapling ${PROXY_SSL_OCSP_STAPLING}; - ssl_stapling_verify ${PROXY_SSL_OCSP_STAPLING}; + ssl_verify_client ${SSL_VERIFY}; + ssl_verify_depth ${SSL_VERIFY_DEPTH}; - ssl_verify_client ${PROXY_SSL_VERIFY}; + PROXY_SSL_CONFIG location / { client_max_body_size 0; diff --git a/nginx/templates/includes/proxy_backend_ssl.conf.template b/nginx/templates/includes/proxy_backend_ssl.conf.template new file mode 100644 index 00000000..f105e9c8 --- /dev/null +++ b/nginx/templates/includes/proxy_backend_ssl.conf.template @@ -0,0 +1,8 @@ +proxy_ssl_certificate ${PROXY_SSL_CERT}; +proxy_ssl_certificate_key ${PROXY_SSL_CERT_KEY}; + +proxy_ssl_protocols ${PROXY_SSL_PROTOCOLS}; +proxy_ssl_ciphers ${PROXY_SSL_CIPHERS}; + +proxy_ssl_verify ${PROXY_SSL_VERIFY}; +proxy_ssl_verify_depth ${PROXY_SSL_VERIFY_DEPTH}; diff --git a/nginx/templates/nginx.conf.template b/nginx/templates/nginx.conf.template index 08acd62a..51f0f819 100644 --- a/nginx/templates/nginx.conf.template +++ b/nginx/templates/nginx.conf.template @@ -1,7 +1,7 @@ load_module modules/ngx_http_modsecurity_module.so; worker_processes auto; -pid /var/run/nginx.pid; +pid /tmp/nginx.pid; events { worker_connections ${WORKER_CONNECTIONS}; @@ -10,7 +10,7 @@ events { http { include /etc/nginx/mime.types; default_type application/octet-stream; - keepalive_timeout ${TIMEOUT}; + keepalive_timeout ${KEEPALIVE_TIMEOUT}; sendfile on; resolver DNS_SERVER valid=5s; diff --git a/openresty/Dockerfile-alpine b/openresty/Dockerfile-alpine new file mode 100644 index 00000000..d08c40c1 --- /dev/null +++ b/openresty/Dockerfile-alpine @@ -0,0 +1,257 @@ +# Current latest Openresty version is here. +# 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 + +ARG OPENRESTY_VERSION +ARG MODSEC3_VERSION="n/a" +ARG NGINX_VERSION="n/a" + +# Note: pcre-dev (PCRE 1) is required by the build description, +# even though the build will use PCRE2. +RUN set -eux; \ + apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + ca-certificates \ + coreutils \ + curl-dev \ + g++ \ + gcc \ + geoip-dev \ + git \ + libc-dev \ + libfuzzy2-dev \ + libmaxminddb-dev \ + libstdc++ \ + libtool \ + libxml2-dev \ + libxml2 \ + libxslt-dev \ + libxslt \ + linux-headers \ + lmdb-dev \ + make \ + patch \ + pkgconfig \ + pcre-dev \ + pcre2-dev \ + yajl-dev \ + gd \ + gd-dev \ + zlib-dev + + +WORKDIR /sources + +# Download ModSecurity and compile it. +RUN set -eux; \ + git clone https://github.com/SpiderLabs/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; \ + sed -ie "s/i386-linux-gnu/${ARCH}/g" build/pcre2.m4; \ + ./build.sh; \ + ./configure --with-yajl --with-ssdeep --with-lmdb --with-geoip --enable-silent-rules --with-pcre2; \ + make install; \ + strip /usr/local/modsecurity/lib/lib*.so* + +# We use latest version of the ModSecurity nginx connector. +# 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}; \ + 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-); \ + eval ./configure $COMPILEOPTIONS --add-dynamic-module=../../../ModSecurity-nginx; \ + 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 + + +# Generate self-signed certificates (if needed) +RUN mkdir -p /usr/share/TLS +COPY openresty/openssl.conf /usr/share/TLS +RUN /usr/local/openresty/openssl/bin/openssl req -x509 -days 365 -new \ + -config /usr/share/TLS/openssl.conf \ + -keyout /usr/share/TLS/server.key \ + -out /usr/share/TLS/server.crt + +# Generate/Download Diffie-Hellman parameter files +RUN /usr/local/openresty/openssl/bin/openssl dhparam -out /usr/share/TLS/dhparam-1024.pem 1024 +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 + +ARG CRS_RELEASE + +# hadolint ignore=DL3008,SC2016 +RUN set -eux; \ + apk add --no-cache \ + ca-certificates \ + curl \ + gnupg; \ + mkdir /opt/owasp-crs; \ + curl -SL https://github.com/coreruleset/coreruleset/archive/v${CRS_RELEASE}.tar.gz -o v${CRS_RELEASE}.tar.gz; \ + curl -SL https://github.com/coreruleset/coreruleset/releases/download/v${CRS_RELEASE}/coreruleset-${CRS_RELEASE}.tar.gz.asc -o coreruleset-${CRS_RELEASE}.tar.gz.asc; \ + gpg --fetch-key https://coreruleset.org/security.asc; \ + gpg --verify coreruleset-${CRS_RELEASE}.tar.gz.asc v${CRS_RELEASE}.tar.gz; \ + tar -zxf v${CRS_RELEASE}.tar.gz --strip-components=1 -C /opt/owasp-crs; \ + rm -f v${CRS_RELEASE}.tar.gz coreruleset-${CRS_RELEASE}.tar.gz.asc; \ + mv -v /opt/owasp-crs/crs-setup.conf.example /opt/owasp-crs/crs-setup.conf + +FROM openresty/openresty:${OPENRESTY_VERSION}-alpine-fat + +ARG MODSEC3_VERSION + +LABEL maintainer="Taavi Ansper " + +ENV ACCESSLOG=/var/log/nginx/access.log \ + BACKEND=http://localhost:80 \ + DNS_SERVER= \ + ERRORLOG=/var/log/nginx/error.log \ + KEEPALIVE_TIMEOUT=60s \ + LOGLEVEL=warn \ + METRICS_ALLOW_FROM='127.0.0.0/24' \ + METRICS_DENY_FROM='all' \ + METRICSLOG=/dev/null \ + MODSEC_AUDIT_ENGINE="RelevantOnly" \ + MODSEC_AUDIT_LOG_FORMAT=JSON \ + MODSEC_AUDIT_LOG_TYPE=Serial \ + MODSEC_AUDIT_LOG=/dev/stdout \ + MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ + MODSEC_AUDIT_STORAGE=/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_PCRE_MATCH_LIMIT_RECURSION=100000 \ + MODSEC_PCRE_MATCH_LIMIT=100000 \ + MODSEC_REQ_BODY_ACCESS=on \ + MODSEC_REQ_BODY_LIMIT=13107200 \ + MODSEC_REQ_BODY_LIMIT_ACTION="Reject" \ + MODSEC_REQ_BODY_JSON_DEPTH_LIMIT=512 \ + MODSEC_REQ_BODY_NOFILES_LIMIT=131072 \ + MODSEC_RESP_BODY_ACCESS=on \ + MODSEC_RESP_BODY_LIMIT=1048576 \ + MODSEC_RESP_BODY_LIMIT_ACTION="ProcessPartial" \ + MODSEC_RESP_BODY_MIMETYPE="text/plain text/html text/xml" \ + MODSEC_RULE_ENGINE=on \ + MODSEC_STATUS_ENGINE="Off" \ + MODSEC_TAG=modsecurity \ + MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ + MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ + MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ + PORT=80 \ + NGINX_ALWAYS_TLS_REDIRECT=off \ + SET_REAL_IP_FROM="127.0.0.1" \ + REAL_IP_HEADER="X-REAL-IP" \ + REAL_IP_PROXY_HEADER="X-REAL-IP" \ + REAL_IP_RECURSIVE="on" \ + PROXY_SSL=off \ + PROXY_SSL_CERT=/etc/nginx/conf/proxy.crt \ + PROXY_SSL_CERT_KEY=/etc/nginx/conf/proxy.key \ + PROXY_SSL_CIPHERS="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="TLSv1.2 TLSv1.3" \ + PROXY_SSL_VERIFY=off \ + PROXY_SSL_VERIFY_DEPTH=1 \ + PROXY_TIMEOUT=60s \ + SERVER_NAME=localhost \ + SERVER_TOKENS=off \ + SSL_CERT=/etc/nginx/conf/server.crt \ + SSL_CERT_KEY=/etc/nginx/conf/server.key \ + SSL_CIPHERS="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_DH_BITS=2048 \ + SSL_OCSP_STAPLING=on \ + SSL_PORT=443 \ + SSL_PREFER_CIPHERS=off \ + SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ + SSL_VERIFY=off \ + SSL_VERIFY_DEPTH=1 \ + WORKER_CONNECTIONS=1024 \ + # Change this from normal nginx setup. Do not add /usr/lib or /lib + LD_LIBRARY_PATH=/usr/local/lib:/usr/local/openresty \ + NGINX_ENVSUBST_OUTPUT_DIR=/usr/local/openresty/nginx/conf \ + # CRS specific variables + PARANOIA=1 \ + ANOMALY_INBOUND=5 \ + ANOMALY_OUTBOUND=4 \ + BLOCKING_PARANOIA=1 + +COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/ +COPY --from=build /usr/local/openresty/nginx/modules/ngx_http_modsecurity_module.so /usr/local/openresty/nginx/modules/ngx_http_modsecurity_module.so +COPY --from=build /usr/share/TLS/server.key /usr/local/openresty/nginx/conf/server.key +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. +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-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 +COPY src/opt/modsecurity/activate-plugins.sh /docker-entrypoint.d/94-activate-plugins.sh +COPY src/opt/modsecurity/activate-rules.sh /docker-entrypoint.d/95-activate-rules.sh + +# Openresty specific block. +COPY openresty/templates/nginx.conf.template /usr/local/openresty/nginx/templates +COPY openresty/docker-entrypoint.sh / +COPY openresty/docker-entrypoint.d/*.sh /docker-entrypoint.d/ + + +RUN set -eux; \ + apk add --no-cache \ + curl \ + curl-dev \ + libfuzzy2 \ + libmaxminddb-dev \ + libstdc++ \ + libxml2-dev \ + lmdb-dev \ + moreutils \ + tzdata \ + pcre \ + pcre2 \ + # Alpine needs GNU 'sed' because the 'sed' program shipped with busybox does not support 'z' parameter for separating lines with a 'NUL' character. + sed \ + yajl; \ + # Install lua modules here + luarocks install lua-resty-openidc; \ + mkdir /var/log/nginx; \ + mkdir -p /tmp/modsecurity/data; \ + mkdir -p /tmp/modsecurity/upload; \ + mkdir -p /tmp/modsecurity/tmp; \ + mkdir -p /usr/local/modsecurity; \ + # Comment out the SecDisableBackendCompression option since it is not supported in V3 + sed -i 's/^\(SecDisableBackendCompression .*\)/# \1/' /usr/local/openresty/nginx/templates/modsecurity.d/modsecurity-override.conf.template; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ + ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC3_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ + ln -sv /opt/owasp-crs /etc/modsecurity.d/; \ + chmod -R g=u /var/log/ /var/run/ /usr/local/openresty/nginx/ /etc/modsecurity.d/ + +EXPOSE 80 + +HEALTHCHECK CMD /usr/local/bin/healthcheck + +# The Openresty image is not based on the nginx image. +# This Dockerfile integrates the docker-entrypoint and envsubst logic from there into here. +ENTRYPOINT ["/docker-entrypoint.sh"] + +CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"] diff --git a/openresty/docker-entrypoint.d/20-envsubst-on-templates.sh b/openresty/docker-entrypoint.d/20-envsubst-on-templates.sh new file mode 100755 index 00000000..b90d9a9c --- /dev/null +++ b/openresty/docker-entrypoint.d/20-envsubst-on-templates.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +set -e + +ME=$(basename $0) + +entrypoint_log() { + if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then + echo "$@" + fi +} + +auto_envsubst() { + local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/usr/local/openresty/nginx/templates}" + local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" + local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/usr/local/openresty/nginx/conf}" + local filter="${NGINX_ENVSUBST_FILTER:-}" + + local template defined_envs relative_path output_path subdir + defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null )) + [ -d "$template_dir" ] || return 0 + if [ ! -w "$output_dir" ]; then + entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable" + return 0 + fi + find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do + relative_path="${template#$template_dir/}" + output_path="$output_dir/${relative_path%$suffix}" + subdir=$(dirname "$relative_path") + # create a subdirectory where the template file exists + mkdir -p "$output_dir/$subdir" + entrypoint_log "$ME: Running envsubst on $template to $output_path" + envsubst "$defined_envs" < "$template" > "$output_path" + done +} + +auto_envsubst + +exit 0 diff --git a/openresty/docker-entrypoint.d/25-listen-on-ipv6-by-default.sh b/openresty/docker-entrypoint.d/25-listen-on-ipv6-by-default.sh new file mode 100755 index 00000000..8c75c997 --- /dev/null +++ b/openresty/docker-entrypoint.d/25-listen-on-ipv6-by-default.sh @@ -0,0 +1,67 @@ +#!/bin/sh +# vim:sw=4:ts=4:et + +set -e + +entrypoint_log() { + if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then + echo "$@" + fi +} + +ME=$(basename $0) +DEFAULT_CONF_FILE="usr/local/openresty/nginx/conf/conf.d/default.conf" + +# check if we have ipv6 available +if [ ! -f "/proc/net/if_inet6" ]; then + entrypoint_log "$ME: info: ipv6 not available" + exit 0 +fi + +if [ ! -f "/$DEFAULT_CONF_FILE" ]; then + entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist" + exit 0 +fi + +# check if the file can be modified, e.g. not on a r/o filesystem +touch /$DEFAULT_CONF_FILE 2>/dev/null || { entrypoint_log "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; } + +# check if the file is already modified, e.g. on a container restart +grep -q "listen \[::]\:80;" /$DEFAULT_CONF_FILE && { entrypoint_log "$ME: info: IPv6 listen already enabled"; exit 0; } + +if [ -f "/etc/os-release" ]; then + . /etc/os-release +else + entrypoint_log "$ME: info: can not guess the operating system" + exit 0 +fi + +entrypoint_log "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE" + +case "$ID" in + "debian") + CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3) + echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || { + entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version" + exit 0 + } + ;; + "alpine") + CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2) + echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || { + entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version" + exit 0 + } + ;; + *) + entrypoint_log "$ME: info: Unsupported distribution" + exit 0 + ;; +esac + +# enable ipv6 on default.conf listen sockets +sed -i -E 's,listen 80;,listen 80;\n listen [::]:80;,' /$DEFAULT_CONF_FILE + +entrypoint_log "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE" + +exit 0 diff --git a/openresty/docker-entrypoint.d/30-tune-worker-processes.sh b/openresty/docker-entrypoint.d/30-tune-worker-processes.sh new file mode 100755 index 00000000..6314e52e --- /dev/null +++ b/openresty/docker-entrypoint.d/30-tune-worker-processes.sh @@ -0,0 +1,188 @@ +#!/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 + +[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0 + +touch /usr/local/openresty/nginx/nginx.conf 2>/dev/null || { echo >&2 "$ME: error: can not modify /usr/local/openresty/nginx/nginx.conf (read-only file system?)"; exit 0; } + +ceildiv() { + num=$1 + div=$2 + echo $(( (num + div - 1) / div )) +} + +get_cpuset() { + cpusetroot=$1 + cpusetfile=$2 + ncpu=0 + [ -f "$cpusetroot/$cpusetfile" ] || return 1 + for token in $( tr ',' ' ' < "$cpusetroot/$cpusetfile" ); do + case "$token" in + *-*) + count=$( seq $(echo "$token" | tr '-' ' ') | wc -l ) + ncpu=$(( ncpu+count )) + ;; + *) + ncpu=$(( ncpu+1 )) + ;; + esac + done + echo "$ncpu" +} + +get_quota() { + cpuroot=$1 + ncpu=0 + [ -f "$cpuroot/cpu.cfs_quota_us" ] || return 1 + [ -f "$cpuroot/cpu.cfs_period_us" ] || return 1 + cfs_quota=$( cat "$cpuroot/cpu.cfs_quota_us" ) + cfs_period=$( cat "$cpuroot/cpu.cfs_period_us" ) + [ "$cfs_quota" = "-1" ] && return 1 + [ "$cfs_period" = "0" ] && return 1 + ncpu=$( ceildiv "$cfs_quota" "$cfs_period" ) + [ "$ncpu" -gt 0 ] || return 1 + echo "$ncpu" +} + +get_quota_v2() { + cpuroot=$1 + ncpu=0 + [ -f "$cpuroot/cpu.max" ] || return 1 + cfs_quota=$( cut -d' ' -f 1 < "$cpuroot/cpu.max" ) + cfs_period=$( cut -d' ' -f 2 < "$cpuroot/cpu.max" ) + [ "$cfs_quota" = "max" ] && return 1 + [ "$cfs_period" = "0" ] && return 1 + ncpu=$( ceildiv "$cfs_quota" "$cfs_period" ) + [ "$ncpu" -gt 0 ] || return 1 + echo "$ncpu" +} + +get_cgroup_v1_path() { + needle=$1 + found= + foundroot= + mountpoint= + + [ -r "/proc/self/mountinfo" ] || return 1 + [ -r "/proc/self/cgroup" ] || return 1 + + while IFS= read -r line; do + case "$needle" in + "cpuset") + case "$line" in + *cpuset*) + found=$( echo "$line" | cut -d ' ' -f 4,5 ) + break + ;; + esac + ;; + "cpu") + case "$line" in + *cpuset*) + ;; + *cpu,cpuacct*|*cpuacct,cpu|*cpuacct*|*cpu*) + found=$( echo "$line" | cut -d ' ' -f 4,5 ) + break + ;; + esac + esac + done << __EOF__ +$( grep -F -- '- cgroup ' /proc/self/mountinfo ) +__EOF__ + + while IFS= read -r line; do + controller=$( echo "$line" | cut -d: -f 2 ) + case "$needle" in + "cpuset") + case "$controller" in + cpuset) + mountpoint=$( echo "$line" | cut -d: -f 3 ) + break + ;; + esac + ;; + "cpu") + case "$controller" in + cpu,cpuacct|cpuacct,cpu|cpuacct|cpu) + mountpoint=$( echo "$line" | cut -d: -f 3 ) + break + ;; + esac + ;; + esac +done << __EOF__ +$( grep -F -- 'cpu' /proc/self/cgroup ) +__EOF__ + + case "${found%% *}" in + "/") + foundroot="${found##* }$mountpoint" + ;; + "$mountpoint") + foundroot="${found##* }" + ;; + esac + echo "$foundroot" +} + +get_cgroup_v2_path() { + found= + foundroot= + mountpoint= + + [ -r "/proc/self/mountinfo" ] || return 1 + [ -r "/proc/self/cgroup" ] || return 1 + + while IFS= read -r line; do + found=$( echo "$line" | cut -d ' ' -f 4,5 ) + done << __EOF__ +$( grep -F -- '- cgroup2 ' /proc/self/mountinfo ) +__EOF__ + + while IFS= read -r line; do + mountpoint=$( echo "$line" | cut -d: -f 3 ) +done << __EOF__ +$( grep -F -- '0::' /proc/self/cgroup ) +__EOF__ + + case "${found%% *}" in + "") + return 1 + ;; + "/") + foundroot="${found##* }$mountpoint" + ;; + "$mountpoint" | /../*) + foundroot="${found##* }" + ;; + esac + echo "$foundroot" +} + +ncpu_online=$( getconf _NPROCESSORS_ONLN ) +ncpu_cpuset= +ncpu_quota= +ncpu_cpuset_v2= +ncpu_quota_v2= + +cpuset=$( get_cgroup_v1_path "cpuset" ) && ncpu_cpuset=$( get_cpuset "$cpuset" "cpuset.effective_cpus" ) || ncpu_cpuset=$ncpu_online +cpu=$( get_cgroup_v1_path "cpu" ) && ncpu_quota=$( get_quota "$cpu" ) || ncpu_quota=$ncpu_online +cgroup_v2=$( get_cgroup_v2_path ) && ncpu_cpuset_v2=$( get_cpuset "$cgroup_v2" "cpuset.cpus.effective" ) || ncpu_cpuset_v2=$ncpu_online +cgroup_v2=$( get_cgroup_v2_path ) && ncpu_quota_v2=$( get_quota_v2 "$cgroup_v2" ) || ncpu_quota_v2=$ncpu_online + +ncpu=$( printf "%s\n%s\n%s\n%s\n%s\n" \ + "$ncpu_online" \ + "$ncpu_cpuset" \ + "$ncpu_quota" \ + "$ncpu_cpuset_v2" \ + "$ncpu_quota_v2" \ + | sort -n \ + | head -n 1 ) + +sed -i.bak -r 's/^(worker_processes)(.*)$/# Commented out by '"$ME"' on '"$(date)"'\n#\1\2\n\1 '"$ncpu"';/' /usr/local/openresty/nginx/nginx.conf diff --git a/openresty/docker-entrypoint.d/90-copy-modsecurity-config.sh b/openresty/docker-entrypoint.d/90-copy-modsecurity-config.sh new file mode 100755 index 00000000..162b530e --- /dev/null +++ b/openresty/docker-entrypoint.d/90-copy-modsecurity-config.sh @@ -0,0 +1,14 @@ +#!/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 + +touch /etc/modsecurity.d/modsecurity-override.conf 2>/dev/null || { echo >&2 "$ME: error: can not modify /etc/modsecurity.d/modsecurity-override.conf (read-only file system?)"; exit 1; } + +cp /usr/local/openresty/nginx/conf/modsecurity.d/*.conf /etc/modsecurity.d 2>/dev/null || { echo >&2 "$ME: error: cannot copy config files to /etc/modsecurity.d"; exit 2; } + +exit 0 diff --git a/openresty/docker-entrypoint.d/91-update-resolver.sh b/openresty/docker-entrypoint.d/91-update-resolver.sh new file mode 100755 index 00000000..5ddb6b45 --- /dev/null +++ b/openresty/docker-entrypoint.d/91-update-resolver.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 + +DNS_SERVER="${DNS_SERVER:-$(grep -i '^nameserver' /etc/resolv.conf | head -n1 | cut -d ' ' -f2)}" + +sed -i.bak -r 's/DNS_SERVER/'"${DNS_SERVER}"'/' /usr/local/openresty/nginx/conf/nginx.conf diff --git a/openresty/docker-entrypoint.d/92-update-real_ip.sh b/openresty/docker-entrypoint.d/92-update-real_ip.sh new file mode 100755 index 00000000..74caf2be --- /dev/null +++ b/openresty/docker-entrypoint.d/92-update-real_ip.sh @@ -0,0 +1,13 @@ +#!/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 + +# split comma separated IP addresses into multiple `set_real_ip xxx;` lines +SET_REAL_IP_FROM="$(echo "${SET_REAL_IP_FROM}" | awk -F, '{for(i=1; i<=NF; i++) printf "set_real_ip_from "$i";\\n"}')" + +sed -i.bak -r 's#SET_REAL_IP_FROM#'"${SET_REAL_IP_FROM}"'#' /usr/local/openresty/nginx/conf/includes/proxy_backend.conf diff --git a/openresty/docker-entrypoint.sh b/openresty/docker-entrypoint.sh new file mode 100755 index 00000000..cc1335de --- /dev/null +++ b/openresty/docker-entrypoint.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# vim:sw=4:ts=4:et + +set -e + +entrypoint_log() { + if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then + echo "$@" + fi +} + +if [ "$1" = "/usr/local/openresty/bin/openresty" ]; then + if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then + entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration" + + entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/" + find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do + case "$f" in + *.envsh) + if [ -x "$f" ]; then + entrypoint_log "$0: Sourcing $f"; + . "$f" + else + # warn on shell scripts without exec bit + entrypoint_log "$0: Ignoring $f, not executable"; + fi + ;; + *.sh) + if [ -x "$f" ]; then + entrypoint_log "$0: Launching $f"; + "$f" + else + # warn on shell scripts without exec bit + entrypoint_log "$0: Ignoring $f, not executable"; + fi + ;; + *) entrypoint_log "$0: Ignoring $f";; + esac + done + + entrypoint_log "$0: Configuration complete; ready for start up" + else + entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration" + fi +fi + +exec "$@" diff --git a/openresty/openssl.conf b/openresty/openssl.conf new file mode 100644 index 00000000..560223af --- /dev/null +++ b/openresty/openssl.conf @@ -0,0 +1,15 @@ +[req] +default_bits=4096 +encrypt_key=no +default_md=sha256 +distinguished_name=req_sub +prompt=no + +[req_sub] +commonName="localhost" +emailAddress="none@none.com" +countryName="US" +stateOrProvinceName="NY" +localityName="NY" +organizationName="MyOrg" +organizationalUnitName="MyUnit" diff --git a/openresty/templates/nginx.conf.template b/openresty/templates/nginx.conf.template new file mode 100644 index 00000000..9031e654 --- /dev/null +++ b/openresty/templates/nginx.conf.template @@ -0,0 +1,32 @@ +# nginx.conf -- docker-openresty-modsecurity-crs + +# Enables the use of JIT for regular expressions to speed-up their processing. +pcre_jit on; + +load_module modules/ngx_http_modsecurity_module.so; + +worker_processes auto; +pid /var/run/nginx.pid; + +events { + worker_connections ${WORKER_CONNECTIONS}; +} + +http { + include /usr/local/openresty/nginx/conf/mime.types; + default_type application/octet-stream; + keepalive_timeout ${KEEPALIVE_TIMEOUT}; + sendfile on; + + # Openresty specific paths. + client_body_temp_path /var/run/openresty/nginx-client-body; + proxy_temp_path /var/run/openresty/nginx-proxy; + fastcgi_temp_path /var/run/openresty/nginx-fastcgi; + uwsgi_temp_path /var/run/openresty/nginx-uwsgi; + scgi_temp_path /var/run/openresty/nginx-scgi; + + resolver DNS_SERVER valid=5s; + # Load the specific files from /usr/local/openresty folder instead of /etc/nginx + # Simplifies the usage of envsubst. Otherwise we need to two template output folders. + include /usr/local/openresty/nginx/conf/conf.d/*.conf; +} diff --git a/src/etc/modsecurity.d/modsecurity-override.conf b/src/etc/modsecurity.d/modsecurity-override.conf index cc797772..461c667a 100644 --- a/src/etc/modsecurity.d/modsecurity-override.conf +++ b/src/etc/modsecurity.d/modsecurity-override.conf @@ -1,5 +1,5 @@ # Original of the latest recommended version: -# https://github.com/SpiderLabs/ModSecurity/blob/v3/master/modsecurity.conf-recommended +# https://github.com/owasp-modsecurity/ModSecurity/blob/v3/master/modsecurity.conf-recommended SecArgumentSeparator & SecAuditEngine ${MODSEC_AUDIT_ENGINE}