├── .github ├── dependabot.yml └── workflows │ ├── dispatcher.yml │ ├── dockerimage.yml │ └── verifyimage.yml ├── LICENSE ├── README.md ├── docker-bake.hcl ├── docker-compose.yml ├── src ├── bin │ └── healthcheck └── etc │ └── modsecurity.d │ ├── modsecurity-override.conf │ └── setup.conf ├── v2-apache ├── Dockerfile ├── Dockerfile-alpine ├── conf │ └── extra │ │ ├── httpd-locations.conf │ │ ├── httpd-modsecurity.conf │ │ ├── httpd-ssl.conf │ │ └── httpd-vhosts.conf └── openssl.conf └── v3-nginx ├── Dockerfile ├── Dockerfile-alpine ├── docker-entrypoint.d ├── 90-copy-modsecurity-config.sh ├── 91-update-resolver.sh └── 92-update-real_ip.sh ├── openssl.conf └── templates ├── conf.d ├── default.conf.template ├── logging.conf.template └── modsecurity.conf.template ├── includes ├── location_common.conf.template └── proxy_backend.conf.template ├── modsecurity.d └── .gitkeep └── nginx.conf.template /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Keep Dockerfile up to date, batching pull requests weekly 4 | - package_ecosystem: "docker" 5 | directory: "v2-apache/" 6 | schedule: 7 | interval: "weekly" 8 | # Keep Dockerfile up to date, batching pull requests weekly 9 | - package_ecosystem: "docker" 10 | directory: "v3-nginx/" 11 | schedule: 12 | interval: "weekly" 13 | -------------------------------------------------------------------------------- /.github/workflows/dispatcher.yml: -------------------------------------------------------------------------------- 1 | name: Test all platforms 2 | on: 3 | workflow_dispatch: 4 | 5 | env: 6 | REPO: "owasp/modsecurity" 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | image: ["apache", "nginx"] 14 | variant: ["", "-alpine"] 15 | platform: ["linux/amd64", "linux/arm64/v8", "linux/arm/v7", "linux/i386"] 16 | include: 17 | - image: apache 18 | modsec_version: "2.9.6" 19 | - image: nginx 20 | modsec_version: "3.0.8" 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v3 24 | with: 25 | fetch-depth: 1 26 | 27 | # https://github.com/docker/setup-qemu-action 28 | - name: Set up QEMU 29 | uses: docker/setup-qemu-action@v2 30 | 31 | # https://github.com/docker/setup-buildx-action 32 | - name: Set up Docker Buildx 33 | uses: docker/setup-buildx-action@v2 34 | with: 35 | driver-opts: image=moby/buildkit:master 36 | 37 | - name: Docker meta ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.modsec_version }} 38 | id: meta 39 | uses: docker/metadata-action@v4 40 | with: 41 | images: | 42 | ${{ env.REPO }} 43 | flavor: | 44 | latest=false 45 | tags: | 46 | type=raw,value=${{ matrix.image }}${{ matrix.variant }} 47 | type=semver,pattern={{major}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 48 | type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 49 | type=semver,pattern={{version}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 50 | 51 | - name: Build ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.platform }} 52 | uses: docker/bake-action@v2.2.0 53 | with: 54 | files: | 55 | ./docker-bake.hcl 56 | ${{ steps.meta.outputs.bake-file }} 57 | targets: ${{ matrix.image }}${{ matrix.variant }} 58 | set: | 59 | "${{ matrix.image }}${{ matrix.variant }}.platform=${{ matrix.platform }}" 60 | "${{ matrix.image }}${{ matrix.variant }}.args.MODSEC_VERSION=${{ matrix.modsec_version }}" 61 | pull: true 62 | load: true 63 | 64 | - name: Run ${{ matrix.image }}${{ matrix.variant }} 65 | run: | 66 | TAG=$(docker image inspect -f '{{ json .RepoTags }}' ${{ env.REPO }}:${{ matrix.image }}${{ matrix.variant }} | jq -r '.[0]') 67 | echo "Starting container with TAG=$TAG" 68 | docker run --pull "never" -d --name ${{ matrix.image }}${{ matrix.variant }}-test "$TAG" 69 | docker logs ${{ matrix.image }}${{ matrix.variant }}-test 70 | 71 | - name: Verify ${{ matrix.image }}${{ matrix.variant }} 72 | run: | 73 | docker logs "${{ matrix.image }}${{ matrix.variant }}-test" 74 | [ $(docker inspect ${{ matrix.image }}${{ matrix.variant }}-test --format='{{.State.Running}}') = 'true' ] 75 | -------------------------------------------------------------------------------- /.github/workflows/dockerimage.yml: -------------------------------------------------------------------------------- 1 | name: Build images for Docker Hub 2 | on: 3 | push: 4 | branches: 5 | - master 6 | workflow_dispatch: 7 | inputs: 8 | logLevel: 9 | description: 'Log level' 10 | required: true 11 | default: 'warning' 12 | type: choice 13 | options: 14 | - info 15 | - warning 16 | - debug 17 | env: 18 | REPO: "owasp/modsecurity" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | image: ["apache", "nginx"] 26 | variant: ["", "-alpine"] 27 | include: 28 | - image: apache 29 | modsec_version: "2.9.6" 30 | - image: nginx 31 | modsec_version: "3.0.8" 32 | platform: 33 | - linux/amd64 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v3 37 | with: 38 | fetch-depth: 1 39 | 40 | # https://github.com/docker/setup-qemu-action 41 | - name: Set up QEMU 42 | uses: docker/setup-qemu-action@v2 43 | 44 | # https://github.com/docker/setup-buildx-action 45 | - name: Set up Docker Buildx 46 | uses: docker/setup-buildx-action@v2 47 | with: 48 | driver-opts: image=moby/buildkit:master 49 | 50 | - name: Login to DockerHub 51 | uses: docker/login-action@v2 52 | with: 53 | username: ${{ secrets.dockerhub_user }} 54 | password: ${{ secrets.dockerhub_token }} 55 | 56 | - name: Docker meta ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.modsec_version }} 57 | id: meta 58 | uses: docker/metadata-action@v4 59 | with: 60 | images: | 61 | ${{ env.REPO }} 62 | flavor: | 63 | latest=false 64 | tags: | 65 | type=raw,value=${{ matrix.image }}${{ matrix.variant }} 66 | type=semver,pattern={{major}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 67 | type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 68 | type=semver,pattern={{version}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 69 | 70 | - name: Build and push ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.modsec_version }} 71 | uses: docker/bake-action@v2.2.0 72 | with: 73 | targets: ${{ matrix.image }}${{ matrix.variant }} 74 | set: | 75 | "${{ matrix.image }}${{ matrix.variant }}.args.MODSEC_VERSION=${{ matrix.modsec_version }}" 76 | files: | 77 | ./docker-bake.hcl 78 | ${{ steps.meta.outputs.bake-file }} 79 | push: true 80 | -------------------------------------------------------------------------------- /.github/workflows/verifyimage.yml: -------------------------------------------------------------------------------- 1 | name: Verify Images 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | - develop 7 | 8 | env: 9 | REPO: "owasp/modsecurity" 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | image: ["apache", "nginx"] 17 | variant: ["", "-alpine"] 18 | platform: ["linux/amd64"] 19 | include: 20 | - image: apache 21 | modsec_version: "2.9.6" 22 | - image: nginx 23 | modsec_version: "3.0.8" 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v3 27 | with: 28 | fetch-depth: 1 29 | 30 | # https://github.com/docker/setup-qemu-action 31 | - name: Set up QEMU 32 | uses: docker/setup-qemu-action@v2 33 | 34 | # https://github.com/docker/setup-buildx-action 35 | - name: Set up Docker Buildx 36 | uses: docker/setup-buildx-action@v2 37 | with: 38 | driver-opts: image=moby/buildkit:master 39 | 40 | - name: Docker meta ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.modsec_version }} 41 | id: meta 42 | uses: docker/metadata-action@v4 43 | with: 44 | images: | 45 | ${{ env.REPO }} 46 | flavor: | 47 | latest=false 48 | tags: | 49 | type=raw,value=${{ matrix.image }}${{ matrix.variant }} 50 | type=semver,pattern={{major}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 51 | type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 52 | type=semver,pattern={{version}},value=v${{ matrix.modsec_version }},suffix=-{{date 'YYYYMMDDHHMM'}} 53 | 54 | - name: Build ${{ matrix.image }}${{ matrix.variant }} - ${{ matrix.platform }} 55 | uses: docker/bake-action@v2.2.0 56 | with: 57 | files: | 58 | ./docker-bake.hcl 59 | ${{ steps.meta.outputs.bake-file }} 60 | targets: ${{ matrix.image }}${{ matrix.variant }} 61 | set: | 62 | "${{ matrix.image }}${{ matrix.variant }}.platform=${{ matrix.platform }}" 63 | "${{ matrix.image }}${{ matrix.variant }}.args.MODSEC_VERSION=${{ matrix.modsec_version }}" 64 | pull: true 65 | load: true 66 | 67 | - name: Run ${{ matrix.image }}${{ matrix.variant }} 68 | run: | 69 | TAG=$(docker image inspect -f '{{ json .RepoTags }}' ${{ env.REPO }}:${{ matrix.image }}${{ matrix.variant }} | jq -r '.[0]') 70 | echo "Starting container with TAG=$TAG" 71 | docker run --pull "never" -d --name ${{ matrix.image }}${{ matrix.variant }}-test "$TAG" 72 | docker logs ${{ matrix.image }}${{ matrix.variant }}-test 73 | 74 | - name: Verify ${{ matrix.image }}${{ matrix.variant }} 75 | run: | 76 | docker logs "${{ matrix.image }}${{ matrix.variant }}-test" 77 | [ $(docker inspect ${{ matrix.image }}${{ matrix.variant }}-test --format='{{.State.Running}}') = 'true' ] 78 | while true 79 | do 80 | STATUS=$(docker inspect ${{ matrix.image }}${{ matrix.variant }}-test --format='{{.State.Health.Status}}') 81 | case ${STATUS} in 82 | healthy) 83 | echo "$(date -u) Healthy!!!" 84 | sleep 1 85 | exit 0;; 86 | unhealthy) 87 | echo "$(date -u) Unhealthy!!!" 88 | sleep 1 89 | exit 9;; 90 | starting) 91 | echo "$(date -u) starting!!!";; 92 | *) 93 | echo "Huh? ${STATUS}" 94 | sleep 1 95 | exit 10;; 96 | esac 97 | sleep 1 98 | done 99 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ModSecurity Docker Image 2 | 3 | > **Note** 4 | > 5 | > ⚠️ This repository has been archived. 6 | > 7 | > We used to build `owasp/modsecurity-crs` via `owasp/modsecurity` (this repository), but it has become error prone and cumbersome. We have opted to merge the two repositories and will no longer build `owasp/modescurity`. 8 | > 9 | > Please visit https://github.com/coreruleset/modsecurity-crs-docker. 10 | 11 | 12 | [![dockeri.co](http://dockeri.co/image/owasp/modsecurity)](https://hub.docker.com/r/owasp/modsecurity/) 13 | 14 | [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fcoreruleset%2Fmodsecurity-docker%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/coreruleset/modsecurity-docker/goto?ref=master 15 | ) [![GitHub issues](https://img.shields.io/github/issues-raw/coreruleset/modsecurity-docker.svg)](https://github.com/coreruleset/modsecurity-docker/issues 16 | ) [![GitHub PRs](https://img.shields.io/github/issues-pr-raw/coreruleset/modsecurity-docker.svg)](https://github.com/coreruleset/modsecurity-docker/pulls 17 | ) [![License](https://img.shields.io/github/license/coreruleset/modsecurity-docker.svg)](https://github.com/coreruleset/modsecurity-docker/blob/master/LICENSE) 18 | 19 | ## Supported tags and respective `Dockerfile` links 20 | 21 | * `3-YYYYMMDDHHMM`, `3.0-YYYYMMDDHHMM`, `3.0.8-YYYYMMDDHHMM`, `nginx` ([master/v3-nginx/Dockerfile](https://github.com/coreruleset/modsecurity-docker/blob/master/v3-nginx/Dockerfile)) – *last stable ModSecurity v3 on Nginx 1.22 official stable base image* 22 | * `2-YYYYMMDDHHMM`, `2.9-YYYYMMDDHHMM`, `2.9.6-YYYYMMDDHHMM`, `apache` ([master/v2-apache/Dockerfile](https://github.com/coreruleset/modsecurity-docker/blob/master/v2-apache/Dockerfile)) – *last stable ModSecurity v2 on Apache 2.4 official stable base image* 23 | 24 | ⚠️ 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:nginx` or `owasp/modsecurity:apache`. If you need a stable long term image, use the one with the build date in `YYYYMMDDHHMM` format, example `owasp/modsecurity:3-202209141209` or `owasp/modsecurity:2.9.6-alpine-202209141209` for example. You have been warned. 25 | 26 | 🆕 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 https://docs.docker.com/engine/reference/builder/#healthcheck for more information. 27 | 28 | ## Supported variants 29 | 30 | We have support for [alpine linux](https://www.alpinelinux.org/) variants of the base images. Just add `-alpine` and you will get it. Examples: 31 | 32 | * `3-alpine-YYYYMMDDHHMM`, `3.0-alpine-YYYYMMDDHHMM`, `3.0.8-alpine-YYYYMMDDHHMM`, `nginx-alpine` ([master/v3-nginx/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-docker/blob/master/v3-nginx/Dockerfile-alpine) – *last stable ModSecurity v3 on Nginx 1.22 Alpine official stable base image* 33 | * `2-alpine-YYYYMMDDHHMM`, `2.9-alpine-YYYYMMDDHHMM`, `2.9.6-alpine-YYYYMMDDHHMM`, `apache-alpine` ([master/v2-apache/Dockerfile-alpine](https://github.com/coreruleset/modsecurity-docker/blob/master/v2-apache/Dockerfile-alpine)) – *last stable ModSecurity v2 on Apache 2.4 Alpine official stable base image* 34 | 35 | ⚠️ 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:nginx-alpine` or `owasp/modsecurity:apache-alpine`. If you need a stable long term image, use the one with the build date in `YYYYMMDDHHMM` format, example `owasp/modsecurity:3-202209141209-alpine` or `owasp/modsecurity:2.9.6-202209141209` for example. You have been warned. 36 | 37 | ## Supported architectures 38 | 39 | 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. 40 | 41 | There is a new file `docker-bake.hcl` used for this purpose. To build for new platforms, just use this example: 42 | 43 | ```bash 44 | $ docker buildx use $(docker buildx create --platform linux/amd64,linux/arm64,linux/arm/v8) 45 | $ docker buildx bake -f docker-bake.hcl 46 | ``` 47 | 48 | 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: 49 | ``` 50 | docker buildx version 51 | github.com/docker/buildx v0.9.1 ed00243a0ce2a0aee75311b06e32d33b44729689 52 | ``` 53 | 54 | If you want to see the targets of the build, use: 55 | ``` 56 | docker buildx bake -f ./docker-bake.hcl --print 57 | ``` 58 | 59 | We are building now for these architectures: 60 | - linux/amd64 61 | - linux/i386 62 | - linux/arm64 63 | - linux/arm/v7 64 | 65 | You can find additional examples on how to use `buildx` in this repository's GitHub actions. 66 | 67 | ## Quick reference 68 | 69 | * **Where to get help**: the [CRS-Support Docker Repo](https://github.com/coreruleset/modsecurity-docker), the [Core Rule Set Slack Channel](https://join.slack.com/t/owasp/shared_invite/enQtNjExMTc3MTg0MzU4LTViMDg1MmJiMzMwZGUxZjgxZWQ1MTE0NTBlOTBhNjhhZDIzZTZiNmEwOTJlYjdkMzAxMGVhNDkwNDNiNjZiOWQ) (#coreruleset on owasp.slack.com), or [Stack Overflow](https://stackoverflow.com/questions/tagged/mod-security) 70 | 71 | * **Where to file issues**: the [Core Rule Set Docker Repo](https://github.com/coreruleset/modsecurity-docker) 72 | 73 | * **Maintained By**: The Core Rule Set Project maintainers 74 | 75 | ## What is ModSecurity 76 | 77 | ModSecurity is an open source, cross platform Web Application Firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis. 78 | 79 | ## How to use this image 80 | 81 | This image only contains ModSecurity built from the code provided on the [ModSecurity Github Repo](https://github.com/SpiderLabs/ModSecurity). **THE CORE RULE SET IS NOT PROVIDED IN THIS IMAGE**, but it should not be hard to extend. On the other hand, **IF YOU WANT MODSECURITY WITH THE CORE RULE SET please visit the [OWASP Core Rule Set (CRS) DockerHub Repo](https://hub.docker.com/r/owasp/modsecurity-crs/)**. 82 | 83 | 1. Create a Dockerfile in your project and copy your code into container. 84 | ``` 85 | FROM owasp/modsecurity:apache 86 | COPY ./public-html/ . 87 | ``` 88 | 89 | 2. run the commands to build and run the Docker image. 90 | ``` 91 | $ docker build -t my-modsec . 92 | $ docker run -p 8080:80 my-modsec 93 | ``` 94 | 95 | 3. Visit http://localhost:8080 and your page. 96 | 97 | ### Nginx based images breaking change 98 | 99 | | ⚠️ WARNING | 100 | |:---------------------------| 101 | | Nginx based images are now based on upstream nginx. This changed the way the config file for nginx is generated. | 102 | 103 | If using the [Nginx environment variables](https://github.com/coreruleset/modsecurity-docker#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. 104 | 105 | An example can be seen in the [docker-compose](https://github.com/coreruleset/modsecurity-docker/blob/master/docker-compose.yml) file. 106 | 107 | > 💬 What happens if I want to make changes in a different file, like `/etc/nginx/conf.d/default.conf`? 108 | > 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. 109 | 110 | ### TLS/HTTPS 111 | 112 | The TLS is configured by default on port 443. Note: The default configuration uses self signed certificates, to use your own certificates (recommended) COPY or mount (-v) your server.crt and server.key into `/usr/local/apache2/conf/`. Please remember you'll need to forward the HTTPS port. 113 | 114 | ``` 115 | $ docker build -t my-modsec . 116 | $ docker run -p 8443:443 my-modsec 117 | ``` 118 | 119 | 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. 120 | 121 | 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). 122 | 123 | ### Proxying 124 | 125 | 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. 126 | 127 | ``` 128 | $ docker build -t my-modsec . -f 129 | $ docker run -p 8080:80 -e PROXY_SSL=on -e BACKEND=http://example.com my-modsec 130 | ``` 131 | 132 | ### ServerName 133 | 134 | 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`. 135 | ``` 136 | $ docker build -t modsec . 137 | $ docker run -p 8080:80 -e SERVER_NAME=myhost my-modsec 138 | ``` 139 | 140 | ### Apache ENV Variables 141 | 142 | | Name | Description| 143 | | -------- | ------------------------------------------------------------------- | 144 | | ACCESSLOG | A string value indicating the location of the custom log file (Default: `/var/log/apache2/access.log`) | 145 | | APACHE_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | 146 | | 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. | 147 | | 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. | 148 | | BACKEND | A string indicating the partial URL for the remote server of the `ProxyPass` directive (Default: `http://localhost:80`) | 149 | | BACKEND_WS | A string indicating the IP/URL of the WebSocket service (Default: `ws://localhost:8080`) | 150 | | ERRORLOG | A string value indicating the location of the error log file (Default: `/var/log/apache2/error.log`) | 151 | | H2_PROTOCOLS | A string value indicating the protocols supported by the HTTP2 module (Default: `h2 http/1.1`) | 152 | | LOGLEVEL | A string value controlling the number of messages logged to the error_log (Default: `warn`) | 153 | | 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`) | 154 | | METRICS_DENY_FROM | A string indicating a range of IP adresses that cannot access the metrics (Default: `All`) | 155 | | METRICSLOG | A string indicating the path of the metrics log (Default: `/dev/null`) | 156 | | PORT | An integer value indicating the port where the webserver is listening to (Default: `80`) | 157 | | 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`) | 158 | | PROXY_PRESERVE_HOST | A string indicating the use of incoming Host HTTP request header for proxy request (Default: `on`) | 159 | | PROXY_SSL_CERT_KEY | A string indicating the path to the server PEM-encoded private key file (Default: `/usr/local/apache2/conf/server.key`) | 160 | | 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`) | 161 | | PROXY_SSL_CHECK_PEER_NAME | A string indicating if the host name checking for remote server certificates is to be enabled (Default: `on`) | 162 | | PROXY_SSL_VERIFY | A string value indicating the type of remote server Certificate verification (Default: `none`) | 163 | | PROXY_SSL | A string indicating SSL Proxy Engine Operation Switch (Default: `off`) | 164 | | PROXY_TIMEOUT | Number of seconds for proxied requests to time out (Default: `60`) | 165 | | REMOTEIP_INT_PROXY | A string indicating the client intranet IP addresses trusted to present the RemoteIPHeader value (Default: `10.1.0.0/16`) | 166 | | REQ_HEADER_FORWARDED_PROTO | A string indicating the transfer protocol of the initial request (Default: `https`) | 167 | | SERVER_ADMIN | A string value indicating the address where problems with the server should be e-mailed (Default: `root@localhost`) | 168 | | SERVER_NAME | A string value indicating the server name (Default: `localhost`) | 169 | | 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"` | 170 | | SSL_ENGINE | A string indicating the SSL Engine Operation Switch (Default: `off`) | 171 | | 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`) | 172 | | SSL_PORT | Port number where the SSL enabled webserver is listening (Default: `443`) | 173 | | 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"`) | 174 | | 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"`) | 175 | | 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"` | 176 | | 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`) | 177 | | 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`) | 178 | | TIMEOUT | Number of seconds before receiving and sending timeout (Default: `60`) | 179 | | WORKER_CONNECTIONS | Maximum number of MPM request worker processes (Default: `400`) | 180 | 181 | 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`. 182 | 183 | ### Nginx ENV Variables 184 | 185 | | Name | Description| 186 | | -------- | ------------------------------------------------------------------- | 187 | | ACCESSLOG | A string value indicating the location of the access log file (Default: `/var/log/nginx/access.log`) | 188 | | BACKEND | A string indicating the partial URL for the remote server of the `proxy_pass` directive (Default: `http://localhost:80`) | 189 | | 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*) | 190 | | ERRORLOG | A string value indicating the location of the error log file (Default: `/proc/self/fd/2`) | 191 | | LOGLEVEL | A string value controlling the number of messages logged to the error_log (Default: `warn`) | 192 | | METRICS_ALLOW_FROM | A string indicating a single range of IP adresses that can access the metrics (Default: `127.0.0.0/24`) | 193 | | METRICS_DENY_FROM | A string indicating a range of IP adresses that cannot access the metrics (Default: `all`) | 194 | | METRICSLOG | A string value indicating the location of metrics log file (Default: `/dev/null`) | 195 | | NGINX_ALWAYS_TLS_REDIRECT | A string value indicating if http should redirect to https (Allowed values: `on`, `off`. Default: `off`) | 196 | | PORT | An integer value indicating the port where the webserver is listening to (Default: `80`) | 197 | | 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) | 198 | | 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) | 199 | | 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) | 200 | | 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`) | 201 | | PROXY_SSL_CERT_KEY | A string value indicating the path to the server PEM-encoded private key file (Default: `/etc/nginx/conf/server.key`) | 202 | | 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;`| 203 | | PROXY_SSL_DH_BITS | A numeric value indicating the size (in bits) to use for the generated DH-params file (Default 2048) | 204 | | PROXY_SSL_OCSP_STAPLING | A string value indicating if ssl_stapling and ssl_stapling_verify should be enabled (Allowed values: `on`, `off`. Default: `off`) | 205 | | 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`)| 206 | | PROXY_SSL_PROTOCOLS | A string value indicating the ssl protocols to enable (default: `TTLSv1.2 TLSv1.3`)| 207 | | PROXY_SSL_VERIFY | A string value indicating if the client certificates should be verified (Allowed values: `on`, `off`. Default: `off`) | 208 | | PROXY_TIMEOUT | Number of seconds for proxied requests to time out connections (Default: `60s`) | 209 | | SSL_PORT | Port number where the SSL enabled webserver is listening (Default: `443`) | 210 | | TIMEOUT | Number of seconds for a keep-alive client connection to stay open on the server side (Default: `60s`) | 211 | | WORKER_CONNECTIONS | Maximum number of simultaneous connections that can be opened by a worker process (Default: `1024`) | 212 | 213 | ### ModSecurity ENV Variables 214 | 215 | 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. 216 | 217 | | Name | Description| 218 | | -------- | ------------------------------------------------------------------- | 219 | | 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. | 220 | | MODSEC_AUDIT_LOG | A string indicating the path to the main audit log file or the concurrent logging index file (Default: `/dev/stdout`) | 221 | | 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. | 222 | | 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. | 223 | | 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. | 224 | | MODSEC_AUDIT_STORAGE | A string indicating the directory where concurrent audit log entries are to be stored (Default: `/var/log/modsecurity/audit/`) | 225 | | 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`) | 226 | | MODSEC_DEBUG_LOG | A string indicating the path to the ModSecurity debug log file (Default: `/dev/null`) | 227 | | 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). | 228 | | MODSEC_DISABLE_BACKEND_COMPRESSION | A string indicating whether or not to disable backend compression (Default: `Off`). 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 | 229 | | 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) | 230 | | MODSEC_PCRE_MATCH_LIMIT_RECURSION | An integer value indicating the limit for the depth of recursion when calling PCRE function (Default: `100000`) | 231 | | 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. | 232 | | 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. | 233 | | 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. | 234 | | 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. | 235 | | 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. | 236 | | 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. | 237 | | MODSEC_RESP_BODY_LIMIT | An integer value indicating the maximum response body size accepted for buffering (Default: `1048576`) | 238 | | 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. | 239 | | 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). | 240 | | 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. | 241 | | 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. | 242 | | MODSEC_TAG | A string indicating the default tag action, which will be inherited by the rules in the same configuration context (Default: `modsecurity`) | 243 | | MODSEC_TMP_DIR | A string indicating the path where temporary files will be created (Default: `/tmp/modsecurity/tmp`) | 244 | | MODSEC_TMP_SAVE_UPLOADED_FILES | A string indicating if temporary uploaded files are saved (Default: `On`) (only relevant in Apache - ModSecurity v2) | 245 | | MODSEC_UPLOAD_DIR | A string indicating the path where intercepted files will be stored (Default: `/tmp/modsecurity/upload`) | 246 | | 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}\''`) | 247 | | 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}\''`) | 248 | -------------------------------------------------------------------------------- /docker-bake.hcl: -------------------------------------------------------------------------------- 1 | # docker-bake.hcl 2 | variable "apache_modsec_version" { 3 | default = "2.9.6" 4 | } 5 | 6 | variable "nginx_modsec_version" { 7 | default = "3.0.8" 8 | } 9 | 10 | variable "REPO" { 11 | default = "owasp/modsecurity" 12 | } 13 | 14 | function "major" { 15 | params = [version] 16 | result = split(".", version)[0] 17 | } 18 | 19 | function "minor" { 20 | params = [version] 21 | result = join(".", slice(split(".", version),0,2)) 22 | } 23 | 24 | function "patch" { 25 | params = [version] 26 | result = join(".", slice(split(".", version),0,3)) 27 | } 28 | 29 | function "tag" { 30 | params = [tag] 31 | result = ["${REPO}:${tag}"] 32 | } 33 | 34 | function "vtag" { 35 | params = [semver, variant] 36 | result = concat( 37 | tag("${major(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), 38 | tag("${minor(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}"), 39 | tag("${patch(semver)}${variant}-${formatdate("YYYYMMDDHHMM", timestamp())}") 40 | ) 41 | } 42 | 43 | group "default" { 44 | targets = [ 45 | "apache", 46 | "apache-alpine", 47 | "nginx", 48 | "nginx-alpine" 49 | ] 50 | } 51 | 52 | target "docker-metadata-action" {} 53 | 54 | target "build" { 55 | inherits = ["docker-metadata-action"] 56 | context = "./" 57 | platforms = [ 58 | "linux/amd64", 59 | "linux/arm64/v8", 60 | "linux/arm/v7", 61 | "linux/i386" 62 | ] 63 | } 64 | 65 | target "apache" { 66 | inherits = ["build"] 67 | dockerfile="v2-apache/Dockerfile" 68 | tags = concat(tag("apache"), 69 | vtag("${apache_modsec_version}", "") 70 | ) 71 | args = { 72 | MODSEC_VERSION = "${apache_modsec_version}" 73 | } 74 | } 75 | 76 | target "apache-alpine" { 77 | inherits = ["build"] 78 | dockerfile="v2-apache/Dockerfile-alpine" 79 | tags = concat(tag("apache-alpine"), 80 | vtag("${apache_modsec_version}", "-alpine") 81 | ) 82 | args = { 83 | MODSEC_VERSION = "${apache_modsec_version}" 84 | } 85 | } 86 | 87 | target "nginx" { 88 | inherits = ["build"] 89 | dockerfile="v3-nginx/Dockerfile" 90 | tags = concat(tag("nginx"), 91 | vtag("${nginx_modsec_version}", "") 92 | ) 93 | args = { 94 | MODSEC_VERSION = "${nginx_modsec_version}" 95 | } 96 | } 97 | 98 | target "nginx-alpine" { 99 | inherits = ["build"] 100 | dockerfile="v3-nginx/Dockerfile-alpine" 101 | tags = concat(tag("nginx-alpine"), 102 | vtag("${nginx_modsec_version}", "-alpine") 103 | ) 104 | args = { 105 | MODSEC_VERSION = "${nginx_modsec_version}" 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3' 3 | services: 4 | apache-waf: 5 | build: 6 | context: . 7 | dockerfile: v2-apache/Dockerfile 8 | environment: 9 | BACKEND: http://backend # https://httpbin.org 10 | PORT: "8080" 11 | SSL_PORT: "8443" 12 | METRICS_ALLOW_FROM: All 13 | APACHE_ALWAYS_TLS_REDIRECT: "on" 14 | ports: 15 | - "8080:8080" 16 | - "8443:8443" 17 | user: "10001" 18 | depends_on: 19 | - backend 20 | apache-waf-alpine: 21 | build: 22 | context: . 23 | dockerfile: v2-apache/Dockerfile-alpine 24 | environment: 25 | BACKEND: http://backend # https://httpbin.org 26 | PORT: "8080" 27 | SSL_PORT: "4443" 28 | METRICS_ALLOW_FROM: All 29 | ports: 30 | - "8080:8080" 31 | - "4443:4443" 32 | user: "10001" 33 | depends_on: 34 | - backend 35 | nginx-waf: 36 | build: 37 | context: . 38 | dockerfile: v3-nginx/Dockerfile 39 | environment: 40 | BACKEND: http://backend # https://httpbin.org 41 | PORT: "8080" 42 | SSL_PORT: "4443" 43 | DNS_SERVER: "1.1.1.1" 44 | METRICS_ALLOW_FROM: all 45 | ports: 46 | - "8081:8080" 47 | - "4444:4443" 48 | user: "10001" 49 | depends_on: 50 | - backend 51 | # If you need to modify nginx config, mount your volume as the template file 52 | # volumes: 53 | # - ./nginx/nginx.conf:/etc/nginx/templates/nginx.conf.template:rw 54 | nginx-waf-alpine: 55 | build: 56 | context: . 57 | dockerfile: v3-nginx/Dockerfile-alpine 58 | environment: 59 | BACKEND: http://backend # https://httpbin.org 60 | PORT: "8080" 61 | SSL_PORT: "4443" 62 | DNS_SERVER: "1.1.1.1" 63 | METRICS_ALLOW_FROM: all 64 | ports: 65 | - "8081:8080" 66 | - "4444:4443" 67 | user: "10001" 68 | depends_on: 69 | - backend 70 | # If you need to modify nginx config, mount your volume as the template file 71 | # volumes: 72 | # - ./nginx/nginx.conf:/etc/nginx/templates/nginx.conf.template:rw 73 | backend: 74 | image: docker.io/kennethreitz/httpbin 75 | -------------------------------------------------------------------------------- /src/bin/healthcheck: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Health Check running web server. 4 | # Endpoint /healthz should always return 200. 5 | 6 | scheme="https" 7 | host="localhost" 8 | port="${SSL_PORT}" 9 | 10 | if [ "$(env | grep -c APACHE)" -gt 1 ] && [ "${SSL_ENGINE}" = "off" ] 11 | then 12 | scheme="http" 13 | port="${PORT}" 14 | fi 15 | 16 | curl -sk "${scheme}://${host}:${port}/healthz" -------------------------------------------------------------------------------- /src/etc/modsecurity.d/modsecurity-override.conf: -------------------------------------------------------------------------------- 1 | # Original of the latest recommended version: 2 | # https://github.com/SpiderLabs/ModSecurity/blob/v3/master/modsecurity.conf-recommended 3 | 4 | SecArgumentSeparator & 5 | SecAuditEngine ${MODSEC_AUDIT_ENGINE} 6 | SecAuditLog ${MODSEC_AUDIT_LOG} 7 | SecAuditLogFormat ${MODSEC_AUDIT_LOG_FORMAT} 8 | SecAuditLogParts ${MODSEC_AUDIT_LOG_PARTS} 9 | SecAuditLogRelevantStatus "^(?:5|4(?!04))" 10 | SecAuditLogStorageDir ${MODSEC_AUDIT_STORAGE} 11 | SecAuditLogType ${MODSEC_AUDIT_LOG_TYPE} 12 | SecCookieFormat 0 13 | SecDataDir ${MODSEC_DATA_DIR} 14 | SecDebugLog ${MODSEC_DEBUG_LOG} 15 | SecDebugLogLevel ${MODSEC_DEBUG_LOGLEVEL} 16 | SecDisableBackendCompression ${MODSEC_DISABLE_BACKEND_COMPRESSION} 17 | SecPcreMatchLimit ${MODSEC_PCRE_MATCH_LIMIT} 18 | SecPcreMatchLimitRecursion ${MODSEC_PCRE_MATCH_LIMIT_RECURSION} 19 | SecRequestBodyAccess ${MODSEC_REQ_BODY_ACCESS} 20 | SecRequestBodyLimit ${MODSEC_REQ_BODY_LIMIT} 21 | SecRequestBodyJsonDepthLimit ${MODSEC_REQ_BODY_JSON_DEPTH_LIMIT} 22 | SecRequestBodyLimitAction ${MODSEC_REQ_BODY_LIMIT_ACTION} 23 | SecRequestBodyNoFilesLimit ${MODSEC_REQ_BODY_NOFILES_LIMIT} 24 | SecResponseBodyAccess ${MODSEC_RESP_BODY_ACCESS} 25 | SecResponseBodyLimit ${MODSEC_RESP_BODY_LIMIT} 26 | SecResponseBodyLimitAction ${MODSEC_RESP_BODY_LIMIT_ACTION} 27 | SecResponseBodyMimeType ${MODSEC_RESP_BODY_MIMETYPE} 28 | SecRuleEngine ${MODSEC_RULE_ENGINE} 29 | SecStatusEngine ${MODSEC_STATUS_ENGINE} 30 | SecTmpDir ${MODSEC_TMP_DIR} 31 | SecTmpSaveUploadedFiles ${MODSEC_TMP_SAVE_UPLOADED_FILES} 32 | SecUnicodeMapFile unicode.mapping 20127 33 | SecUploadDir ${MODSEC_UPLOAD_DIR} 34 | SecUploadFileMode 0644 35 | -------------------------------------------------------------------------------- /src/etc/modsecurity.d/setup.conf: -------------------------------------------------------------------------------- 1 | # Allow custom configuration of modsecurity 2 | Include /etc/modsecurity.d/modsecurity.conf 3 | Include /etc/modsecurity.d/modsecurity-override.conf 4 | -------------------------------------------------------------------------------- /v2-apache/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG APACHE_VERSION=2.4 2 | 3 | FROM httpd:${APACHE_VERSION} as build 4 | 5 | ARG MODSEC_VERSION=2.9.6 6 | 7 | RUN set -eux; \ 8 | echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ 9 | apt-get update -qq; \ 10 | apt-get install -y -qq --no-install-recommends --no-install-suggests \ 11 | automake \ 12 | ca-certificates \ 13 | g++ \ 14 | git \ 15 | libapr1-dev \ 16 | libaprutil1-dev \ 17 | libcurl4-gnutls-dev \ 18 | libfuzzy-dev \ 19 | libpcre++-dev \ 20 | libtool \ 21 | libxml2-dev \ 22 | libyajl-dev \ 23 | lua5.2-dev \ 24 | make \ 25 | pkgconf \ 26 | wget 27 | 28 | RUN set -eux; \ 29 | wget --quiet https://github.com/SpiderLabs/ModSecurity/archive/refs/tags/v${MODSEC_VERSION}.tar.gz; \ 30 | tar -zxvf v${MODSEC_VERSION}.tar.gz; \ 31 | cd ModSecurity-${MODSEC_VERSION}; \ 32 | ./autogen.sh; \ 33 | ./configure --with-yajl --with-ssdeep; \ 34 | make; \ 35 | make install; \ 36 | make clean 37 | 38 | # Generate self-signed certificates (if needed) 39 | RUN mkdir -p /usr/share/TLS 40 | COPY v2-apache/openssl.conf /usr/share/TLS 41 | RUN openssl req -x509 -days 365 -new \ 42 | -config /usr/share/TLS/openssl.conf \ 43 | -keyout /usr/share/TLS/server.key \ 44 | -out /usr/share/TLS/server.crt 45 | 46 | FROM httpd:${APACHE_VERSION} 47 | 48 | ARG MODSEC_VERSION=2.9.6 49 | 50 | LABEL maintainer="Felipe Zipitria " 51 | 52 | ENV APACHE_ALWAYS_TLS_REDIRECT=off \ 53 | ACCESSLOG=/var/log/apache2/access.log \ 54 | BACKEND=http://localhost:80 \ 55 | BACKEND_WS=ws://localhost:8080 \ 56 | ERRORLOG=/var/log/apache2/error.log \ 57 | APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ 58 | APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ 59 | H2_PROTOCOLS='h2 http/1.1' \ 60 | LOGLEVEL=warn \ 61 | METRICS_ALLOW_FROM='127.0.0.0/255.0.0.0 ::1/128' \ 62 | METRICS_DENY_FROM='All' \ 63 | METRICSLOG='/dev/null' \ 64 | MODSEC_AUDIT_ENGINE="RelevantOnly" \ 65 | MODSEC_AUDIT_LOG_FORMAT=JSON \ 66 | MODSEC_AUDIT_LOG_TYPE=Serial \ 67 | MODSEC_AUDIT_LOG=/dev/stdout \ 68 | MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ 69 | MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ 70 | MODSEC_DATA_DIR=/tmp/modsecurity/data \ 71 | MODSEC_DEBUG_LOG=/dev/null \ 72 | MODSEC_DEBUG_LOGLEVEL=0 \ 73 | MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ 74 | MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ 75 | MODSEC_DISABLE_BACKEND_COMPRESSION="Off" \ 76 | MODSEC_PCRE_MATCH_LIMIT_RECURSION=500000 \ 77 | MODSEC_PCRE_MATCH_LIMIT=500000 \ 78 | MODSEC_REQ_BODY_ACCESS=on \ 79 | MODSEC_REQ_BODY_LIMIT=13107200 \ 80 | MODSEC_REQ_BODY_LIMIT_ACTION="Reject" \ 81 | MODSEC_REQ_BODY_JSON_DEPTH_LIMIT=512 \ 82 | MODSEC_REQ_BODY_NOFILES_LIMIT=131072 \ 83 | MODSEC_RESP_BODY_ACCESS=on \ 84 | MODSEC_RESP_BODY_LIMIT=1048576 \ 85 | MODSEC_RESP_BODY_LIMIT_ACTION="ProcessPartial" \ 86 | MODSEC_RESP_BODY_MIMETYPE="text/plain text/html text/xml" \ 87 | MODSEC_RULE_ENGINE=on \ 88 | MODSEC_STATUS_ENGINE="Off" \ 89 | MODSEC_TAG=modsecurity \ 90 | MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ 91 | MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ 92 | MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ 93 | PORT=80 \ 94 | PROXY_ERROR_OVERRIDE=on \ 95 | PROXY_PRESERVE_HOST=on \ 96 | PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ 97 | PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ 98 | PROXY_SSL_CERT=/usr/local/apache2/conf/server.crt \ 99 | PROXY_SSL_CHECK_PEER_NAME=off \ 100 | PROXY_SSL_VERIFY=none \ 101 | PROXY_SSL=on \ 102 | PROXY_TIMEOUT=60 \ 103 | REMOTEIP_INT_PROXY='10.1.0.0/16' \ 104 | REQ_HEADER_FORWARDED_PROTO='https' \ 105 | SERVER_ADMIN=root@localhost \ 106 | SERVER_NAME=localhost \ 107 | 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" \ 108 | SSL_ENGINE=on \ 109 | SSL_HONOR_CIPHER_ORDER=off \ 110 | SSL_PORT=443 \ 111 | SSL_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ 112 | SSL_PROXY_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ 113 | 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" \ 114 | SSL_SESSION_TICKETS=off \ 115 | SSL_USE_STAPLING=On \ 116 | TIMEOUT=60 \ 117 | WORKER_CONNECTIONS=400 118 | 119 | RUN set -eux; \ 120 | echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ 121 | apt-get update -qq; \ 122 | apt-get install -qq -y --no-install-recommends --no-install-suggests \ 123 | ca-certificates \ 124 | curl \ 125 | libcurl3-gnutls \ 126 | libfuzzy2 \ 127 | libxml2 \ 128 | libyajl2; \ 129 | apt-get clean; \ 130 | rm -rf /var/lib/apt/lists/*; \ 131 | mkdir -p /etc/modsecurity.d/; \ 132 | mkdir -p /tmp/modsecurity/data; \ 133 | mkdir -p /tmp/modsecurity/upload; \ 134 | mkdir -p /tmp/modsecurity/tmp; \ 135 | chown -R $(awk '/^User/ { print $2;}' /usr/local/apache2/conf/httpd.conf) /tmp/modsecurity; \ 136 | mkdir -p /var/log/apache2/ 137 | 138 | COPY --from=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so 139 | COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf 140 | COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping 141 | COPY --from=build /usr/share/TLS/server.key /usr/local/apache2/conf/server.key 142 | COPY --from=build /usr/share/TLS/server.crt /usr/local/apache2/conf/server.crt 143 | COPY src/etc/modsecurity.d/*.conf /etc/modsecurity.d/ 144 | COPY src/bin/healthcheck /usr/local/bin/healthcheck 145 | COPY v2-apache/conf/extra/*.conf /usr/local/apache2/conf/extra/ 146 | 147 | RUN set -eux; \ 148 | sed -i -E 's|(Listen) [0-9]+|\1 ${PORT}|' /usr/local/apache2/conf/httpd.conf; \ 149 | sed -i -E 's|(ServerTokens) Full|\1 Prod|' /usr/local/apache2/conf/extra/httpd-default.conf; \ 150 | sed -i -E 's|#(ServerName) www.example.com:80|\1 ${SERVER_NAME}|' /usr/local/apache2/conf/httpd.conf; \ 151 | sed -i -E 's|(ServerAdmin) you@example.com|\1 ${SERVER_ADMIN}|' /usr/local/apache2/conf/httpd.conf; \ 152 | sed -i -E 's|^(\s*CustomLog)(\s+\S+)+|\1 ${ACCESSLOG} modsec "env=!nologging"|g' /usr/local/apache2/conf/httpd.conf; \ 153 | sed -i -E 's|^(\s*ErrorLog)\s+\S+|\1 ${ERRORLOG}|g' /usr/local/apache2/conf/httpd.conf; \ 154 | sed -i -E 's|^(\s*TransferLog)\s+\S+|\1 ${ACCESSLOG}|g' /usr/local/apache2/conf/httpd.conf; \ 155 | sed -i -E 's|#(LoadModule unique_id_module)|\1|' /usr/local/apache2/conf/httpd.conf; \ 156 | sed -i -E 's|#(LoadModule rewrite_module modules/mod_rewrite.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 157 | sed -i -E 's|#(LoadModule proxy_module modules/mod_proxy.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 158 | sed -i -E 's|#(LoadModule proxy_http_module modules/mod_proxy_http.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 159 | sed -i -E 's|#(LoadModule remoteip_module modules/mod_remoteip.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 160 | sed -i -E 's|#(LoadModule socache_shmcb_module modules/mod_socache_shmcb.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 161 | sed -i -E 's|#(LoadModule ssl_module modules/mod_ssl.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 162 | sed -i -E 's|#(LoadModule http2_module modules/mod_http2.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 163 | sed -i -E 's|#(Include conf/extra/httpd-default.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 164 | sed -i -E 's|#(Include conf/extra/httpd-proxy.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 165 | sed -i -E 's|#(Include conf/extra/httpd-ssl.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 166 | sed -i -E 's|#(Include conf/extra/httpd-vhosts.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 167 | echo 'Include conf/extra/httpd-locations.conf' >> /usr/local/apache2/conf/httpd.conf; \ 168 | echo 'Include conf/extra/httpd-modsecurity.conf' >> /usr/local/apache2/conf/httpd.conf; \ 169 | sed -i -E 's|(MaxRequestWorkers[ ]*)[0-9]*|\1${WORKER_CONNECTIONS}|' /usr/local/apache2/conf/extra/httpd-mpm.conf; \ 170 | chgrp -R 0 /var/log/ /usr/local/apache2/; \ 171 | chmod -R g=u /var/log/ /usr/local/apache2/ 172 | 173 | HEALTHCHECK CMD /usr/local/bin/healthcheck 174 | 175 | # Use httpd-foreground from upstream 176 | -------------------------------------------------------------------------------- /v2-apache/Dockerfile-alpine: -------------------------------------------------------------------------------- 1 | ARG APACHE_VERSION=2.4 2 | 3 | FROM httpd:${APACHE_VERSION}-alpine as build 4 | 5 | ARG MODSEC_VERSION=2.9.6 6 | 7 | # see https://httpd.apache.org/docs/2.4/install.html#requirements 8 | RUN set -eux; \ 9 | apk add --no-cache --virtual .build-deps \ 10 | automake \ 11 | autoconf \ 12 | apr-dev \ 13 | apr-util-dev \ 14 | ca-certificates \ 15 | coreutils \ 16 | curl-dev \ 17 | dpkg-dev dpkg \ 18 | geoip-dev \ 19 | gcc \ 20 | g++ \ 21 | gnupg \ 22 | libc-dev \ 23 | libfuzzy2-dev \ 24 | libmaxminddb-dev \ 25 | libstdc++ \ 26 | linux-headers \ 27 | libtool \ 28 | lmdb-dev \ 29 | libxml2-dev \ 30 | yajl-dev \ 31 | lua-dev \ 32 | make \ 33 | openssl \ 34 | openssl-dev \ 35 | pcre-dev \ 36 | zlib-dev 37 | 38 | RUN set -eux; \ 39 | wget --quiet https://github.com/SpiderLabs/ModSecurity/archive/refs/tags/v${MODSEC_VERSION}.tar.gz; \ 40 | tar -zxvf v${MODSEC_VERSION}.tar.gz; \ 41 | cd ModSecurity-${MODSEC_VERSION}; \ 42 | ./autogen.sh; \ 43 | ./configure --with-yajl --with-ssdeep --with-lmdb; \ 44 | make; \ 45 | make install; \ 46 | make clean 47 | 48 | # Generate self-signed certificates (if needed) 49 | RUN mkdir -p /usr/share/TLS 50 | COPY v2-apache/openssl.conf /usr/share/TLS 51 | RUN openssl req -x509 -days 365 -new \ 52 | -config /usr/share/TLS/openssl.conf \ 53 | -keyout /usr/share/TLS/server.key \ 54 | -out /usr/share/TLS/server.crt 55 | 56 | FROM httpd:${APACHE_VERSION}-alpine 57 | 58 | ARG MODSEC_VERSION=2.9.6 59 | 60 | LABEL maintainer="Felipe Zipitria " 61 | 62 | ENV APACHE_ALWAYS_TLS_REDIRECT=off \ 63 | APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ 64 | APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \ 65 | ACCESSLOG=/var/log/apache2/access.log \ 66 | BACKEND=http://localhost:80 \ 67 | BACKEND_WS=ws://localhost:8080 \ 68 | ERRORLOG=/var/log/apache2/error.log \ 69 | H2_PROTOCOLS='h2 http/1.1' \ 70 | LOGLEVEL=warn \ 71 | METRICS_ALLOW_FROM='127.0.0.0/255.0.0.0 ::1/128' \ 72 | METRICS_DENY_FROM='All' \ 73 | METRICSLOG='/dev/null' \ 74 | MODSEC_AUDIT_ENGINE="RelevantOnly" \ 75 | MODSEC_AUDIT_LOG_FORMAT=JSON \ 76 | MODSEC_AUDIT_LOG_TYPE=Serial \ 77 | MODSEC_AUDIT_LOG=/dev/stdout \ 78 | MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ 79 | MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ 80 | MODSEC_DATA_DIR=/tmp/modsecurity/data \ 81 | MODSEC_DEBUG_LOG=/dev/null \ 82 | MODSEC_DEBUG_LOGLEVEL=0 \ 83 | MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ 84 | MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ 85 | MODSEC_DISABLE_BACKEND_COMPRESSION="Off" \ 86 | MODSEC_PCRE_MATCH_LIMIT_RECURSION=500000 \ 87 | MODSEC_PCRE_MATCH_LIMIT=500000 \ 88 | MODSEC_REQ_BODY_ACCESS=on \ 89 | MODSEC_REQ_BODY_LIMIT=13107200 \ 90 | MODSEC_REQ_BODY_LIMIT_ACTION="Reject" \ 91 | MODSEC_REQ_BODY_JSON_DEPTH_LIMIT=512 \ 92 | MODSEC_REQ_BODY_NOFILES_LIMIT=131072 \ 93 | MODSEC_RESP_BODY_ACCESS=on \ 94 | MODSEC_RESP_BODY_LIMIT=1048576 \ 95 | MODSEC_RESP_BODY_LIMIT_ACTION="ProcessPartial" \ 96 | MODSEC_RESP_BODY_MIMETYPE="text/plain text/html text/xml" \ 97 | MODSEC_RULE_ENGINE=on \ 98 | MODSEC_STATUS_ENGINE="Off" \ 99 | MODSEC_TAG=modsecurity \ 100 | MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ 101 | MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ 102 | MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ 103 | PORT=80 \ 104 | PROXY_ERROR_OVERRIDE=on \ 105 | PROXY_PRESERVE_HOST=on \ 106 | PROXY_SSL_CA_CERT=/etc/ssl/certs/ca-certificates.crt \ 107 | PROXY_SSL_CERT_KEY=/usr/local/apache2/conf/server.key \ 108 | PROXY_SSL_CERT=/usr/local/apache2/conf/server.crt \ 109 | PROXY_SSL_CHECK_PEER_NAME=off \ 110 | PROXY_SSL_VERIFY=none \ 111 | PROXY_SSL=on \ 112 | PROXY_TIMEOUT=60 \ 113 | REMOTEIP_INT_PROXY='10.1.0.0/16' \ 114 | REQ_HEADER_FORWARDED_PROTO='https' \ 115 | SERVER_ADMIN=root@localhost \ 116 | SERVER_NAME=localhost \ 117 | 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" \ 118 | SSL_ENGINE=on \ 119 | SSL_HONOR_CIPHER_ORDER=off \ 120 | SSL_PORT=443 \ 121 | SSL_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ 122 | SSL_PROXY_PROTOCOL="all -SSLv3 -TLSv1 -TLSv1.1" \ 123 | 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" \ 124 | SSL_SESSION_TICKETS=off \ 125 | SSL_USE_STAPLING=On \ 126 | TIMEOUT=60 \ 127 | WORKER_CONNECTIONS=400 128 | 129 | RUN set -eux; \ 130 | apk add --no-cache \ 131 | ca-certificates \ 132 | curl \ 133 | libfuzzy2 \ 134 | libxml2 \ 135 | moreutils \ 136 | tzdata \ 137 | yajl 138 | 139 | COPY --from=build /usr/local/apache2/modules/mod_security2.so /usr/local/apache2/modules/mod_security2.so 140 | COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/modsecurity.conf-recommended /etc/modsecurity.d/modsecurity.conf 141 | COPY --from=build /usr/local/apache2/ModSecurity-${MODSEC_VERSION}/unicode.mapping /etc/modsecurity.d/unicode.mapping 142 | COPY --from=build /usr/share/TLS/server.key /usr/local/apache2/conf/server.key 143 | COPY --from=build /usr/share/TLS/server.crt /usr/local/apache2/conf/server.crt 144 | COPY src/etc/modsecurity.d/*.conf /etc/modsecurity.d/ 145 | COPY src/bin/healthcheck /usr/local/bin/healthcheck 146 | COPY v2-apache/conf/extra/*.conf /usr/local/apache2/conf/extra/ 147 | 148 | RUN set -eux; \ 149 | sed -i -E 's|(Listen) [0-9]+|\1 ${PORT}|' /usr/local/apache2/conf/httpd.conf; \ 150 | sed -i -E 's|(ServerTokens) Full|\1 Prod|' /usr/local/apache2/conf/extra/httpd-default.conf; \ 151 | sed -i -E 's|#(ServerName) www.example.com:80|\1 ${SERVER_NAME}|' /usr/local/apache2/conf/httpd.conf; \ 152 | sed -i -E 's|(ServerAdmin) you@example.com|\1 ${SERVER_ADMIN}|' /usr/local/apache2/conf/httpd.conf; \ 153 | sed -i -E 's|^(\s*CustomLog)(\s+\S+)+|\1 ${ACCESSLOG} modsec "env=!nologging"|g' /usr/local/apache2/conf/httpd.conf; \ 154 | sed -i -E 's|^(\s*ErrorLog)\s+\S+|\1 ${ERRORLOG}|g' /usr/local/apache2/conf/httpd.conf; \ 155 | sed -i -E 's|^(\s*TransferLog)\s+\S+|\1 ${ACCESSLOG}|g' /usr/local/apache2/conf/httpd.conf; \ 156 | sed -i -E 's|#(LoadModule unique_id_module)|\1|' /usr/local/apache2/conf/httpd.conf; \ 157 | sed -i -E 's|#(LoadModule rewrite_module modules/mod_rewrite.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 158 | sed -i -E 's|#(LoadModule proxy_module modules/mod_proxy.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 159 | sed -i -E 's|#(LoadModule proxy_http_module modules/mod_proxy_http.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 160 | sed -i -E 's|#(LoadModule remoteip_module modules/mod_remoteip.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 161 | sed -i -E 's|#(LoadModule socache_shmcb_module modules/mod_socache_shmcb.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 162 | sed -i -E 's|#(LoadModule ssl_module modules/mod_ssl.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 163 | sed -i -E 's|#(LoadModule http2_module modules/mod_http2.so)|\1|' /usr/local/apache2/conf/httpd.conf; \ 164 | sed -i -E 's|#(Include conf/extra/httpd-default.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 165 | sed -i -E 's|#(Include conf/extra/httpd-proxy.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 166 | sed -i -E 's|#(Include conf/extra/httpd-ssl.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 167 | sed -i -E 's|#(Include conf/extra/httpd-vhosts.conf)|\1|' /usr/local/apache2/conf/httpd.conf; \ 168 | echo 'Include conf/extra/httpd-locations.conf' >> /usr/local/apache2/conf/httpd.conf; \ 169 | echo 'Include conf/extra/httpd-modsecurity.conf' >> /usr/local/apache2/conf/httpd.conf; \ 170 | sed -i -E 's|(MaxRequestWorkers[ ]*)[0-9]*|\1${WORKER_CONNECTIONS}|' /usr/local/apache2/conf/extra/httpd-mpm.conf 171 | 172 | RUN set -eux; \ 173 | mkdir -p /var/log/apache2; \ 174 | mkdir -p /tmp/modsecurity/data; \ 175 | mkdir -p /tmp/modsecurity/upload; \ 176 | mkdir -p /tmp/modsecurity/tmp; \ 177 | chown -R $(awk '/^User/ { print $2;}' /usr/local/apache2/conf/httpd.conf) /tmp/modsecurity /var/log/apache2; \ 178 | chgrp -R 0 /var/log/ /usr/local/apache2/; \ 179 | chmod -R g=u /var/log/ /usr/local/apache2/ 180 | 181 | HEALTHCHECK CMD /usr/local/bin/healthcheck 182 | 183 | # Use httpd-foreground from upstream 184 | -------------------------------------------------------------------------------- /v2-apache/conf/extra/httpd-locations.conf: -------------------------------------------------------------------------------- 1 | 2 | SetEnv nologging 3 | RewriteEngine on 4 | RewriteRule .* - [R=200,L] 5 | ErrorDocument 200 "OK" 6 | ProxyPass ! 7 | 8 | 9 | 10 | SetEnv nologging 11 | Order deny,allow 12 | Deny from ${METRICS_DENY_FROM} 13 | Allow from ${METRICS_ALLOW_FROM} 14 | ProxyPass ! 15 | SetHandler server-status 16 | 17 | -------------------------------------------------------------------------------- /v2-apache/conf/extra/httpd-modsecurity.conf: -------------------------------------------------------------------------------- 1 | LoadModule security2_module /usr/local/apache2/modules/mod_security2.so 2 | 3 | Timeout ${TIMEOUT} 4 | 5 | # The "common" and "combined" formats are predefined 6 | LogFormat ${APACHE_LOGFORMAT} modsec 7 | LogFormat ${APACHE_METRICS_LOGFORMAT} metricslog 8 | 9 | LogLevel ${LOGLEVEL} 10 | 11 | CustomLog ${METRICSLOG} metricslog "env=!nologging" 12 | 13 | 14 | RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500 15 | 16 | 17 | Include /etc/modsecurity.d/setup.conf 18 | -------------------------------------------------------------------------------- /v2-apache/conf/extra/httpd-ssl.conf: -------------------------------------------------------------------------------- 1 | Listen ${SSL_PORT} 2 | 3 | SSLProxyProtocol ${SSL_PROXY_PROTOCOL} 4 | SSLProxyCipherSuite ${SSL_PROXY_CIPHER_SUITE} 5 | 6 | SSLPassPhraseDialog builtin 7 | 8 | SSLProtocol ${SSL_PROTOCOL} 9 | SSLCipherSuite ${SSL_CIPHER_SUITE} 10 | SSLHonorCipherOrder ${SSL_HONOR_CIPHER_ORDER} 11 | SSLSessionTickets ${SSL_SESSION_TICKETS} 12 | 13 | SSLUseStapling ${SSL_USE_STAPLING} 14 | SSLStaplingCache "shmcb:logs/ssl_stapling(32768)" 15 | 16 | SSLSessionCache "shmcb:logs/ssl_scache(512000)" 17 | SSLSessionCacheTimeout 300 18 | -------------------------------------------------------------------------------- /v2-apache/conf/extra/httpd-vhosts.conf: -------------------------------------------------------------------------------- 1 | # Apache VirtualHost configuration for both HTTP and SSL 2 | 3 | ProxyErrorOverride ${PROXY_ERROR_OVERRIDE} 4 | ProxyPass / ${BACKEND}/ disablereuse=on 5 | ProxyPassReverse / ${BACKEND}/ 6 | ProxyPreserveHost ${PROXY_PRESERVE_HOST} 7 | ProxyRequests off 8 | ProxyTimeout ${PROXY_TIMEOUT} 9 | 10 | RemoteIPHeader X-Forwarded-For 11 | RemoteIPInternalProxy ${REMOTEIP_INT_PROXY} 12 | 13 | RequestHeader set X-Forwarded-Proto "${REQ_HEADER_FORWARDED_PROTO}" 14 | RequestHeader set X-Real-IP %{REMOTE_ADDR}s 15 | RequestHeader set X-Unique-ID %{UNIQUE_ID}e 16 | 17 | RewriteCond %{HTTP:Upgrade} websocket [NC] 18 | RewriteCond %{HTTP:Connection} upgrade [NC] 19 | RewriteEngine on 20 | RewriteRule .* "${BACKEND_WS}%{REQUEST_URI}" [P] 21 | 22 | ServerName ${SERVER_NAME} 23 | ServerAdmin ${SERVER_ADMIN} 24 | 25 | SSLProxyEngine ${PROXY_SSL} 26 | SSLProxyVerify ${PROXY_SSL_VERIFY} 27 | SSLProxyCheckPeerName ${PROXY_SSL_CHECK_PEER_NAME} 28 | SSLProxyCACertificateFile ${PROXY_SSL_CA_CERT} 29 | 30 | UseCanonicalName on 31 | 32 | 33 | RewriteEngine On 34 | RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/ 35 | RewriteCond %{ENV:APACHE_ALWAYS_TLS_REDIRECT} on 36 | RewriteRule ^(.*)$ https://%{SERVER_NAME}:${SSL_PORT}$1 [L,R=301] 37 | 38 | 39 | 40 | Protocols ${H2_PROTOCOLS} 41 | SSLEngine ${SSL_ENGINE} 42 | SSLCertificateFile ${PROXY_SSL_CERT} 43 | SSLCertificateKeyFile ${PROXY_SSL_CERT_KEY} 44 | 45 | -------------------------------------------------------------------------------- /v2-apache/openssl.conf: -------------------------------------------------------------------------------- 1 | [req] 2 | default_bits=4096 3 | encrypt_key=no 4 | default_md=sha256 5 | distinguished_name=req_sub 6 | prompt=no 7 | 8 | [req_sub] 9 | commonName="localhost" 10 | emailAddress="none@none.com" 11 | countryName="US" 12 | stateOrProvinceName="NY" 13 | localityName="NY" 14 | organizationName="MyOrg" 15 | organizationalUnitName="MyUnit" 16 | -------------------------------------------------------------------------------- /v3-nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG NGINX_VERSION="1.22.1" 2 | 3 | FROM nginx:${NGINX_VERSION} as build 4 | 5 | ARG MODSEC_VERSION=3.0.8 \ 6 | LMDB_VERSION=0.9.29 7 | 8 | # Note: libpcre++-dev (PCRE3) is required by the build description, 9 | # even though the build will use PCRE2. 10 | RUN set -eux; \ 11 | echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ 12 | apt-get update -qq; \ 13 | LD_LIBRARY_PATH="" apt-get install -y -qq --no-install-recommends --no-install-suggests \ 14 | automake \ 15 | cmake \ 16 | doxygen \ 17 | g++ \ 18 | git \ 19 | libcurl4-gnutls-dev \ 20 | libfuzzy-dev \ 21 | libgeoip-dev \ 22 | liblua5.3-dev \ 23 | libpcre++-dev \ 24 | libpcre2-dev \ 25 | libtool \ 26 | libxml2-dev \ 27 | libyajl-dev \ 28 | make \ 29 | patch \ 30 | pkg-config \ 31 | ruby \ 32 | zlib1g-dev; \ 33 | apt-get clean; \ 34 | rm -rf /var/lib/apt/lists/* 35 | 36 | WORKDIR /sources 37 | 38 | RUN set -eux; \ 39 | git clone https://github.com/LMDB/lmdb --branch LMDB_${LMDB_VERSION} --depth 1; \ 40 | make -C lmdb/libraries/liblmdb install; \ 41 | strip /usr/local/lib/liblmdb*.so* 42 | 43 | RUN set -eux; \ 44 | git clone https://github.com/SpiderLabs/ModSecurity --branch v"${MODSEC_VERSION}" --depth 1 --recursive; \ 45 | cd ModSecurity; \ 46 | ARCH=$(gcc -print-multiarch); \ 47 | sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \ 48 | sed -ie "s/i386-linux-gnu/${ARCH}/g" build/pcre2.m4; \ 49 | ./build.sh; \ 50 | ./configure --with-yajl --with-ssdeep --with-geoip --with-pcre2 --enable-silent-rules; \ 51 | make install; \ 52 | strip /usr/local/modsecurity/lib/lib*.so* 53 | 54 | # We use master 55 | RUN set -eux; \ 56 | git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ 57 | curl -sSL https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -o nginx-${NGINX_VERSION}.tar.gz; \ 58 | tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ 59 | cd ./nginx-${NGINX_VERSION}; \ 60 | ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx; \ 61 | make modules; \ 62 | strip objs/ngx_http_modsecurity_module.so; \ 63 | cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/; \ 64 | mkdir /etc/modsecurity.d; \ 65 | curl -sSL https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended \ 66 | -o /etc/modsecurity.d/modsecurity.conf; \ 67 | curl -sSL https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/unicode.mapping \ 68 | -o /etc/modsecurity.d/unicode.mapping 69 | 70 | # Generate self-signed certificates (if needed) 71 | RUN mkdir -p /usr/share/TLS 72 | COPY v3-nginx/openssl.conf /usr/share/TLS 73 | RUN openssl req -x509 -days 365 -new \ 74 | -config /usr/share/TLS/openssl.conf \ 75 | -keyout /usr/share/TLS/server.key \ 76 | -out /usr/share/TLS/server.crt 77 | 78 | # Generate/Download Diffie-Hellman parameter files 79 | RUN openssl dhparam -out /usr/share/TLS/dhparam-1024.pem 1024 80 | RUN curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /usr/share/TLS/dhparam-2048.pem 81 | RUN curl -sSL https://ssl-config.mozilla.org/ffdhe4096.txt -o /usr/share/TLS/dhparam-4096.pem 82 | 83 | FROM nginx:${NGINX_VERSION} 84 | 85 | ARG MODSEC_VERSION=3.0.8 \ 86 | LMDB_VERSION=0.9.29 87 | 88 | LABEL maintainer="Felipe Zipitria " 89 | 90 | ENV ACCESSLOG=/var/log/nginx/access.log \ 91 | BACKEND=http://localhost:80 \ 92 | DNS_SERVER= \ 93 | ERRORLOG=/var/log/nginx/error.log \ 94 | LOGLEVEL=warn \ 95 | METRICS_ALLOW_FROM='127.0.0.0/24' \ 96 | METRICS_DENY_FROM='all' \ 97 | METRICSLOG=/dev/null \ 98 | MODSEC_AUDIT_ENGINE="RelevantOnly" \ 99 | MODSEC_AUDIT_LOG_FORMAT=JSON \ 100 | MODSEC_AUDIT_LOG_TYPE=Serial \ 101 | MODSEC_AUDIT_LOG=/dev/stdout \ 102 | MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ 103 | MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ 104 | MODSEC_DATA_DIR=/tmp/modsecurity/data \ 105 | MODSEC_DEBUG_LOG=/dev/null \ 106 | MODSEC_DEBUG_LOGLEVEL=0 \ 107 | MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ 108 | MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ 109 | MODSEC_PCRE_MATCH_LIMIT_RECURSION=100000 \ 110 | MODSEC_PCRE_MATCH_LIMIT=100000 \ 111 | MODSEC_REQ_BODY_ACCESS=on \ 112 | MODSEC_REQ_BODY_LIMIT=13107200 \ 113 | MODSEC_REQ_BODY_LIMIT_ACTION="Reject" \ 114 | MODSEC_REQ_BODY_JSON_DEPTH_LIMIT=512 \ 115 | MODSEC_REQ_BODY_NOFILES_LIMIT=131072 \ 116 | MODSEC_RESP_BODY_ACCESS=on \ 117 | MODSEC_RESP_BODY_LIMIT=1048576 \ 118 | MODSEC_RESP_BODY_LIMIT_ACTION="ProcessPartial" \ 119 | MODSEC_RESP_BODY_MIMETYPE="text/plain text/html text/xml" \ 120 | MODSEC_RULE_ENGINE=on \ 121 | MODSEC_STATUS_ENGINE="Off" \ 122 | MODSEC_TAG=modsecurity \ 123 | MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ 124 | MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ 125 | MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ 126 | PORT=80 \ 127 | NGINX_ALWAYS_TLS_REDIRECT=off \ 128 | SET_REAL_IP_FROM="127.0.0.1" \ 129 | REAL_IP_HEADER="X-REAL-IP" \ 130 | REAL_IP_RECURSIVE="on" \ 131 | PROXY_TIMEOUT=60s \ 132 | PROXY_SSL_CERT=/etc/nginx/conf/server.crt \ 133 | PROXY_SSL_CERT_KEY=/etc/nginx/conf/server.key \ 134 | PROXY_SSL_DH_BITS=2048 \ 135 | PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ 136 | 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" \ 137 | PROXY_SSL_PREFER_CIPHERS=off \ 138 | PROXY_SSL_VERIFY=off \ 139 | PROXY_SSL_OCSP_STAPLING=off \ 140 | SERVER_NAME=localhost \ 141 | SSL_PORT=443 \ 142 | TIMEOUT=60s \ 143 | WORKER_CONNECTIONS=1024 \ 144 | LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib \ 145 | NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx 146 | 147 | RUN set -eux; \ 148 | echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; \ 149 | apt-get update -qq; \ 150 | LD_LIBRARY_PATH="" apt-get install -y -qq --no-install-recommends --no-install-suggests \ 151 | ca-certificates \ 152 | curl \ 153 | libcurl4-gnutls-dev \ 154 | libfuzzy2 \ 155 | liblua5.3 \ 156 | libxml2 \ 157 | libyajl2 \ 158 | moreutils; \ 159 | rm -rf /var/lib/apt/lists/*; \ 160 | apt-get clean; \ 161 | mkdir /etc/nginx/ssl; \ 162 | mkdir -p /tmp/modsecurity/data; \ 163 | mkdir -p /tmp/modsecurity/upload; \ 164 | mkdir -p /tmp/modsecurity/tmp; \ 165 | mkdir -p /usr/local/modsecurity; \ 166 | chown -R nginx:nginx /tmp/modsecurity 167 | 168 | COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/ 169 | COPY --from=build /etc/nginx/modules/ngx_http_modsecurity_module.so /etc/nginx/modules/ngx_http_modsecurity_module.so 170 | COPY --from=build /usr/local/lib/liblmdb.so /usr/local/lib/ 171 | COPY --from=build /usr/share/TLS/server.key /etc/nginx/conf/server.key 172 | COPY --from=build /usr/share/TLS/server.crt /etc/nginx/conf/server.crt 173 | COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ 174 | COPY --from=build /etc/modsecurity.d/unicode.mapping /etc/modsecurity.d/unicode.mapping 175 | COPY --from=build /etc/modsecurity.d/modsecurity.conf /etc/modsecurity.d/modsecurity.conf 176 | COPY v3-nginx/templates /etc/nginx/templates/ 177 | COPY src/etc/modsecurity.d/modsecurity-override.conf /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template 178 | COPY src/etc/modsecurity.d/setup.conf /etc/nginx/templates/modsecurity.d/setup.conf.template 179 | COPY src/bin/healthcheck /usr/local/bin/healthcheck 180 | COPY v3-nginx/docker-entrypoint.d/*.sh /docker-entrypoint.d/ 181 | 182 | # Comment out the SecDisableBackendCompression option since it is not supported in V3 183 | RUN sed -i 's/^\(SecDisableBackendCompression .*\)/# \1/' /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template 184 | 185 | RUN set -eux; \ 186 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ 187 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ 188 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ 189 | chgrp -R 0 /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/; \ 190 | chmod -R g=u /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/ 191 | 192 | HEALTHCHECK CMD /usr/local/bin/healthcheck 193 | -------------------------------------------------------------------------------- /v3-nginx/Dockerfile-alpine: -------------------------------------------------------------------------------- 1 | ARG NGINX_VERSION="1.22.1" 2 | 3 | FROM nginx:${NGINX_VERSION}-alpine as build 4 | 5 | ARG MODSEC_VERSION=3.0.8 6 | 7 | # Note: pcre-dev (PCRE3) is required by the build description, 8 | # even though the build will use PCRE2. 9 | RUN set -eux; \ 10 | apk add --no-cache --virtual .build-deps \ 11 | autoconf \ 12 | automake \ 13 | ca-certificates \ 14 | coreutils \ 15 | curl-dev \ 16 | g++ \ 17 | gcc \ 18 | geoip-dev \ 19 | git \ 20 | libc-dev \ 21 | libfuzzy2-dev \ 22 | libmaxminddb-dev \ 23 | libstdc++ \ 24 | libtool \ 25 | libxml2-dev \ 26 | linux-headers \ 27 | lmdb-dev \ 28 | make \ 29 | openssl \ 30 | openssl-dev \ 31 | patch \ 32 | pkgconfig \ 33 | pcre-dev \ 34 | pcre2-dev \ 35 | yajl-dev \ 36 | zlib-dev 37 | 38 | WORKDIR /sources 39 | 40 | RUN set -eux; \ 41 | git clone https://github.com/SpiderLabs/ModSecurity --branch v"${MODSEC_VERSION}" --depth 1 --recursive; \ 42 | cd ModSecurity; \ 43 | ARCH=$(gcc -print-multiarch); \ 44 | sed -ie "s/i386-linux-gnu/${ARCH}/g" build/ssdeep.m4; \ 45 | sed -ie "s/i386-linux-gnu/${ARCH}/g" build/pcre2.m4; \ 46 | ./build.sh; \ 47 | ./configure --with-yajl --with-ssdeep --with-lmdb --with-geoip --with-pcre2 --enable-silent-rules; \ 48 | make install; \ 49 | strip /usr/local/modsecurity/lib/lib*.so* 50 | 51 | # We use master 52 | RUN set -eux; \ 53 | git clone -b master --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git; \ 54 | wget --quiet http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz; \ 55 | tar -xzf nginx-${NGINX_VERSION}.tar.gz; \ 56 | cd ./nginx-${NGINX_VERSION}; \ 57 | ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx; \ 58 | make modules; \ 59 | cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules/; \ 60 | mkdir /etc/modsecurity.d; \ 61 | wget --quiet https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended \ 62 | -O /etc/modsecurity.d/modsecurity.conf; \ 63 | wget --quiet https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/unicode.mapping \ 64 | -O /etc/modsecurity.d/unicode.mapping 65 | 66 | # Generate self-signed certificates (if needed) 67 | RUN mkdir -p /usr/share/TLS 68 | COPY v3-nginx/openssl.conf /usr/share/TLS 69 | RUN openssl req -x509 -days 365 -new \ 70 | -config /usr/share/TLS/openssl.conf \ 71 | -keyout /usr/share/TLS/server.key \ 72 | -out /usr/share/TLS/server.crt 73 | 74 | # Generate/Download Diffie-Hellman parameter files 75 | RUN openssl dhparam -out /usr/share/TLS/dhparam-1024.pem 1024 76 | RUN curl -sSL https://ssl-config.mozilla.org/ffdhe2048.txt -o /usr/share/TLS/dhparam-2048.pem 77 | RUN curl -sSL https://ssl-config.mozilla.org/ffdhe4096.txt -o /usr/share/TLS/dhparam-4096.pem 78 | 79 | FROM nginx:${NGINX_VERSION}-alpine 80 | 81 | ARG MODSEC_VERSION=3.0.8 82 | 83 | LABEL maintainer="Felipe Zipitria " 84 | 85 | ENV ACCESSLOG=/var/log/nginx/access.log \ 86 | BACKEND=http://localhost:80 \ 87 | DNS_SERVER= \ 88 | ERRORLOG=/var/log/nginx/error.log \ 89 | LOGLEVEL=warn \ 90 | METRICS_ALLOW_FROM='127.0.0.0/24' \ 91 | METRICS_DENY_FROM='all' \ 92 | METRICSLOG=/dev/null \ 93 | MODSEC_AUDIT_ENGINE="RelevantOnly" \ 94 | MODSEC_AUDIT_LOG_FORMAT=JSON \ 95 | MODSEC_AUDIT_LOG_TYPE=Serial \ 96 | MODSEC_AUDIT_LOG=/dev/stdout \ 97 | MODSEC_AUDIT_LOG_PARTS='ABIJDEFHZ' \ 98 | MODSEC_AUDIT_STORAGE=/var/log/modsecurity/audit/ \ 99 | MODSEC_DATA_DIR=/tmp/modsecurity/data \ 100 | MODSEC_DEBUG_LOG=/dev/null \ 101 | MODSEC_DEBUG_LOGLEVEL=0 \ 102 | MODSEC_DEFAULT_PHASE1_ACTION="phase:1,pass,log,tag:'\${MODSEC_TAG}'" \ 103 | MODSEC_DEFAULT_PHASE2_ACTION="phase:2,pass,log,tag:'\${MODSEC_TAG}'" \ 104 | MODSEC_PCRE_MATCH_LIMIT_RECURSION=100000 \ 105 | MODSEC_PCRE_MATCH_LIMIT=100000 \ 106 | MODSEC_REQ_BODY_ACCESS=on \ 107 | MODSEC_REQ_BODY_LIMIT=13107200 \ 108 | MODSEC_REQ_BODY_LIMIT_ACTION="Reject" \ 109 | MODSEC_REQ_BODY_JSON_DEPTH_LIMIT=512 \ 110 | MODSEC_REQ_BODY_NOFILES_LIMIT=131072 \ 111 | MODSEC_RESP_BODY_ACCESS=on \ 112 | MODSEC_RESP_BODY_LIMIT=1048576 \ 113 | MODSEC_RESP_BODY_LIMIT_ACTION="ProcessPartial" \ 114 | MODSEC_RESP_BODY_MIMETYPE="text/plain text/html text/xml" \ 115 | MODSEC_RULE_ENGINE=on \ 116 | MODSEC_STATUS_ENGINE="Off" \ 117 | MODSEC_TAG=modsecurity \ 118 | MODSEC_TMP_DIR=/tmp/modsecurity/tmp \ 119 | MODSEC_TMP_SAVE_UPLOADED_FILES="on" \ 120 | MODSEC_UPLOAD_DIR=/tmp/modsecurity/upload \ 121 | PORT=80 \ 122 | NGINX_ALWAYS_TLS_REDIRECT=off \ 123 | SET_REAL_IP_FROM="127.0.0.1" \ 124 | REAL_IP_HEADER="X-REAL-IP" \ 125 | REAL_IP_RECURSIVE="on" \ 126 | PROXY_TIMEOUT=60s \ 127 | PROXY_SSL_CERT=/etc/nginx/conf/server.crt \ 128 | PROXY_SSL_CERT_KEY=/etc/nginx/conf/server.key \ 129 | PROXY_SSL_DH_BITS=2048 \ 130 | PROXY_SSL_PROTOCOLS="TLSv1.2 TLSv1.3" \ 131 | 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" \ 132 | PROXY_SSL_PREFER_CIPHERS=off \ 133 | PROXY_SSL_VERIFY=off \ 134 | PROXY_SSL_OCSP_STAPLING=off \ 135 | SERVER_NAME=localhost \ 136 | SSL_PORT=443 \ 137 | TIMEOUT=60s \ 138 | WORKER_CONNECTIONS=1024 \ 139 | LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib \ 140 | NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx 141 | 142 | RUN set -eux; \ 143 | apk add --no-cache \ 144 | curl \ 145 | curl-dev \ 146 | libfuzzy2 \ 147 | libmaxminddb-dev \ 148 | libstdc++ \ 149 | libxml2-dev \ 150 | lmdb-dev \ 151 | moreutils \ 152 | tzdata \ 153 | pcre \ 154 | pcre2 \ 155 | yajl; \ 156 | mkdir /etc/nginx/ssl/; \ 157 | mkdir -p /tmp/modsecurity/data; \ 158 | mkdir -p /tmp/modsecurity/upload; \ 159 | mkdir -p /tmp/modsecurity/tmp; \ 160 | chown -R nginx:nginx /usr/share/nginx /tmp/modsecurity 161 | 162 | COPY --from=build /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/ 163 | COPY --from=build /etc/nginx/modules/ngx_http_modsecurity_module.so /etc/nginx/modules/ngx_http_modsecurity_module.so 164 | COPY --from=build /usr/share/TLS/server.key /etc/nginx/conf/server.key 165 | COPY --from=build /usr/share/TLS/server.crt /etc/nginx/conf/server.crt 166 | COPY --from=build /usr/share/TLS/dhparam-* /etc/ssl/certs/ 167 | COPY --from=build /etc/modsecurity.d/unicode.mapping /etc/modsecurity.d/unicode.mapping 168 | COPY --from=build /etc/modsecurity.d/modsecurity.conf /etc/modsecurity.d/modsecurity.conf 169 | COPY v3-nginx/templates /etc/nginx/templates/ 170 | COPY src/etc/modsecurity.d/modsecurity-override.conf /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template 171 | COPY src/etc/modsecurity.d/setup.conf /etc/nginx/templates/modsecurity.d/setup.conf.template 172 | COPY src/bin/healthcheck /usr/local/bin/healthcheck 173 | COPY v3-nginx/docker-entrypoint.d/*.sh /docker-entrypoint.d/ 174 | 175 | # Comment out the SecDisableBackendCompression option since it is not supported in V3 176 | RUN sed -i 's/^\(SecDisableBackendCompression .*\)/# \1/' /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template 177 | 178 | RUN set -eux; \ 179 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3.0; \ 180 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so.3; \ 181 | ln -s /usr/local/modsecurity/lib/libmodsecurity.so.${MODSEC_VERSION} /usr/local/modsecurity/lib/libmodsecurity.so; \ 182 | chgrp -R 0 /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/; \ 183 | chmod -R g=u /var/cache/nginx/ /var/log/ /var/run/ /usr/share/nginx/ /etc/nginx/ /etc/modsecurity.d/ 184 | 185 | WORKDIR /usr/share/nginx/html 186 | 187 | HEALTHCHECK CMD /usr/local/bin/healthcheck 188 | -------------------------------------------------------------------------------- /v3-nginx/docker-entrypoint.d/90-copy-modsecurity-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # vim:sw=2:ts=2:sts=2:et 3 | 4 | set -eu 5 | 6 | LC_ALL=C 7 | ME=$( basename "$0" ) 8 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 9 | 10 | 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; } 11 | 12 | cp /etc/nginx/modsecurity.d/*.conf /etc/modsecurity.d 2>/dev/null || { echo >&2 "$ME: error: cannot copy config files to /etc/modsecurity.d"; exit 2; } 13 | 14 | exit 0 15 | -------------------------------------------------------------------------------- /v3-nginx/docker-entrypoint.d/91-update-resolver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # vim:sw=2:ts=2:sts=2:et 3 | 4 | set -eu 5 | 6 | LC_ALL=C 7 | ME=$( basename "$0" ) 8 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 9 | 10 | DNS_SERVER="${DNS_SERVER:-$(grep -i '^nameserver' /etc/resolv.conf | head -n1 | cut -d ' ' -f2)}" 11 | 12 | sed -i.bak -r 's/DNS_SERVER/'"${DNS_SERVER}"'/' /etc/nginx/nginx.conf 13 | -------------------------------------------------------------------------------- /v3-nginx/docker-entrypoint.d/92-update-real_ip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # vim:sw=2:ts=2:sts=2:et 3 | 4 | set -eu 5 | 6 | LC_ALL=C 7 | ME=$( basename "$0" ) 8 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 9 | 10 | # split comma separated IP addresses into multiple `set_real_ip xxx;` lines 11 | SET_REAL_IP_FROM="$(echo "${SET_REAL_IP_FROM}" | awk -F, '{for(i=1; i<=NF; i++) printf "set_real_ip_from "$i";\\n"}')" 12 | 13 | sed -i.bak -r 's#SET_REAL_IP_FROM#'"${SET_REAL_IP_FROM}"'#' /etc/nginx/includes/proxy_backend.conf 14 | -------------------------------------------------------------------------------- /v3-nginx/openssl.conf: -------------------------------------------------------------------------------- 1 | [req] 2 | default_bits=4096 3 | encrypt_key=no 4 | default_md=sha256 5 | distinguished_name=req_sub 6 | prompt=no 7 | 8 | [req_sub] 9 | commonName="localhost" 10 | emailAddress="none@none.com" 11 | countryName="US" 12 | stateOrProvinceName="NY" 13 | localityName="NY" 14 | organizationName="MyOrg" 15 | organizationalUnitName="MyUnit" 16 | -------------------------------------------------------------------------------- /v3-nginx/templates/conf.d/default.conf.template: -------------------------------------------------------------------------------- 1 | # Nginx configuration for both HTTP and SSL 2 | 3 | map $http_upgrade $connection_upgrade { 4 | default upgrade; 5 | '' close; 6 | } 7 | 8 | server { 9 | listen ${PORT} default_server; 10 | 11 | server_name ${SERVER_NAME}; 12 | set $upstream ${BACKEND}; 13 | set $always_redirect ${NGINX_ALWAYS_TLS_REDIRECT}; 14 | 15 | location / { 16 | client_max_body_size 0; 17 | 18 | if ($always_redirect = on) { 19 | return 301 https://$host$request_uri; 20 | } 21 | 22 | include includes/proxy_backend.conf; 23 | 24 | index index.html index.htm; 25 | root /usr/share/nginx/html; 26 | } 27 | 28 | include includes/location_common.conf; 29 | 30 | } 31 | 32 | server { 33 | listen ${SSL_PORT} ssl; 34 | 35 | server_name ${SERVER_NAME}; 36 | set $upstream ${BACKEND}; 37 | 38 | ssl_certificate ${PROXY_SSL_CERT}; 39 | ssl_certificate_key ${PROXY_SSL_CERT_KEY}; 40 | ssl_session_timeout 1d; 41 | ssl_session_cache shared:MozSSL:10m; 42 | ssl_session_tickets off; 43 | 44 | ssl_dhparam /etc/ssl/certs/dhparam-${PROXY_SSL_DH_BITS}.pem; 45 | 46 | ssl_protocols ${PROXY_SSL_PROTOCOLS}; 47 | ssl_ciphers ${PROXY_SSL_CIPHERS}; 48 | ssl_prefer_server_ciphers ${PROXY_SSL_PREFER_CIPHERS}; 49 | 50 | ssl_stapling ${PROXY_SSL_OCSP_STAPLING}; 51 | ssl_stapling_verify ${PROXY_SSL_OCSP_STAPLING}; 52 | 53 | ssl_verify_client ${PROXY_SSL_VERIFY}; 54 | 55 | location / { 56 | client_max_body_size 0; 57 | 58 | include includes/proxy_backend.conf; 59 | 60 | index index.html index.htm; 61 | root /usr/share/nginx/html; 62 | } 63 | 64 | include includes/location_common.conf; 65 | } 66 | -------------------------------------------------------------------------------- /v3-nginx/templates/conf.d/logging.conf.template: -------------------------------------------------------------------------------- 1 | # The "combined" log format is predefined 2 | log_format main '$realip_remote_addr - $remote_user [$time_local] "$request" ' 3 | '$status $body_bytes_sent "$http_referer" ' 4 | '"$http_user_agent" "$http_x_forwarded_for"'; 5 | 6 | access_log ${ACCESSLOG} main; 7 | access_log ${METRICSLOG} combined; 8 | 9 | error_log ${ERRORLOG} ${LOGLEVEL}; 10 | -------------------------------------------------------------------------------- /v3-nginx/templates/conf.d/modsecurity.conf.template: -------------------------------------------------------------------------------- 1 | modsecurity on; 2 | modsecurity_rules_file /etc/modsecurity.d/setup.conf; 3 | -------------------------------------------------------------------------------- /v3-nginx/templates/includes/location_common.conf.template: -------------------------------------------------------------------------------- 1 | 2 | location /healthz { 3 | access_log off; 4 | add_header Content-Type text/plain; 5 | return 200 "OK"; 6 | } 7 | 8 | location /metrics/nginx { 9 | access_log off; 10 | allow ${METRICS_ALLOW_FROM}; 11 | deny ${METRICS_DENY_FROM}; 12 | proxy_store off; 13 | stub_status; 14 | } 15 | 16 | error_page 500 502 503 504 /50x.html; 17 | location = /50x.html { 18 | root /usr/share/nginx/html; 19 | } 20 | -------------------------------------------------------------------------------- /v3-nginx/templates/includes/proxy_backend.conf.template: -------------------------------------------------------------------------------- 1 | proxy_set_header Host $host; 2 | proxy_set_header Proxy ""; 3 | proxy_set_header Upgrade $http_upgrade; 4 | proxy_set_header Connection $connection_upgrade; 5 | proxy_set_header ${REAL_IP_HEADER} $remote_addr; 6 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 7 | proxy_set_header X-Forwarded-Port $server_port; 8 | proxy_set_header X-Forwarded-Proto $scheme; 9 | 10 | proxy_http_version 1.1; 11 | proxy_buffering off; 12 | proxy_connect_timeout 60s; 13 | proxy_read_timeout 36000s; 14 | proxy_redirect off; 15 | 16 | proxy_pass_header Authorization; 17 | proxy_pass $upstream; 18 | 19 | SET_REAL_IP_FROM 20 | real_ip_header ${REAL_IP_HEADER}; 21 | real_ip_recursive ${REAL_IP_RECURSIVE}; 22 | -------------------------------------------------------------------------------- /v3-nginx/templates/modsecurity.d/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coreruleset/modsecurity-docker/bf60dcb29fad101c5b90edf272909742e4e85929/v3-nginx/templates/modsecurity.d/.gitkeep -------------------------------------------------------------------------------- /v3-nginx/templates/nginx.conf.template: -------------------------------------------------------------------------------- 1 | load_module modules/ngx_http_modsecurity_module.so; 2 | 3 | worker_processes auto; 4 | pid /var/run/nginx.pid; 5 | 6 | events { 7 | worker_connections ${WORKER_CONNECTIONS}; 8 | } 9 | 10 | http { 11 | include /etc/nginx/mime.types; 12 | default_type application/octet-stream; 13 | keepalive_timeout ${TIMEOUT}; 14 | sendfile on; 15 | 16 | resolver DNS_SERVER valid=5s; 17 | include /etc/nginx/conf.d/*.conf; 18 | } 19 | --------------------------------------------------------------------------------