Compare commits
266 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd0c7b1e53 | ||
|
|
1e6d62ce79 | ||
|
|
1a4e21481e | ||
|
|
bcaca6f034 | ||
|
|
424214fd56 | ||
|
|
82b42d5b9c | ||
|
|
db4e2cf266 | ||
|
|
0ef82619b8 | ||
|
|
f2655e331d | ||
|
|
d51ae1c1b9 | ||
|
|
cd0438b8ce | ||
|
|
f9a042526e | ||
|
|
15ac64b05f | ||
|
|
e0f8895e9a | ||
|
|
e852298352 | ||
|
|
972a284efd | ||
|
|
5258d8e58f | ||
|
|
acb4bea97d | ||
|
|
42067e864a | ||
|
|
217bddabfd | ||
|
|
c5fba13674 | ||
|
|
1b21f9eac3 | ||
|
|
389e050943 | ||
|
|
05a89c3037 | ||
|
|
a0ed8a27e9 | ||
|
|
d0ac5e3059 | ||
|
|
b16f8f11ad | ||
|
|
a23ed06e66 | ||
|
|
6b9be078b8 | ||
|
|
8e198ed82e | ||
|
|
c3b527afe8 | ||
|
|
972e5471d1 | ||
|
|
b246c6d7e2 | ||
|
|
b78fd55427 | ||
|
|
945241339a | ||
|
|
1af2264fab | ||
|
|
6f28708c10 | ||
|
|
a9f886804a | ||
|
|
3a078326c5 | ||
|
|
d43b82b757 | ||
|
|
3850cacb9c | ||
|
|
c00c7f46a0 | ||
|
|
163af4a49d | ||
|
|
98e85eb99f | ||
|
|
2e63bb0256 | ||
|
|
6546a0edb7 | ||
|
|
ab00381746 | ||
|
|
9f7097de0d | ||
|
|
24d6337a57 | ||
|
|
bfb5319c16 | ||
|
|
4c77a14825 | ||
|
|
4e45fa3874 | ||
|
|
a9a26b82d9 | ||
|
|
00d91dcaaa | ||
|
|
650ad7ea49 | ||
|
|
7045c0c2b6 | ||
|
|
f0f432487b | ||
|
|
fdc02be051 | ||
|
|
fb799765a4 | ||
|
|
d53f02b5b3 | ||
|
|
7b9722fac4 | ||
|
|
31ed4ff834 | ||
|
|
bc5f3ee88e | ||
|
|
a6b21aae8c | ||
|
|
64aa9c2530 | ||
|
|
5d94cc8f43 | ||
|
|
e7ee21cbb5 | ||
|
|
a0f8cbdac1 | ||
|
|
178d7a6849 | ||
|
|
ca81535bb3 | ||
|
|
062fa3e78a | ||
|
|
95f2d2af9c | ||
|
|
e55dff8128 | ||
|
|
f0f1c79d40 | ||
|
|
3d2f5e2389 | ||
|
|
b079c99fb9 | ||
|
|
2e403c6ebc | ||
|
|
f75a05584e | ||
|
|
148edf6814 | ||
|
|
a19d8aa041 | ||
|
|
480cff86bc | ||
|
|
35df3423d0 | ||
|
|
29f4069de7 | ||
|
|
72e4384596 | ||
|
|
a4a2647737 | ||
|
|
892e533694 | ||
|
|
a056141609 | ||
|
|
0772a9ba8e | ||
|
|
33e0ffd5b1 | ||
|
|
4cb3e089e3 | ||
|
|
8808f161c5 | ||
|
|
1c60ec9804 | ||
|
|
b13ff34569 | ||
|
|
58f2926e95 | ||
|
|
9de628f3eb | ||
|
|
6cc1abc893 | ||
|
|
a824e15684 | ||
|
|
fd52bb7c8d | ||
|
|
0938b20eb8 | ||
|
|
b948e08bd5 | ||
|
|
fde14d1621 | ||
|
|
8a4eb3f2a3 | ||
|
|
2a0b84074a | ||
|
|
aec22d1a81 | ||
|
|
028fc61b4f | ||
|
|
a903960b4c | ||
|
|
a28f06f08f | ||
|
|
6c8bc6b349 | ||
|
|
2b3b4a5c3f | ||
|
|
57e4247eab | ||
|
|
f9d4e90894 | ||
|
|
4f024ec566 | ||
|
|
bc46fc3d4c | ||
|
|
0be1da18a6 | ||
|
|
3cedc0ae13 | ||
|
|
f1d5c07cc1 | ||
|
|
c9a6b6c27d | ||
|
|
b199464a73 | ||
|
|
4a9d64d9d9 | ||
|
|
31536a3fe2 | ||
|
|
7b47c7304f | ||
|
|
83e7ce9cde | ||
|
|
0ad5159a33 | ||
|
|
6240d8e28d | ||
|
|
2f80f64dd5 | ||
|
|
e98da9b637 | ||
|
|
d9f7706969 | ||
|
|
75f299978c | ||
|
|
ef34b2cec1 | ||
|
|
9b9110214a | ||
|
|
9e2a8070e4 | ||
|
|
733136ac1a | ||
|
|
fa172ce5a9 | ||
|
|
f6a9184ae9 | ||
|
|
d37dc2b629 | ||
|
|
f7c115edff | ||
|
|
dfbb091361 | ||
|
|
8e4a65feca | ||
|
|
0573ba7b5a | ||
|
|
bcd421de09 | ||
|
|
2ec28c79cb | ||
|
|
fec60a4b14 | ||
|
|
dd7d1a2c78 | ||
|
|
0c1883472d | ||
|
|
4e6eab794d | ||
|
|
b23135b663 | ||
|
|
ace9be3979 | ||
|
|
8958e5107c | ||
|
|
b2cfc15c2a | ||
|
|
94bef079a8 | ||
|
|
50266c2285 | ||
|
|
22e2fe869f | ||
|
|
55186bbef5 | ||
|
|
d8286ced7c | ||
|
|
44de2253d2 | ||
|
|
6d73fbdedb | ||
|
|
b6809266af | ||
|
|
4e178b474c | ||
|
|
021147f9d9 | ||
|
|
5a26d06c87 | ||
|
|
bc01427def | ||
|
|
652614f41b | ||
|
|
24d9cce82f | ||
|
|
f866ef6325 | ||
|
|
1a32e7c02c | ||
|
|
7180378d0c | ||
|
|
6e66571fb9 | ||
|
|
f44e41cede | ||
|
|
26db144df4 | ||
|
|
a68ad53c3f | ||
|
|
01bba1d3f6 | ||
|
|
0597074438 | ||
|
|
bc3c17a2f0 | ||
|
|
556836b499 | ||
|
|
22612f1757 | ||
|
|
50c279617b | ||
|
|
ef8969e2cf | ||
|
|
0dc2a5ec25 | ||
|
|
9a207dfdc5 | ||
|
|
a60fbbb5b3 | ||
|
|
a1b9010d9e | ||
|
|
3178545c2f | ||
|
|
36b8760d4d | ||
|
|
8bb6676f58 | ||
|
|
4234f82c01 | ||
|
|
b99fb27df5 | ||
|
|
876fcd1814 | ||
|
|
26dc796155 | ||
|
|
280d189864 | ||
|
|
5f845680ff | ||
|
|
d12369c900 | ||
|
|
366e39f591 | ||
|
|
71741b2d34 | ||
|
|
2fca4cd014 | ||
|
|
fccf14627f | ||
|
|
b3684efaf6 | ||
|
|
82548378ae | ||
|
|
b926b0db62 | ||
|
|
6713f56ec1 | ||
|
|
2b923c05c1 | ||
|
|
71cf3cf5c1 | ||
|
|
8e3dbf1c70 | ||
|
|
49ada6a8c5 | ||
|
|
947e86f7c3 | ||
|
|
a12561a85b | ||
|
|
6b19bd0264 | ||
|
|
6738b28b99 | ||
|
|
010c0fd6d4 | ||
|
|
ecf30a71f7 | ||
|
|
ffc4fc950e | ||
|
|
b9955699b7 | ||
|
|
860fd1ace5 | ||
|
|
eb5d13fb8d | ||
|
|
ca41987cd6 | ||
|
|
3af1b397fa | ||
|
|
72a09eac6d | ||
|
|
0d3f7d3925 | ||
|
|
6be082e0a9 | ||
|
|
4947796c99 | ||
|
|
ba197dfa43 | ||
|
|
4dd1ff8479 | ||
|
|
f771ec43f1 | ||
|
|
e241b0c939 | ||
|
|
d03a1a6e3b | ||
|
|
2c9c9fb62c | ||
|
|
deb28c5991 | ||
|
|
2ea7331dad | ||
|
|
92ee40819e | ||
|
|
2ccfb26e81 | ||
|
|
70f9f8417e | ||
|
|
c4aef1d606 | ||
|
|
a385183d88 | ||
|
|
cec47f3a75 | ||
|
|
c894c8370e | ||
|
|
f73b088f79 | ||
|
|
130c6752dd | ||
|
|
f97ea67855 | ||
|
|
8504299861 | ||
|
|
4a8da40cf2 | ||
|
|
0114c7b09f | ||
|
|
bebe89afb0 | ||
|
|
b2cceb608c | ||
|
|
37f5e4ed71 | ||
|
|
98568a57c9 | ||
|
|
4991922878 | ||
|
|
bcb8acc364 | ||
|
|
a9279053a4 | ||
|
|
60057a17e3 | ||
|
|
d0366fcc0d | ||
|
|
b448d91ca8 | ||
|
|
e309ce6fd5 | ||
|
|
37090dc66e | ||
|
|
6bb6facd88 | ||
|
|
a1fcbd4b83 | ||
|
|
09a2a4f9e5 | ||
|
|
1e02368e8a | ||
|
|
bbb5134a39 | ||
|
|
b0f93fb840 | ||
|
|
c892f037db | ||
|
|
731c0f61df | ||
|
|
93543d3962 | ||
|
|
5ec9e6ab49 | ||
|
|
cc0d0af8d2 | ||
|
|
43d2097d14 | ||
|
|
f880e5e2aa | ||
|
|
9636013f5e |
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
.git
|
||||||
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -11,7 +11,7 @@ assignees: ''
|
|||||||
Concise description of what you're trying to do, the expected behavior and the current bug.
|
Concise description of what you're trying to do, the expected behavior and the current bug.
|
||||||
|
|
||||||
**How to reproduce**
|
**How to reproduce**
|
||||||
Give steps on how to reproduce the bug (e.g. : commands, configs, tests, environment, version, ...).
|
Give steps on how to reproduce the bug (e.g. : commands, yaml, configs, tests, environment, version, ...).
|
||||||
|
|
||||||
**Logs**
|
**Logs**
|
||||||
The logs generated by bunkerized-nginx. **DON'T FORGET TO REMOVE PRIVATE DATA LIKE IP ADDRESSES !**
|
The logs generated by BunkerWeb. **DON'T FORGET TO REMOVE PRIVATE DATA LIKE IP ADDRESSES !**
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -2,7 +2,7 @@
|
|||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
title: "[FEATURE]"
|
title: "[FEATURE]"
|
||||||
labels: enhancement
|
labels: feature
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
name: Automatic test on autoconf
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
pull_request:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Build the image
|
|
||||||
run: docker build -t autotest-autoconf -f autoconf/Dockerfile .
|
|
||||||
- name: Run Trivy security scanner
|
|
||||||
uses: aquasecurity/trivy-action@master
|
|
||||||
with:
|
|
||||||
image-ref: 'autotest-autoconf'
|
|
||||||
format: 'table'
|
|
||||||
exit-code: '1'
|
|
||||||
ignore-unfixed: true
|
|
||||||
severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
name: Automatic test on ui
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
pull_request:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Build the image
|
|
||||||
run: docker build -t autotest-ui -f ui/Dockerfile .
|
|
||||||
- name: Run Trivy security scanner
|
|
||||||
uses: aquasecurity/trivy-action@master
|
|
||||||
with:
|
|
||||||
image-ref: 'autotest-ui'
|
|
||||||
format: 'table'
|
|
||||||
exit-code: '1'
|
|
||||||
ignore-unfixed: true
|
|
||||||
severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
|
|
||||||
|
|
||||||
|
|
||||||
26
.github/workflows/autotest-bunkerized-nginx.yml
vendored
26
.github/workflows/autotest-bunkerized-nginx.yml
vendored
@ -1,26 +0,0 @@
|
|||||||
name: Automatic test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
pull_request:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Build the image
|
|
||||||
run: docker build -t autotest .
|
|
||||||
- name: Run autotest
|
|
||||||
run: docker run autotest test
|
|
||||||
- name: Run Trivy security scanner
|
|
||||||
uses: aquasecurity/trivy-action@master
|
|
||||||
with:
|
|
||||||
image-ref: 'autotest'
|
|
||||||
format: 'table'
|
|
||||||
exit-code: '1'
|
|
||||||
ignore-unfixed: true
|
|
||||||
severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL'
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
name: Build and push bunkerized-nginx-autoconf
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set variables
|
|
||||||
run: |
|
|
||||||
VER=$(cat VERSION | tr -d '\n')
|
|
||||||
echo "VERSION=$VER" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Setup QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Setup Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push (dev)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/dev'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: autoconf/Dockerfile
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx-autoconf:dev
|
|
||||||
|
|
||||||
- name: Build and push (master)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: autoconf/Dockerfile
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx-autoconf:latest,bunkerity/bunkerized-nginx-autoconf:${{ env.VERSION }}
|
|
||||||
50
.github/workflows/build-bunkerized-nginx-ui.yml
vendored
50
.github/workflows/build-bunkerized-nginx-ui.yml
vendored
@ -1,50 +0,0 @@
|
|||||||
name: Build and push bunkerized-nginx-ui
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set variables
|
|
||||||
run: |
|
|
||||||
VER=$(cat VERSION | tr -d '\n')
|
|
||||||
echo "VERSION=$VER" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Setup QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Setup Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push (dev)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/dev'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ui/Dockerfile
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx-ui:dev
|
|
||||||
|
|
||||||
- name: Build and push (master)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: ui/Dockerfile
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx-ui:latest,bunkerity/bunkerized-nginx-ui:${{ env.VERSION }}
|
|
||||||
65
.github/workflows/build-bunkerized-nginx.yml
vendored
65
.github/workflows/build-bunkerized-nginx.yml
vendored
@ -1,65 +0,0 @@
|
|||||||
name: Build and push bunkerized-nginx
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev, master]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set variables
|
|
||||||
run: |
|
|
||||||
VER=$(cat VERSION | tr -d '\n')
|
|
||||||
echo "VERSION=$VER" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Setup QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
|
|
||||||
- name: Setup Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
|
|
||||||
- name: Setup Docker cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
if: github.ref == 'refs/heads/dev'
|
|
||||||
with:
|
|
||||||
path: /tmp/.buildx-cache
|
|
||||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-buildx-
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build and push (dev)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/dev'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx:dev
|
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache
|
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
|
||||||
|
|
||||||
- name: Move Docker cache
|
|
||||||
if: github.ref == 'refs/heads/dev'
|
|
||||||
run: |
|
|
||||||
rm -rf /tmp/.buildx-cache
|
|
||||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
|
||||||
|
|
||||||
- name: Build and push (master)
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8
|
|
||||||
push: true
|
|
||||||
tags: bunkerity/bunkerized-nginx:latest,bunkerity/bunkerized-nginx:${{ env.VERSION }}
|
|
||||||
402
.github/workflows/dev.yml
vendored
Normal file
402
.github/workflows/dev.yml
vendored
Normal file
@ -0,0 +1,402 @@
|
|||||||
|
name: Automatic test, build, push and deploy (DEV)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [dev]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
# Build for amd64
|
||||||
|
build-bw-amd64:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-amd64-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-amd64-cache,mode=min
|
||||||
|
- name: Build BW autoconf for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-autoconf-amd64-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-amd64-cache,mode=min
|
||||||
|
- name: Build BW UI for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-ui-amd64-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-amd64-cache,mode=min
|
||||||
|
|
||||||
|
# Build bunkerweb/386
|
||||||
|
build-bw-386:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-tests-386:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-386-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-386-cache,mode=min
|
||||||
|
- name: Build BW autoconf for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-autoconf-tests-386:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-autoconf-386-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-386-cache,mode=min
|
||||||
|
- name: Build BW UI for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-autoconf-tests-386:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-ui-386-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-386-cache,mode=min
|
||||||
|
|
||||||
|
# Build bunkerweb/arm
|
||||||
|
build-bw-arm:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Setup SSH for ARM node
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_KEY" > ~/.ssh/id_rsa_arm
|
||||||
|
chmod 600 ~/.ssh/id_rsa_arm
|
||||||
|
echo "$SSH_CONFIG" > ~/.ssh/config
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.ARM_SSH_KEY }}
|
||||||
|
SSH_CONFIG: ${{ secrets.ARM_SSH_CONFIG }}
|
||||||
|
- name: Append ARM node to buildx
|
||||||
|
run: |
|
||||||
|
docker buildx create --append --name ${{ steps.buildx.outputs.name }} --node arm --platform linux/arm64,linux/arm/v7,linux/arm/v6 ssh://ubuntu@arm
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-tests-arm:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-arm-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-arm-cache,mode=min
|
||||||
|
- name: Build BW autoconf for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-autoconf-tests-arm:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-autoconf-arm-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-arm-cache,mode=min
|
||||||
|
- name: Build BW UI for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-ui-tests-arm:latest
|
||||||
|
cache-from: type=registry,ref=bunkerity/cache:bw-ui-arm-cache
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-arm-cache,mode=min
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
tests:
|
||||||
|
needs: build-bw-amd64
|
||||||
|
runs-on: [self-hosted, X64]
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
- name: Set variables
|
||||||
|
run: |
|
||||||
|
VER=$(cat VERSION | tr -d '\n')
|
||||||
|
if [ "$GITHUB_REF" = "refs/heads/master" ] ; then
|
||||||
|
echo "BUILD_MODE=prod" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "BUILD_MODE=dev" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Import images to local registry
|
||||||
|
- name: Import BW image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest 10.20.1.1:5000/bw-tests:latest && docker push 10.20.1.1:5000/bw-tests:latest
|
||||||
|
- name: Import BW autoconf image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest 10.20.1.1:5000/bw-autoconf-tests:latest && docker push 10.20.1.1:5000/bw-autoconf-tests:latest
|
||||||
|
- name: Import BW UI image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest 10.20.1.1:5000/bw-ui-tests:latest && docker push 10.20.1.1:5000/bw-ui-tests:latest
|
||||||
|
|
||||||
|
# CVE check on OS
|
||||||
|
- name: Check security vulnerabilities for BW
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
- name: Check security vulnerabilities for autoconf
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-autoconf-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
- name: Check security vulnerabilities for UI
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-ui-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
- name: Run Docker tests
|
||||||
|
run: ./tests/docker.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run autoconf tests
|
||||||
|
run: ./tests/autoconf.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Swarm tests
|
||||||
|
run: ./tests/swarm.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Kubernetes tests
|
||||||
|
run: ./tests/kubernetes.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Linux tests
|
||||||
|
run: ./tests/linux.sh ${{ env.BUILD_MODE }}
|
||||||
|
|
||||||
|
# Push to dev registries
|
||||||
|
push-docker:
|
||||||
|
needs: [tests, build-bw-386, build-bw-arm]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
- name: Setup SSH for ARM node
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_KEY" > ~/.ssh/id_rsa_arm
|
||||||
|
chmod 600 ~/.ssh/id_rsa_arm
|
||||||
|
echo "$SSH_CONFIG" > ~/.ssh/config
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.ARM_SSH_KEY }}
|
||||||
|
SSH_CONFIG: ${{ secrets.ARM_SSH_CONFIG }}
|
||||||
|
- name: Append ARM node to buildx
|
||||||
|
run: |
|
||||||
|
docker buildx create --append --name ${{ steps.buildx.outputs.name }} --node arm --platform linux/arm64,linux/arm/v7,linux/arm/v6 ssh://ubuntu@arm
|
||||||
|
|
||||||
|
# Build and push
|
||||||
|
- name: Build and push BW
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb:staging,bunkerity/bunkerweb:dev
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-arm-cache
|
||||||
|
- name: Build and push BW autoconf
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf:staging,bunkerity/bunkerweb-autoconf:dev
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-arm-cache
|
||||||
|
- name: Build and push BW UI
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui:staging,bunkerity/bunkerweb-ui:dev
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-arm-cache
|
||||||
|
|
||||||
|
# Push to PackageCloud
|
||||||
|
push-linux:
|
||||||
|
needs: tests
|
||||||
|
runs-on: [self-hosted, X64]
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set variables
|
||||||
|
run: |
|
||||||
|
VER=$(cat VERSION | tr -d '\n')
|
||||||
|
echo "VERSION=$VER" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Remove Ubuntu DEB from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb-dev/ubuntu/jammy bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Ubuntu DEB to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/dev/ubuntu/bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb-dev
|
||||||
|
PACKAGECLOUD-DISTRIB: ubuntu/jammy
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove Debian DEB from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb-dev/debian/bullseye bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Debian DEB to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/dev/debian/bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb-dev
|
||||||
|
PACKAGECLOUD-DISTRIB: debian/bullseye
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove CentOS RPM from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb-dev/el/8 bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push CentOS RPM to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/dev/centos/bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb-dev
|
||||||
|
PACKAGECLOUD-DISTRIB: el/8
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove Fedora RPM from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb-dev/fedora/36 bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Fedora RPM to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/dev/fedora/bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb-dev
|
||||||
|
PACKAGECLOUD-DISTRIB: fedora/36
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
# Deploy to staging infrastructure
|
||||||
|
deploy:
|
||||||
|
needs: push-docker
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: k8s login (staging)
|
||||||
|
uses: azure/k8s-set-context@v2
|
||||||
|
with:
|
||||||
|
method: kubeconfig
|
||||||
|
kubeconfig: ${{ secrets.KUBE_CONFIG_STAGING }}
|
||||||
|
|
||||||
|
- name: k8s deploy (staging)
|
||||||
|
run: kubectl rollout restart deployment bunkerweb-controller && kubectl rollout restart daemonset bunkerweb
|
||||||
529
.github/workflows/prod.yml
vendored
Normal file
529
.github/workflows/prod.yml
vendored
Normal file
@ -0,0 +1,529 @@
|
|||||||
|
name: Automatic test, build, push and deploy (PROD)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
# Build for amd64
|
||||||
|
build-bw-amd64:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-amd64-cache,mode=min
|
||||||
|
- name: Build BW autoconf for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-amd64-cache,mode=min
|
||||||
|
- name: Build BW UI for amd64
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-amd64-cache,mode=min
|
||||||
|
|
||||||
|
# Build bunkerweb/386
|
||||||
|
build-bw-386:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-tests-386:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-386-cache,mode=min
|
||||||
|
- name: Build BW autoconf for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-autoconf-tests-386:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-386-cache,mode=min
|
||||||
|
- name: Build BW UI for 386
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/386
|
||||||
|
tags: bunkerweb-autoconf-tests-386:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-386-cache,mode=min
|
||||||
|
|
||||||
|
# Build bunkerweb/arm
|
||||||
|
build-bw-arm:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Setup SSH for ARM node
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_KEY" > ~/.ssh/id_rsa_arm
|
||||||
|
chmod 600 ~/.ssh/id_rsa_arm
|
||||||
|
echo "$SSH_CONFIG" > ~/.ssh/config
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.ARM_SSH_KEY }}
|
||||||
|
SSH_CONFIG: ${{ secrets.ARM_SSH_CONFIG }}
|
||||||
|
- name: Append ARM node to buildx
|
||||||
|
run: |
|
||||||
|
docker buildx create --append --name ${{ steps.buildx.outputs.name }} --node arm --platform linux/arm64,linux/arm/v7,linux/arm/v6 ssh://ubuntu@arm
|
||||||
|
|
||||||
|
# Build images
|
||||||
|
- name: Build BW for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-tests-arm:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-arm-cache,mode=min
|
||||||
|
- name: Build BW autoconf for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-autoconf-tests-arm:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-autoconf-arm-cache,mode=min
|
||||||
|
- name: Build BW UI for ARM
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/arm64,linux/arm/v7
|
||||||
|
tags: bunkerweb-ui-tests-arm:latest
|
||||||
|
cache-to: type=registry,ref=bunkerity/cache:bw-ui-arm-cache,mode=min
|
||||||
|
|
||||||
|
# Build linux ubuntu
|
||||||
|
build-bw-ubuntu:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build image
|
||||||
|
- name: Build BW ubuntu
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: linux/Dockerfile-ubuntu
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ubuntu:latest
|
||||||
|
|
||||||
|
# Build linux debian
|
||||||
|
build-bw-debian:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build image
|
||||||
|
- name: Build BW debian
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: linux/Dockerfile-debian
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-debian:latest
|
||||||
|
|
||||||
|
# Build linux centos
|
||||||
|
build-bw-centos:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build image
|
||||||
|
- name: Build BW centos
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: linux/Dockerfile-centos
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-centos:latest
|
||||||
|
|
||||||
|
# Build linux fedora
|
||||||
|
build-bw-fedora:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Build image
|
||||||
|
- name: Build BW fedora
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: linux/Dockerfile-fedora
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-fedora:latest
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
tests:
|
||||||
|
needs: [build-bw-amd64, build-bw-ubuntu, build-bw-debian, build-bw-centos, build-bw-fedora]
|
||||||
|
runs-on: [self-hosted, X64]
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
- name: Set variables
|
||||||
|
run: |
|
||||||
|
VER=$(cat VERSION | tr -d '\n')
|
||||||
|
if [ "$GITHUB_REF" = "refs/heads/master" ] ; then
|
||||||
|
echo "BUILD_MODE=prod" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "BUILD_MODE=dev" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Import images to local registry
|
||||||
|
- name: Import BW image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests-amd64:latest 10.20.1.1:5000/bw-tests:latest && docker push 10.20.1.1:5000/bw-tests:latest
|
||||||
|
- name: Import BW autoconf image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf-tests-amd64:latest 10.20.1.1:5000/bw-autoconf-tests:latest && docker push 10.20.1.1:5000/bw-autoconf-tests:latest
|
||||||
|
- name: Import BW UI image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui-tests-amd64:latest 10.20.1.1:5000/bw-ui-tests:latest && docker push 10.20.1.1:5000/bw-ui-tests:latest
|
||||||
|
- name: Import Ubuntu image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ubuntu:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ubuntu:latest bw-ubuntu-tests:latest
|
||||||
|
- name: Import Debian image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-debian:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-debian:latest bw-debian-tests:latest
|
||||||
|
- name: Import Centos image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-centos:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-centos:latest bw-centos-tests:latest
|
||||||
|
- name: Import Fedora image
|
||||||
|
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-fedora:latest && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-fedora:latest bw-fedora-tests:latest
|
||||||
|
|
||||||
|
# CVE check on OS
|
||||||
|
- name: Check security vulnerabilities for BW
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
- name: Check security vulnerabilities for autoconf
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-autoconf-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
- name: Check security vulnerabilities for UI
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
vuln-type: os
|
||||||
|
image-ref: 10.20.1.1:5000/bw-ui-tests:latest
|
||||||
|
format: table
|
||||||
|
exit-code: 1
|
||||||
|
ignore-unfixed: false
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
- name: Run Docker tests
|
||||||
|
run: ./tests/docker.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run autoconf tests
|
||||||
|
run: ./tests/autoconf.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Swarm tests
|
||||||
|
run: ./tests/swarm.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Kubernetes tests
|
||||||
|
run: ./tests/kubernetes.sh ${{ env.BUILD_MODE }}
|
||||||
|
- name: Run Linux tests
|
||||||
|
run: ./tests/linux.sh ${{ env.BUILD_MODE }}
|
||||||
|
|
||||||
|
# Push to dev registries
|
||||||
|
push-docker:
|
||||||
|
needs: [tests, build-bw-386, build-bw-arm]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Prepare
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Set variables
|
||||||
|
run: |
|
||||||
|
VER=$(cat VERSION | tr -d '\n')
|
||||||
|
echo "VERSION=$VER" >> $GITHUB_ENV
|
||||||
|
- name: Setup Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
- name: Login to private repository
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.PRIVATE_REGISTRY }}
|
||||||
|
username: registry
|
||||||
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
- name: Setup SSH for ARM node
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_KEY" > ~/.ssh/id_rsa_arm
|
||||||
|
chmod 600 ~/.ssh/id_rsa_arm
|
||||||
|
echo "$SSH_CONFIG" > ~/.ssh/config
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.ARM_SSH_KEY }}
|
||||||
|
SSH_CONFIG: ${{ secrets.ARM_SSH_CONFIG }}
|
||||||
|
- name: Append ARM node to buildx
|
||||||
|
run: |
|
||||||
|
docker buildx create --append --name ${{ steps.buildx.outputs.name }} --node arm --platform linux/arm64,linux/arm/v7,linux/arm/v6 ssh://ubuntu@arm
|
||||||
|
|
||||||
|
# Build and push
|
||||||
|
- name: Build and push BW
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb:latest,bunkerity/bunkerweb:latest,bunkerity/bunkerweb:${{ env.VERSION }}
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-arm-cache
|
||||||
|
- name: Build and push BW autoconf
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: autoconf/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-autoconf:latest,bunkerity/bunkerweb-autoconf:latest,bunkerity/bunkerweb-autoconf:${{ env.VERSION }}
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-autoconf-arm-cache
|
||||||
|
- name: Build and push BW UI
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ui/Dockerfile
|
||||||
|
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-ui:latest,bunkerity/bunkerweb-ui:latest,bunkerity/bunkerweb-ui:${{ env.VERSION }}
|
||||||
|
cache-from: |
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-amd64-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-386-cache
|
||||||
|
type=registry,ref=bunkerity/cache:bw-ui-arm-cache
|
||||||
|
|
||||||
|
# Push to PackageCloud
|
||||||
|
push-linux:
|
||||||
|
needs: tests
|
||||||
|
runs-on: [self-hosted, X64]
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set variables
|
||||||
|
run: |
|
||||||
|
VER=$(cat VERSION | tr -d '\n')
|
||||||
|
echo "VERSION=$VER" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Remove Ubuntu DEB from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb/ubuntu/jammy bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Ubuntu DEB to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/prod/ubuntu/bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb
|
||||||
|
PACKAGECLOUD-DISTRIB: ubuntu/jammy
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove Debian DEB from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb/debian/bullseye bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Debian DEB to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/prod/debian/bunkerweb_${{ env.VERSION }}-1_amd64.deb
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb
|
||||||
|
PACKAGECLOUD-DISTRIB: debian/bullseye
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove CentOS RPM from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb/el/8 bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push CentOS RPM to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/prod/centos/bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb
|
||||||
|
PACKAGECLOUD-DISTRIB: el/8
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove Fedora RPM from packagecloud
|
||||||
|
run: package_cloud yank bunkerity/bunkerweb/fedora/36 bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push Fedora RPM to packagecloud
|
||||||
|
uses: danielmundi/upload-packagecloud@v1
|
||||||
|
with:
|
||||||
|
PACKAGE-NAME: /opt/packages/prod/fedora/bunkerweb-${{ env.VERSION }}-1.x86_64.rpm
|
||||||
|
PACKAGECLOUD-USERNAME: bunkerity
|
||||||
|
PACKAGECLOUD-REPO: bunkerweb
|
||||||
|
PACKAGECLOUD-DISTRIB: fedora/36
|
||||||
|
PACKAGECLOUD-TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
|
||||||
|
|
||||||
|
# Deploy to staging infrastructure
|
||||||
|
# deploy:
|
||||||
|
# needs: push-docker
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# steps:
|
||||||
|
|
||||||
|
# - name: Checkout source code
|
||||||
|
# uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# - name: k8s login (staging)
|
||||||
|
# uses: azure/k8s-set-context@v2
|
||||||
|
# with:
|
||||||
|
# method: kubeconfig
|
||||||
|
# kubeconfig: ${{ secrets.KUBE_CONFIG_STAGING }}
|
||||||
|
|
||||||
|
# - name: k8s deploy (staging)
|
||||||
|
# run: kubectl rollout restart deployment bunkerweb-controller && kubectl rollout restart daemonset bunkerweb
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
|
site/
|
||||||
.idea/
|
.idea/
|
||||||
docs/_build/
|
.vscode/
|
||||||
|
**/__pycache__/
|
||||||
|
ui/env/
|
||||||
|
|||||||
73
CHANGELOG.md
73
CHANGELOG.md
@ -1,5 +1,78 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.4.1 - 2022/16/06
|
||||||
|
- Fix sending local IPs to BunkerNet when DISABLE_DEFAULT_SERVER=yes
|
||||||
|
- Fix certbot bug when AUTOCONF_MODE=yes
|
||||||
|
- Fix certbot bug when MULTISITE=no
|
||||||
|
- Add reverse proxy timeouts settings
|
||||||
|
- Add auth_request settings
|
||||||
|
- Add authentik and authelia examples
|
||||||
|
- Prebuilt Docker images for arm64 and armv7
|
||||||
|
- Improve documentation for Linux integration
|
||||||
|
- Various fixes in the documentation
|
||||||
|
|
||||||
|
## v1.4.0 - 2022/06/06
|
||||||
|
|
||||||
|
- Project renamed to BunkerWeb
|
||||||
|
- Internal architecture fully revised with a modular approach
|
||||||
|
- Improved CI/CD with automatic tests for multiple integrations
|
||||||
|
- Plugin improvement
|
||||||
|
- Volume improvement for container-based integrations
|
||||||
|
- Web UI improvement with various new features
|
||||||
|
- Web tool to generate settings from a user-friendly UI
|
||||||
|
- Linux packages
|
||||||
|
- Various bug fixes
|
||||||
|
|
||||||
|
## v1.3.2 - 2021/10/24
|
||||||
|
|
||||||
|
- Use API instead of a shared folder for Swarm and Kubernetes integrations
|
||||||
|
- Beta integration of distributed bad IPs database through a remote API
|
||||||
|
- Improvement of the request limiting feature : hour/day rate and multiple URL support
|
||||||
|
- Various bug fixes related to antibot feature
|
||||||
|
- Init support of Arch Linux
|
||||||
|
- Fix Moodle example
|
||||||
|
- Fix ROOT_FOLDER bug in serve-files.conf when using the UI
|
||||||
|
- Update default values for PERMISSIONS_POLICY and FEATURE_POLICY
|
||||||
|
- Disable COUNTRY ban if IP is local
|
||||||
|
|
||||||
|
## v1.3.1 - 2021/09/02
|
||||||
|
|
||||||
|
- Use ModSecurity v3.0.4 instead of v3.0.5 to fix memory leak
|
||||||
|
- Fix ignored variables to control jobs
|
||||||
|
- Fix bug when LISTEN_HTTP=no and MULTISITE=yes
|
||||||
|
- Add CUSTOM_HEADER variable
|
||||||
|
- Add REVERSE_PROXY_BUFFERING variable
|
||||||
|
- Add REVERSE_PROXY_KEEPALIVE variable
|
||||||
|
- Fix documentation for modsec and modsec-crs special folders
|
||||||
|
|
||||||
|
## v1.3.0 - 2021/08/23
|
||||||
|
|
||||||
|
- Kubernetes integration in beta
|
||||||
|
- Linux integration in beta
|
||||||
|
- autoconf refactoring
|
||||||
|
- jobs refactoring
|
||||||
|
- UI refactoring
|
||||||
|
- UI security : login/password authentication and CRSF protection
|
||||||
|
- various dependencies updates
|
||||||
|
- move CrowdSec as an external plugin
|
||||||
|
- Authelia support
|
||||||
|
- improve various regexes
|
||||||
|
- add INJECT_BODY variable
|
||||||
|
- add WORKER_PROCESSES variable
|
||||||
|
- add USE_LETS_ENCRYPT_STAGING variable
|
||||||
|
- add LOCAL_PHP and LOCAL_PHP_PATH variables
|
||||||
|
- add REDIRECT_TO variable
|
||||||
|
|
||||||
|
## v1.2.8 - 2021/07/22
|
||||||
|
|
||||||
|
- Fix broken links in README
|
||||||
|
- Fix regex for EMAIL_LETS_ENCRYPT
|
||||||
|
- Fix regex for REMOTE_PHP and REMOTE_PHP_PATH
|
||||||
|
- Fix regex for SELF_SIGNED_*
|
||||||
|
- Fix various bugs related to web UI
|
||||||
|
- Fix bug in autoconf (missing instances parameter to reload function)
|
||||||
|
- Remove old .env files when generating a new configuration
|
||||||
|
|
||||||
## v1.2.7 - 2021/06/14
|
## v1.2.7 - 2021/06/14
|
||||||
|
|
||||||
- Add custom robots.txt and sitemap to RTD
|
- Add custom robots.txt and sitemap to RTD
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# Contributing to bunkerized-nginx
|
# Contributing to bunkerweb
|
||||||
|
|
||||||
First off all, thanks for being here and showing your support to the project !
|
First off all, thanks for being here and showing your support to the project !
|
||||||
|
|
||||||
@ -6,19 +6,16 @@ We accept many types of contributions whether they are technical or not. Every c
|
|||||||
|
|
||||||
## Talk about the project
|
## Talk about the project
|
||||||
|
|
||||||
The first thing you can do is to talk about the project. You can share it on social media, make a blog post about it or simply tell your friends/colleagues that's an awesome project.
|
The first thing you can do is to talk about the project. You can share it on social media (by the way, you can can also follow us on [LinkedIn](https://www.linkedin.com/company/bunkerity/), [Twitter](https://twitter.com/bunkerity) and [GitHub](https://github.com/bunkerity)), make a blog post about it or simply tell your friends/colleagues that's an awesome project..
|
||||||
|
|
||||||
## Join the community chat
|
## Join the community
|
||||||
|
|
||||||
You can join [the community chat](https://coso.me/bunkerity-chat) to talk about the project and ask for help. Please note that you can choose the platform you want, thanks to [matterbridge](https://github.com/42wim/matterbridge) all messages coming from a platform are relayed to the others.
|
You can join the [Discord server](https://discord.com/invite/fTf46FmtyD), the [GitHub discussions](https://github.com/bunkerity/bunkerweb/discussions) and the [/r/BunkerWeb](https://www.reddit.com/r/BunkerWeb) subreddit to talk about the project and help others.
|
||||||
|
|
||||||
## Reporting bugs / ask for features
|
## Reporting bugs / ask for features
|
||||||
|
|
||||||
The preferred way to report bugs and asking for features is using [issues](https://github.com/bunkerity/bunkerized-nginx/issues). Before opening a new one, please check if a related issue is already opened using the "filters" bar. When creating a new issue please select and fill the "Bug report" or "Feature request" template.
|
The preferred way to report bugs and asking for features is using [issues](https://github.com/bunkerity/bunkerweb/issues). Before opening a new one, please check if a related issue is already opened using the "filters" bar. When creating a new issue please select and fill the "Bug report" or "Feature request" template.
|
||||||
|
|
||||||
## Code contribution
|
## Code contribution
|
||||||
|
|
||||||
The preferred way to contribute code is using [pull requests](https://github.com/bunkerity/bunkerized-nginx/pulls). Before creating a pull request, please check if your code is related to an opened issue. If that's not the case, you should first create an issue so we can discuss about it. This procedure is here to avoid wasting your time in case the PR will be rejected. For minor changes (e.g. : typo, quick fix, ...), opening an issue might be facultative. **Don't forget to edit the documentations when needed !**
|
The preferred way to contribute code is using [pull requests](https://github.com/bunkerity/bunkerweb/pulls). Before creating a pull request, please check if your code is related to an opened issue. If that's not the case, you should first create an issue so we can discuss about it. This procedure is here to avoid wasting your time in case the PR will be rejected. For minor changes (e.g. : typo, quick fix, ...), opening an issue might be facultative. **Don't forget to edit the documentations when needed !**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
102
Dockerfile
102
Dockerfile
@ -1,40 +1,86 @@
|
|||||||
FROM nginx:1.20.1-alpine
|
FROM nginx:1.20.2-alpine AS builder
|
||||||
|
|
||||||
COPY nginx-keys/ /tmp/nginx-keys
|
# Copy dependencies sources folder
|
||||||
COPY compile.sh /tmp/compile.sh
|
COPY deps /tmp/bunkerweb/deps
|
||||||
RUN chmod +x /tmp/compile.sh && \
|
|
||||||
/tmp/compile.sh && \
|
|
||||||
rm -rf /tmp/*
|
|
||||||
|
|
||||||
COPY dependencies.sh /tmp/dependencies.sh
|
# Compile and install dependencies
|
||||||
RUN chmod +x /tmp/dependencies.sh && \
|
RUN apk add --no-cache --virtual build bash build autoconf libtool automake geoip-dev g++ gcc curl-dev libxml2-dev pcre-dev make linux-headers musl-dev gd-dev gnupg brotli-dev openssl-dev patch readline-dev && \
|
||||||
/tmp/dependencies.sh && \
|
mkdir -p /opt/bunkerweb/deps && \
|
||||||
rm -rf /tmp/dependencies.sh
|
chmod +x /tmp/bunkerweb/deps/install.sh && \
|
||||||
|
bash /tmp/bunkerweb/deps/install.sh && \
|
||||||
|
apk del build
|
||||||
|
|
||||||
COPY gen/ /opt/gen
|
# Copy python requirements
|
||||||
COPY entrypoint/ /opt/entrypoint
|
COPY deps/requirements.txt /opt/bunkerweb/deps/requirements.txt
|
||||||
COPY confs/ /opt/confs
|
|
||||||
COPY scripts/ /opt/scripts
|
|
||||||
COPY lua/ /usr/local/lib/lua
|
|
||||||
COPY antibot/ /antibot
|
|
||||||
COPY defaults/ /defaults
|
|
||||||
COPY settings.json /opt
|
|
||||||
COPY misc/cron /etc/crontabs/nginx
|
|
||||||
|
|
||||||
COPY prepare.sh /tmp/prepare.sh
|
# Install python requirements
|
||||||
RUN chmod +x /tmp/prepare.sh && \
|
RUN apk add --no-cache --virtual build py3-pip gcc python3-dev musl-dev libffi-dev openssl-dev cargo && \
|
||||||
/tmp/prepare.sh && \
|
pip install wheel && \
|
||||||
rm -f /tmp/prepare.sh
|
mkdir /opt/bunkerweb/deps/python && \
|
||||||
|
pip install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/deps/requirements.txt && \
|
||||||
|
apk del build
|
||||||
|
|
||||||
# Fix CVE-2021-22901, CVE-2021-22898 and CVE-2021-22897
|
FROM nginx:1.20.2-alpine
|
||||||
RUN apk add "curl>=7.77.0-r0"
|
|
||||||
|
|
||||||
VOLUME /www /http-confs /server-confs /modsec-confs /modsec-crs-confs /cache /pre-server-confs /acme-challenge /plugins
|
# Copy dependencies
|
||||||
|
COPY --from=builder /opt/bunkerweb /opt/bunkerweb
|
||||||
|
|
||||||
|
# Copy files
|
||||||
|
# can't exclude deps from . so we are copying everything by hand
|
||||||
|
COPY api /opt/bunkerweb/api
|
||||||
|
COPY cli /opt/bunkerweb/cli
|
||||||
|
COPY confs /opt/bunkerweb/confs
|
||||||
|
COPY core /opt/bunkerweb/core
|
||||||
|
COPY gen /opt/bunkerweb/gen
|
||||||
|
COPY helpers /opt/bunkerweb/helpers
|
||||||
|
COPY job /opt/bunkerweb/job
|
||||||
|
COPY lua /opt/bunkerweb/lua
|
||||||
|
COPY misc /opt/bunkerweb/misc
|
||||||
|
COPY utils /opt/bunkerweb/utils
|
||||||
|
COPY settings.json /opt/bunkerweb/settings.json
|
||||||
|
COPY VERSION /opt/bunkerweb/VERSION
|
||||||
|
|
||||||
|
# Install runtime dependencies, pypi packages, move bwcli, create data folders and set permissions
|
||||||
|
RUN apk add --no-cache bash python3 libgcc libstdc++ openssl git && \
|
||||||
|
chown root:nginx /opt/bunkerweb/modules && \
|
||||||
|
chmod 750 /opt/bunkerweb/modules && \
|
||||||
|
chmod 740 /opt/bunkerweb/modules/*.so && \
|
||||||
|
cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
|
||||||
|
mkdir /opt/bunkerweb/configs && \
|
||||||
|
for dir in $(echo "cache configs configs/http configs/stream configs/server-http configs/server-stream configs/default-server-http configs/default-server-stream configs/modsec configs/modsec-crs letsencrypt plugins www") ; do mkdir -p "/data/${dir}" && ln -s "/data/${dir}" "/opt/bunkerweb/${dir}" ; done && \
|
||||||
|
chown -R root:nginx /data && \
|
||||||
|
chmod -R 770 /data && \
|
||||||
|
mkdir /opt/bunkerweb/tmp && \
|
||||||
|
chown -R root:nginx /opt/bunkerweb && \
|
||||||
|
find /opt/bunkerweb -type f -exec chmod 0740 {} \; && \
|
||||||
|
find /opt/bunkerweb -type d -exec chmod 0750 {} \; && \
|
||||||
|
chmod 770 /opt/bunkerweb/cache /opt/bunkerweb/tmp && \
|
||||||
|
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /opt/bunkerweb/helpers/*.sh /usr/local/bin/bwcli /opt/bunkerweb/deps/python/bin/* && \
|
||||||
|
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
|
||||||
|
chown root:nginx /usr/local/bin/bwcli && \
|
||||||
|
chown -R nginx:nginx /etc/nginx && \
|
||||||
|
ln -s /data/letsencrypt /etc/letsencrypt && \
|
||||||
|
mkdir /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
chown root:nginx /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
chmod 770 /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
chown -R root:nginx /etc/nginx && \
|
||||||
|
chmod -R 770 /etc/nginx && \
|
||||||
|
rm -f /var/log/nginx/* && \
|
||||||
|
ln -s /proc/1/fd/2 /var/log/nginx/error.log && \
|
||||||
|
ln -s /proc/1/fd/2 /var/log/nginx/modsec_audit.log && \
|
||||||
|
ln -s /proc/1/fd/1 /var/log/nginx/access.log && \
|
||||||
|
ln -s /proc/1/fd/1 /var/log/nginx/jobs.log && \
|
||||||
|
ln -s /proc/1/fd/1 /var/log/letsencrypt/letsencrypt.log
|
||||||
|
|
||||||
|
# Fix CVE-2022-27405 and CVE-2022-27406
|
||||||
|
RUN apk add "freetype>=2.10.4-r3"
|
||||||
|
|
||||||
|
VOLUME /data
|
||||||
|
|
||||||
EXPOSE 8080/tcp 8443/tcp
|
EXPOSE 8080/tcp 8443/tcp
|
||||||
|
|
||||||
USER nginx:nginx
|
USER nginx:nginx
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 CMD [ -f /tmp/nginx.pid ] || exit 1
|
HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=6 CMD /opt/bunkerweb/helpers/healthcheck.sh
|
||||||
|
|
||||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.sh"]
|
ENTRYPOINT ["/opt/bunkerweb/helpers/entrypoint.sh"]
|
||||||
|
|||||||
668
README.md
668
README.md
@ -1,439 +1,287 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://github.com/bunkerity/bunkerized-nginx/blob/master/logo.png?raw=true" width="425" />
|
<img alt="BunkerWeb logo" src="https://github.com/bunkerity/bunkerweb/raw/master/logo.png" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/bunkerized--nginx-1.2.7-blue" />
|
<img src="https://img.shields.io/badge/bunkerweb-1.4.1-blue" />
|
||||||
<img src="https://img.shields.io/badge/nginx-1.20.1-blue" />
|
<img src="https://img.shields.io/github/last-commit/bunkerity/bunkerweb" />
|
||||||
<img src="https://img.shields.io/github/last-commit/bunkerity/bunkerized-nginx" />
|
<img src="https://img.shields.io/github/workflow/status/bunkerity/bunkerweb/Automatic%20test%2C%20build%2C%20push%20and%20deploy%20%28DEV%29?label=CI%2FCD%20dev" />
|
||||||
<img src="https://img.shields.io/github/workflow/status/bunkerity/bunkerized-nginx/Automatic%20test?label=automatic%20test" />
|
<img src="https://img.shields.io/github/workflow/status/bunkerity/bunkerweb/Automatic%20test%2C%20build%2C%20push%20and%20deploy%20%28PROD%29?label=CI%2FCD%20prod" />
|
||||||
<img src="https://img.shields.io/github/workflow/status/bunkerity/bunkerized-nginx/Build%20and%20push%20bunkerized-nginx?label=docker%20build" />
|
<img src="https://img.shields.io/github/issues/bunkerity/bunkerweb">
|
||||||
<img src="https://img.shields.io/readthedocs/bunkerized-nginx" />
|
<img src="https://img.shields.io/github/issues-pr/bunkerity/bunkerweb">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<strong>
|
📓 <a href="https://docs.bunkerweb.io">Documentation</a>
|
||||||
<a href="https://bunkerized-nginx.readthedocs.io">Documentation</a>
|
|
|
||||||
<span> | </span>
|
👨💻 <a href="https://demo.bunkerweb.io">Demo</a>
|
||||||
<a href="https://github.com/bunkerity/bunkerized-nginx/tree/master/examples">Examples</a>
|
|
|
||||||
<span> | </span>
|
🛡️ <a href="https://github.com/bunkerity/bunkerweb/tree/master/examples">Examples</a>
|
||||||
<a href="https://www.bunkerity.com/category/bunkerized-nginx/">Blog posts</a>
|
|
|
||||||
<span> | </span>
|
💬 <a href="https://discord.com/invite/fTf46FmtyD">Chat</a>
|
||||||
<a href="https://coso.me/bunkerity-chat">Community chat</a>
|
|
|
||||||
<span> | </span>
|
📝 <a href="https://github.com/bunkerity/bunkerweb/discussions">Forum</a>
|
||||||
<a href="https://coso.me/bunkerity">Follow us</a>
|
|
|
||||||
</strong>
|
⚙️ <a href="https://config.bunkerweb.io">Configurator</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
nginx Docker image secure by default.
|
> Make security by default great again !
|
||||||
|
|
||||||
Avoid the hassle of following security best practices "by hand" each time you need a web server or reverse proxy. Bunkerized-nginx provides generic security configs, settings and tools so you don't need to do it yourself.
|
# Bunkerweb
|
||||||
|
|
||||||
Non-exhaustive list of features :
|
<p align="center">
|
||||||
- HTTPS support with transparent Let's Encrypt automation
|
<img alt="overview" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/intro-overview.svg" />
|
||||||
- State-of-the-art web security : HTTP security headers, prevent leaks, TLS hardening, ...
|
</p>
|
||||||
- Integrated ModSecurity WAF with the OWASP Core Rule Set
|
|
||||||
- Automatic ban of strange behaviors
|
|
||||||
- Antibot challenge through cookie, javascript, captcha or recaptcha v3
|
|
||||||
- Block TOR, proxies, bad user-agents, countries, ...
|
|
||||||
- Block known bad IP with DNSBL and CrowdSec
|
|
||||||
- Prevent bruteforce attacks with rate limiting
|
|
||||||
- Plugins system for external security checks (e.g. : ClamAV)
|
|
||||||
- Easy to configure with environment variables or web UI
|
|
||||||
- Automatic configuration with container labels
|
|
||||||
- Docker Swarm support
|
|
||||||
|
|
||||||
Fooling automated tools/scanners :
|
BunkerWeb is a web server based on the notorious [NGINX](https://nginx.org/) and focused on security.
|
||||||
|
|
||||||
<img src="https://github.com/bunkerity/bunkerized-nginx/blob/master/demo.gif?raw=true" />
|
It integrates into existing environments ([Linux](#linux), [Docker](#docker), [Swarm](#swarm), [Kubernetes](#Kubernetes), …) to make your web services "secure by default" without any hassle. The security best practices are automatically applied for you while keeping control of every setting to meet your use case.
|
||||||
|
|
||||||
You can find a live demo at https://demo-nginx.bunkerity.com, feel free to do some security tests.
|
BunkerWeb contains primary [security features](#security-tuning) as part of the core but can be easily extended with additional ones thanks to a [plugin system](#plugins).
|
||||||
|
|
||||||
# Table of contents
|
## Why BunkerWeb ?
|
||||||
<details>
|
|
||||||
<summary>Click to show</summary>
|
|
||||||
|
|
||||||
- [Table of contents](#table-of-contents)
|
- **Easy integration into existing environments** : support for Linux, Docker, Swarm and Kubernetes
|
||||||
- [Quickstart guide](#quickstart-guide)
|
- **Highly customizable** : enable, disable and configure features easily to meet your use case
|
||||||
* [Run HTTP server with default settings](#run-http-server-with-default-settings)
|
- **Secure by default** : offers out-of-the-box and hassle-free minimal security for your web services
|
||||||
* [In combination with PHP](#in-combination-with-php)
|
- **Free as in "freedom"** : licensed under the free [AGPLv3 license](https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||||
* [Run HTTPS server with automated Let's Encrypt](#run-https-server-with-automated-lets-encrypt)
|
|
||||||
* [As a reverse proxy](#as-a-reverse-proxy)
|
## Security features
|
||||||
* [Behind a reverse proxy](#behind-a-reverse-proxy)
|
|
||||||
* [Multisite](#multisite)
|
A non-exhaustive list of security features :
|
||||||
* [Automatic configuration](#automatic-configuration)
|
|
||||||
* [Swarm mode](#swarm-mode)
|
- **HTTPS** support with transparent **Let's Encrypt** automation
|
||||||
* [Web UI](#web-ui)
|
- **State-of-the-art web security** : HTTP security headers, prevent leaks, TLS hardening, ...
|
||||||
- [Security tuning](#security-tuning)
|
- Integrated **ModSecurity WAF** with the **OWASP Core Rule Set**
|
||||||
- [Going further](#going-further)
|
- **Automatic ban** of strange behaviors based on HTTP status code
|
||||||
- [License](#license)
|
- Apply **connections and requests limit** for clients
|
||||||
- [Contributing](#contributing)
|
- **Block bots** by asking them to solve a **challenge** (e.g. : cookie, javascript, captcha, hCaptcha or reCAPTCHA)
|
||||||
</details>
|
- **Block known bad IPs** with external blacklists and DNSBL
|
||||||
|
- And much more ...
|
||||||
|
|
||||||
|
Learn more about the core security features in the [security tuning](https://docs.bunkerweb.io/latest/security-tuning) section of the documentation.
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Demo GIF" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/demo.gif" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
A demo website protected with BunkerWeb is available at [demo.bunkerweb.io](https://demo.bunkerweb.io). Feel free to visit it and perform some security tests.
|
||||||
|
|
||||||
|
# Concepts
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="BunkerWeb logo" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/concepts.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
You will find more information about the key concepts of BunkerWeb in the [documentation](https://docs.bunkerweb.io/latest/concepts).
|
||||||
|
|
||||||
|
## Integrations
|
||||||
|
|
||||||
|
The first concept is the integration of BunkerWeb into the target environment. We prefer to use the word "integration" instead of "installation" because one of the goals of BunkerWeb is to integrate seamlessly into existing environments.
|
||||||
|
|
||||||
|
The following integrations are officially supported :
|
||||||
|
|
||||||
|
- [Docker](https://docs.bunkerweb.io/latest/integrations/#docker)
|
||||||
|
- [Docker autoconf](https://docs.bunkerweb.io/latest/integrations/#docker-autoconf)
|
||||||
|
- [Swarm](https://docs.bunkerweb.io/latest/integrations/#swarm)
|
||||||
|
- [Kubernetes](https://docs.bunkerweb.io/latest/integrations/#kubernetes)
|
||||||
|
- [Linux](https://docs.bunkerweb.io/latest/integrations/#linux)
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
Once BunkerWeb is integrated into your environment, you will need to configure it to serve and protect your web applications.
|
||||||
|
|
||||||
|
Configuration of BunkerWeb is done using what we called the "settings" or "variables". Each setting is identified by a name like `AUTO_LETS_ENCRYPT` or `USE_ANTIBOT` for example. You can assign values to the settings to configure BunkerWeb.
|
||||||
|
|
||||||
|
Here is a dummy example of a BunkerWeb configuration :
|
||||||
|
|
||||||
|
```conf
|
||||||
|
SERVER_NAME=www.example.com
|
||||||
|
AUTO_LETS_ENCRYPT=yes
|
||||||
|
USE_ANTIBOT=captcha
|
||||||
|
REFERRER_POLICY=no-referrer
|
||||||
|
USE_MODSECURITY=no
|
||||||
|
USE_GZIP=yes
|
||||||
|
USE_BROTLI=no
|
||||||
|
```
|
||||||
|
|
||||||
|
You will find an easy to use settings generator at [config.bunkerweb.io](https://config.bunkerweb.io).
|
||||||
|
|
||||||
|
## Multisite mode
|
||||||
|
|
||||||
|
The multisite mode is a crucial concept to understand when using BunkerWeb. Because the goal is to protect web applications, we intrinsically inherit the concept of "virtual host" or "vhost" (more info [here](https://en.wikipedia.org/wiki/Virtual_hosting)) which makes it possible to serve multiple web applications from a single (or a cluster of) instance.
|
||||||
|
|
||||||
|
By default, the multisite mode of BunkerWeb is disabled which means that only one web application will be served and all the settings will be applied to it. The typical use case is when you have a single application to protect : you don't have to worry about the multisite and the default behavior should be the right one for you.
|
||||||
|
|
||||||
|
When multisite mode is enabled, BunkerWeb will serve and protect multiple web applications. Each web application is identified by a unique server name and have its own set of settings. The typical use case is when you have multiple applications to protect and you want to use a single (or a cluster depending of the integration) instance of BunkerWeb.
|
||||||
|
|
||||||
|
## Custom configurations
|
||||||
|
|
||||||
|
Because meeting all the use cases only using the settings is not an option (even with [external plugins](https://docs.bunkerweb.io/latest/plugins)), you can use custom configurations to solve your specific challenges.
|
||||||
|
|
||||||
|
Under the hood, BunkerWeb uses the notorious NGINX web server, that's why you can leverage its configuration system for your specific needs. Custom NGINX configurations can be included in different [contexts](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/#contexts) like HTTP or server (all servers and/or specific server block).
|
||||||
|
|
||||||
|
Another core component of BunkerWeb is the ModSecurity Web Application Firewall : you can also use custom configurations to fix some false positives or add custom rules for example.
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Docker" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/integration-docker.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
We provide ready to use prebuilt images for x64, x86, armv7 and arm64 platforms on [Docker Hub](https://hub.docker.com/r/bunkerity/bunkerweb) using the `bunkerity/bunkerweb` tag.
|
||||||
|
|
||||||
|
Usage and configuration of the BunkerWeb container are based on :
|
||||||
|
|
||||||
|
- **Environment variables** to configure BunkerWeb and meet your use cases
|
||||||
|
- **Volume** to cache important data and mount custom configuration files
|
||||||
|
- **Networks** to expose ports for clients and connect to upstream web services
|
||||||
|
|
||||||
|
You will find more information in the [Docker integration section](https://docs.bunkerweb.io/latest/integrations/#docker) of the documentation.
|
||||||
|
|
||||||
|
## Docker autoconf
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Docker autoconf" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/integration-autoconf.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
The downside of using environment variables is that the container needs to be recreated each time there is an update which is not very convenient. To counter that issue, you can use another image called **autoconf** which will listen for Docker events and automatically reconfigure BunkerWeb in real-time without recreating the container.
|
||||||
|
|
||||||
|
Instead of defining environment variables for the BunkerWeb container, you simply add **labels** to your web applications containers and the **autoconf** will "automagically" take care of the rest.
|
||||||
|
|
||||||
|
You will find more information in the [Docker autoconf section](https://docs.bunkerweb.io/latest/integrations/#docker-autoconf) of the documentation.
|
||||||
|
|
||||||
|
## Swarm
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Swarm" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/integration-swarm.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
To automatically configure BunkerWeb instances, a special service, called **autoconf**, will be scheduled on a manager node. That service will listen for Docker Swarm events like service creation or deletion and automatically configure the **BunkerWeb instances** in real-time without downtime.
|
||||||
|
|
||||||
|
Like the [Docker autoconf integration](#docker-autoconf), configuration for web services is defined using labels starting with the special **bunkerweb.** prefix.
|
||||||
|
|
||||||
|
The recommended setup is to schedule the **BunkerWeb service** as a **global service** on all worker nodes and the **autoconf service** as a **single replicated service** on a manager node.
|
||||||
|
|
||||||
|
You will find more information in the [Swarm section](https://docs.bunkerweb.io/latest/integrations/#swarm) of the documentation.
|
||||||
|
|
||||||
|
## Kubernetes
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Kubernetes" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/integration-kubernetes.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
The autoconf acts as an [Ingress controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/) and will configure the BunkerWeb instances according to the [Ingress resources](https://kubernetes.io/docs/concepts/services-networking/ingress/). It also monitors other Kubernetes objects like [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) for custom configurations.
|
||||||
|
|
||||||
|
You will find more information in the [Kubernetes section](https://docs.bunkerweb.io/latest/integrations/#kubernetes) of the documentation.
|
||||||
|
|
||||||
|
## Linux
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Linux" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/integration-linux.svg" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
List of supported Linux distros :
|
||||||
|
|
||||||
|
- Debian 11 "Bullseye"
|
||||||
|
- Ubuntu 22.04 "Jammy"
|
||||||
|
- Fedora 36
|
||||||
|
- CentOS Stream 8
|
||||||
|
|
||||||
|
Repositories of Linux packages for BunkerWeb are available on [PackageCloud](https://packagecloud.io/bunkerity/bunkerweb), they provide a bash script to automatically add and trust the repository (but you can also follow the [manual installation](https://packagecloud.io/bunkerity/bunkerweb/install) instructions if you prefer).
|
||||||
|
|
||||||
|
You will find more information in the [Linux section](https://docs.bunkerweb.io/latest/integrations/#linux) of the documentation.
|
||||||
|
|
||||||
# Quickstart guide
|
# Quickstart guide
|
||||||
|
|
||||||
## Run HTTP server with default settings
|
Once you have setup BunkerWeb with the integration of your choice, you can follow the [quickstart guide](https://docs.bunkerweb.io/latest/quickstart-guide/) that will cover the following common use cases :
|
||||||
|
- Protecting a single HTTP application
|
||||||
```shell
|
- Protecting multiple HTTP application
|
||||||
docker run -p 80:8080 -v /path/to/web/files:/www:ro bunkerity/bunkerized-nginx
|
- Retrieving the real IP of clients when operating behind a load balancer
|
||||||
```
|
- Adding custom configurations
|
||||||
|
|
||||||
Web files are stored in the /www directory, the container will serve files from there. Please note that *bunkerized-nginx* doesn't run as root but as an unprivileged user with UID/GID 101 therefore you should set the rights of */path/to/web/files* accordingly.
|
|
||||||
|
|
||||||
## In combination with PHP
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker network create mynet
|
|
||||||
```
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --network mynet \
|
|
||||||
-p 80:8080 \
|
|
||||||
-v /path/to/web/files:/www:ro \
|
|
||||||
-e REMOTE_PHP=myphp \
|
|
||||||
-e REMOTE_PHP_PATH=/app \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --network mynet \
|
|
||||||
--name myphp \
|
|
||||||
-v /path/to/web/files:/app \
|
|
||||||
php:fpm
|
|
||||||
```
|
|
||||||
|
|
||||||
The `REMOTE_PHP` environment variable lets you define the address of a remote PHP-FPM instance that will execute the .php files. `REMOTE_PHP_PATH` must be set to the directory where the PHP container will find the files.
|
|
||||||
|
|
||||||
## Run HTTPS server with automated Let's Encrypt
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-p 443:8443 \
|
|
||||||
-v /path/to/web/files:/www:ro \
|
|
||||||
-v /where/to/save/certificates:/etc/letsencrypt \
|
|
||||||
-e SERVER_NAME=www.yourdomain.com \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
Certificates are stored in the /etc/letsencrypt directory, you should save it on your local drive. Please note that *bunkerized-nginx* doesn't run as root but as an unprivileged user with UID/GID 101 therefore you should set the rights of */where/to/save/certificates* accordingly.
|
|
||||||
|
|
||||||
If you don't want your webserver to listen on HTTP add the environment variable `LISTEN_HTTP` with a *no* value (e.g. HTTPS only). But Let's Encrypt needs the port 80 to be opened so redirecting the port is mandatory.
|
|
||||||
|
|
||||||
Here you have three environment variables :
|
|
||||||
- `SERVER_NAME` : define the FQDN of your webserver, this is mandatory for Let's Encrypt (www.yourdomain.com should point to your IP address)
|
|
||||||
- `AUTO_LETS_ENCRYPT` : enable automatic Let's Encrypt creation and renewal of certificates
|
|
||||||
- `REDIRECT_HTTP_TO_HTTPS` : enable HTTP to HTTPS redirection
|
|
||||||
|
|
||||||
## As a reverse proxy
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-e USE_REVERSE_PROXY=yes \
|
|
||||||
-e REVERSE_PROXY_URL=/ \
|
|
||||||
-e REVERSE_PROXY_HOST=http://myserver:8080 \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
This is a simple reverse proxy to a unique application. If you have more than one application you can add more REVERSE_PROXY_URL/REVERSE_PROXY_HOST by appending a suffix number like this :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-e USE_REVERSE_PROXY=yes \
|
|
||||||
-e REVERSE_PROXY_URL_1=/app1/ \
|
|
||||||
-e REVERSE_PROXY_HOST_1=http://myapp1:3000/ \
|
|
||||||
-e REVERSE_PROXY_URL_2=/app2/ \
|
|
||||||
-e REVERSE_PROXY_HOST_2=http://myapp2:3000/ \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
## Behind a reverse proxy
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-v /path/to/web/files:/www \
|
|
||||||
-e PROXY_REAL_IP=yes \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
The `PROXY_REAL_IP` environment variable, when set to *yes*, activates the [ngx_http_realip_module](https://nginx.org/en/docs/http/ngx_http_realip_module.html) to get the real client IP from the reverse proxy.
|
|
||||||
|
|
||||||
See [this section](https://bunkerized-nginx.readthedocs.io/en/latest/environment_variables.html#reverse-proxy) if you need to tweak some values (trusted ip/network, header, ...).
|
|
||||||
|
|
||||||
## Multisite
|
|
||||||
|
|
||||||
By default, bunkerized-nginx will only create one server block. When setting the `MULTISITE` environment variable to *yes*, one server block will be created for each host defined in the `SERVER_NAME` environment variable.
|
|
||||||
You can set/override values for a specific server by prefixing the environment variable with one of the server name previously defined.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-p 443:8443 \
|
|
||||||
-v /where/to/save/certificates:/etc/letsencrypt \
|
|
||||||
-e SERVER_NAME=app1.domain.com app2.domain.com \
|
|
||||||
-e MULTISITE=yes \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
-e USE_REVERSE_PROXY=yes \
|
|
||||||
-e app1.domain.com_REVERSE_PROXY_URL=/ \
|
|
||||||
-e app1.domain.com_REVERSE_PROXY_HOST=http://myapp1:8000 \
|
|
||||||
-e app2.domain.com_REVERSE_PROXY_URL=/ \
|
|
||||||
-e app2.domain.com_REVERSE_PROXY_HOST=http://myapp2:8000 \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
The `USE_REVERSE_PROXY` is a *global* variable that will be applied to each server block. Whereas the `app1.domain.com_*` and `app2.domain.com_*` will only be applied to the app1.domain.com and app2.domain.com server block respectively.
|
|
||||||
|
|
||||||
When serving files, the web root directory should contains subdirectories named as the servers defined in the `SERVER_NAME` environment variable. Here is an example :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-p 443:8443 \
|
|
||||||
-v /where/to/save/certificates:/etc/letsencrypt \
|
|
||||||
-v /where/are/web/files:/www:ro \
|
|
||||||
-e SERVER_NAME=app1.domain.com app2.domain.com \
|
|
||||||
-e MULTISITE=yes \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
-e app1.domain.com_REMOTE_PHP=php1 \
|
|
||||||
-e app1.domain.com_REMOTE_PHP_PATH=/app \
|
|
||||||
-e app2.domain.com_REMOTE_PHP=php2 \
|
|
||||||
-e app2.domain.com_REMOTE_PHP_PATH=/app \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
The */where/are/web/files* directory should have a structure like this :
|
|
||||||
```shell
|
|
||||||
/where/are/web/files
|
|
||||||
├── app1.domain.com
|
|
||||||
│ └── index.php
|
|
||||||
│ └── ...
|
|
||||||
└── app2.domain.com
|
|
||||||
└── index.php
|
|
||||||
└── ...
|
|
||||||
```
|
|
||||||
|
|
||||||
## Automatic configuration
|
|
||||||
|
|
||||||
The downside of using environment variables is that you need to recreate a new container each time you want to add or remove a web service. An alternative is to use the *bunkerized-nginx-autoconf* image which listens for Docker events and "automagically" generates the configuration.
|
|
||||||
|
|
||||||
First we need a volume that will store the configurations :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker volume create nginx_conf
|
|
||||||
```
|
|
||||||
|
|
||||||
Then we run bunkerized-nginx with the `bunkerized-nginx.AUTOCONF` label, mount the created volume at /etc/nginx and set some default configurations for our services (e.g. : automatic Let's Encrypt and HTTP to HTTPS redirect) :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker network create mynet
|
|
||||||
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-p 443:8443 \
|
|
||||||
--network mynet \
|
|
||||||
-v /where/to/save/certificates:/etc/letsencrypt \
|
|
||||||
-v /where/are/web/files:/www:ro \
|
|
||||||
-v nginx_conf:/etc/nginx \
|
|
||||||
-e SERVER_NAME= \
|
|
||||||
-e MULTISITE=yes \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
-l bunkerized.nginx.AUTOCONF \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
When setting `SERVER_NAME` to nothing bunkerized-nginx won't create any server block (in case we only want automatic configuration).
|
|
||||||
|
|
||||||
Once bunkerized-nginx is created, let's setup the autoconf container :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run -v /var/run/docker.sock:/var/run/docker.sock:ro \
|
|
||||||
-v nginx_conf:/etc/nginx \
|
|
||||||
bunkerity/bunkerized-nginx-autoconf
|
|
||||||
```
|
|
||||||
|
|
||||||
We can now create a new container and use labels to dynamically configure bunkerized-nginx. Labels for automatic configuration are the same as environment variables but with the "bunkerized-nginx." prefix.
|
|
||||||
|
|
||||||
Here is a PHP example :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --network mynet \
|
|
||||||
--name myapp \
|
|
||||||
-v /where/are/web/files/app.domain.com:/app \
|
|
||||||
-l bunkerized-nginx.SERVER_NAME=app.domain.com \
|
|
||||||
-l bunkerized-nginx.REMOTE_PHP=myapp \
|
|
||||||
-l bunkerized-nginx.REMOTE_PHP_PATH=/app \
|
|
||||||
php:fpm
|
|
||||||
```
|
|
||||||
|
|
||||||
And a reverse proxy example :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --network mynet \
|
|
||||||
--name anotherapp \
|
|
||||||
-l bunkerized-nginx.SERVER_NAME=app2.domain.com \
|
|
||||||
-l bunkerized-nginx.USE_REVERSE_PROXY=yes \
|
|
||||||
-l bunkerized-nginx.REVERSE_PROXY_URL=/ \
|
|
||||||
-l bunkerized-nginx.REVERSE_PROXY_HOST=http://anotherapp \
|
|
||||||
tutum/hello-world
|
|
||||||
```
|
|
||||||
|
|
||||||
## Swarm mode
|
|
||||||
|
|
||||||
Automatic configuration through labels is also supported in swarm mode. The *bunkerized-nginx-autoconf* is used to listen for Swarm events (e.g. service create/rm) and "automagically" edit configurations files and reload nginx.
|
|
||||||
|
|
||||||
As a use case we will assume the following :
|
|
||||||
- Some managers are also workers (they will only run the *autoconf* container for obvious security reasons)
|
|
||||||
- The bunkerized-nginx service will be deployed on all workers (global mode) so clients can connect to each of them (e.g. load balancing, CDN, edge proxy, ...)
|
|
||||||
- There is a shared folder mounted on managers and workers (e.g. NFS, GlusterFS, CephFS, ...)
|
|
||||||
|
|
||||||
Let's start by creating the network to allow communications between our services :
|
|
||||||
```shell
|
|
||||||
docker network create -d overlay mynet
|
|
||||||
```
|
|
||||||
|
|
||||||
We can now create the *autoconf* service that will listen to swarm events :
|
|
||||||
```shell
|
|
||||||
docker service create --name autoconf \
|
|
||||||
--network mynet \
|
|
||||||
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock,ro \
|
|
||||||
--mount type=bind,source=/shared/confs,destination=/etc/nginx \
|
|
||||||
--mount type=bind,source=/shared/letsencrypt,destination=/etc/letsencrypt \
|
|
||||||
--mount type=bind,source=/shared/acme-challenge,destination=/acme-challenge \
|
|
||||||
-e SWARM_MODE=yes \
|
|
||||||
-e API_URI=/ChangeMeToSomethingHardToGuess \
|
|
||||||
--replicas 1 \
|
|
||||||
--constraint node.role==manager \
|
|
||||||
bunkerity/bunkerized-nginx-autoconf
|
|
||||||
```
|
|
||||||
|
|
||||||
**You need to change `API_URI` to something hard to guess since there is no other security mechanism to protect the API at the moment.**
|
|
||||||
|
|
||||||
When *autoconf* is created, it's time for the *bunkerized-nginx* service to be up :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker service create --name nginx \
|
|
||||||
--network mynet \
|
|
||||||
-p published=80,target=8080,mode=host \
|
|
||||||
-p published=443,target=8443,mode=host \
|
|
||||||
--mount type=bind,source=/shared/confs,destination=/etc/nginx \
|
|
||||||
--mount type=bind,source=/shared/letsencrypt,destination=/etc/letsencrypt,ro \
|
|
||||||
--mount type=bind,source=/shared/acme-challenge,destination=/acme-challenge,ro \
|
|
||||||
--mount type=bind,source=/shared/www,destination=/www,ro \
|
|
||||||
-e SWARM_MODE=yes \
|
|
||||||
-e USE_API=yes \
|
|
||||||
-e API_URI=/ChangeMeToSomethingHardToGuess \
|
|
||||||
-e MULTISITE=yes \
|
|
||||||
-e SERVER_NAME= \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
-l bunkerized-nginx.AUTOCONF \
|
|
||||||
--mode global \
|
|
||||||
--constraint node.role==worker \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
The `API_URI` value must be the same as the one specified for the *autoconf* service.
|
|
||||||
|
|
||||||
We can now create a new service and use labels to dynamically configure bunkerized-nginx. Labels for automatic configuration are the same as environment variables but with the "bunkerized-nginx." prefix.
|
|
||||||
|
|
||||||
Here is a PHP example :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker service create --name myapp \
|
|
||||||
--network mynet \
|
|
||||||
--mount type=bind,source=/shared/www/app.domain.com,destination=/app \
|
|
||||||
-l bunkerized-nginx.SERVER_NAME=app.domain.com \
|
|
||||||
-l bunkerized-nginx.REMOTE_PHP=myapp \
|
|
||||||
-l bunkerized-nginx.REMOTE_PHP_PATH=/app \
|
|
||||||
--constraint node.role==worker \
|
|
||||||
php:fpm
|
|
||||||
```
|
|
||||||
|
|
||||||
And a reverse proxy example :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker service create --name anotherapp \
|
|
||||||
--network mynet \
|
|
||||||
-l bunkerized-nginx.SERVER_NAME=app2.domain.com \
|
|
||||||
-l bunkerized-nginx.USE_REVERSE_PROXY=yes \
|
|
||||||
-l bunkerized-nginx.REVERSE_PROXY_URL=/ \
|
|
||||||
-l bunkerized-nginx.REVERSE_PROXY_HOST=http://anotherapp \
|
|
||||||
--constraint node.role==worker \
|
|
||||||
tutum/hello-world
|
|
||||||
```
|
|
||||||
|
|
||||||
## Web UI
|
|
||||||
|
|
||||||
A dedicated image, *bunkerized-nginx-ui*, lets you manage bunkerized-nginx instances and services configurations through a web user interface. This feature is still in beta, feel free to open a new issue if you find a bug and/or you have an idea to improve it.
|
|
||||||
|
|
||||||
First we need a volume that will store the configurations and a network because bunkerized-nginx will be used as a reverse proxy for the web UI :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker volume create nginx_conf
|
|
||||||
docker network create mynet
|
|
||||||
```
|
|
||||||
|
|
||||||
Let's create the bunkerized-nginx-ui container that will host the web UI behind bunkerized-nginx :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --network mynet \
|
|
||||||
--name myui \
|
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
|
||||||
-v nginx_conf:/etc/nginx \
|
|
||||||
-e ABSOLUTE_URI=https://admin.domain.com/webui/ \
|
|
||||||
bunkerity/bunkerized-nginx-ui
|
|
||||||
```
|
|
||||||
|
|
||||||
You will need to edit the `ABSOLUTE_URI` environment variable to reflect your actual URI of the web UI.
|
|
||||||
|
|
||||||
We can now setup the bunkerized-nginx instance with the `bunkerized-nginx.UI` label and a reverse proxy configuration for our web UI :
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker network create mynet
|
|
||||||
|
|
||||||
docker run -p 80:8080 \
|
|
||||||
-p 443:8443 \
|
|
||||||
--network mynet \
|
|
||||||
-v nginx_conf:/etc/nginx \
|
|
||||||
-v /where/are/web/files:/www:ro \
|
|
||||||
-v /where/to/save/certificates:/etc/letsencrypt \
|
|
||||||
-e SERVER_NAME=admin.domain.com \
|
|
||||||
-e MULTISITE=yes \
|
|
||||||
-e AUTO_LETS_ENCRYPT=yes \
|
|
||||||
-e REDIRECT_HTTP_TO_HTTPS=yes \
|
|
||||||
-e DISABLE_DEFAULT_SERVER=yes \
|
|
||||||
-e admin.domain.com_USE_MODSECURITY=no \
|
|
||||||
-e admin.domain.com_SERVE_FILES=no \
|
|
||||||
-e admin.domain.com_USE_AUTH_BASIC=yes \
|
|
||||||
-e admin.domain.com_AUTH_BASIC_USER=admin \
|
|
||||||
-e admin.domain.com_AUTH_BASIC_PASSWORD=password \
|
|
||||||
-e admin.domain.com_USE_REVERSE_PROXY=yes \
|
|
||||||
-e admin.domain.com_REVERSE_PROXY_URL=/webui/ \
|
|
||||||
-e admin.domain.com_REVERSE_PROXY_HOST=http://myui:5000/ \
|
|
||||||
-l bunkerized-nginx.UI \
|
|
||||||
bunkerity/bunkerized-nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
The `AUTH_BASIC` environment variables let you define a login/password that must be provided before accessing to the web UI. At the moment, there is no authentication mechanism integrated into bunkerized-nginx-ui so **using auth basic with a strong password coupled with a "hard to guess" URI is strongly recommended**.
|
|
||||||
|
|
||||||
Web UI should now be accessible from https://admin.domain.com/webui/.
|
|
||||||
|
|
||||||
# Security tuning
|
# Security tuning
|
||||||
|
|
||||||
bunkerized-nginx comes with a set of predefined security settings that you can (and you should) tune to meet your own use case. We recommend you to read the [security tuning](https://bunkerized-nginx.readthedocs.io/en/latest/security_tuning.html) section of the documentation.
|
BunkerWeb offers many security features that you can configure with [settings](/settings). Even if the default values of settings ensure a minimal "security by default", we strongly recommend you to tune them. By doing so you will be able to ensure a security level of your choice but also manage false positives.
|
||||||
|
|
||||||
# Going further
|
You will find more information in the [security tuning section](https://docs.bunkerweb.io/latest/security-tuning) of the documentation.
|
||||||
|
|
||||||
- [Official documentation](https://bunkerized-nginx.readthedocs.io/)
|
# Settings
|
||||||
- [Full concrete examples](https://github.com/bunkerity/bunkerized-nginx/tree/master/examples)
|
|
||||||
- [Tutorials in our blog](https://www.bunkerity.com/blog)
|
To help you tuning BunkerWeb we have made an easy to use settings generator tool available at [config.bunkerweb.io](https://config.bunkerweb.io).
|
||||||
|
|
||||||
|
As a general rule when multisite mode is enabled, if you want to apply settings with multisite context to a specific server you will need to add the primary (first) server name as a prefix like `www.example.com_USE_ANTIBOT=captcha` or `myapp.example.com_USE_GZIP=yes` for example.
|
||||||
|
|
||||||
|
When settings are considered as "multiple", it means that you can have multiple groups of settings for the same feature by adding numbers as suffix like `REVERSE_PROXY_URL_1=/subdir`, `REVERSE_PROXY_HOST_1=http://myhost1`, `REVERSE_PROXY_URL_2=/anotherdir`, `REVERSE_PROXY_HOST_2=http://myhost2`, ... for example.
|
||||||
|
|
||||||
|
Check the [settings section](https://docs.bunkerweb.io/latest/settings) of the documentation to get the full list.
|
||||||
|
|
||||||
|
# Web UI
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="Linux" src="https://github.com/bunkerity/bunkerweb/raw/master/docs/assets/img/demo_bunkerweb_ui.gif" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
The "Web UI" is a web application that helps you manage your BunkerWeb instance using a user-friendly interface instead of the command-line one.
|
||||||
|
|
||||||
|
- Start, stop, restart and reload your BunkerWeb instance
|
||||||
|
- Add, edit and delete settings for your web applications
|
||||||
|
- Add, edit and delete custom configurations for NGINX and ModSecurity
|
||||||
|
- Install and uninstall external plugins
|
||||||
|
- View the logs and search pattern
|
||||||
|
|
||||||
|
You will find more information in the [Web UI section](https://docs.bunkerweb.io/latest/web-ui) of the documentation.
|
||||||
|
|
||||||
|
# Plugins
|
||||||
|
|
||||||
|
BunkerWeb comes with a plugin system to make it possible to easily add new features. Once a plugin is installed, you can manage it using additional settings defined by the plugin.
|
||||||
|
|
||||||
|
Here is the list of "official" plugins that we maintain (see the [bunkerweb-plugins](https://github.com/bunkerity/bunkerweb-plugins) repository for more information) :
|
||||||
|
|
||||||
|
| Name | Version | Description | Link |
|
||||||
|
| :------------: | :-----: | :------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------: |
|
||||||
|
| **ClamAV** | 0.1 | Automatically scans uploaded files with the ClamAV antivirus engine and denies the request when a file is detected as malicious. | [bunkerweb-plugins/clamav](https://github.com/bunkerity/bunkerweb-plugins/tree/main/clamav) |
|
||||||
|
| **CrowdSec** | 0.1 | CrowdSec bouncer for BunkerWeb. | [bunkerweb-plugins/crowdsec](https://github.com/bunkerity/bunkerweb-plugins/tree/main/crowdsec) |
|
||||||
|
| **VirusTotal** | 0.1 | Automatically scans uploaded files with the VirusTotal API and denies the request when a file is detected as malicious. | [bunkerweb-plugins/virustotal](https://github.com/bunkerity/bunkerweb-plugins/tree/main/virustotal) |
|
||||||
|
|
||||||
|
You will find more information in the [plugins section](https://docs.bunkerweb.io/latest/plugins) of the documentation.
|
||||||
|
|
||||||
|
# Support
|
||||||
|
|
||||||
|
## Professional
|
||||||
|
|
||||||
|
We offer professional services related to BunkerWeb like :
|
||||||
|
|
||||||
|
* Consulting
|
||||||
|
* Support
|
||||||
|
* Custom development
|
||||||
|
* Partnership
|
||||||
|
|
||||||
|
Please contact us at [contact@bunkerity.com](mailto:contact@bunkerity.com) if you are interested.
|
||||||
|
|
||||||
|
## Community
|
||||||
|
|
||||||
|
To get free community support you can use the following medias :
|
||||||
|
|
||||||
|
* The #help channel of BunkerWeb in the [Discord server](https://discord.com/invite/fTf46FmtyD)
|
||||||
|
* The help category of [GitHub dicussions](https://github.com/bunkerity/bunkerweb/discussions)
|
||||||
|
* The [/r/BunkerWeb](https://www.reddit.com/r/BunkerWeb) subreddit
|
||||||
|
* The [Server Fault](https://serverfault.com/) and [Super User](https://superuser.com/) forums
|
||||||
|
|
||||||
|
Please don't use [GitHub issues](https://github.com/bunkerity/bunkerweb/issues) to ask for help, use it only for bug reports and feature requests.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
This project is licensed under the terms of the [GNU Affero General Public License (AGPL) version 3](https://github.com/bunkerity/bunkerized-nginx/LICENSE.md).
|
This project is licensed under the terms of the [GNU Affero General Public License (AGPL) version 3](https://github.com/bunkerity/bunkerweb/tree/master/LICENSE.md).
|
||||||
|
|
||||||
# Contributing
|
# Contribute
|
||||||
|
|
||||||
If you would like to contribute to the project you can read the [contributing guidelines](https://github.com/bunkerity/bunkerized-nginx/CONTRIBUTING.md) to get started.
|
If you would like to contribute to the plugins you can read the [contributing guidelines](https://github.com/bunkerity/bunkerweb/tree/master/LICENSE.md) to get started.
|
||||||
|
|
||||||
|
# Security policy
|
||||||
|
|
||||||
|
We take security bugs as serious issues and encourage responsible disclosure, see our [security policy](https://github.com/bunkerity/bunkerweb/tree/master/SECURITY.md) for more information.
|
||||||
17
SECURITY.md
Normal file
17
SECURITY.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Security policy
|
||||||
|
|
||||||
|
Even though this project is focused on security, it is still prone to possible vulnerabilities. We consider every security bug as a serious issue and will try our best to address it.
|
||||||
|
|
||||||
|
## Responsible disclosure
|
||||||
|
|
||||||
|
If you have found a security bug, please send us an email at security \[@\] bunkerity.com with technical details so we can resolve it as soon as possible.
|
||||||
|
|
||||||
|
Here is a non-exhaustive list of issues we consider as high risk :
|
||||||
|
- Vulnerability in the code
|
||||||
|
- Bypass of a security feature
|
||||||
|
- Vulnerability in a third-party dependency
|
||||||
|
- Risk in the supply chain
|
||||||
|
|
||||||
|
## Bounty
|
||||||
|
|
||||||
|
To encourage responsible disclosure, we may reward you with a bounty at the sole discretion of the maintainers.
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<form method="POST" action="%s">
|
|
||||||
<img src="data:image/jpeg;base64,%s" /><br>
|
|
||||||
Captcha : <input type="text" name="captcha" /><br />
|
|
||||||
<input type="submit" value="send" />
|
|
||||||
</form>
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Website protection</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #1d70b7;
|
|
||||||
}
|
|
||||||
.centered {
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="centered" style="color: white;">
|
|
||||||
<h1>As a security measure, we ask you to complete this captcha to access our website :</h1>
|
|
||||||
%CAPTCHA%
|
|
||||||
<div>🛡️ this website is protected with <a href="https://github.com/bunkerity/bunkerized-nginx" target="_blank">bunkerized-nginx</a> 🛡️</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
<script>
|
|
||||||
async function digestMessage(message) {
|
|
||||||
const msgUint8 = new TextEncoder().encode(message);
|
|
||||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);
|
|
||||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
||||||
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
||||||
return hashHex;
|
|
||||||
}
|
|
||||||
(async () => {
|
|
||||||
const nonce = '%s';
|
|
||||||
var i = 0;
|
|
||||||
while (true) {
|
|
||||||
var digestHex = await digestMessage(nonce + i.toString());
|
|
||||||
if (digestHex.startsWith("0000")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('POST', '%s');
|
|
||||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
||||||
xhr.onload = function() {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
window.location.replace('%s');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.send(encodeURI('challenge=' + i.toString()));
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Website protection</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #1d70b7;
|
|
||||||
}
|
|
||||||
.centered {
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
border: 16px solid #1d70b7;
|
|
||||||
border-top: 16px solid #2dab66;
|
|
||||||
border-radius: 50%;
|
|
||||||
width: 120px;
|
|
||||||
height: 120px;
|
|
||||||
animation: spin 2s linear infinite;
|
|
||||||
display: block;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
0% { transform: rotate(0deg); }
|
|
||||||
100% { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="centered" style="color: white;">
|
|
||||||
<div class="loader"></div>
|
|
||||||
<noscript>
|
|
||||||
<h1 style="color: red;">In order to access this website, you need to enable JavaScript.</h1>
|
|
||||||
</noscript>
|
|
||||||
<h1>Please wait while we are doing some security checks...</h1>
|
|
||||||
🛡️ this website is protected with <a href="https://github.com/bunkerity/bunkerized-nginx" target="_blank">bunkerized-nginx</a> 🛡️
|
|
||||||
</div>
|
|
||||||
%JAVASCRIPT%
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
<form method="POST" action="%s" id="form">
|
|
||||||
<input type="hidden" name="token" id="token">
|
|
||||||
</form>
|
|
||||||
<script>
|
|
||||||
grecaptcha.ready(function() {
|
|
||||||
grecaptcha.execute('%s', {action: 'recaptcha'}).then(function(token) {
|
|
||||||
document.getElementById("token").value = token;
|
|
||||||
document.getElementById("form").submit();
|
|
||||||
});;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@ -1 +0,0 @@
|
|||||||
<script src="https://www.google.com/recaptcha/api.js?render=%s"></script>
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Website protection</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #1d70b7;
|
|
||||||
}
|
|
||||||
.centered {
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
border: 16px solid #1d70b7;
|
|
||||||
border-top: 16px solid #2dab66;
|
|
||||||
border-radius: 50%;
|
|
||||||
width: 120px;
|
|
||||||
height: 120px;
|
|
||||||
animation: spin 2s linear infinite;
|
|
||||||
display: block;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
0% { transform: rotate(0deg); }
|
|
||||||
100% { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
%RECAPTCHA_HEAD%
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="centered" style="color: white;">
|
|
||||||
<div class="loader"></div>
|
|
||||||
<noscript>
|
|
||||||
<h1 style="color: red;">In order to access this website, you need to enable JavaScript.</h1>
|
|
||||||
</noscript>
|
|
||||||
<h1>Please wait while we are doing some security checks...</h1>
|
|
||||||
🛡️ this website is protected with <a href="https://github.com/bunkerity/bunkerized-nginx" target="_blank">bunkerized-nginx</a> 🛡️
|
|
||||||
</div>
|
|
||||||
%RECAPTCHA_BODY%
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
32
api/API.py
Normal file
32
api/API.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from requests import request
|
||||||
|
|
||||||
|
class API :
|
||||||
|
|
||||||
|
def __init__(self, endpoint, host="bwapi") :
|
||||||
|
self.__endpoint = endpoint
|
||||||
|
self.__host = host
|
||||||
|
|
||||||
|
def get_endpoint(self) :
|
||||||
|
return self.__endpoint
|
||||||
|
|
||||||
|
def get_host(self) :
|
||||||
|
return self.__host
|
||||||
|
|
||||||
|
def request(self, method, url, data=None, files=None, timeout=(10, 30)) :
|
||||||
|
try :
|
||||||
|
headers = {}
|
||||||
|
headers["User-Agent"] = "bwapi"
|
||||||
|
headers["Host"] = self.__host
|
||||||
|
if type(data) is dict :
|
||||||
|
resp = request(method, self.__endpoint + url, json=data, timeout=timeout, headers=headers)
|
||||||
|
elif type(data) is bytes :
|
||||||
|
resp = request(method, self.__endpoint + url, data=data, timeout=timeout, headers=headers)
|
||||||
|
elif files is not None :
|
||||||
|
resp = request(method, self.__endpoint + url, files=files, timeout=timeout, headers=headers)
|
||||||
|
elif data is None :
|
||||||
|
resp = request(method, self.__endpoint + url, timeout=timeout, headers=headers)
|
||||||
|
else :
|
||||||
|
return False, "unsupported data type", None, None
|
||||||
|
except Exception as e :
|
||||||
|
return False, str(e), None, None
|
||||||
|
return True, "ok", resp.status_code, resp.json()
|
||||||
@ -1,195 +0,0 @@
|
|||||||
from Config import Config
|
|
||||||
|
|
||||||
import utils
|
|
||||||
|
|
||||||
import os, time
|
|
||||||
|
|
||||||
class AutoConf :
|
|
||||||
|
|
||||||
def __init__(self, swarm, api) :
|
|
||||||
self.__swarm = swarm
|
|
||||||
self.__servers = {}
|
|
||||||
self.__instances = {}
|
|
||||||
self.__env = {}
|
|
||||||
self.__config = Config(self.__swarm, api)
|
|
||||||
|
|
||||||
def get_server(self, id) :
|
|
||||||
if id in self.__servers :
|
|
||||||
return self.__servers[id]
|
|
||||||
return False
|
|
||||||
|
|
||||||
def reload(self) :
|
|
||||||
return self.__config.reload(self.__instances)
|
|
||||||
|
|
||||||
def __gen_env(self) :
|
|
||||||
self.__env.clear()
|
|
||||||
# TODO : check actual state (e.g. : running, stopped ?)
|
|
||||||
for id, instance in self.__instances.items() :
|
|
||||||
env = []
|
|
||||||
if self.__swarm :
|
|
||||||
env = instance.attrs["Spec"]["TaskTemplate"]["ContainerSpec"]["Env"]
|
|
||||||
else :
|
|
||||||
env = instance.attrs["Config"]["Env"]
|
|
||||||
for entry in env :
|
|
||||||
self.__env[entry.split("=")[0]] = entry.replace(entry.split("=")[0] + "=", "", 1)
|
|
||||||
blacklist = ["NGINX_VERSION", "NJS_VERSION", "PATH", "PKG_RELEASE"]
|
|
||||||
for entry in blacklist :
|
|
||||||
if entry in self.__env :
|
|
||||||
del self.__env[entry]
|
|
||||||
if not "SERVER_NAME" in self.__env or self.__env["SERVER_NAME"] == "" :
|
|
||||||
self.__env["SERVER_NAME"] = []
|
|
||||||
else :
|
|
||||||
self.__env["SERVER_NAME"] = self.__env["SERVER_NAME"].split(" ")
|
|
||||||
for server in self.__servers :
|
|
||||||
(id, name, labels) = self.__get_infos(self.__servers[server])
|
|
||||||
first_server = labels["bunkerized-nginx.SERVER_NAME"].split(" ")[0]
|
|
||||||
for label in labels :
|
|
||||||
if label.startswith("bunkerized-nginx.") :
|
|
||||||
self.__env[first_server + "_" + label.replace("bunkerized-nginx.", "", 1)] = labels[label]
|
|
||||||
for server_name in labels["bunkerized-nginx.SERVER_NAME"].split(" ") :
|
|
||||||
if not server_name in self.__env["SERVER_NAME"] :
|
|
||||||
self.__env["SERVER_NAME"].append(server_name)
|
|
||||||
self.__env["SERVER_NAME"] = " ".join(self.__env["SERVER_NAME"])
|
|
||||||
|
|
||||||
def pre_process(self, objs) :
|
|
||||||
for instance in objs :
|
|
||||||
(id, name, labels) = self.__get_infos(instance)
|
|
||||||
if "bunkerized-nginx.AUTOCONF" in labels :
|
|
||||||
if self.__swarm :
|
|
||||||
self.__process_instance(instance, "create", id, name, labels)
|
|
||||||
else :
|
|
||||||
if instance.status in ("restarting", "running", "created", "exited") :
|
|
||||||
self.__process_instance(instance, "create", id, name, labels)
|
|
||||||
if instance.status == "running" :
|
|
||||||
self.__process_instance(instance, "start", id, name, labels)
|
|
||||||
|
|
||||||
for server in objs :
|
|
||||||
(id, name, labels) = self.__get_infos(server)
|
|
||||||
if "bunkerized-nginx.SERVER_NAME" in labels :
|
|
||||||
if self.__swarm :
|
|
||||||
self.__process_server(server, "create", id, name, labels)
|
|
||||||
else :
|
|
||||||
if server.status in ("restarting", "running", "created", "exited") :
|
|
||||||
self.__process_server(server, "create", id, name, labels)
|
|
||||||
if server.status == "running" :
|
|
||||||
self.__process_server(server, "start", id, name, labels)
|
|
||||||
|
|
||||||
def process(self, obj, event) :
|
|
||||||
(id, name, labels) = self.__get_infos(obj)
|
|
||||||
if "bunkerized-nginx.AUTOCONF" in labels :
|
|
||||||
self.__process_instance(obj, event, id, name, labels)
|
|
||||||
elif "bunkerized-nginx.SERVER_NAME" in labels :
|
|
||||||
self.__process_server(obj, event, id, name, labels)
|
|
||||||
|
|
||||||
def __get_infos(self, obj) :
|
|
||||||
if self.__swarm :
|
|
||||||
id = obj.id
|
|
||||||
name = obj.name
|
|
||||||
labels = obj.attrs["Spec"]["Labels"]
|
|
||||||
else :
|
|
||||||
id = obj.id
|
|
||||||
name = obj.name
|
|
||||||
labels = obj.labels
|
|
||||||
return (id, name, labels)
|
|
||||||
|
|
||||||
def __process_instance(self, instance, event, id, name, labels) :
|
|
||||||
|
|
||||||
if event == "create" :
|
|
||||||
self.__instances[id] = instance
|
|
||||||
self.__gen_env()
|
|
||||||
utils.log("[*] bunkerized-nginx instance created : " + name + " / " + id)
|
|
||||||
if self.__swarm and len(self.__instances) == 1 :
|
|
||||||
if self.__config.generate(self.__env) :
|
|
||||||
utils.log("[*] Initial config succeeded")
|
|
||||||
if not self.__config.swarm_wait(self.__instances) :
|
|
||||||
utils.log("[!] Removing bunkerized-nginx instances from list (API not available)")
|
|
||||||
del self.__instances[id]
|
|
||||||
else :
|
|
||||||
utils.log("[!] Initial config failed")
|
|
||||||
elif not self.__swarm and len(self.__instances) == 1 :
|
|
||||||
utils.log("[*] Wait until bunkerized-nginx is healthy (timeout = 120s) ...")
|
|
||||||
i = 0
|
|
||||||
healthy = False
|
|
||||||
while i < 120 :
|
|
||||||
self.__instances[id].reload()
|
|
||||||
if self.__instances[id].attrs["State"]["Health"]["Status"] == "healthy" :
|
|
||||||
healthy = True
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
i = i + 1
|
|
||||||
if not healthy :
|
|
||||||
utils.log("[!] Removing bunkerized-nginx instances from list (unhealthy)")
|
|
||||||
del self.__instances[id]
|
|
||||||
|
|
||||||
elif event == "start" :
|
|
||||||
self.__instances[id].reload()
|
|
||||||
self.__gen_env()
|
|
||||||
utils.log("[*] bunkerized-nginx instance started : " + name + " / " + id)
|
|
||||||
|
|
||||||
elif event == "die" :
|
|
||||||
self.__instances[id].reload()
|
|
||||||
self.__gen_env()
|
|
||||||
utils.log("[*] bunkerized-nginx instance stopped : " + name + " / " + id)
|
|
||||||
|
|
||||||
elif event == "destroy" or event == "remove" :
|
|
||||||
del self.__instances[id]
|
|
||||||
self.__gen_env()
|
|
||||||
utils.log("[*] bunkerized-nginx instance removed : " + name + " / " + id)
|
|
||||||
|
|
||||||
def __process_server(self, instance, event, id, name, labels) :
|
|
||||||
|
|
||||||
vars = { k.replace("bunkerized-nginx.", "", 1) : v for k, v in labels.items() if k.startswith("bunkerized-nginx.")}
|
|
||||||
|
|
||||||
if event == "create" :
|
|
||||||
utils.log("[*] Generating config for " + vars["SERVER_NAME"] + " ...")
|
|
||||||
self.__servers[id] = instance
|
|
||||||
self.__gen_env()
|
|
||||||
if self.__config.generate(self.__env) :
|
|
||||||
utils.log("[*] Generated config for " + vars["SERVER_NAME"])
|
|
||||||
if self.__swarm :
|
|
||||||
utils.log("[*] Activating config for " + vars["SERVER_NAME"] + " ...")
|
|
||||||
if self.__config.reload(self.__instances) :
|
|
||||||
utils.log("[*] Activated config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't activate config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't generate config for " + vars["SERVER_NAME"])
|
|
||||||
del self.__servers[id]
|
|
||||||
self.__gen_env()
|
|
||||||
self.__config.generate(self.__env)
|
|
||||||
|
|
||||||
elif event == "start" :
|
|
||||||
if id in self.__servers :
|
|
||||||
self.__servers[id].reload()
|
|
||||||
utils.log("[*] Activating config for " + vars["SERVER_NAME"] + " ...")
|
|
||||||
self.__gen_env()
|
|
||||||
if self.__config.reload(self.__instances) :
|
|
||||||
utils.log("[*] Activated config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't activate config for " + vars["SERVER_NAME"])
|
|
||||||
|
|
||||||
elif event == "die" :
|
|
||||||
if id in self.__servers :
|
|
||||||
self.__servers[id].reload()
|
|
||||||
utils.log("[*] Deactivating config for " + vars["SERVER_NAME"])
|
|
||||||
self.__gen_env()
|
|
||||||
if self.__config.reload() :
|
|
||||||
utils.log("[*] Deactivated config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't deactivate config for " + vars["SERVER_NAME"])
|
|
||||||
|
|
||||||
elif event == "destroy" or event == "remove" :
|
|
||||||
if id in self.__servers :
|
|
||||||
utils.log("[*] Removing config for " + vars["SERVER_NAME"])
|
|
||||||
del self.__servers[id]
|
|
||||||
self.__gen_env()
|
|
||||||
if self.__config.generate(self.__env) :
|
|
||||||
utils.log("[*] Removed config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't remove config for " + vars["SERVER_NAME"])
|
|
||||||
utils.log("[*] Deactivating config for " + vars["SERVER_NAME"])
|
|
||||||
if self.__config.reload(self.__instances) :
|
|
||||||
utils.log("[*] Deactivated config for " + vars["SERVER_NAME"])
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't deactivate config for " + vars["SERVER_NAME"])
|
|
||||||
|
|
||||||
@ -1,125 +1,217 @@
|
|||||||
#!/usr/bin/python3
|
from traceback import format_exc
|
||||||
|
from threading import Thread, Lock
|
||||||
|
from time import sleep
|
||||||
|
from subprocess import run, DEVNULL, STDOUT
|
||||||
|
from glob import glob
|
||||||
|
from shutil import rmtree
|
||||||
|
from os import makedirs
|
||||||
|
from os.path import dirname
|
||||||
|
from json import loads
|
||||||
|
|
||||||
import utils
|
from API import API
|
||||||
import subprocess, shutil, os, traceback, requests, time
|
from JobScheduler import JobScheduler
|
||||||
|
from ApiCaller import ApiCaller
|
||||||
|
from ConfigCaller import ConfigCaller
|
||||||
|
from logger import log
|
||||||
|
|
||||||
class Config :
|
class Config(ApiCaller, ConfigCaller) :
|
||||||
|
|
||||||
def __init__(self, swarm, api) :
|
def __init__(self, ctrl_type, lock=None) :
|
||||||
self.__swarm = swarm
|
ApiCaller.__init__(self)
|
||||||
self.__api = api
|
ConfigCaller.__init__(self)
|
||||||
|
self.__ctrl_type = ctrl_type
|
||||||
|
self.__lock = lock
|
||||||
|
self.__instances = []
|
||||||
|
self.__services = []
|
||||||
|
self.__configs = []
|
||||||
|
self.__config = {}
|
||||||
|
self.__scheduler = None
|
||||||
|
self.__scheduler_thread = None
|
||||||
|
self.__schedule = False
|
||||||
|
self.__schedule_lock = Lock()
|
||||||
|
|
||||||
def __jobs(self, type) :
|
def __get_full_env(self) :
|
||||||
utils.log("[*] Starting jobs (type = " + type + ") ...")
|
env_instances = {}
|
||||||
proc = subprocess.run(["/bin/su", "-c", "/opt/entrypoint/" + type + "-jobs.sh", "nginx"], capture_output=True)
|
for instance in self.__instances :
|
||||||
stdout = proc.stdout.decode("ascii")
|
for variable, value in instance["env"].items() :
|
||||||
stderr = proc.stderr.decode("ascii")
|
env_instances[variable] = value
|
||||||
if len(stdout) > 1 :
|
env_services = {}
|
||||||
utils.log("[*] Jobs stdout :")
|
if not "SERVER_NAME" in env_instances :
|
||||||
utils.log(stdout)
|
env_instances["SERVER_NAME"] = ""
|
||||||
if stderr != "" :
|
for service in self.__services :
|
||||||
utils.log("[!] Jobs stderr :")
|
for variable, value in service.items() :
|
||||||
utils.log(stderr)
|
env_services[service["SERVER_NAME"].split(" ")[0] + "_" + variable] = value
|
||||||
if proc.returncode != 0 :
|
if env_instances["SERVER_NAME"] != "" :
|
||||||
utils.log("[!] Jobs error : return code != 0")
|
env_instances["SERVER_NAME"] += " "
|
||||||
return False
|
env_instances["SERVER_NAME"] += service["SERVER_NAME"].split(" ")[0]
|
||||||
|
return self._full_env(env_instances, env_services)
|
||||||
|
|
||||||
|
def __scheduler_run_pending(self) :
|
||||||
|
schedule = True
|
||||||
|
while schedule :
|
||||||
|
self.__scheduler.run_pending()
|
||||||
|
sleep(1)
|
||||||
|
self.__schedule_lock.acquire()
|
||||||
|
schedule = self.__schedule
|
||||||
|
self.__schedule_lock.release()
|
||||||
|
|
||||||
|
def update_needed(self, instances, services, configs=None) :
|
||||||
|
if instances != self.__instances :
|
||||||
return True
|
return True
|
||||||
|
if services != self.__services :
|
||||||
def swarm_wait(self, instances) :
|
|
||||||
try :
|
|
||||||
with open("/etc/nginx/autoconf", "w") as f :
|
|
||||||
f.write("ok")
|
|
||||||
utils.log("[*] Waiting for bunkerized-nginx tasks ...")
|
|
||||||
i = 1
|
|
||||||
started = False
|
|
||||||
while i <= 10 :
|
|
||||||
time.sleep(i)
|
|
||||||
if self.__ping(instances) :
|
|
||||||
started = True
|
|
||||||
break
|
|
||||||
i = i + 1
|
|
||||||
utils.log("[!] Waiting " + str(i) + " seconds before retrying to contact bunkerized-nginx tasks")
|
|
||||||
if started :
|
|
||||||
utils.log("[*] bunkerized-nginx tasks started")
|
|
||||||
return True
|
return True
|
||||||
else :
|
if configs is not None and configs != self.__configs :
|
||||||
utils.log("[!] bunkerized-nginx tasks are not started")
|
|
||||||
except Exception as e :
|
|
||||||
utils.log("[!] Error while waiting for Swarm tasks : " + str(e))
|
|
||||||
return False
|
|
||||||
|
|
||||||
def generate(self, env) :
|
|
||||||
try :
|
|
||||||
# Write environment variables to a file
|
|
||||||
with open("/tmp/variables.env", "w") as f :
|
|
||||||
for k, v in env.items() :
|
|
||||||
f.write(k + "=" + v + "\n")
|
|
||||||
|
|
||||||
# Call the generator
|
|
||||||
proc = subprocess.run(["/bin/su", "-c", "/opt/gen/main.py --settings /opt/settings.json --templates /opt/confs --output /etc/nginx --variables /tmp/variables.env", "nginx"], capture_output=True)
|
|
||||||
|
|
||||||
# Print stdout/stderr
|
|
||||||
stdout = proc.stdout.decode("ascii")
|
|
||||||
stderr = proc.stderr.decode("ascii")
|
|
||||||
if len(stdout) > 1 :
|
|
||||||
utils.log("[*] Generator output :")
|
|
||||||
utils.log(stdout)
|
|
||||||
if stderr != "" :
|
|
||||||
utils.log("[*] Generator error :")
|
|
||||||
utils.log(error)
|
|
||||||
|
|
||||||
# We're done
|
|
||||||
if proc.returncode == 0 :
|
|
||||||
if self.__swarm :
|
|
||||||
return self.__jobs("pre")
|
|
||||||
return True
|
|
||||||
utils.log("[!] Error while generating site config for " + env["SERVER_NAME"] + " : return code = " + str(proc.returncode))
|
|
||||||
|
|
||||||
except Exception as e :
|
|
||||||
utils.log("[!] Exception while generating site config : " + str(e))
|
|
||||||
return False
|
|
||||||
|
|
||||||
def reload(self, instances) :
|
|
||||||
if self.__api_call(instances, "/reload") :
|
|
||||||
if self.__swarm :
|
|
||||||
return self.__jobs("post")
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __ping(self, instances) :
|
def __get_config(self) :
|
||||||
return self.__api_call(instances, "/ping")
|
config = {}
|
||||||
|
# extract instances variables
|
||||||
|
for instance in self.__instances :
|
||||||
|
for variable, value in instance["env"].items() :
|
||||||
|
config[variable] = value
|
||||||
|
# extract services variables
|
||||||
|
server_names = []
|
||||||
|
for service in self.__services :
|
||||||
|
first_server = service["SERVER_NAME"].split(" ")[0]
|
||||||
|
server_names.append(first_server)
|
||||||
|
for variable, value in service.items() :
|
||||||
|
config[first_server + "_" + variable] = value
|
||||||
|
config["SERVER_NAME"] = " ".join(server_names)
|
||||||
|
return config
|
||||||
|
|
||||||
def __api_call(self, instances, path) :
|
def __get_apis(self) :
|
||||||
|
apis = []
|
||||||
|
for instance in self.__instances :
|
||||||
|
endpoint = "http://" + instance["hostname"] + ":5000"
|
||||||
|
host = "bwapi"
|
||||||
|
if "API_SERVER_NAME" in instance["env"] :
|
||||||
|
host = instance["env"]["API_SERVER_NAME"]
|
||||||
|
apis.append(API(endpoint, host=host))
|
||||||
|
return apis
|
||||||
|
|
||||||
|
def __write_configs(self) :
|
||||||
ret = True
|
ret = True
|
||||||
for instance_id, instance in instances.items() :
|
for config_type in self.__configs :
|
||||||
# Reload the instance object just in case
|
rmtree("/data/configs/" + config_type)
|
||||||
instance.reload()
|
makedirs("/data/configs/" + config_type, exist_ok=True)
|
||||||
# Reload via API
|
for file, data in self.__configs[config_type].items() :
|
||||||
if self.__swarm :
|
path = "/data/configs/" + config_type + "/" + file
|
||||||
# Send POST request on http://serviceName.NodeID.TaskID:8000/action
|
if not path.endswith(".conf") :
|
||||||
name = instance.name
|
path += ".conf"
|
||||||
for task in instance.tasks() :
|
makedirs(dirname(path), exist_ok=True)
|
||||||
if task["Status"]["State"] != "running" :
|
|
||||||
continue
|
|
||||||
nodeID = task["NodeID"]
|
|
||||||
taskID = task["ID"]
|
|
||||||
fqdn = name + "." + nodeID + "." + taskID
|
|
||||||
req = False
|
|
||||||
try :
|
try :
|
||||||
req = requests.post("http://" + fqdn + ":8080" + self.__api + path)
|
mode = "w"
|
||||||
|
if type(data) is bytes :
|
||||||
|
mode = "wb"
|
||||||
|
with open(path, mode) as f :
|
||||||
|
f.write(data)
|
||||||
except :
|
except :
|
||||||
pass
|
print(format_exc())
|
||||||
if req and req.status_code == 200 and req.text == "ok" :
|
log("CONFIG", "❌", "Can't save file " + path)
|
||||||
utils.log("[*] Sent API order " + path + " to instance " + fqdn + " (service.node.task)")
|
|
||||||
else :
|
|
||||||
utils.log("[!] Can't send API order " + path + " to instance " + fqdn + " (service.node.task)")
|
|
||||||
ret = False
|
|
||||||
# Send SIGHUP to running instance
|
|
||||||
elif instance.status == "running" :
|
|
||||||
try :
|
|
||||||
instance.kill("SIGHUP")
|
|
||||||
utils.log("[*] Sent SIGHUP signal to bunkerized-nginx instance " + instance.name + " / " + instance.id)
|
|
||||||
except docker.errors.APIError as e :
|
|
||||||
utils.log("[!] Docker error while sending SIGHUP signal : " + str(e))
|
|
||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def apply(self, instances, services, configs=None) :
|
||||||
|
|
||||||
|
success = True
|
||||||
|
|
||||||
|
# stop scheduler just in case caller didn't do it
|
||||||
|
self.stop_scheduler()
|
||||||
|
|
||||||
|
# update values
|
||||||
|
# order here is important :
|
||||||
|
# __get_scheduler needs apis
|
||||||
|
# __get_apis needs __config
|
||||||
|
# __get_full_env needs __instances and __services
|
||||||
|
self.__instances = instances
|
||||||
|
self.__services = services
|
||||||
|
self.__configs = configs
|
||||||
|
self.__config = self.__get_full_env()
|
||||||
|
self._set_apis(self.__get_apis())
|
||||||
|
|
||||||
|
# write configs
|
||||||
|
ret = self.__write_configs()
|
||||||
|
if not ret :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "saving custom configs failed, configuration will not work as expected...")
|
||||||
|
|
||||||
|
# get env
|
||||||
|
env = self.__get_full_env()
|
||||||
|
|
||||||
|
# run jobs once
|
||||||
|
i = 1
|
||||||
|
for instance in self.__instances :
|
||||||
|
endpoint = "http://" + instance["hostname"] + ":5000"
|
||||||
|
host = "bwapi"
|
||||||
|
if "API_SERVER_NAME" in instance["env"] :
|
||||||
|
host = instance["env"]["API_SERVER_NAME"]
|
||||||
|
env["CLUSTER_INSTANCE_" + str(i)] = endpoint + " " + host
|
||||||
|
i += 1
|
||||||
|
if self.__scheduler is None :
|
||||||
|
self.__scheduler = JobScheduler(env=env, lock=self.__lock, apis=self._get_apis())
|
||||||
|
ret = self.__scheduler.reload(env)
|
||||||
|
if not ret :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "scheduler.reload() failed, configuration will not work as expected...")
|
||||||
|
|
||||||
|
# write config to /tmp/variables.env
|
||||||
|
with open("/tmp/variables.env", "w") as f :
|
||||||
|
for variable, value in self.__config.items() :
|
||||||
|
f.write(variable + "=" + value + "\n")
|
||||||
|
|
||||||
|
# run the generator
|
||||||
|
cmd = "python /opt/bunkerweb/gen/main.py --settings /opt/bunkerweb/settings.json --templates /opt/bunkerweb/confs --output /etc/nginx --variables /tmp/variables.env"
|
||||||
|
proc = run(cmd.split(" "), stdin=DEVNULL, stderr=STDOUT)
|
||||||
|
if proc.returncode != 0 :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "config generator failed, configuration will not work as expected...")
|
||||||
|
cmd = "chown -R root:101 /etc/nginx"
|
||||||
|
run(cmd.split(" "), stdin=DEVNULL, stdout=DEVNULL, stderr=STDOUT)
|
||||||
|
cmd = "chmod -R 770 /etc/nginx"
|
||||||
|
run(cmd.split(" "), stdin=DEVNULL, stdout=DEVNULL, stderr=STDOUT)
|
||||||
|
|
||||||
|
# send nginx configs
|
||||||
|
# send data folder
|
||||||
|
# reload nginx
|
||||||
|
ret = self._send_files("/etc/nginx", "/confs")
|
||||||
|
if not ret :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "sending nginx configs failed, configuration will not work as expected...")
|
||||||
|
ret = self._send_files("/data", "/data")
|
||||||
|
if not ret :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "sending custom configs failed, configuration will not work as expected...")
|
||||||
|
ret = self._send_to_apis("POST", "/reload")
|
||||||
|
if not ret :
|
||||||
|
success = False
|
||||||
|
log("CONFIG", "❌", "reload failed, configuration will not work as expected...")
|
||||||
|
|
||||||
|
return success
|
||||||
|
|
||||||
|
def start_scheduler(self) :
|
||||||
|
if self.__scheduler_thread is not None and self.__scheduler_thread.is_alive() :
|
||||||
|
raise Exception("scheduler is already running, can't run it twice")
|
||||||
|
self.__schedule = True
|
||||||
|
self.__scheduler_thread = Thread(target=self.__scheduler_run_pending)
|
||||||
|
self.__scheduler_thread.start()
|
||||||
|
|
||||||
|
def stop_scheduler(self) :
|
||||||
|
if self.__scheduler_thread is not None and self.__scheduler_thread.is_alive() :
|
||||||
|
self.__schedule_lock.acquire()
|
||||||
|
self.__schedule = False
|
||||||
|
self.__schedule_lock.release()
|
||||||
|
self.__scheduler_thread.join()
|
||||||
|
self.__scheduler_thread = None
|
||||||
|
|
||||||
|
def reload_scheduler(self, env) :
|
||||||
|
if self.__scheduler_thread is None :
|
||||||
|
return self.__scheduler.reload(env=env, apis=self._get_apis())
|
||||||
|
|
||||||
|
def __get_scheduler(self, env) :
|
||||||
|
self.__schedule_lock.acquire()
|
||||||
|
if self.__schedule :
|
||||||
|
self.__schedule_lock.release()
|
||||||
|
raise Exception("can't create new scheduler, old one is still running...")
|
||||||
|
self.__schedule_lock.release()
|
||||||
|
return JobScheduler(env=env, lock=self.__lock, apis=self._get_apis())
|
||||||
|
|||||||
79
autoconf/Controller.py
Normal file
79
autoconf/Controller.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
from Config import Config
|
||||||
|
|
||||||
|
from logger import log
|
||||||
|
|
||||||
|
class Controller(ABC) :
|
||||||
|
|
||||||
|
def __init__(self, ctrl_type, lock=None) :
|
||||||
|
self._type = ctrl_type
|
||||||
|
self._instances = []
|
||||||
|
self._services = []
|
||||||
|
self._supported_config_types = ["http", "stream", "server-http", "server-stream", "default-server-http", "modsec", "modsec-crs"]
|
||||||
|
self._configs = {}
|
||||||
|
for config_type in self._supported_config_types :
|
||||||
|
self._configs[config_type] = {}
|
||||||
|
self._config = Config(ctrl_type, lock)
|
||||||
|
|
||||||
|
def wait(self, wait_time) :
|
||||||
|
while True :
|
||||||
|
self._instances = self.get_instances()
|
||||||
|
if len(self._instances) == 0 :
|
||||||
|
log("CONTROLLER", "⚠️", "No instance found, waiting " + str(wait_time) + "s ...")
|
||||||
|
sleep(wait_time)
|
||||||
|
continue
|
||||||
|
all_ready = True
|
||||||
|
for instance in self._instances :
|
||||||
|
if not instance["health"] :
|
||||||
|
log("CONTROLLER", "⚠️", "Instance " + instance["name"] + " is not ready, waiting " + str(wait_time) + "s ...")
|
||||||
|
sleep(wait_time)
|
||||||
|
all_ready = False
|
||||||
|
break
|
||||||
|
if all_ready :
|
||||||
|
break
|
||||||
|
return self._instances
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _get_controller_instances(self) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _to_instances(self, controller_instance) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_instances(self) :
|
||||||
|
instances = []
|
||||||
|
for controller_instance in self._get_controller_instances() :
|
||||||
|
for instance in self._to_instances(controller_instance) :
|
||||||
|
instances.append(instance)
|
||||||
|
return instances
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _get_controller_services(self) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _to_services(self, controller_service) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_services(self) :
|
||||||
|
services = []
|
||||||
|
for controller_service in self._get_controller_services() :
|
||||||
|
for service in self._to_services(controller_service) :
|
||||||
|
services.append(service)
|
||||||
|
return services
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_configs(self) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def apply_config(self) :
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def process_events(self) :
|
||||||
|
pass
|
||||||
63
autoconf/DockerController.py
Normal file
63
autoconf/DockerController.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import traceback
|
||||||
|
|
||||||
|
from docker import DockerClient
|
||||||
|
|
||||||
|
from Controller import Controller
|
||||||
|
from logger import log
|
||||||
|
|
||||||
|
class DockerController(Controller) :
|
||||||
|
|
||||||
|
def __init__(self, docker_host) :
|
||||||
|
super().__init__("docker")
|
||||||
|
self.__client = DockerClient(base_url=docker_host)
|
||||||
|
|
||||||
|
def _get_controller_instances(self) :
|
||||||
|
return self.__client.containers.list(filters={"label" : "bunkerweb.AUTOCONF"})
|
||||||
|
|
||||||
|
def _to_instances(self, controller_instance) :
|
||||||
|
instance = {}
|
||||||
|
instance["name"] = controller_instance.name
|
||||||
|
instance["hostname"] = controller_instance.name
|
||||||
|
instance["health"] = controller_instance.status == "running" and controller_instance.attrs["State"]["Health"]["Status"] == "healthy"
|
||||||
|
instance["env"] = {}
|
||||||
|
for env in controller_instance.attrs["Config"]["Env"] :
|
||||||
|
variable = env.split("=")[0]
|
||||||
|
if variable in ["PATH", "NGINX_VERSION", "NJS_VERSION", "PKG_RELEASE"] :
|
||||||
|
continue
|
||||||
|
value = env.replace(variable + "=", "", 1)
|
||||||
|
instance["env"][variable] = value
|
||||||
|
return [instance]
|
||||||
|
|
||||||
|
def _get_controller_services(self) :
|
||||||
|
return self.__client.containers.list(filters={"label" : "bunkerweb.SERVER_NAME"})
|
||||||
|
|
||||||
|
def _to_services(self, controller_service) :
|
||||||
|
service = {}
|
||||||
|
for variable, value in controller_service.labels.items() :
|
||||||
|
if not variable.startswith("bunkerweb.") :
|
||||||
|
continue
|
||||||
|
service[variable.replace("bunkerweb.", "", 1)] = value
|
||||||
|
return [service]
|
||||||
|
|
||||||
|
def get_configs(self) :
|
||||||
|
raise("get_configs is not supported with DockerController")
|
||||||
|
|
||||||
|
def apply_config(self) :
|
||||||
|
return self._config.apply(self._instances, self._services, configs=self._configs)
|
||||||
|
|
||||||
|
def process_events(self) :
|
||||||
|
for event in self.__client.events(decode=True, filters={"type": "container"}) :
|
||||||
|
self._instances = self.get_instances()
|
||||||
|
self._services = self.get_services()
|
||||||
|
if not self._config.update_needed(self._instances, self._services) :
|
||||||
|
continue
|
||||||
|
log("DOCKER-CONTROLLER", "ℹ️", "Catched docker event, deploying new configuration ...")
|
||||||
|
try :
|
||||||
|
ret = self.apply_config()
|
||||||
|
if not ret :
|
||||||
|
log("DOCKER-CONTROLLER", "❌", "Error while deploying new configuration")
|
||||||
|
else :
|
||||||
|
log("DOCKER-CONTROLLER", "ℹ️", "Successfully deployed new configuration 🚀")
|
||||||
|
except :
|
||||||
|
log("DOCKER-CONTROLLER", "❌", "Exception while deploying new configuration :")
|
||||||
|
print(traceback.format_exc())
|
||||||
@ -1,22 +1,54 @@
|
|||||||
FROM alpine
|
FROM python:3-alpine
|
||||||
|
|
||||||
COPY autoconf/dependencies.sh /tmp
|
# Install dependencies
|
||||||
RUN chmod +x /tmp/dependencies.sh && \
|
COPY deps/requirements.txt /opt/bunkerweb/deps/requirements.txt
|
||||||
/tmp/dependencies.sh && \
|
RUN apk add --no-cache --virtual build gcc python3-dev musl-dev libffi-dev openssl-dev cargo && \
|
||||||
rm -f /tmp/dependencies.sh
|
mkdir /opt/bunkerweb/deps/python && \
|
||||||
|
pip install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/deps/requirements.txt && \
|
||||||
|
apk del build
|
||||||
|
|
||||||
COPY gen/ /opt/gen
|
# Copy files
|
||||||
COPY entrypoint/ /opt/entrypoint
|
# can't exclude specific files/dir from . so we are copying everything by hand
|
||||||
COPY confs/global/ /opt/confs/global
|
COPY api /opt/bunkerweb/api
|
||||||
COPY confs/site/ /opt/confs/site
|
COPY cli /opt/bunkerweb/cli
|
||||||
COPY scripts/ /opt/scripts
|
COPY confs /opt/bunkerweb/confs
|
||||||
COPY settings.json /opt
|
COPY core /opt/bunkerweb/core
|
||||||
COPY misc/cron /etc/crontabs/nginx
|
COPY gen /opt/bunkerweb/gen
|
||||||
COPY autoconf/* /opt/entrypoint/
|
COPY helpers /opt/bunkerweb/helpers
|
||||||
|
COPY job /opt/bunkerweb/job
|
||||||
|
COPY utils /opt/bunkerweb/utils
|
||||||
|
COPY settings.json /opt/bunkerweb/settings.json
|
||||||
|
COPY VERSION /opt/bunkerweb/VERSION
|
||||||
|
COPY autoconf /opt/bunkerweb/autoconf
|
||||||
|
|
||||||
COPY autoconf/prepare.sh /tmp
|
# Add nginx user, drop bwcli, setup data folders, permissions and logging
|
||||||
RUN chmod +x /tmp/prepare.sh && \
|
RUN apk add --no-cache git && \
|
||||||
/tmp/prepare.sh && \
|
ln -s /usr/local/bin/python3 /usr/bin/python3 && \
|
||||||
rm -f /tmp/prepare.sh
|
addgroup -g 101 nginx && \
|
||||||
|
adduser -h /var/cache/nginx -g nginx -s /bin/sh -G nginx -D -H -u 101 nginx && \
|
||||||
|
apk add --no-cache bash && \
|
||||||
|
cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
|
||||||
|
mkdir /opt/bunkerweb/configs && \
|
||||||
|
for dir in $(echo "cache configs configs/http configs/stream configs/server-http configs/server-stream configs/default-server-http configs/default-server-stream configs/modsec configs/modsec-crs letsencrypt plugins www") ; do ln -s "/data/${dir}" "/opt/bunkerweb/${dir}" ; done && \
|
||||||
|
mkdir /opt/bunkerweb/tmp && \
|
||||||
|
chown -R root:nginx /opt/bunkerweb && \
|
||||||
|
find /opt/bunkerweb -type f -exec chmod 0740 {} \; && \
|
||||||
|
find /opt/bunkerweb -type d -exec chmod 0750 {} \; && \
|
||||||
|
chmod 770 /opt/bunkerweb/tmp && \
|
||||||
|
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /usr/local/bin/bwcli /opt/bunkerweb/helpers/*.sh /opt/bunkerweb/autoconf/main.py /opt/bunkerweb/deps/python/bin/* && \
|
||||||
|
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
|
||||||
|
chown root:nginx /usr/local/bin/bwcli && \
|
||||||
|
mkdir /etc/nginx && \
|
||||||
|
chown -R nginx:nginx /etc/nginx && \
|
||||||
|
chmod -R 770 /etc/nginx && \
|
||||||
|
ln -s /data/letsencrypt /etc/letsencrypt && \
|
||||||
|
mkdir /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
chown root:nginx /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
chmod 770 /var/log/letsencrypt /var/lib/letsencrypt && \
|
||||||
|
ln -s /proc/1/fd/1 /var/log/letsencrypt/letsencrypt.log
|
||||||
|
|
||||||
ENTRYPOINT ["/opt/entrypoint/entrypoint.sh"]
|
VOLUME /data /etc/nginx
|
||||||
|
|
||||||
|
WORKDIR /opt/bunkerweb/autoconf
|
||||||
|
|
||||||
|
CMD ["python", "/opt/bunkerweb/autoconf/main.py"]
|
||||||
|
|||||||
191
autoconf/IngressController.py
Normal file
191
autoconf/IngressController.py
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
from traceback import format_exc
|
||||||
|
from kubernetes import client, config, watch
|
||||||
|
from threading import Thread, Lock
|
||||||
|
from logger import log
|
||||||
|
|
||||||
|
from Controller import Controller
|
||||||
|
from ConfigCaller import ConfigCaller
|
||||||
|
|
||||||
|
class IngressController(Controller, ConfigCaller) :
|
||||||
|
|
||||||
|
def __init__(self) :
|
||||||
|
Controller.__init__(self, "kubernetes")
|
||||||
|
ConfigCaller.__init__(self)
|
||||||
|
config.load_incluster_config()
|
||||||
|
self.__corev1 = client.CoreV1Api()
|
||||||
|
self.__networkingv1 = client.NetworkingV1Api()
|
||||||
|
self.__internal_lock = Lock()
|
||||||
|
|
||||||
|
def _get_controller_instances(self) :
|
||||||
|
controller_instances = []
|
||||||
|
for pod in self.__corev1.list_pod_for_all_namespaces(watch=False).items :
|
||||||
|
if pod.metadata.annotations != None and "bunkerweb.io/AUTOCONF" in pod.metadata.annotations :
|
||||||
|
controller_instances.append(pod)
|
||||||
|
return controller_instances
|
||||||
|
|
||||||
|
def _to_instances(self, controller_instance) :
|
||||||
|
instance = {}
|
||||||
|
instance["name"] = controller_instance.metadata.name
|
||||||
|
instance["hostname"] = controller_instance.status.pod_ip
|
||||||
|
health = False
|
||||||
|
if controller_instance.status.conditions is not None :
|
||||||
|
for condition in controller_instance.status.conditions :
|
||||||
|
if condition.type == "Ready" and condition.status == "True" :
|
||||||
|
health = True
|
||||||
|
break
|
||||||
|
instance["health"] = health
|
||||||
|
instance["env"] = {}
|
||||||
|
for env in controller_instance.spec.containers[0].env :
|
||||||
|
if env.value is not None :
|
||||||
|
instance["env"][env.name] = env.value
|
||||||
|
else :
|
||||||
|
instance["env"][env.name] = ""
|
||||||
|
for controller_service in self._get_controller_services() :
|
||||||
|
if controller_service.metadata.annotations is not None :
|
||||||
|
for annotation, value in controller_service.metadata.annotations.items() :
|
||||||
|
if not annotation.startswith("bunkerweb.io/") :
|
||||||
|
continue
|
||||||
|
variable = annotation.replace("bunkerweb.io/", "", 1)
|
||||||
|
if self._is_setting(variable) :
|
||||||
|
instance["env"][variable] = value
|
||||||
|
return [instance]
|
||||||
|
|
||||||
|
def _get_controller_services(self) :
|
||||||
|
return self.__networkingv1.list_ingress_for_all_namespaces(watch=False).items
|
||||||
|
|
||||||
|
def _to_services(self, controller_service) :
|
||||||
|
if controller_service.spec is None or controller_service.spec.rules is None :
|
||||||
|
return []
|
||||||
|
services = []
|
||||||
|
# parse rules
|
||||||
|
for rule in controller_service.spec.rules :
|
||||||
|
if rule.host is None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported ingress rule without host.")
|
||||||
|
continue
|
||||||
|
service = {}
|
||||||
|
service["SERVER_NAME"] = rule.host
|
||||||
|
if rule.http is None :
|
||||||
|
services.append(service)
|
||||||
|
continue
|
||||||
|
location = 1
|
||||||
|
for path in rule.http.paths :
|
||||||
|
if path.path is None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported ingress rule without path.")
|
||||||
|
continue
|
||||||
|
if path.backend.service is None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported ingress rule without backend service.")
|
||||||
|
continue
|
||||||
|
if path.backend.service.port is None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported ingress rule without backend service port.")
|
||||||
|
continue
|
||||||
|
if path.backend.service.port.number is None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported ingress rule without backend service port number.")
|
||||||
|
continue
|
||||||
|
service_list = self.__corev1.list_service_for_all_namespaces(watch=False, field_selector="metadata.name=" + path.backend.service.name).items
|
||||||
|
if len(service_list) == 0 :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring ingress rule with service " + path.backend.service.name + " : service not found.")
|
||||||
|
continue
|
||||||
|
reverse_proxy_host = "http://" + path.backend.service.name + "." + service_list[0].metadata.namespace + ".svc.cluster.local:" + str(path.backend.service.port.number)
|
||||||
|
service["USE_REVERSE_PROXY"] = "yes"
|
||||||
|
service["REVERSE_PROXY_HOST_" + str(location)] = reverse_proxy_host
|
||||||
|
service["REVERSE_PROXY_URL_" + str(location)] = path.path
|
||||||
|
location += 1
|
||||||
|
services.append(service)
|
||||||
|
|
||||||
|
# parse tls
|
||||||
|
if controller_service.spec.tls is not None :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported tls.")
|
||||||
|
|
||||||
|
# parse annotations
|
||||||
|
if controller_service.metadata.annotations is not None :
|
||||||
|
for service in services :
|
||||||
|
for annotation, value in controller_service.metadata.annotations.items() :
|
||||||
|
if not annotation.startswith("bunkerweb.io/") :
|
||||||
|
continue
|
||||||
|
variable = annotation.replace("bunkerweb.io/", "", 1)
|
||||||
|
if not variable.startswith(service["SERVER_NAME"].split(" ")[0] + "_") :
|
||||||
|
continue
|
||||||
|
variable = variable.replace(service["SERVER_NAME"].split(" ")[0] + "_", "", 1)
|
||||||
|
if self._is_multisite_setting(variable) :
|
||||||
|
service[variable] = value
|
||||||
|
return services
|
||||||
|
|
||||||
|
def get_configs(self) :
|
||||||
|
configs = {}
|
||||||
|
supported_config_types = ["http", "stream", "server-http", "server-stream", "default-server-http", "modsec", "modsec-crs"]
|
||||||
|
for config_type in supported_config_types :
|
||||||
|
configs[config_type] = {}
|
||||||
|
for configmap in self.__corev1.list_config_map_for_all_namespaces(watch=False).items :
|
||||||
|
if configmap.metadata.annotations is None or "bunkerweb.io/CONFIG_TYPE" not in configmap.metadata.annotations :
|
||||||
|
continue
|
||||||
|
config_type = configmap.metadata.annotations["bunkerweb.io/CONFIG_TYPE"]
|
||||||
|
if config_type not in supported_config_types :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring unsupported CONFIG_TYPE " + config_type + " for ConfigMap " + configmap.metadata.name)
|
||||||
|
continue
|
||||||
|
if not configmap.data :
|
||||||
|
log("INGRESS-CONTROLLER", "⚠️", "Ignoring blank ConfigMap " + configmap.metadata.name)
|
||||||
|
continue
|
||||||
|
config_site = ""
|
||||||
|
if "bunkerweb.io/CONFIG_SITE" in configmap.metadata.annotations :
|
||||||
|
config_site = configmap.metadata.annotations["bunkerweb.io/CONFIG_SITE"] + "/"
|
||||||
|
for config_name, config_data in configmap.data.items() :
|
||||||
|
configs[config_type][config_site + config_name] = config_data
|
||||||
|
return configs
|
||||||
|
|
||||||
|
def __watch(self, watch_type) :
|
||||||
|
w = watch.Watch()
|
||||||
|
what = None
|
||||||
|
if watch_type == "pod" :
|
||||||
|
what = self.__corev1.list_pod_for_all_namespaces
|
||||||
|
elif watch_type == "ingress" :
|
||||||
|
what = self.__networkingv1.list_ingress_for_all_namespaces
|
||||||
|
elif watch_type == "configmap" :
|
||||||
|
what = self.__corev1.list_config_map_for_all_namespaces
|
||||||
|
else :
|
||||||
|
raise Exception("unsupported watch_type " + watch_type)
|
||||||
|
while True :
|
||||||
|
locked = False
|
||||||
|
try :
|
||||||
|
for event in w.stream(what) :
|
||||||
|
self.__internal_lock.acquire()
|
||||||
|
locked = True
|
||||||
|
self._instances = self.get_instances()
|
||||||
|
self._services = self.get_services()
|
||||||
|
self._configs = self.get_configs()
|
||||||
|
if not self._config.update_needed(self._instances, self._services, configs=self._configs) :
|
||||||
|
self.__internal_lock.release()
|
||||||
|
locked = False
|
||||||
|
continue
|
||||||
|
log("INGRESS-CONTROLLER", "ℹ️", "Catched kubernetes event, deploying new configuration ...")
|
||||||
|
try :
|
||||||
|
ret = self.apply_config()
|
||||||
|
if not ret :
|
||||||
|
log("INGRESS-CONTROLLER", "❌", "Error while deploying new configuration ...")
|
||||||
|
else :
|
||||||
|
log("INGRESS-CONTROLLER", "ℹ️", "Successfully deployed new configuration 🚀")
|
||||||
|
except :
|
||||||
|
log("INGRESS-CONTROLLER", "❌", "Exception while deploying new configuration :")
|
||||||
|
print(format_exc())
|
||||||
|
self.__internal_lock.release()
|
||||||
|
locked = False
|
||||||
|
except Exception as e :
|
||||||
|
log("INGRESS-CONTROLLER", "❌", "Exception while reading k8s event (type = " + watch_type + ") : ")
|
||||||
|
print(format_exc())
|
||||||
|
if locked :
|
||||||
|
self.__internal_lock.release()
|
||||||
|
|
||||||
|
def apply_config(self) :
|
||||||
|
self._config.stop_scheduler()
|
||||||
|
ret = self._config.apply(self._instances, self._services, configs=self._configs)
|
||||||
|
self._config.start_scheduler()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def process_events(self) :
|
||||||
|
watch_types = ["pod", "ingress", "configmap"]
|
||||||
|
threads = []
|
||||||
|
for watch_type in watch_types :
|
||||||
|
threads.append(Thread(target=self.__watch, args=(watch_type,)))
|
||||||
|
for thread in threads :
|
||||||
|
thread.start()
|
||||||
|
for thread in threads :
|
||||||
|
thread.join()
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import socketserver, threading, utils, os, stat
|
|
||||||
|
|
||||||
class ReloadServerHandler(socketserver.StreamRequestHandler):
|
|
||||||
|
|
||||||
def handle(self) :
|
|
||||||
try :
|
|
||||||
data = self.request.recv(512)
|
|
||||||
if not data :
|
|
||||||
return
|
|
||||||
with self.server.lock :
|
|
||||||
ret = self.server.autoconf.reload()
|
|
||||||
if ret :
|
|
||||||
self.request.sendall("ok".encode("utf-8"))
|
|
||||||
else :
|
|
||||||
self.request.sendall("ko".encode("utf-8"))
|
|
||||||
except Exception as e :
|
|
||||||
utils.log("Exception " + str(e))
|
|
||||||
|
|
||||||
def run_reload_server(autoconf, lock) :
|
|
||||||
server = socketserver.UnixStreamServer("/tmp/autoconf.sock", ReloadServerHandler)
|
|
||||||
os.chown("/tmp/autoconf.sock", 0, 101)
|
|
||||||
os.chmod("/tmp/autoconf.sock", 0o770)
|
|
||||||
server.autoconf = autoconf
|
|
||||||
server.lock = lock
|
|
||||||
thread = threading.Thread(target=server.serve_forever)
|
|
||||||
thread.daemon = True
|
|
||||||
thread.start()
|
|
||||||
return (server, thread)
|
|
||||||
97
autoconf/SwarmController.py
Normal file
97
autoconf/SwarmController.py
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
from traceback import format_exc
|
||||||
|
from threading import Thread, Lock
|
||||||
|
from docker import DockerClient
|
||||||
|
from logger import log
|
||||||
|
from base64 import b64decode
|
||||||
|
|
||||||
|
from Controller import Controller
|
||||||
|
|
||||||
|
class SwarmController(Controller) :
|
||||||
|
|
||||||
|
def __init__(self, docker_host) :
|
||||||
|
super().__init__("swarm")
|
||||||
|
self.__client = DockerClient(base_url=docker_host)
|
||||||
|
self.__internal_lock = Lock()
|
||||||
|
|
||||||
|
def _get_controller_instances(self) :
|
||||||
|
return self.__client.services.list(filters={"label" : "bunkerweb.AUTOCONF"})
|
||||||
|
|
||||||
|
def _to_instances(self, controller_instance) :
|
||||||
|
instances = []
|
||||||
|
instance_env = {}
|
||||||
|
for env in controller_instance.attrs["Spec"]["TaskTemplate"]["ContainerSpec"]["Env"] :
|
||||||
|
variable = env.split("=")[0]
|
||||||
|
value = env.replace(variable + "=", "", 1)
|
||||||
|
instance_env[variable] = value
|
||||||
|
for task in controller_instance.tasks() :
|
||||||
|
instance = {}
|
||||||
|
instance["name"] = task["ID"]
|
||||||
|
instance["hostname"] = controller_instance.name + "." + task["NodeID"] + "." + task["ID"]
|
||||||
|
instance["health"] = task["Status"]["State"] == "running"
|
||||||
|
instance["env"] = instance_env
|
||||||
|
instances.append(instance)
|
||||||
|
return instances
|
||||||
|
|
||||||
|
def _get_controller_services(self) :
|
||||||
|
return self.__client.services.list(filters={"label" : "bunkerweb.SERVER_NAME"})
|
||||||
|
|
||||||
|
def _to_services(self, controller_service) :
|
||||||
|
service = {}
|
||||||
|
for variable, value in controller_service.attrs["Spec"]["Labels"].items() :
|
||||||
|
if not variable.startswith("bunkerweb.") :
|
||||||
|
continue
|
||||||
|
service[variable.replace("bunkerweb.", "", 1)] = value
|
||||||
|
return [service]
|
||||||
|
|
||||||
|
def get_configs(self) :
|
||||||
|
configs = {}
|
||||||
|
for config_type in self._supported_config_types :
|
||||||
|
configs[config_type] = {}
|
||||||
|
for config in self.__client.configs.list(filters={"label" : "bunkerweb.CONFIG_TYPE"}) :
|
||||||
|
config_type = config.attrs["Spec"]["Labels"]["bunkerweb.CONFIG_TYPE"]
|
||||||
|
config_name = config.name
|
||||||
|
if config_type not in self._supported_config_types :
|
||||||
|
log("SWARM-CONTROLLER", "⚠️", "Ignoring unsupported CONFIG_TYPE " + config_type + " for Config " + config_name)
|
||||||
|
continue
|
||||||
|
config_site = ""
|
||||||
|
if "bunkerweb.CONFIG_SITE" in config.attrs["Spec"]["Labels"] :
|
||||||
|
config_site = config.attrs["Spec"]["Labels"]["bunkerweb.CONFIG_SITE"] + "/"
|
||||||
|
configs[config_type][config_site + config_name] = b64decode(config.attrs["Spec"]["Data"])
|
||||||
|
return configs
|
||||||
|
|
||||||
|
def apply_config(self) :
|
||||||
|
self._config.stop_scheduler()
|
||||||
|
ret = self._config.apply(self._instances, self._services, configs=self._configs)
|
||||||
|
self._config.start_scheduler()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def __event(self, event_type) :
|
||||||
|
for event in self.__client.events(decode=True, filters={"type": event_type}) :
|
||||||
|
self.__internal_lock.acquire()
|
||||||
|
self._instances = self.get_instances()
|
||||||
|
self._services = self.get_services()
|
||||||
|
self._configs = self.get_configs()
|
||||||
|
if not self._config.update_needed(self._instances, self._services, configs=self._configs) :
|
||||||
|
self.__internal_lock.release()
|
||||||
|
continue
|
||||||
|
log("SWARM-CONTROLLER", "ℹ️", "Catched Swarm event, deploying new configuration ...")
|
||||||
|
try :
|
||||||
|
ret = self.apply_config()
|
||||||
|
if not ret :
|
||||||
|
log("SWARM-CONTROLLER", "❌", "Error while deploying new configuration ...")
|
||||||
|
else :
|
||||||
|
log("SWARM-CONTROLLER", "ℹ️", "Successfully deployed new configuration 🚀")
|
||||||
|
except :
|
||||||
|
log("SWARM-CONTROLLER", "❌", "Exception while deploying new configuration :")
|
||||||
|
print(format_exc())
|
||||||
|
self.__internal_lock.release()
|
||||||
|
|
||||||
|
def process_events(self) :
|
||||||
|
event_types = ["service", "config"]
|
||||||
|
threads = []
|
||||||
|
for event_type in event_types :
|
||||||
|
threads.append(Thread(target=self.__event, args=(event_type,)))
|
||||||
|
for thread in threads :
|
||||||
|
thread.start()
|
||||||
|
for thread in threads :
|
||||||
|
thread.join()
|
||||||
@ -1,71 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from AutoConf import AutoConf
|
|
||||||
from ReloadServer import run_reload_server
|
|
||||||
import utils
|
|
||||||
import docker, os, stat, sys, select, threading
|
|
||||||
|
|
||||||
# Connect to the endpoint
|
|
||||||
endpoint = "/var/run/docker.sock"
|
|
||||||
if not os.path.exists(endpoint) or not stat.S_ISSOCK(os.stat(endpoint).st_mode) :
|
|
||||||
utils.log("[!] /var/run/docker.sock not found (is it mounted ?)")
|
|
||||||
sys.exit(1)
|
|
||||||
try :
|
|
||||||
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')
|
|
||||||
except Exception as e :
|
|
||||||
utils.log("[!] Can't instantiate DockerClient : " + str(e))
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
# Check if we are in Swarm mode
|
|
||||||
swarm = os.getenv("SWARM_MODE") == "yes"
|
|
||||||
|
|
||||||
# Our object to process events
|
|
||||||
api = ""
|
|
||||||
if swarm :
|
|
||||||
api = os.getenv("API_URI")
|
|
||||||
autoconf = AutoConf(swarm, api)
|
|
||||||
lock = threading.Lock()
|
|
||||||
if swarm :
|
|
||||||
(server, thread) = run_reload_server(autoconf, lock)
|
|
||||||
|
|
||||||
# Get all bunkerized-nginx instances and web services created before
|
|
||||||
try :
|
|
||||||
if swarm :
|
|
||||||
before = client.services.list(filters={"label" : "bunkerized-nginx.AUTOCONF"}) + client.services.list(filters={"label" : "bunkerized-nginx.SERVER_NAME"})
|
|
||||||
else :
|
|
||||||
before = client.containers.list(all=True, filters={"label" : "bunkerized-nginx.AUTOCONF"}) + client.containers.list(filters={"label" : "bunkerized-nginx.SERVER_NAME"})
|
|
||||||
except docker.errors.APIError as e :
|
|
||||||
utils.log("[!] Docker API error " + str(e))
|
|
||||||
sys.exit(3)
|
|
||||||
|
|
||||||
# Process them before events
|
|
||||||
autoconf.pre_process(before)
|
|
||||||
|
|
||||||
# Process events received from Docker
|
|
||||||
try :
|
|
||||||
utils.log("[*] Listening for Docker events ...")
|
|
||||||
for event in client.events(decode=True) :
|
|
||||||
|
|
||||||
# Process only container/service events
|
|
||||||
if (swarm and event["Type"] != "service") or (not swarm and event["Type"] != "container") :
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get Container/Service object
|
|
||||||
try :
|
|
||||||
if swarm :
|
|
||||||
id = service_id=event["Actor"]["ID"]
|
|
||||||
server = client.services.get(service_id=id)
|
|
||||||
else :
|
|
||||||
id = event["id"]
|
|
||||||
server = client.containers.get(id)
|
|
||||||
except docker.errors.NotFound as e :
|
|
||||||
server = autoconf.get_server(id)
|
|
||||||
if not server :
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Process the event
|
|
||||||
autoconf.process(server, event["Action"])
|
|
||||||
|
|
||||||
except docker.errors.APIError as e :
|
|
||||||
utils.log("[!] Docker API error " + str(e))
|
|
||||||
sys.exit(4)
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# install dependencies
|
|
||||||
apk add py3-pip bash certbot curl openssl
|
|
||||||
pip3 install docker requests jinja2
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
echo "[*] Starting autoconf ..."
|
|
||||||
|
|
||||||
# check permissions
|
|
||||||
su -s "/opt/entrypoint/permissions.sh" nginx
|
|
||||||
if [ "$?" -ne 0 ] ; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$SWARM_MODE" = "yes" ] ; then
|
|
||||||
chown -R root:nginx /etc/nginx
|
|
||||||
chmod -R 770 /etc/nginx
|
|
||||||
fi
|
|
||||||
|
|
||||||
# trap SIGTERM and SIGINT
|
|
||||||
function trap_exit() {
|
|
||||||
echo "[*] Catched stop operation"
|
|
||||||
echo "[*] Stopping crond ..."
|
|
||||||
pkill -TERM crond
|
|
||||||
echo "[*] Stopping autoconf ..."
|
|
||||||
pkill -TERM python3
|
|
||||||
}
|
|
||||||
trap "trap_exit" TERM INT QUIT
|
|
||||||
|
|
||||||
# start cron
|
|
||||||
crond
|
|
||||||
|
|
||||||
# run autoconf app
|
|
||||||
/opt/entrypoint/app.py &
|
|
||||||
pid="$!"
|
|
||||||
|
|
||||||
# wait while app is up
|
|
||||||
wait "$pid"
|
|
||||||
|
|
||||||
# stop
|
|
||||||
echo "[*] autoconf stopped"
|
|
||||||
exit 0
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
curl -Lo manifest-tool https://github.com/estesp/manifest-tool/releases/download/v1.0.3/manifest-tool-linux-amd64
|
|
||||||
chmod +x manifest-tool
|
|
||||||
|
|
||||||
VERSION=$(cat VERSION | tr -d '\n')
|
|
||||||
if [ "$SOURCE_BRANCH" = "dev" ] ; then
|
|
||||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx-autoconf:dev-ARCHVARIANT --target bunkerity/bunkerized-nginx-autoconf:dev
|
|
||||||
elif [ "$SOURCE_BRANCH" = "master" ] ; then
|
|
||||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx-autoconf:ARCHVARIANT --target bunkerity/bunkerized-nginx-autoconf:${VERSION}
|
|
||||||
./manifest-tool push from-args --ignore-missing --platforms linux/amd64,linux/386,linux/arm/v7,linux/arm64/v8 --template bunkerity/bunkerized-nginx-autoconf:ARCHVARIANT --target bunkerity/bunkerized-nginx-autoconf:latest
|
|
||||||
fi
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Register qemu-*-static for all supported processors except the
|
|
||||||
# current one, but also remove all registered binfmt_misc before
|
|
||||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
|
||||||
69
autoconf/main.py
Normal file
69
autoconf/main.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import signal, os, traceback, time, subprocess
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append("/opt/bunkerweb/deps/python")
|
||||||
|
sys.path.append("/opt/bunkerweb/utils")
|
||||||
|
sys.path.append("/opt/bunkerweb/api")
|
||||||
|
sys.path.append("/opt/bunkerweb/job")
|
||||||
|
|
||||||
|
from SwarmController import SwarmController
|
||||||
|
from IngressController import IngressController
|
||||||
|
from DockerController import DockerController
|
||||||
|
from logger import log
|
||||||
|
|
||||||
|
# Get variables
|
||||||
|
swarm = os.getenv("SWARM_MODE", "no") == "yes"
|
||||||
|
kubernetes = os.getenv("KUBERNETES_MODE", "no") == "yes"
|
||||||
|
docker_host = os.getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||||
|
wait_retry_interval = int(os.getenv("WAIT_RETRY_INTERVAL", "5"))
|
||||||
|
|
||||||
|
def exit_handler(signum, frame) :
|
||||||
|
log("AUTOCONF", "ℹ️", "Stop signal received, exiting...")
|
||||||
|
os._exit(0)
|
||||||
|
signal.signal(signal.SIGINT, exit_handler)
|
||||||
|
signal.signal(signal.SIGTERM, exit_handler)
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
|
# Setup /data folder if needed
|
||||||
|
#if swarm or kubernetes :
|
||||||
|
proc = subprocess.run(["/opt/bunkerweb/helpers/data.sh", "AUTOCONF"], stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
||||||
|
if proc.returncode != 0 :
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
# Instantiate the controller
|
||||||
|
if swarm :
|
||||||
|
log("AUTOCONF", "ℹ️", "Swarm mode detected")
|
||||||
|
controller = SwarmController(docker_host)
|
||||||
|
elif kubernetes :
|
||||||
|
log("AUTOCONF", "ℹ️", "Kubernetes mode detected")
|
||||||
|
controller = IngressController()
|
||||||
|
else :
|
||||||
|
log("AUTOCONF", "ℹ️", "Docker mode detected")
|
||||||
|
controller = DockerController(docker_host)
|
||||||
|
|
||||||
|
# Wait for instances
|
||||||
|
log("AUTOCONF", "ℹ️", "Waiting for BunkerWeb instances ...")
|
||||||
|
instances = controller.wait(wait_retry_interval)
|
||||||
|
log("AUTOCONF", "ℹ️", "BunkerWeb instances are ready 🚀")
|
||||||
|
i = 1
|
||||||
|
for instance in instances :
|
||||||
|
log("AUTOCONF", "ℹ️", "Instance #" + str(i) + " : " + instance["name"])
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Run first configuration
|
||||||
|
ret = controller.apply_config()
|
||||||
|
if not ret :
|
||||||
|
log("AUTOCONF", "❌", "Error while applying initial configuration")
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
# Process events
|
||||||
|
log("AUTOCONF", "ℹ️", "Processing events ...")
|
||||||
|
controller.process_events()
|
||||||
|
|
||||||
|
except :
|
||||||
|
log("AUTOCONF", "❌", "Exception while running autoconf :")
|
||||||
|
print(traceback.format_exc())
|
||||||
|
sys.exit(1)
|
||||||
@ -1,44 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# create nginx user
|
|
||||||
addgroup -g 101 nginx
|
|
||||||
adduser -h /var/cache/nginx -g nginx -s /bin/sh -G nginx -D -H -u 101 nginx
|
|
||||||
|
|
||||||
# prepare /opt
|
|
||||||
chown -R root:nginx /opt
|
|
||||||
find /opt -type f -exec chmod 0740 {} \;
|
|
||||||
find /opt -type d -exec chmod 0750 {} \;
|
|
||||||
chmod ugo+x /opt/entrypoint/* /opt/scripts/*
|
|
||||||
chmod ugo+x /opt/gen/main.py
|
|
||||||
chmod 770 /opt
|
|
||||||
chmod 440 /opt/settings.json
|
|
||||||
|
|
||||||
# prepare /var/log
|
|
||||||
ln -s /proc/1/fd/1 /var/log/jobs.log
|
|
||||||
mkdir /var/log/letsencrypt
|
|
||||||
chown nginx:nginx /var/log/letsencrypt
|
|
||||||
chmod 770 /var/log/letsencrypt
|
|
||||||
|
|
||||||
# prepare /etc/letsencrypt
|
|
||||||
mkdir /etc/letsencrypt
|
|
||||||
chown root:nginx /etc/letsencrypt
|
|
||||||
chmod 770 /etc/letsencrypt
|
|
||||||
|
|
||||||
# prepare /var/lib/letsencrypt
|
|
||||||
mkdir /var/lib/letsencrypt
|
|
||||||
chown root:nginx /var/lib/letsencrypt
|
|
||||||
chmod 770 /var/lib/letsencrypt
|
|
||||||
|
|
||||||
# prepare /cache
|
|
||||||
mkdir /cache
|
|
||||||
chown root:nginx /cache
|
|
||||||
chmod 770 /cache
|
|
||||||
|
|
||||||
# prepare /acme-challenge
|
|
||||||
mkdir /acme-challenge
|
|
||||||
chown root:nginx /acme-challenge
|
|
||||||
chmod 770 /acme-challenge
|
|
||||||
|
|
||||||
# prepare /etc/crontabs/nginx
|
|
||||||
chown root:nginx /etc/crontabs/nginx
|
|
||||||
chmod 440 /etc/crontabs/nginx
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import sys, socket, os
|
|
||||||
|
|
||||||
if not os.path.exists("/tmp/autoconf.sock") :
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try :
|
|
||||||
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
||||||
client.connect("/tmp/autoconf.sock")
|
|
||||||
client.send("reload".encode("utf-8"))
|
|
||||||
data = client.recv(512)
|
|
||||||
client.close()
|
|
||||||
if not data or data.decode("utf-8") != "ok" :
|
|
||||||
sys.exit(3)
|
|
||||||
except Exception as e :
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
def log(event) :
|
|
||||||
print("[" + str(datetime.datetime.now().replace(microsecond=0)) + "] " + event, flush=True)
|
|
||||||
|
|
||||||
def replace_in_file(file, old_str, new_str) :
|
|
||||||
with open(file) as f :
|
|
||||||
data = f.read()
|
|
||||||
data = data[::-1].replace(old_str[::-1], new_str[::-1], 1)[::-1]
|
|
||||||
with open(file, "w") as f :
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
def install_cron(service, vars, crons) :
|
|
||||||
for var in vars :
|
|
||||||
if var in crons :
|
|
||||||
with open("/etc/crontabs/root", "a+") as f :
|
|
||||||
f.write(vars[var] + " /opt/cron/" + crons[var] + ".py " + service["Actor"]["ID"])
|
|
||||||
|
|
||||||
def uninstall_cron(service, vars, crons) :
|
|
||||||
for var in vars :
|
|
||||||
if var in crons :
|
|
||||||
replace_in_file("/etc/crontabs/root", vars[var] + " /opt/cron/" + crons[var] + ".py " + service["Actor"]["ID"] + "\n", "")
|
|
||||||
99
cli/CLI.py
Normal file
99
cli/CLI.py
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
from os.path import isfile
|
||||||
|
from dotenv import dotenv_values
|
||||||
|
from docker import DockerClient
|
||||||
|
from kubernetes import client, config
|
||||||
|
|
||||||
|
from ApiCaller import ApiCaller
|
||||||
|
from API import API
|
||||||
|
|
||||||
|
class CLI(ApiCaller) :
|
||||||
|
|
||||||
|
def __init__(self) :
|
||||||
|
self.__variables = dotenv_values("/etc/nginx/variables.env")
|
||||||
|
self.__integration = self.__detect_integration()
|
||||||
|
super().__init__(self.__get_apis())
|
||||||
|
|
||||||
|
def __detect_integration(self) :
|
||||||
|
ret = "unknown"
|
||||||
|
distrib = ""
|
||||||
|
if isfile("/etc/os-release") :
|
||||||
|
with open("/etc/os-release", "r") as f :
|
||||||
|
if "Alpine" in f.read() :
|
||||||
|
distrib = "alpine"
|
||||||
|
else :
|
||||||
|
distrib = "other"
|
||||||
|
# Docker case
|
||||||
|
if distrib == "alpine" and isfile("/usr/sbin/nginx") :
|
||||||
|
return "docker"
|
||||||
|
# Linux case
|
||||||
|
if distrib == "other" :
|
||||||
|
return "linux"
|
||||||
|
# Swarm case
|
||||||
|
if self.__variables["SWARM_MODE"] == "yes" :
|
||||||
|
return "swarm"
|
||||||
|
# Kubernetes case
|
||||||
|
if self.__variables["KUBERNETES_MODE"] == "yes" :
|
||||||
|
return "kubernetes"
|
||||||
|
# Autoconf case
|
||||||
|
if distrib == "alpine" :
|
||||||
|
return "autoconf"
|
||||||
|
|
||||||
|
raise Exception("can't detect integration")
|
||||||
|
|
||||||
|
def __get_apis(self) :
|
||||||
|
# Docker case
|
||||||
|
if self.__integration == "docker" :
|
||||||
|
return [API("http://127.0.0.1:" + self.__variables["API_HTTP_PORT"], host=self.__variables["API_SERVER_NAME"])]
|
||||||
|
|
||||||
|
# Autoconf case
|
||||||
|
if self.__integration == "autoconf" :
|
||||||
|
docker_client = DockerClient()
|
||||||
|
apis = []
|
||||||
|
for container in self.__client.containers.list(filters={"label" : "bunkerweb.AUTOCONF"}) :
|
||||||
|
port = "5000"
|
||||||
|
host = "bwapi"
|
||||||
|
for env in container.attrs["Config"]["Env"] :
|
||||||
|
if env.startswith("API_HTTP_PORT=") :
|
||||||
|
port = env.split("=")[1]
|
||||||
|
elif env.startswith("API_SERVER_NAME=") :
|
||||||
|
host = env.split("=")[1]
|
||||||
|
apis.append(API("http://" + container.name + ":" + port, host=host))
|
||||||
|
return apis
|
||||||
|
|
||||||
|
# Swarm case
|
||||||
|
if self.__integration == "swarm" :
|
||||||
|
docker_client = DockerClient()
|
||||||
|
apis = []
|
||||||
|
for service in self.__client.services.list(filters={"label" : "bunkerweb.AUTOCONF"}) :
|
||||||
|
port = "5000"
|
||||||
|
host = "bwapi"
|
||||||
|
for env in service.attrs["Spec"]["TaskTemplate"]["ContainerSpec"]["Env"] :
|
||||||
|
if env.startswith("API_HTTP_PORT=") :
|
||||||
|
port = env.split("=")[1]
|
||||||
|
elif env.startswith("API_SERVER_NAME=") :
|
||||||
|
host = env.split("=")[1]
|
||||||
|
for task in service.tasks() :
|
||||||
|
apis.append(API("http://" + service.name + "." + task["NodeID"] + "." + task["ID"] + ":" + port, host=host))
|
||||||
|
return apis
|
||||||
|
|
||||||
|
# Kubernetes case
|
||||||
|
if self.__integration == "kubernetes" :
|
||||||
|
config.load_incluster_config()
|
||||||
|
corev1 = client.CoreV1Api()
|
||||||
|
apis = []
|
||||||
|
for pod in corev1.list_pod_for_all_namespaces(watch=False).items :
|
||||||
|
if pod.metadata.annotations != None and "bunkerweb.io/AUTOCONF" in pod.metadata.annotations and pod.status.pod_ip :
|
||||||
|
port = "5000"
|
||||||
|
host = "bwapi"
|
||||||
|
for env in pod.spec.containers[0].env :
|
||||||
|
if env.name == "API_HTTP_PORT" :
|
||||||
|
port = env.value
|
||||||
|
elif env.name == "API_SERVER_NAME" :
|
||||||
|
host = env.value
|
||||||
|
apis.append(API("http://" + pod.status.pod_ip + ":" + port, host=host))
|
||||||
|
return apis
|
||||||
|
|
||||||
|
def unban(self, ip) :
|
||||||
|
if self._send_to_apis("POST", "/unban", data={"ip": ip}) :
|
||||||
|
return True, "IP " + ip + " has been unbanned"
|
||||||
|
return False, "error"
|
||||||
52
cli/main.py
Normal file
52
cli/main.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse, traceback, os
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append("/opt/bunkerweb/deps/python")
|
||||||
|
sys.path.append("/opt/bunkerweb/cli")
|
||||||
|
sys.path.append("/opt/bunkerweb/utils")
|
||||||
|
sys.path.append("/opt/bunkerweb/api")
|
||||||
|
|
||||||
|
from logger import log
|
||||||
|
from CLI import CLI
|
||||||
|
|
||||||
|
if __name__ == "__main__" :
|
||||||
|
|
||||||
|
try :
|
||||||
|
# Global parser
|
||||||
|
parser = argparse.ArgumentParser(description="BunkerWeb Command Line Interface")
|
||||||
|
subparsers = parser.add_subparsers(help="command", dest="command")
|
||||||
|
|
||||||
|
# Unban subparser
|
||||||
|
parser_unban = subparsers.add_parser("unban", help="remove a ban from the cache")
|
||||||
|
parser_unban.add_argument("ip", type=str, help="IP address to unban")
|
||||||
|
|
||||||
|
# Parse args
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Instantiate CLI
|
||||||
|
cli = CLI()
|
||||||
|
|
||||||
|
# Execute command
|
||||||
|
ret, err = False, "unknown command"
|
||||||
|
if args.command == "unban" :
|
||||||
|
ret, err = cli.unban(args.ip)
|
||||||
|
|
||||||
|
if not ret :
|
||||||
|
print("CLI command status : ❌ (fail)")
|
||||||
|
print(err)
|
||||||
|
os._exit(1)
|
||||||
|
else :
|
||||||
|
print("CLI command status : ✔️ (success)")
|
||||||
|
print(err)
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
except SystemExit as se :
|
||||||
|
sys.exit(se.code)
|
||||||
|
except :
|
||||||
|
print("❌ Error while executing bwcli : ")
|
||||||
|
print(traceback.format_exc())
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
163
compile.sh
163
compile.sh
@ -1,163 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
function git_secure_checkout() {
|
|
||||||
path="$1"
|
|
||||||
commit="$2"
|
|
||||||
ret=$(pwd)
|
|
||||||
cd $path
|
|
||||||
git checkout "${commit}^{commit}"
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo "[!] Commit hash $commit is absent from submodules $path !"
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
cd $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
function git_secure_clone() {
|
|
||||||
repo="$1"
|
|
||||||
commit="$2"
|
|
||||||
folder=$(echo "$repo" | sed -E "s@https://github.com/.*/(.*)\.git@\1@")
|
|
||||||
git clone "$repo"
|
|
||||||
cd "$folder"
|
|
||||||
git checkout "${commit}^{commit}"
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo "[!] Commit hash $commit is absent from repository $repo !"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
NTASK=$(nproc)
|
|
||||||
|
|
||||||
# install build dependencies
|
|
||||||
apk add --no-cache --virtual build autoconf libtool automake git geoip-dev yajl-dev g++ gcc curl-dev libxml2-dev pcre-dev make linux-headers libmaxminddb-dev musl-dev lua-dev gd-dev gnupg brotli-dev openssl-dev
|
|
||||||
|
|
||||||
# compile and install ModSecurity library
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/SpiderLabs/ModSecurity.git 753145fbd1d6751a6b14fdd700921eb3cc3a1d35
|
|
||||||
cd ModSecurity
|
|
||||||
./build.sh
|
|
||||||
git submodule init
|
|
||||||
git submodule update
|
|
||||||
git_secure_checkout bindings/python 47a6925df187f96e4593afab18dc92d5f22bd4d5
|
|
||||||
git_secure_checkout others/libinjection bf234eb2f385b969c4f803b35fda53cffdd93922
|
|
||||||
git_secure_checkout test/test-cases/secrules-language-tests d03f4c1e930440df46c1faa37d820a919704d9da
|
|
||||||
./configure --enable-static=no --disable-doxygen-doc --disable-dependency-tracking
|
|
||||||
make -j $NTASK
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
# download and install CRS rules
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/coreruleset/coreruleset.git 7776fe23f127fd2315bad0e400bdceb2cabb97dc
|
|
||||||
cd coreruleset
|
|
||||||
mkdir /opt/owasp
|
|
||||||
cp -r rules /opt/owasp/crs
|
|
||||||
cp crs-setup.conf.example /opt/owasp/crs.conf
|
|
||||||
|
|
||||||
# get nginx modules
|
|
||||||
cd /tmp
|
|
||||||
# ModSecurity connector for nginx
|
|
||||||
git_secure_clone https://github.com/SpiderLabs/ModSecurity-nginx.git 2497e6ac654d0b117b9534aa735b757c6b11c84f
|
|
||||||
# headers more
|
|
||||||
git_secure_clone https://github.com/openresty/headers-more-nginx-module.git d6d7ebab3c0c5b32ab421ba186783d3e5d2c6a17
|
|
||||||
# geoip
|
|
||||||
git_secure_clone https://github.com/leev/ngx_http_geoip2_module.git 1cabd8a1f68ea3998f94e9f3504431970f848fbf
|
|
||||||
# cookie
|
|
||||||
git_secure_clone https://github.com/AirisX/nginx_cookie_flag_module.git c4ff449318474fbbb4ba5f40cb67ccd54dc595d4
|
|
||||||
# brotli
|
|
||||||
git_secure_clone https://github.com/google/ngx_brotli.git 9aec15e2aa6feea2113119ba06460af70ab3ea62
|
|
||||||
|
|
||||||
# LUA requirements
|
|
||||||
git_secure_clone https://github.com/openresty/luajit2.git fe32831adcb3f5fe9259a9ce404fc54e1399bba3
|
|
||||||
cd luajit2
|
|
||||||
make -j $NTASK
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-resty-core.git b7d0a681bb41e6e3f29e8ddc438ef26fd819bb19
|
|
||||||
cd lua-resty-core
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-resty-lrucache.git b2035269ac353444ac65af3969692bcae4fc1605
|
|
||||||
cd lua-resty-lrucache
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-resty-dns.git 24c9a69808aedfaf029ae57707cdef75d83e2d19
|
|
||||||
cd lua-resty-dns
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/bungle/lua-resty-session.git f300870ce4eee3f4903e0565c589f1faf0c1c5aa
|
|
||||||
cd lua-resty-session
|
|
||||||
cp -r lib/resty/* /usr/local/lib/lua/resty
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/bungle/lua-resty-random.git 17b604f7f7dd217557ca548fc1a9a0d373386480
|
|
||||||
cd lua-resty-random
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-resty-string.git 9a543f8531241745f8814e8e02475351042774ec
|
|
||||||
cd lua-resty-string
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-cjson.git 0df488874f52a881d14b5876babaa780bb6200ee
|
|
||||||
cd lua-cjson
|
|
||||||
make -j $NTASK
|
|
||||||
make install
|
|
||||||
make install-extra
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/ittner/lua-gd.git 2ce8e478a8591afd71e607506bc8c64b161bbd30
|
|
||||||
cd lua-gd
|
|
||||||
make -j $NTASK
|
|
||||||
make INSTALL_PATH=/usr/local/lib/lua/5.1 install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/ledgetech/lua-resty-http.git 984fdc26054376384e3df238fb0f7dfde01cacf1
|
|
||||||
cd lua-resty-http
|
|
||||||
make install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/Neopallium/lualogging.git cadc4e8fd652be07a65b121a3e024838db330c15
|
|
||||||
cd lualogging
|
|
||||||
cp -r src/* /usr/local/lib/lua
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/diegonehab/luasocket.git 5b18e475f38fcf28429b1cc4b17baee3b9793a62
|
|
||||||
cd luasocket
|
|
||||||
make -j $NTASK
|
|
||||||
make CDIR_linux=lib/lua/5.1 LDIR_linux=lib/lua install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/brunoos/luasec.git c6704919bdc85f3324340bdb35c2795a02f7d625
|
|
||||||
cd luasec
|
|
||||||
make linux -j $NTASK
|
|
||||||
make LUACPATH=/usr/local/lib/lua/5.1 LUAPATH=/usr/local/lib/lua install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/crowdsecurity/lua-cs-bouncer.git 3c235c813fc453dcf51a391bc9e9a36ca77958b0
|
|
||||||
cd lua-cs-bouncer
|
|
||||||
mkdir /usr/local/lib/lua/crowdsec
|
|
||||||
cp lib/*.lua /usr/local/lib/lua/crowdsec
|
|
||||||
sed -i 's/require "lrucache"/require "resty.lrucache"/' /usr/local/lib/lua/crowdsec/CrowdSec.lua
|
|
||||||
sed -i 's/require "config"/require "crowdsec.config"/' /usr/local/lib/lua/crowdsec/CrowdSec.lua
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/hamishforbes/lua-resty-iputils.git 3151d6485e830421266eee5c0f386c32c835dba4
|
|
||||||
cd lua-resty-iputils
|
|
||||||
make LUA_LIB_DIR=/usr/local/lib/lua install
|
|
||||||
cd /tmp
|
|
||||||
git_secure_clone https://github.com/openresty/lua-nginx-module.git 2d23bc4f0a29ed79aaaa754c11bffb1080aa44ba
|
|
||||||
export LUAJIT_LIB=/usr/local/lib
|
|
||||||
export LUAJIT_INC=/usr/local/include/luajit-2.1
|
|
||||||
|
|
||||||
# compile and install dynamic modules
|
|
||||||
cd /tmp
|
|
||||||
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
|
|
||||||
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc
|
|
||||||
gpg --import /tmp/nginx-keys/*.key
|
|
||||||
check=$(gpg --verify /tmp/nginx-${NGINX_VERSION}.tar.gz.asc /tmp/nginx-${NGINX_VERSION}.tar.gz 2>&1 | grep "^gpg: Good signature from ")
|
|
||||||
if [ "$check" = "" ] ; then
|
|
||||||
echo "[!] Wrong signature from nginx source !"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
|
|
||||||
cd nginx-$NGINX_VERSION
|
|
||||||
CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p')
|
|
||||||
CONFARGS=${CONFARGS/-Os -fomit-frame-pointer -g/-Os}
|
|
||||||
./configure $CONFARGS --add-dynamic-module=/tmp/ModSecurity-nginx --add-dynamic-module=/tmp/headers-more-nginx-module --add-dynamic-module=/tmp/ngx_http_geoip2_module --add-dynamic-module=/tmp/nginx_cookie_flag_module --add-dynamic-module=/tmp/lua-nginx-module --add-dynamic-module=/tmp/ngx_brotli
|
|
||||||
make -j $NTASK modules
|
|
||||||
cp ./objs/*.so /usr/lib/nginx/modules
|
|
||||||
|
|
||||||
# remove build dependencies
|
|
||||||
apk del build
|
|
||||||
38
confs/api.conf
Normal file
38
confs/api.conf
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
server {
|
||||||
|
server_name {{ API_SERVER_NAME }};
|
||||||
|
|
||||||
|
# HTTP listen
|
||||||
|
listen 0.0.0.0:{{ API_HTTP_PORT }};
|
||||||
|
listen 127.0.0.1:{{ API_HTTP_PORT }};
|
||||||
|
|
||||||
|
# maximum body size for API
|
||||||
|
client_max_body_size 1G;
|
||||||
|
|
||||||
|
# default mime type is JSON
|
||||||
|
default_type 'application/json';
|
||||||
|
|
||||||
|
# check IP and do the API call
|
||||||
|
access_by_lua_block {
|
||||||
|
local api = require "api"
|
||||||
|
local logger = require "logger"
|
||||||
|
if not ngx.var.http_host or ngx.var.http_host ~= "{{ API_SERVER_NAME }}" then
|
||||||
|
logger.log(ngx.WARN, "API", "Wrong Host header from IP " .. ngx.var.remote_addr)
|
||||||
|
return ngx.exit(ngx.HTTP_CLOSE)
|
||||||
|
end
|
||||||
|
local ok, err = api:is_allowed_ip()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.WARN, "API", "Can't validate access from IP " .. ngx.var.remote_addr .. " : " .. err)
|
||||||
|
return ngx.exit(ngx.HTTP_CLOSE)
|
||||||
|
end
|
||||||
|
logger.log(ngx.NOTICE, "API", "Validated access from IP " .. ngx.var.remote_addr)
|
||||||
|
local ok, err, status, resp = api:do_api_call()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.WARN, "API", "Call from " .. ngx.var.remote_addr .. " on " .. ngx.var.uri .. " failed : " .. err)
|
||||||
|
else
|
||||||
|
logger.log(ngx.NOTICE, "API", "Successful call from " .. ngx.var.remote_addr .. " on " .. ngx.var.uri .. " : " .. err)
|
||||||
|
end
|
||||||
|
ngx.status = status
|
||||||
|
ngx.say(resp)
|
||||||
|
return ngx.exit(status)
|
||||||
|
}
|
||||||
|
}
|
||||||
15
confs/default-server-http.conf
Normal file
15
confs/default-server-http.conf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
server {
|
||||||
|
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
# HTTP listen
|
||||||
|
{% if LISTEN_HTTP == "yes" +%}
|
||||||
|
listen 0.0.0.0:{{ HTTP_PORT }} default_server {% if USE_PROXY_PROTOCOL == "yes" %}proxy_protocol{% endif %};
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# include core and plugins default-server configurations
|
||||||
|
include /etc/nginx/default-server-http/*.conf;
|
||||||
|
|
||||||
|
# include custom default-server configurations
|
||||||
|
include /opt/bunkerweb/configs/default-server-http/*.conf;
|
||||||
|
}
|
||||||
25
confs/fastcgi_params
Normal file
25
confs/fastcgi_params
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
fastcgi_param QUERY_STRING $query_string;
|
||||||
|
fastcgi_param REQUEST_METHOD $request_method;
|
||||||
|
fastcgi_param CONTENT_TYPE $content_type;
|
||||||
|
fastcgi_param CONTENT_LENGTH $content_length;
|
||||||
|
|
||||||
|
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||||
|
fastcgi_param REQUEST_URI $request_uri;
|
||||||
|
fastcgi_param DOCUMENT_URI $document_uri;
|
||||||
|
fastcgi_param DOCUMENT_ROOT $document_root;
|
||||||
|
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
||||||
|
fastcgi_param REQUEST_SCHEME $scheme;
|
||||||
|
fastcgi_param HTTPS $https if_not_empty;
|
||||||
|
|
||||||
|
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
|
||||||
|
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
|
||||||
|
|
||||||
|
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||||
|
fastcgi_param REMOTE_PORT $remote_port;
|
||||||
|
fastcgi_param SERVER_ADDR $server_addr;
|
||||||
|
fastcgi_param SERVER_PORT $server_port;
|
||||||
|
fastcgi_param SERVER_NAME $server_name;
|
||||||
|
|
||||||
|
# PHP only, required if PHP was built with --enable-force-cgi-redirect
|
||||||
|
fastcgi_param REDIRECT_STATUS 200;
|
||||||
@ -1,31 +0,0 @@
|
|||||||
location ~ ^%API_URI%/ping {
|
|
||||||
return 444;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ %API_URI% {
|
|
||||||
|
|
||||||
rewrite_by_lua_block {
|
|
||||||
|
|
||||||
local api = require "api"
|
|
||||||
local api_whitelist_ip = { %API_WHITELIST_IP% }
|
|
||||||
local api_uri = "%API_URI%"
|
|
||||||
local logger = require "logger"
|
|
||||||
|
|
||||||
if api.is_api_call(api_uri, api_whitelist_ip) then
|
|
||||||
ngx.header.content_type = 'text/plain'
|
|
||||||
if api.do_api_call(api_uri) then
|
|
||||||
logger.log(ngx.NOTICE, "API", "API call " .. ngx.var.request_uri .. " successfull from " .. ngx.var.remote_addr)
|
|
||||||
ngx.say("ok")
|
|
||||||
else
|
|
||||||
logger.log(ngx.WARN, "API", "API call " .. ngx.var.request_uri .. " failed from " .. ngx.var.remote_addr)
|
|
||||||
ngx.say("ko")
|
|
||||||
end
|
|
||||||
|
|
||||||
ngx.exit(ngx.HTTP_OK)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
# todo : if api_uri == "random"
|
|
||||||
rewrite_by_lua_block {
|
|
||||||
|
|
||||||
local api = require "api"
|
|
||||||
local api_whitelist_ip = {% raw %}{{% endraw %}{% if API_WHITELIST_IP != ""%}{% set elements = API_WHITELIST_IP.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
local api_uri = "{{ API_URI }}"
|
|
||||||
local logger = require "logger"
|
|
||||||
|
|
||||||
if api.is_api_call(api_uri, api_whitelist_ip) then
|
|
||||||
ngx.header.content_type = 'text/plain'
|
|
||||||
if api.do_api_call(api_uri) then
|
|
||||||
logger.log(ngx.NOTICE, "API", "API call " .. ngx.var.request_uri .. " successfull from " .. ngx.var.remote_addr)
|
|
||||||
ngx.print("ok")
|
|
||||||
else
|
|
||||||
logger.log(ngx.WARN, "API", "API call " .. ngx.var.request_uri .. " failed from " .. ngx.var.remote_addr)
|
|
||||||
ngx.print("ko")
|
|
||||||
end
|
|
||||||
|
|
||||||
ngx.exit(ngx.HTTP_OK)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
API_URL={{ CROWDSEC_HOST }}
|
|
||||||
API_KEY={{ CROWDSEC_KEY }}
|
|
||||||
LOG_FILE=/tmp/lua_mod.log
|
|
||||||
CACHE_EXPIRATION=1
|
|
||||||
CACHE_SIZE=1000
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
geoip2 /etc/nginx/geoip.mmdb {
|
|
||||||
auto_reload 5m;
|
|
||||||
$geoip2_metadata_country_build metadata build_epoch;
|
|
||||||
$geoip2_data_country_code country iso_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
map $geoip2_data_country_code $allowed_country {
|
|
||||||
default {% if WHITELIST_COUNTRY != "" %}no{% else %}yes{% endif %};
|
|
||||||
{% if WHITELIST_COUNTRY != "" %}
|
|
||||||
{% for country in WHITELIST_COUNTRY.split(" ") %}
|
|
||||||
{{ country }} yes;
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% if BLACKLIST_COUNTRY != "" %}
|
|
||||||
{% for country in BLACKLIST_COUNTRY.split(" ") %}
|
|
||||||
{{ country }} no;
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
}
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
init_by_lua_block {
|
|
||||||
|
|
||||||
local dataloader = require "dataloader"
|
|
||||||
local logger = require "logger"
|
|
||||||
local cjson = require "cjson"
|
|
||||||
|
|
||||||
local use_proxies = {% if has_value("BLOCK_PROXIES", "yes") %}true{% else %}false{% endif %}
|
|
||||||
local use_abusers = {% if has_value("BLOCK_ABUSERS", "yes") %}true{% else %}false{% endif %}
|
|
||||||
local use_tor_exit_nodes = {% if has_value("BLOCK_TOR_EXIT_NODE", "yes") %}true{% else %}false{% endif %}
|
|
||||||
local use_user_agents = {% if has_value("BLOCK_USER_AGENT", "yes") %}true{% else %}false{% endif %}
|
|
||||||
local use_referrers = {% if has_value("BLOCK_REFERRER", "yes") %}true{% else %}false{% endif %}
|
|
||||||
local use_crowdsec = {% if has_value("USE_CROWDSEC", "yes") %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
if use_proxies then
|
|
||||||
dataloader.load_ip("/etc/nginx/proxies.list", ngx.shared.proxies_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_abusers then
|
|
||||||
dataloader.load_ip("/etc/nginx/abusers.list", ngx.shared.abusers_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_tor_exit_nodes then
|
|
||||||
dataloader.load_ip("/etc/nginx/tor-exit-nodes.list", ngx.shared.tor_exit_nodes_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_user_agents then
|
|
||||||
dataloader.load_raw("/etc/nginx/user-agents.list", ngx.shared.user_agents_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_referrers then
|
|
||||||
dataloader.load_raw("/etc/nginx/referrers.list", ngx.shared.referrers_data)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_crowdsec then
|
|
||||||
local cs = require "crowdsec.CrowdSec"
|
|
||||||
local ok, err = cs.init("/etc/nginx/crowdsec.conf")
|
|
||||||
if ok == nil then
|
|
||||||
logger.log(ngx.ERR, "CROWDSEC", err)
|
|
||||||
error()
|
|
||||||
end
|
|
||||||
logger.log(ngx.ERR, "CROWDSEC", "*NOT AN ERROR* initialisation done")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Load plugins
|
|
||||||
ngx.shared.plugins_data:safe_set("plugins", nil, 0)
|
|
||||||
local p = io.popen("find /plugins -maxdepth 1 -type d ! -path /plugins")
|
|
||||||
for dir in p:lines() do
|
|
||||||
-- read JSON
|
|
||||||
local file = io.open(dir .. "/plugin.json")
|
|
||||||
if file then
|
|
||||||
-- store settings
|
|
||||||
local data = cjson.decode(file:read("*a"))
|
|
||||||
for k, v in pairs(data.settings) do
|
|
||||||
ngx.shared.plugins_data:safe_set(data.id .. "_" .. k, v, 0)
|
|
||||||
end
|
|
||||||
file:close()
|
|
||||||
-- store plugin
|
|
||||||
local plugins, flags = ngx.shared.plugins_data:get("plugins")
|
|
||||||
if plugins == nil then
|
|
||||||
ngx.shared.plugins_data:safe_set("plugins", data.id, 0)
|
|
||||||
else
|
|
||||||
ngx.shared.plugins_data:safe_set("plugins", plugins .. " " .. data.id, 0)
|
|
||||||
end
|
|
||||||
logger.log(ngx.ERR, "PLUGINS", "*NOT AN ERROR* plugin " .. data.name .. "/" .. data.version .. " has been loaded")
|
|
||||||
else
|
|
||||||
logger.log(ngx.ERR, "PLUGINS", "Can't load " .. dir .. "/plugin.json")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
p:close()
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
types {
|
|
||||||
text/html html htm shtml;
|
|
||||||
text/css css;
|
|
||||||
text/xml xml;
|
|
||||||
image/gif gif;
|
|
||||||
image/jpeg jpeg jpg;
|
|
||||||
application/javascript js;
|
|
||||||
application/atom+xml atom;
|
|
||||||
application/rss+xml rss;
|
|
||||||
|
|
||||||
text/mathml mml;
|
|
||||||
text/plain txt;
|
|
||||||
text/vnd.sun.j2me.app-descriptor jad;
|
|
||||||
text/vnd.wap.wml wml;
|
|
||||||
text/x-component htc;
|
|
||||||
|
|
||||||
image/png png;
|
|
||||||
image/svg+xml svg svgz;
|
|
||||||
image/tiff tif tiff;
|
|
||||||
image/vnd.wap.wbmp wbmp;
|
|
||||||
image/webp webp;
|
|
||||||
image/x-icon ico;
|
|
||||||
image/x-jng jng;
|
|
||||||
image/x-ms-bmp bmp;
|
|
||||||
|
|
||||||
font/woff woff;
|
|
||||||
font/woff2 woff2;
|
|
||||||
|
|
||||||
application/java-archive jar war ear;
|
|
||||||
application/json json;
|
|
||||||
application/mac-binhex40 hqx;
|
|
||||||
application/msword doc;
|
|
||||||
application/pdf pdf;
|
|
||||||
application/postscript ps eps ai;
|
|
||||||
application/rtf rtf;
|
|
||||||
application/vnd.apple.mpegurl m3u8;
|
|
||||||
application/vnd.google-earth.kml+xml kml;
|
|
||||||
application/vnd.google-earth.kmz kmz;
|
|
||||||
application/vnd.ms-excel xls;
|
|
||||||
application/vnd.ms-fontobject eot;
|
|
||||||
application/vnd.ms-powerpoint ppt;
|
|
||||||
application/vnd.oasis.opendocument.graphics odg;
|
|
||||||
application/vnd.oasis.opendocument.presentation odp;
|
|
||||||
application/vnd.oasis.opendocument.spreadsheet ods;
|
|
||||||
application/vnd.oasis.opendocument.text odt;
|
|
||||||
application/vnd.openxmlformats-officedocument.presentationml.presentation
|
|
||||||
pptx;
|
|
||||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
|
||||||
xlsx;
|
|
||||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
|
||||||
docx;
|
|
||||||
application/vnd.wap.wmlc wmlc;
|
|
||||||
application/x-7z-compressed 7z;
|
|
||||||
application/x-cocoa cco;
|
|
||||||
application/x-java-archive-diff jardiff;
|
|
||||||
application/x-java-jnlp-file jnlp;
|
|
||||||
application/x-makeself run;
|
|
||||||
application/x-perl pl pm;
|
|
||||||
application/x-pilot prc pdb;
|
|
||||||
application/x-rar-compressed rar;
|
|
||||||
application/x-redhat-package-manager rpm;
|
|
||||||
application/x-sea sea;
|
|
||||||
application/x-shockwave-flash swf;
|
|
||||||
application/x-stuffit sit;
|
|
||||||
application/x-tcl tcl tk;
|
|
||||||
application/x-x509-ca-cert der pem crt;
|
|
||||||
application/x-xpinstall xpi;
|
|
||||||
application/xhtml+xml xhtml;
|
|
||||||
application/xspf+xml xspf;
|
|
||||||
application/zip zip;
|
|
||||||
|
|
||||||
application/octet-stream bin exe dll;
|
|
||||||
application/octet-stream deb;
|
|
||||||
application/octet-stream dmg;
|
|
||||||
application/octet-stream iso img;
|
|
||||||
application/octet-stream msi msp msm;
|
|
||||||
|
|
||||||
audio/midi mid midi kar;
|
|
||||||
audio/mpeg mp3;
|
|
||||||
audio/ogg ogg;
|
|
||||||
audio/x-m4a m4a;
|
|
||||||
audio/x-realaudio ra;
|
|
||||||
|
|
||||||
video/3gpp 3gpp 3gp;
|
|
||||||
video/mp2t ts;
|
|
||||||
video/mp4 mp4;
|
|
||||||
video/mpeg mpeg mpg;
|
|
||||||
video/quicktime mov;
|
|
||||||
video/webm webm;
|
|
||||||
video/x-flv flv;
|
|
||||||
video/x-m4v m4v;
|
|
||||||
video/x-mng mng;
|
|
||||||
video/x-ms-asf asx asf;
|
|
||||||
video/x-ms-wmv wmv;
|
|
||||||
video/x-msvideo avi;
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
listen 0.0.0.0:{{ HTTPS_PORT }} default_server ssl {% if USE_HTTP2 == "yes" %}http2{% endif %};
|
|
||||||
ssl_certificate /etc/nginx/default-cert.pem;
|
|
||||||
ssl_certificate_key /etc/nginx/default-key.pem;
|
|
||||||
ssl_protocols {{ HTTPS_PROTOCOLS }};
|
|
||||||
ssl_prefer_server_ciphers off;
|
|
||||||
ssl_session_tickets off;
|
|
||||||
ssl_session_timeout 1d;
|
|
||||||
ssl_session_cache shared:MozSSL:10m;
|
|
||||||
{% if "TLSv1.2" in HTTPS_PROTOCOLS %}
|
|
||||||
ssl_dhparam /etc/nginx/dhparam;
|
|
||||||
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;
|
|
||||||
{% endif %}
|
|
||||||
include /etc/nginx/multisite-default-server-lets-encrypt-webroot.conf;
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
location ~ ^/.well-known/acme-challenge/ {
|
|
||||||
root /acme-challenge;
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
server {
|
|
||||||
{% if LISTEN_HTTP == "yes" %}listen 0.0.0.0:{{ HTTP_PORT }} default_server{% endif %};
|
|
||||||
server_name _;
|
|
||||||
{% if has_value("AUTO_LETS_ENCRYPT", "yes") %}include /etc/nginx/multisite-default-server-https.conf;{% endif %}
|
|
||||||
{% if USE_API == "yes" %}
|
|
||||||
location ^~ {{ API_URI }} {
|
|
||||||
include /etc/nginx/api.conf;
|
|
||||||
}
|
|
||||||
{% endif %}
|
|
||||||
{% if DISABLE_DEFAULT_SERVER == "yes" %}include /etc/nginx/multisite-disable-default-server.conf;{% endif %}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
location / {
|
|
||||||
return 444;
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;
|
|
||||||
|
|
||||||
daemon on;
|
|
||||||
|
|
||||||
pid /tmp/nginx-temp.pid;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
use epoll;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
proxy_temp_path /tmp/proxy_temp;
|
|
||||||
client_body_temp_path /tmp/client_temp;
|
|
||||||
fastcgi_temp_path /tmp/fastcgi_temp;
|
|
||||||
uwsgi_temp_path /tmp/uwsgi_temp;
|
|
||||||
scgi_temp_path /tmp/scgi_temp;
|
|
||||||
lua_package_path "/usr/local/lib/lua/?.lua;;";
|
|
||||||
server {
|
|
||||||
listen 0.0.0.0:%HTTP_PORT% default_server;
|
|
||||||
server_name _;
|
|
||||||
location ~ ^/.well-known/acme-challenge/ {
|
|
||||||
root /acme-challenge;
|
|
||||||
}
|
|
||||||
%USE_API%
|
|
||||||
location / {
|
|
||||||
return 444;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,149 +0,0 @@
|
|||||||
# /etc/nginx/nginx.conf
|
|
||||||
|
|
||||||
# load dynamic modules
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_cookie_flag_filter_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_headers_more_filter_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_modsecurity_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so;
|
|
||||||
load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so;
|
|
||||||
|
|
||||||
# run in foreground
|
|
||||||
daemon off;
|
|
||||||
|
|
||||||
# PID file
|
|
||||||
pid /tmp/nginx.pid;
|
|
||||||
|
|
||||||
# worker number = CPU core(s)
|
|
||||||
worker_processes auto;
|
|
||||||
|
|
||||||
# faster regexp
|
|
||||||
pcre_jit on;
|
|
||||||
|
|
||||||
# config files for dynamic modules
|
|
||||||
include /etc/nginx/modules/*.conf;
|
|
||||||
|
|
||||||
# max open files for each worker
|
|
||||||
worker_rlimit_nofile {{ WORKER_RLIMIT_NOFILE }};
|
|
||||||
|
|
||||||
events {
|
|
||||||
# max connections per worker
|
|
||||||
worker_connections {{ WORKER_CONNECTIONS }};
|
|
||||||
|
|
||||||
# epoll seems to be the best on Linux
|
|
||||||
use epoll;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
# zero copy within the kernel
|
|
||||||
sendfile on;
|
|
||||||
|
|
||||||
# send packets only if filled
|
|
||||||
tcp_nopush on;
|
|
||||||
|
|
||||||
# remove 200ms delay
|
|
||||||
tcp_nodelay on;
|
|
||||||
|
|
||||||
# load mime types and set default one
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
# write logs to local syslog
|
|
||||||
log_format logf '{{ LOG_FORMAT }}';
|
|
||||||
access_log /var/log/access.log logf;
|
|
||||||
error_log /var/log/error.log {{ LOG_LEVEL }};
|
|
||||||
|
|
||||||
# temp paths
|
|
||||||
proxy_temp_path /tmp/proxy_temp;
|
|
||||||
client_body_temp_path /tmp/client_temp;
|
|
||||||
fastcgi_temp_path /tmp/fastcgi_temp;
|
|
||||||
uwsgi_temp_path /tmp/uwsgi_temp;
|
|
||||||
scgi_temp_path /tmp/scgi_temp;
|
|
||||||
|
|
||||||
# close connections in FIN_WAIT1 state
|
|
||||||
reset_timedout_connection on;
|
|
||||||
|
|
||||||
# timeouts
|
|
||||||
client_body_timeout 10;
|
|
||||||
client_header_timeout 10;
|
|
||||||
keepalive_timeout 15;
|
|
||||||
send_timeout 10;
|
|
||||||
|
|
||||||
# resolvers to use
|
|
||||||
resolver {{ DNS_RESOLVERS }} ipv6=off;
|
|
||||||
|
|
||||||
# remove ports when sending redirects
|
|
||||||
port_in_redirect off;
|
|
||||||
|
|
||||||
# lua path and dicts
|
|
||||||
lua_package_path "/usr/local/lib/lua/?.lua;/plugins/?.lua;;";
|
|
||||||
{% if has_value("USE_WHITELIST_IP", "yes") %}lua_shared_dict whitelist_ip_cache 10m;{% endif %}
|
|
||||||
{% if has_value("USE_WHITELIST_REVERSE", "yes") %}lua_shared_dict whitelist_reverse_cache 10m;{% endif %}
|
|
||||||
{% if has_value("USE_BLACKLIST_IP", "yes") %}lua_shared_dict blacklist_ip_cache 10m;{% endif %}
|
|
||||||
{% if has_value("USE_BLACKLIST_REVERSE", "yes") %}lua_shared_dict blacklist_reverse_cache 10m;{% endif %}
|
|
||||||
{% if has_value("USE_DNSBL", "yes") %}lua_shared_dict dnsbl_cache 10m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_PROXIES", "yes") %}lua_shared_dict proxies_data 250m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_ABUSERS", "yes") %}lua_shared_dict abusers_data 50m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_TOR_EXIT_NODE", "yes") %}lua_shared_dict tor_exit_nodes_data 1m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_USER_AGENT", "yes") %}lua_shared_dict user_agents_data 1m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_USER_AGENT", "yes") %}lua_shared_dict user_agents_cache 10m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_REFERRER", "yes") %}lua_shared_dict referrers_data 1m;{% endif %}
|
|
||||||
{% if has_value("BLOCK_REFERRER", "yes") %}lua_shared_dict referrers_cache 10m;{% endif %}
|
|
||||||
{% if has_value("USE_BAD_BEHAVIOR", "yes") %}lua_shared_dict behavior_ban 10m;{% endif %}
|
|
||||||
{% if has_value("USE_BAD_BEHAVIOR", "yes") %}lua_shared_dict behavior_count 10m;{% endif %}
|
|
||||||
lua_shared_dict plugins_data 10m;
|
|
||||||
|
|
||||||
# shared memory zone for limit_req
|
|
||||||
{% if has_value("USE_LIMIT_REQ", "yes") %}limit_req_zone $binary_remote_addr$uri zone=limit:{{ LIMIT_REQ_CACHE }} rate={{ LIMIT_REQ_RATE }};{% endif %}
|
|
||||||
|
|
||||||
# shared memory zone for limit_conn
|
|
||||||
{% if has_value("USE_LIMIT_CONN", "yes") %}limit_conn_zone $binary_remote_addr zone=ddos:{{ LIMIT_CONN_CACHE }};{% endif %}
|
|
||||||
|
|
||||||
# whitelist or blacklist country
|
|
||||||
{% if BLACKLIST_COUNTRY != "" or WHITELIST_COUNTRY != "" %}include /etc/nginx/geoip.conf;{% endif %}
|
|
||||||
|
|
||||||
# zone for proxy_cache
|
|
||||||
{% if has_value("USE_PROXY_CACHE", "yes") %}proxy_cache_path /tmp/proxy_cache keys_zone=proxycache:{{ PROXY_CACHE_PATH_ZONE_SIZE }} {{ PROXY_CACHE_PATH_PARAMS }};{% endif %}
|
|
||||||
|
|
||||||
# custom http confs
|
|
||||||
include /http-confs/*.conf;
|
|
||||||
|
|
||||||
# LUA init block
|
|
||||||
include /etc/nginx/init-lua.conf;
|
|
||||||
|
|
||||||
# default server when MULTISITE=yes
|
|
||||||
{% if MULTISITE == "yes" %}include /etc/nginx/multisite-default-server.conf;{% endif %}
|
|
||||||
|
|
||||||
# server config(s)
|
|
||||||
{% if MULTISITE == "yes" and SERVER_NAME != "" %}
|
|
||||||
{% set map_servers = {} %}
|
|
||||||
{% for server_name in SERVER_NAME.split(" ") %}
|
|
||||||
{% if server_name + "_SERVER_NAME" in all %}
|
|
||||||
{% set x = map_servers.update({server_name : all[server_name + "_SERVER_NAME"].split(" ")}) %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% for server_name in SERVER_NAME.split(" ") %}
|
|
||||||
{% if not server_name in map_servers %}
|
|
||||||
{% set found = {"res": false} %}
|
|
||||||
{% for first_server, servers in map_servers.items() %}
|
|
||||||
{% if server_name in servers %}
|
|
||||||
{% set x = found.update({"res" : true}) %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% if not found["res"] %}
|
|
||||||
{% set x = map_servers.update({server_name : [server_name]}) %}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% for first_server in map_servers %}
|
|
||||||
include /etc/nginx/{{ first_server }}/server.conf;
|
|
||||||
{% endfor %}
|
|
||||||
{% elif MULTISITE == "no" %}
|
|
||||||
include /etc/nginx/server.conf;
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
# API
|
|
||||||
{% if USE_API == "yes" %}include /etc/nginx/api.conf;{% endif %}
|
|
||||||
}
|
|
||||||
25
confs/healthcheck.conf
Normal file
25
confs/healthcheck.conf
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
server {
|
||||||
|
|
||||||
|
# healthcheck service for docker, swarm and k8s
|
||||||
|
server_name healthcheck.bunkerweb.io;
|
||||||
|
|
||||||
|
# only listen on localhost
|
||||||
|
listen 127.0.0.1:6000;
|
||||||
|
|
||||||
|
# healthcheck endpoint
|
||||||
|
location ~ ^/healthz$ {
|
||||||
|
keepalive_timeout 0;
|
||||||
|
default_type "text/plain";
|
||||||
|
content_by_lua_block {
|
||||||
|
ngx.say("ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# disable logging
|
||||||
|
access_log off;
|
||||||
|
|
||||||
|
# don't respond to other requests
|
||||||
|
location / {
|
||||||
|
return 444;
|
||||||
|
}
|
||||||
|
}
|
||||||
94
confs/http.conf
Normal file
94
confs/http.conf
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
# /etc/nginx/base_http.conf
|
||||||
|
|
||||||
|
# zero copy within the kernel
|
||||||
|
sendfile on;
|
||||||
|
|
||||||
|
# send packets only if filled
|
||||||
|
tcp_nopush on;
|
||||||
|
|
||||||
|
# remove 200ms delay
|
||||||
|
tcp_nodelay on;
|
||||||
|
|
||||||
|
# load mime types and set default one
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
# access log format
|
||||||
|
log_format logf '{{ LOG_FORMAT }}';
|
||||||
|
access_log /var/log/nginx/access.log logf;
|
||||||
|
|
||||||
|
# temp paths
|
||||||
|
proxy_temp_path /opt/bunkerweb/tmp/proxy_temp;
|
||||||
|
client_body_temp_path /opt/bunkerweb/tmp/client_temp;
|
||||||
|
fastcgi_temp_path /opt/bunkerweb/tmp/fastcgi_temp;
|
||||||
|
uwsgi_temp_path /opt/bunkerweb/tmp/uwsgi_temp;
|
||||||
|
scgi_temp_path /opt/bunkerweb/tmp/scgi_temp;
|
||||||
|
|
||||||
|
# close connections in FIN_WAIT1 state
|
||||||
|
reset_timedout_connection on;
|
||||||
|
|
||||||
|
# timeouts
|
||||||
|
client_body_timeout 10;
|
||||||
|
client_header_timeout 10;
|
||||||
|
keepalive_timeout 15;
|
||||||
|
send_timeout 10;
|
||||||
|
|
||||||
|
# resolvers to use
|
||||||
|
resolver {{ DNS_RESOLVERS }} ipv6=off;
|
||||||
|
|
||||||
|
# remove ports when sending redirects
|
||||||
|
port_in_redirect off;
|
||||||
|
|
||||||
|
# lua path and dicts
|
||||||
|
lua_package_path "/opt/bunkerweb/lua/?.lua;/opt/bunkerweb/core/?.lua;/opt/bunkerweb/plugins/?.lua;/opt/bunkerweb/deps/lib/lua/?.lua;;";
|
||||||
|
lua_package_cpath "/opt/bunkerweb/deps/lib/?.so;/opt/bunkerweb/deps/lib/lua/?.so;;";
|
||||||
|
lua_ssl_trusted_certificate "/opt/bunkerweb/misc/root-ca.pem";
|
||||||
|
lua_ssl_verify_depth 2;
|
||||||
|
lua_shared_dict datastore {{ DATASTORE_MEMORY_SIZE }};
|
||||||
|
|
||||||
|
# LUA init block
|
||||||
|
include /etc/nginx/init-lua.conf;
|
||||||
|
|
||||||
|
# API server
|
||||||
|
{% if USE_API == "yes" %}include /etc/nginx/api.conf;{% endif +%}
|
||||||
|
|
||||||
|
# healthcheck server
|
||||||
|
include /etc/nginx/healthcheck.conf;
|
||||||
|
|
||||||
|
# default server
|
||||||
|
{% if MULTISITE == "yes" or DISABLE_DEFAULT_SERVER == "yes" +%}
|
||||||
|
include /etc/nginx/default-server-http.conf;
|
||||||
|
{% endif +%}
|
||||||
|
|
||||||
|
# disable sending nginx version globally
|
||||||
|
server_tokens off;
|
||||||
|
|
||||||
|
# server config(s)
|
||||||
|
{% if TEMP_NGINX != "yes" +%}
|
||||||
|
{% if MULTISITE == "yes" and SERVER_NAME != "" %}
|
||||||
|
{% set map_servers = {} %}
|
||||||
|
{% for server_name in SERVER_NAME.split(" ") %}
|
||||||
|
{% if server_name + "_SERVER_NAME" in all %}
|
||||||
|
{% set x = map_servers.update({server_name : all[server_name + "_SERVER_NAME"].split(" ")}) %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for server_name in SERVER_NAME.split(" ") %}
|
||||||
|
{% if not server_name in map_servers %}
|
||||||
|
{% set found = {"res": false} %}
|
||||||
|
{% for first_server, servers in map_servers.items() %}
|
||||||
|
{% if server_name in servers %}
|
||||||
|
{% set x = found.update({"res" : true}) %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if not found["res"] %}
|
||||||
|
{% set x = map_servers.update({server_name : [server_name]}) %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for first_server in map_servers +%}
|
||||||
|
include /etc/nginx/{{ first_server }}/server.conf;
|
||||||
|
{% endfor %}
|
||||||
|
{% elif MULTISITE == "no" and SERVER_NAME != "" +%}
|
||||||
|
include /etc/nginx/server.conf;
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
118
confs/init-lua.conf
Normal file
118
confs/init-lua.conf
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
init_by_lua_block {
|
||||||
|
|
||||||
|
local logger = require "logger"
|
||||||
|
local datastore = require "datastore"
|
||||||
|
local plugins = require "plugins"
|
||||||
|
local utils = require "utils"
|
||||||
|
local cjson = require "cjson"
|
||||||
|
|
||||||
|
logger.log(ngx.NOTICE, "INIT", "Init phase started")
|
||||||
|
|
||||||
|
-- Remove previous data from the datastore
|
||||||
|
local data_keys = {"^plugin_", "^variable_", "^plugins$", "^api_", "^misc_"}
|
||||||
|
for i, key in pairs(data_keys) do
|
||||||
|
local ok, err = datastore:delete_all(key)
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't delete " .. key .. " from datastore : " .. err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
logger.log(ngx.INFO, "INIT", "Deleted " .. key .. " from datastore")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load variables into the datastore
|
||||||
|
local file = io.open("/etc/nginx/variables.env")
|
||||||
|
if not file then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't open /etc/nginx/variables.env file")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
file:close()
|
||||||
|
for line in io.lines("/etc/nginx/variables.env") do
|
||||||
|
local variable, value = line:match("(.+)=(.*)")
|
||||||
|
ok, err = datastore:set("variable_" .. variable, value)
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't save variable " .. variable .. " into datastore")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set default values into the datastore
|
||||||
|
ok, err = datastore:set("plugins", cjson.encode({}))
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't set default value for plugins into the datastore : " .. err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
ok, err = utils.set_values()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Error while setting default values : " .. err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- API setup
|
||||||
|
local value, err = datastore:get("variable_USE_API")
|
||||||
|
if not value then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't get variable USE_API from the datastore")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if value == "yes" then
|
||||||
|
value, err = datastore:get("variable_API_WHITELIST_IP")
|
||||||
|
if not value then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't get variable API_WHITELIST_IP from the datastore")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local whitelists = { data = {}}
|
||||||
|
for whitelist in value:gmatch("%S+") do
|
||||||
|
table.insert(whitelists.data, whitelist)
|
||||||
|
end
|
||||||
|
ok, err = datastore:set("api_whitelist_ip", cjson.encode(whitelists))
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't save api_whitelist_ip to datastore : " .. err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Load plugins into the datastore
|
||||||
|
local plugin_paths = {"/opt/bunkerweb/core", "/opt/bunkerweb/plugins"}
|
||||||
|
for i, plugin_path in ipairs(plugin_paths) do
|
||||||
|
local paths = io.popen("find -L " .. plugin_path .. " -maxdepth 1 -type d ! -path " .. plugin_path)
|
||||||
|
for path in paths:lines() do
|
||||||
|
plugin, err = plugins:load(path)
|
||||||
|
if not plugin then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Error while loading plugin from " .. path .. " : " .. err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
logger.log(ngx.NOTICE, "INIT", "Loaded plugin " .. plugin.id .. " v" .. plugin.version)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Call init method of plugins
|
||||||
|
local list, err = plugins:list()
|
||||||
|
if not list then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Can't list loaded plugins : " .. err)
|
||||||
|
list = {}
|
||||||
|
end
|
||||||
|
for i, plugin in ipairs(list) do
|
||||||
|
local ret, plugin_lua = pcall(require, plugin.id .. "/" .. plugin.id)
|
||||||
|
if ret then
|
||||||
|
local plugin_obj = plugin_lua.new()
|
||||||
|
if plugin_obj.init ~= nil then
|
||||||
|
ok, err = plugin_obj:init()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "INIT", "Plugin " .. plugin.id .. " failed on init() : " .. err)
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "INIT", "Successfull init() call for plugin " .. plugin.id .. " : " .. err)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "INIT", "init() method not found in " .. plugin.id .. ", skipped execution")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if plugin_lua:match("not found") then
|
||||||
|
logger.log(ngx.INFO, "INIT", "can't require " .. plugin.id .. " : not found")
|
||||||
|
else
|
||||||
|
logger.log(ngx.ERR, "INIT", "can't require " .. plugin.id .. " : " .. plugin_lua)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.log(ngx.NOTICE, "INIT", "Init phase ended")
|
||||||
|
|
||||||
|
}
|
||||||
99
confs/mime.types
Normal file
99
confs/mime.types
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
|
||||||
|
types {
|
||||||
|
text/html html htm shtml;
|
||||||
|
text/css css;
|
||||||
|
text/xml xml;
|
||||||
|
image/gif gif;
|
||||||
|
image/jpeg jpeg jpg;
|
||||||
|
application/javascript js;
|
||||||
|
application/atom+xml atom;
|
||||||
|
application/rss+xml rss;
|
||||||
|
|
||||||
|
text/mathml mml;
|
||||||
|
text/plain txt;
|
||||||
|
text/vnd.sun.j2me.app-descriptor jad;
|
||||||
|
text/vnd.wap.wml wml;
|
||||||
|
text/x-component htc;
|
||||||
|
|
||||||
|
image/avif avif;
|
||||||
|
image/png png;
|
||||||
|
image/svg+xml svg svgz;
|
||||||
|
image/tiff tif tiff;
|
||||||
|
image/vnd.wap.wbmp wbmp;
|
||||||
|
image/webp webp;
|
||||||
|
image/x-icon ico;
|
||||||
|
image/x-jng jng;
|
||||||
|
image/x-ms-bmp bmp;
|
||||||
|
|
||||||
|
font/woff woff;
|
||||||
|
font/woff2 woff2;
|
||||||
|
|
||||||
|
application/java-archive jar war ear;
|
||||||
|
application/json json;
|
||||||
|
application/mac-binhex40 hqx;
|
||||||
|
application/msword doc;
|
||||||
|
application/pdf pdf;
|
||||||
|
application/postscript ps eps ai;
|
||||||
|
application/rtf rtf;
|
||||||
|
application/vnd.apple.mpegurl m3u8;
|
||||||
|
application/vnd.google-earth.kml+xml kml;
|
||||||
|
application/vnd.google-earth.kmz kmz;
|
||||||
|
application/vnd.ms-excel xls;
|
||||||
|
application/vnd.ms-fontobject eot;
|
||||||
|
application/vnd.ms-powerpoint ppt;
|
||||||
|
application/vnd.oasis.opendocument.graphics odg;
|
||||||
|
application/vnd.oasis.opendocument.presentation odp;
|
||||||
|
application/vnd.oasis.opendocument.spreadsheet ods;
|
||||||
|
application/vnd.oasis.opendocument.text odt;
|
||||||
|
application/vnd.openxmlformats-officedocument.presentationml.presentation
|
||||||
|
pptx;
|
||||||
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||||
|
xlsx;
|
||||||
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
||||||
|
docx;
|
||||||
|
application/vnd.wap.wmlc wmlc;
|
||||||
|
application/wasm wasm;
|
||||||
|
application/x-7z-compressed 7z;
|
||||||
|
application/x-cocoa cco;
|
||||||
|
application/x-java-archive-diff jardiff;
|
||||||
|
application/x-java-jnlp-file jnlp;
|
||||||
|
application/x-makeself run;
|
||||||
|
application/x-perl pl pm;
|
||||||
|
application/x-pilot prc pdb;
|
||||||
|
application/x-rar-compressed rar;
|
||||||
|
application/x-redhat-package-manager rpm;
|
||||||
|
application/x-sea sea;
|
||||||
|
application/x-shockwave-flash swf;
|
||||||
|
application/x-stuffit sit;
|
||||||
|
application/x-tcl tcl tk;
|
||||||
|
application/x-x509-ca-cert der pem crt;
|
||||||
|
application/x-xpinstall xpi;
|
||||||
|
application/xhtml+xml xhtml;
|
||||||
|
application/xspf+xml xspf;
|
||||||
|
application/zip zip;
|
||||||
|
|
||||||
|
application/octet-stream bin exe dll;
|
||||||
|
application/octet-stream deb;
|
||||||
|
application/octet-stream dmg;
|
||||||
|
application/octet-stream iso img;
|
||||||
|
application/octet-stream msi msp msm;
|
||||||
|
|
||||||
|
audio/midi mid midi kar;
|
||||||
|
audio/mpeg mp3;
|
||||||
|
audio/ogg ogg;
|
||||||
|
audio/x-m4a m4a;
|
||||||
|
audio/x-realaudio ra;
|
||||||
|
|
||||||
|
video/3gpp 3gpp 3gp;
|
||||||
|
video/mp2t ts;
|
||||||
|
video/mp4 mp4;
|
||||||
|
video/mpeg mpeg mpg;
|
||||||
|
video/quicktime mov;
|
||||||
|
video/webm webm;
|
||||||
|
video/x-flv flv;
|
||||||
|
video/x-m4v m4v;
|
||||||
|
video/x-mng mng;
|
||||||
|
video/x-ms-asf asx asf;
|
||||||
|
video/x-ms-wmv wmv;
|
||||||
|
video/x-msvideo avi;
|
||||||
|
}
|
||||||
64
confs/nginx.conf
Normal file
64
confs/nginx.conf
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# /etc/nginx/nginx.conf
|
||||||
|
|
||||||
|
# load dynamic modules
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_cookie_flag_filter_module.so;
|
||||||
|
#load_module /opt/bunkerweb/modules/ngx_http_geoip2_module.so;
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_headers_more_filter_module.so;
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_lua_module.so;
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_modsecurity_module.so;
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_brotli_filter_module.so;
|
||||||
|
load_module /opt/bunkerweb/modules/ngx_http_brotli_static_module.so;
|
||||||
|
#load_module /opt/bunkerweb/modules/ngx_stream_geoip2_module.so;
|
||||||
|
#load_module /opt/bunkerweb/modules/ngx_stream_lua_module.so;
|
||||||
|
|
||||||
|
# PID file
|
||||||
|
{% if TEMP_NGINX != "yes" +%}
|
||||||
|
pid /opt/bunkerweb/tmp/nginx.pid;
|
||||||
|
{% else +%}
|
||||||
|
pid /opt/bunkerweb/tmp/nginx-temp.pid;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# worker number (default = auto)
|
||||||
|
worker_processes {{ WORKER_PROCESSES }};
|
||||||
|
|
||||||
|
# faster regexp
|
||||||
|
pcre_jit on;
|
||||||
|
|
||||||
|
# max open files for each worker
|
||||||
|
worker_rlimit_nofile {{ WORKER_RLIMIT_NOFILE }};
|
||||||
|
|
||||||
|
# error log level
|
||||||
|
error_log /var/log/nginx/error.log {{ LOG_LEVEL }};
|
||||||
|
|
||||||
|
# reason env var
|
||||||
|
env REASON;
|
||||||
|
|
||||||
|
events {
|
||||||
|
# max connections per worker
|
||||||
|
worker_connections {{ WORKER_CONNECTIONS }};
|
||||||
|
|
||||||
|
# epoll seems to be the best on Linux
|
||||||
|
use epoll;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
# include base http configuration
|
||||||
|
include /etc/nginx/http.conf;
|
||||||
|
|
||||||
|
# include core and plugins http configurations
|
||||||
|
include /etc/nginx/http/*.conf;
|
||||||
|
|
||||||
|
# include custom http configurations
|
||||||
|
include /opt/bunkerweb/configs/http/*.conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stream {
|
||||||
|
# include base stream configuration
|
||||||
|
# include /etc/nginx/stream.conf;
|
||||||
|
|
||||||
|
# include core and plugins stream configurations
|
||||||
|
# include /etc/nginx/stream/*.conf;
|
||||||
|
|
||||||
|
# include custom stream configurations
|
||||||
|
# include /opt/bunkerweb/configs/stream/*.conf;
|
||||||
|
#}
|
||||||
17
confs/scgi_params
Normal file
17
confs/scgi_params
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
scgi_param REQUEST_METHOD $request_method;
|
||||||
|
scgi_param REQUEST_URI $request_uri;
|
||||||
|
scgi_param QUERY_STRING $query_string;
|
||||||
|
scgi_param CONTENT_TYPE $content_type;
|
||||||
|
|
||||||
|
scgi_param DOCUMENT_URI $document_uri;
|
||||||
|
scgi_param DOCUMENT_ROOT $document_root;
|
||||||
|
scgi_param SCGI 1;
|
||||||
|
scgi_param SERVER_PROTOCOL $server_protocol;
|
||||||
|
scgi_param REQUEST_SCHEME $scheme;
|
||||||
|
scgi_param HTTPS $https if_not_empty;
|
||||||
|
|
||||||
|
scgi_param REMOTE_ADDR $remote_addr;
|
||||||
|
scgi_param REMOTE_PORT $remote_port;
|
||||||
|
scgi_param SERVER_PORT $server_port;
|
||||||
|
scgi_param SERVER_NAME $server_name;
|
||||||
63
confs/server-http/access-lua.conf
Normal file
63
confs/server-http/access-lua.conf
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
access_by_lua_block {
|
||||||
|
|
||||||
|
local logger = require "logger"
|
||||||
|
local datastore = require "datastore"
|
||||||
|
local plugins = require "plugins"
|
||||||
|
|
||||||
|
-- Don't process internal requests
|
||||||
|
if ngx.req.is_internal() then
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "Skipped access phase because request is internal")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "Access phase started")
|
||||||
|
|
||||||
|
-- Process bans as soon as possible
|
||||||
|
local banned, err = datastore:get("bans_ip_" .. ngx.var.remote_addr)
|
||||||
|
if banned then
|
||||||
|
logger.log(ngx.WARN, "ACCESS", "IP " .. ngx.var.remote_addr .. " is banned with reason : " .. banned)
|
||||||
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- List all plugins
|
||||||
|
local list, err = plugins:list()
|
||||||
|
if not list then
|
||||||
|
logger.log(ngx.ERR, "ACCESS", "Can't list loaded plugins : " .. err)
|
||||||
|
list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Call access method of plugins
|
||||||
|
for i, plugin in ipairs(list) do
|
||||||
|
local ret, plugin_lua = pcall(require, plugin.id .. "/" .. plugin.id)
|
||||||
|
if ret then
|
||||||
|
local plugin_obj = plugin_lua.new()
|
||||||
|
if plugin_obj.access ~= nil then
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "Executing access() of " .. plugin.id)
|
||||||
|
local ok, err, ret, value = plugin_obj:access()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "ACCESS", "Error while calling access() on plugin " .. plugin.id .. " : " .. err)
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "Return value from " .. plugin.id .. ".access() is : " .. err)
|
||||||
|
end
|
||||||
|
if ret then
|
||||||
|
if type(value) == "number" then
|
||||||
|
if value == ngx.HTTP_FORBIDDEN then
|
||||||
|
logger.log(ngx.WARN, "ACCESS", "Denied access from " .. plugin.id .. " : " .. err)
|
||||||
|
ngx.var.reason = plugin.id
|
||||||
|
else
|
||||||
|
logger.log(ngx.NOTICE, "ACCESS", plugin.id .. " returned status " .. tostring(value) .. " : " .. err)
|
||||||
|
end
|
||||||
|
return ngx.exit(value)
|
||||||
|
else
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "access() method not found in " .. plugin.id .. ", skipped execution")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.log(ngx.INFO, "ACCESS", "Access phase ended")
|
||||||
|
|
||||||
|
}
|
||||||
44
confs/server-http/log-lua.conf
Normal file
44
confs/server-http/log-lua.conf
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
log_by_lua_block {
|
||||||
|
|
||||||
|
local utils = require "utils"
|
||||||
|
local logger = require "logger"
|
||||||
|
local datastore = require "datastore"
|
||||||
|
local plugins = require "plugins"
|
||||||
|
|
||||||
|
logger.log(ngx.INFO, "LOG", "Log phase started")
|
||||||
|
|
||||||
|
-- List all plugins
|
||||||
|
local list, err = plugins:list()
|
||||||
|
if not list then
|
||||||
|
logger.log(ngx.ERR, "LOG", "Can't list loaded plugins : " .. err)
|
||||||
|
list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Call log method of plugins
|
||||||
|
for i, plugin in ipairs(list) do
|
||||||
|
local ret, plugin_lua = pcall(require, plugin.id .. "/" .. plugin.id)
|
||||||
|
if ret then
|
||||||
|
local plugin_obj = plugin_lua.new()
|
||||||
|
if plugin_obj.log ~= nil then
|
||||||
|
logger.log(ngx.INFO, "LOG", "Executing log() of " .. plugin.id)
|
||||||
|
local ok, err = plugin_obj:log()
|
||||||
|
if not ok then
|
||||||
|
logger.log(ngx.ERR, "LOG", "Error while calling log() on plugin " .. plugin.id .. " : " .. err)
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "LOG", "Return value from " .. plugin.id .. ".log() is : " .. err)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
logger.log(ngx.INFO, "LOG", "log() method not found in " .. plugin.id .. ", skipped execution")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Display reason at info level
|
||||||
|
local reason = utils.get_reason()
|
||||||
|
if reason then
|
||||||
|
logger.log(ngx.INFO, "LOG", "Client was denied with reason : " .. reason)
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.log(ngx.INFO, "LOG", "Log phase ended")
|
||||||
|
|
||||||
|
}
|
||||||
27
confs/server-http/server.conf
Normal file
27
confs/server-http/server.conf
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
server {
|
||||||
|
# server name (vhost)
|
||||||
|
server_name {{ SERVER_NAME }};
|
||||||
|
|
||||||
|
# HTTP listen
|
||||||
|
{% if LISTEN_HTTP == "yes" +%}
|
||||||
|
listen 0.0.0.0:{{ HTTP_PORT }}{% if MULTISITE == "no" and DISABLE_DEFAULT_SERVER == "no" %} default_server{% endif %}{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol{% endif %};
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
index index.php index.html index.htm;
|
||||||
|
|
||||||
|
# custom config
|
||||||
|
include /opt/bunkerweb/configs/server-http/*.conf;
|
||||||
|
{% if MULTISITE == "yes" +%}
|
||||||
|
include /opt/bunkerweb/configs/server-http/{{ SERVER_NAME.split(" ")[0] }}/*.conf;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# reason variable
|
||||||
|
set $reason '';
|
||||||
|
|
||||||
|
# include LUA files
|
||||||
|
include {{ NGINX_PREFIX }}access-lua.conf;
|
||||||
|
include {{ NGINX_PREFIX }}log-lua.conf;
|
||||||
|
|
||||||
|
# include config files
|
||||||
|
include {{ NGINX_PREFIX }}server-http/*.conf;
|
||||||
|
}
|
||||||
@ -1,46 +0,0 @@
|
|||||||
location = {{ ANTIBOT_URI }} {
|
|
||||||
|
|
||||||
default_type 'text/html';
|
|
||||||
|
|
||||||
if ($request_method = GET) {
|
|
||||||
content_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local captcha = require "captcha"
|
|
||||||
local logger = require "logger"
|
|
||||||
if not cookie.is_set("uri") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "captcha fail (1) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local img, res = captcha.get_challenge()
|
|
||||||
cookie.set({captchares = res})
|
|
||||||
local code = captcha.get_code(img, "{{ ANTIBOT_URI }}")
|
|
||||||
ngx.say(code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request_method = POST) {
|
|
||||||
access_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local captcha = require "captcha"
|
|
||||||
local logger = require "logger"
|
|
||||||
if not cookie.is_set("captchares") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "captcha fail (2) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
ngx.req.read_body()
|
|
||||||
local args, err = ngx.req.get_post_args(1)
|
|
||||||
if err == "truncated" or not args or not args["captcha"] then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "captcha fail (3) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local captcha_user = args["captcha"]
|
|
||||||
local check = captcha.check(captcha_user, cookie.get("captchares"))
|
|
||||||
if not check then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "captcha fail (4) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.redirect("{{ ANTIBOT_URI }}")
|
|
||||||
end
|
|
||||||
cookie.set({captcha = "ok"})
|
|
||||||
return ngx.redirect(cookie.get("uri"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
location = {{ ANTIBOT_URI }} {
|
|
||||||
|
|
||||||
default_type 'text/html';
|
|
||||||
|
|
||||||
if ($request_method = GET) {
|
|
||||||
content_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local javascript = require "javascript"
|
|
||||||
local logger = require "logger"
|
|
||||||
if not cookie.is_set("challenge") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "javascript fail (1) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local challenge = cookie.get("challenge")
|
|
||||||
local code = javascript.get_code(challenge, "{{ ANTIBOT_URI }}", cookie.get("uri"))
|
|
||||||
ngx.say(code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request_method = POST) {
|
|
||||||
content_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local javascript = require "javascript"
|
|
||||||
local logger = require "logger"
|
|
||||||
if not cookie.is_set("challenge") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "javascript fail (2) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
ngx.req.read_body()
|
|
||||||
local args, err = ngx.req.get_post_args(1)
|
|
||||||
if err == "truncated" or not args or not args["challenge"] then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "javascript fail (3) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local challenge = args["challenge"]
|
|
||||||
local check = javascript.check(cookie.get("challenge"), challenge)
|
|
||||||
if not check then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "javascript fail (4) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
cookie.set({javascript = "ok"})
|
|
||||||
return ngx.exit(ngx.OK)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
location = {{ ANTIBOT_URI }} {
|
|
||||||
|
|
||||||
default_type 'text/html';
|
|
||||||
|
|
||||||
if ($request_method = GET) {
|
|
||||||
content_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local recaptcha = require "recaptcha"
|
|
||||||
local loggger = require "logger"
|
|
||||||
if not cookie.is_set("uri") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "recaptcha fail (1) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local code = recaptcha.get_code("{{ ANTIBOT_URI }}", "{{ ANTIBOT_RECAPTCHA_SITEKEY }}")
|
|
||||||
ngx.say(code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request_method = POST) {
|
|
||||||
access_by_lua_block {
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local recaptcha = require "recaptcha"
|
|
||||||
local logger = require "logger"
|
|
||||||
if not cookie.is_set("uri") then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "recaptcha fail (2) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
ngx.req.read_body()
|
|
||||||
local args, err = ngx.req.get_post_args(1)
|
|
||||||
if err == "truncated" or not args or not args["token"] then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "recaptcha fail (3) for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
local token = args["token"]
|
|
||||||
local check = recaptcha.check(token, "{{ ANTIBOT_RECAPTCHA_SECRET }}")
|
|
||||||
if check < {{ ANTIBOT_RECAPTCHA_SCORE }} then
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "recaptcha fail (4) for " .. ngx.var.remote_addr .. " (score = " .. tostring(check) .. ")")
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
cookie.set({recaptcha = "ok"})
|
|
||||||
return ngx.redirect(cookie.get("uri"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
auth_basic "{{ AUTH_BASIC_TEXT }}";
|
|
||||||
auth_basic_user_file {{ NGINX_PREFIX }}htpasswd;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
location {{ AUTH_BASIC_LOCATION }} {
|
|
||||||
auth_basic "{{ AUTH_BASIC_TEXT }}";
|
|
||||||
auth_basic_user_file {{ NGINX_PREFIX }}htpasswd;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
etag {{ CLIENT_CACHE_ETAG }};
|
|
||||||
set $cache "";
|
|
||||||
if ($uri ~* \.({{ CLIENT_CACHE_EXTENSIONS }})$) {
|
|
||||||
set $cache "{{ CLIENT_CACHE_CONTROL }}";
|
|
||||||
}
|
|
||||||
add_header Cache-Control $cache;
|
|
||||||
@ -1 +0,0 @@
|
|||||||
more_set_headers "Content-Security-Policy: {{ CONTENT_SECURITY_POLICY }}";
|
|
||||||
@ -1 +0,0 @@
|
|||||||
set_cookie_flag {{ COOKIE_FLAGS }}{% if COOKIE_AUTO_SECURE_FLAG == "yes" %} Secure{% endif %};
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
listen 0.0.0.0:443 ssl {% if HTTP2 == "yes" %}http2{% endif %};
|
|
||||||
ssl_certificate {{ HTTPS_CUSTOM_CERT }};
|
|
||||||
ssl_certificate_key {{ HTTPS_CUSTOM_KEY }};
|
|
||||||
ssl_protocols TLSv1.3;
|
|
||||||
ssl_prefer_server_ciphers off;
|
|
||||||
ssl_session_tickets off;
|
|
||||||
{% if STRICT_TRANSPORT_SECURITY != "" %}
|
|
||||||
more_set_headers 'Strict-Transport-Security: {{ STRICT_TRANSPORT_SECURITY }}';
|
|
||||||
{% endif %}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
if ($host !~ ^({{ SERVER_NAME.replace(" ", "|") }})$) {
|
|
||||||
return 444;
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
{% if ERRORS != "" %}
|
|
||||||
{% for element in ERRORS.split(" ") %}
|
|
||||||
{% set code = element.split("=")[0] %}
|
|
||||||
{% set page = element.split("=")[1] %}
|
|
||||||
error_page {{ code }} {{ page }};
|
|
||||||
|
|
||||||
location = {{ page }} {
|
|
||||||
root {{ ROOT_FOLDER }};
|
|
||||||
modsecurity off;
|
|
||||||
internal;
|
|
||||||
}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% set default_errors = ["400", "401", "403", "404", "429", "500", "501", "502", "503", "504"] %}
|
|
||||||
{% for default_error in default_errors %}
|
|
||||||
{% if not default_error + "=" in ERRORS %}
|
|
||||||
error_page {{ default_error }} /errors/{{ default_error }}.html;
|
|
||||||
|
|
||||||
location = /errors/{{ default_error }}.html {
|
|
||||||
root /defaults;
|
|
||||||
modsecurity off;
|
|
||||||
internal;
|
|
||||||
}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
fastcgi_param SCRIPT_FILENAME {{ REMOTE_PHP_PATH }}/$fastcgi_script_name;
|
|
||||||
fastcgi_param QUERY_STRING $query_string;
|
|
||||||
fastcgi_param REQUEST_METHOD $request_method;
|
|
||||||
fastcgi_param CONTENT_TYPE $content_type;
|
|
||||||
fastcgi_param CONTENT_LENGTH $content_length;
|
|
||||||
|
|
||||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
|
||||||
fastcgi_param REQUEST_URI $request_uri;
|
|
||||||
fastcgi_param DOCUMENT_URI $document_uri;
|
|
||||||
fastcgi_param DOCUMENT_ROOT $document_root;
|
|
||||||
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
|
||||||
fastcgi_param REQUEST_SCHEME $scheme;
|
|
||||||
fastcgi_param HTTPS $https if_not_empty;
|
|
||||||
|
|
||||||
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
|
|
||||||
fastcgi_param SERVER_SOFTWARE nginx;
|
|
||||||
|
|
||||||
fastcgi_param REMOTE_ADDR $remote_addr;
|
|
||||||
fastcgi_param REMOTE_PORT $remote_port;
|
|
||||||
fastcgi_param SERVER_ADDR $server_addr;
|
|
||||||
fastcgi_param SERVER_PORT $server_port;
|
|
||||||
fastcgi_param SERVER_NAME $server_name;
|
|
||||||
|
|
||||||
# PHP only, required if PHP was built with --enable-force-cgi-redirect
|
|
||||||
fastcgi_param REDIRECT_STATUS 200;
|
|
||||||
@ -1 +0,0 @@
|
|||||||
more_set_headers "Feature-Policy: {{ FEATURE_POLICY }}";
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
gzip on;
|
|
||||||
gzip_comp_level {{ GZIP_COMP_LEVEL }};
|
|
||||||
gzip_min_length {{ GZIP_MIN_LENGTH }};
|
|
||||||
gzip_types {{ GZIP_TYPES }};
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{% if USE_AUTH_BASIC == "yes" %}
|
|
||||||
{{ AUTH_BASIC_USER }}:{{ sha512_crypt(AUTH_BASIC_PASSWORD) }}
|
|
||||||
{% endif %}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
listen 0.0.0.0:{{ HTTPS_PORT }} ssl {% if HTTP2 == "yes" %}http2{% endif %};
|
|
||||||
{% set paths = {"cert": "", "key": ""} %}
|
|
||||||
{% if AUTO_LETS_ENCRYPT == "yes" %}
|
|
||||||
{% set x = paths.update({"cert": "/etc/letsencrypt/live/" + FIRST_SERVER + "/fullchain.pem"}) %}
|
|
||||||
{% set x = paths.update({"key": "/etc/letsencrypt/live/" + FIRST_SERVER + "/privkey.pem"}) %}
|
|
||||||
{% elif USE_CUSTOM_HTTPS == "yes" %}
|
|
||||||
{% set x = paths.update({"cert": CUSTOM_HTTPS_CERT}) %}
|
|
||||||
{% set x = paths.update({"key": CUSTOM_HTTPS_KEY}) %}
|
|
||||||
{% elif GENERATE_SELF_SIGNED_SSL == "yes" %}
|
|
||||||
{% if MULTISITE == "yes" %}
|
|
||||||
{% set x = paths.update({"cert": "/etc/nginx/" + FIRST_SERVER + "/self-cert.pem"}) %}
|
|
||||||
{% set x = paths.update({"key": "/etc/nginx/" + FIRST_SERVER + "/self-key.pem"}) %}
|
|
||||||
{% else %}
|
|
||||||
{% set x = paths.update({"cert": "/etc/nginx/self-cert.pem"}) %}
|
|
||||||
{% set x = paths.update({"key": "/etc/nginx/self-key.pem"}) %}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
ssl_certificate {{ paths["cert"] }};
|
|
||||||
ssl_certificate_key {{ paths["key"] }};
|
|
||||||
ssl_protocols {{ HTTPS_PROTOCOLS }};
|
|
||||||
ssl_prefer_server_ciphers on;
|
|
||||||
ssl_session_tickets off;
|
|
||||||
ssl_session_timeout 1d;
|
|
||||||
ssl_session_cache shared:MozSSL:10m;
|
|
||||||
{% if STRICT_TRANSPORT_SECURITY != "" %}
|
|
||||||
more_set_headers 'Strict-Transport-Security: {{ STRICT_TRANSPORT_SECURITY }}';
|
|
||||||
{% endif %}
|
|
||||||
{% if "TLSv1.2" in HTTPS_PROTOCOLS %}
|
|
||||||
ssl_dhparam /etc/nginx/dhparam;
|
|
||||||
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;
|
|
||||||
{% endif %}
|
|
||||||
{% if AUTO_LETS_ENCRYPT %}
|
|
||||||
include {{ NGINX_PREFIX }}lets-encrypt-webroot.conf;
|
|
||||||
{% endif %}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
location ~ ^/.well-known/acme-challenge/ {
|
|
||||||
root /acme-challenge;
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
limit_conn ddos {{ LIMIT_CONN_MAX }};
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
limit_req_status 429;
|
|
||||||
limit_req zone=limit burst={{ LIMIT_REQ_BURST }} nodelay;
|
|
||||||
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
log_by_lua_block {
|
|
||||||
|
|
||||||
-- bad behavior
|
|
||||||
local use_bad_behavior = {% if USE_BAD_BEHAVIOR == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local behavior = require "behavior"
|
|
||||||
local bad_behavior_status_codes = {% raw %}{{% endraw %}{% if BAD_BEHAVIOR_STATUS_CODES != "" %}{% set elements = BAD_BEHAVIOR_STATUS_CODES.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
local bad_behavior_threshold = {{ BAD_BEHAVIOR_THRESHOLD }}
|
|
||||||
local bad_behavior_count_time = {{ BAD_BEHAVIOR_COUNT_TIME }}
|
|
||||||
local bad_behavior_ban_time = {{ BAD_BEHAVIOR_BAN_TIME }}
|
|
||||||
|
|
||||||
if use_bad_behavior then
|
|
||||||
behavior.count(bad_behavior_status_codes, bad_behavior_threshold, bad_behavior_count_time, bad_behavior_ban_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,318 +0,0 @@
|
|||||||
{% if ANTIBOT_SESSION_SECRET == "random" %}
|
|
||||||
set $session_secret {{ random(32) }} ;
|
|
||||||
{% else %}
|
|
||||||
set $session_secret {{ ANTIBOT_SESSION_SECRET }};
|
|
||||||
{% endif %}
|
|
||||||
set $session_check_addr on;
|
|
||||||
|
|
||||||
access_by_lua_block {
|
|
||||||
|
|
||||||
-- disable checks for internal requests
|
|
||||||
if ngx.req.is_internal() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- let's encrypt
|
|
||||||
local use_lets_encrypt = {% if AUTO_LETS_ENCRYPT == "yes" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- external blacklists
|
|
||||||
local use_user_agents = {% if BLOCK_USER_AGENT == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_proxies = {% if BLOCK_PROXIES == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_abusers = {% if BLOCK_ABUSERS == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_tor_exit_nodes = {% if BLOCK_TOR_EXIT_NODE == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_referrers = {% if BLOCK_REFERRER == "yes" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- countries
|
|
||||||
local use_country = {% if WHITELIST_COUNTRY != "" or BLACKLIST_COUNTRY != "" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- crowdsec
|
|
||||||
local use_crowdsec = {% if USE_CROWDSEC == "yes" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- antibot
|
|
||||||
local use_antibot_cookie = {% if USE_ANTIBOT == "cookie" %}true{% else %}false{% endif %}
|
|
||||||
local use_antibot_javascript = {% if USE_ANTIBOT == "javascript" %}true{% else %}false{% endif %}
|
|
||||||
local use_antibot_captcha = {% if USE_ANTIBOT == "captcha" %}true{% else %}false{% endif %}
|
|
||||||
local use_antibot_recaptcha = {% if USE_ANTIBOT == "recaptcha" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- resolvers
|
|
||||||
local dns_resolvers = {% raw %}{{% endraw %}{% if DNS_RESOLVERS != "" %}{% set elements = DNS_RESOLVERS.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
|
|
||||||
-- whitelist
|
|
||||||
local use_whitelist_ip = {% if USE_WHITELIST_IP == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_whitelist_reverse = {% if USE_WHITELIST_REVERSE == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local whitelist_ip_list = {% raw %}{{% endraw %}{% if WHITELIST_IP_LIST != "" %}{% set elements = WHITELIST_IP_LIST.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
local whitelist_reverse_list = {% raw %}{{% endraw %}{% if WHITELIST_REVERSE_LIST != "" %}{% set elements = WHITELIST_REVERSE_LIST.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
|
|
||||||
-- blacklist
|
|
||||||
local use_blacklist_ip = {% if USE_BLACKLIST_IP == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local use_blacklist_reverse = {% if USE_BLACKLIST_REVERSE == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local blacklist_ip_list = {% raw %}{{% endraw %}{% if BLACKLIST_IP_LIST != "" %}{% set elements = BLACKLIST_IP_LIST.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
local blacklist_reverse_list = {% raw %}{{% endraw %}{% if BLACKLIST_REVERSE_LIST != "" %}{% set elements = BLACKLIST_REVERSE_LIST.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
|
|
||||||
-- dnsbl
|
|
||||||
local use_dnsbl = {% if USE_DNSBL == "yes" %}true{% else %}false{% endif %}
|
|
||||||
local dnsbl_list = {% raw %}{{% endraw %}{% if DNSBL_LIST != "" %}{% set elements = DNSBL_LIST.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
|
|
||||||
-- bad behavior
|
|
||||||
local use_bad_behavior = {% if USE_BAD_BEHAVIOR == "yes" %}true{% else %}false{% endif %}
|
|
||||||
|
|
||||||
-- include LUA code
|
|
||||||
local whitelist = require "whitelist"
|
|
||||||
local blacklist = require "blacklist"
|
|
||||||
local dnsbl = require "dnsbl"
|
|
||||||
local cookie = require "cookie"
|
|
||||||
local javascript = require "javascript"
|
|
||||||
local captcha = require "captcha"
|
|
||||||
local recaptcha = require "recaptcha"
|
|
||||||
local iputils = require "resty.iputils"
|
|
||||||
local behavior = require "behavior"
|
|
||||||
local logger = require "logger"
|
|
||||||
|
|
||||||
-- user variables
|
|
||||||
local antibot_uri = "{{ ANTIBOT_URI }}"
|
|
||||||
local whitelist_user_agent = {% raw %}{{% endraw %}{% if WHITELIST_USER_AGENT != "" %}{% set elements = WHITELIST_USER_AGENT.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
local whitelist_uri = {% raw %}{{% endraw %}{% if WHITELIST_URI != "" %}{% set elements = WHITELIST_URI.split(" ") %}{% for i in range(0, elements|length) %}"{{ elements[i] }}"{% if i < elements|length-1 %},{% endif %}{% endfor %}{% endif %}{% raw %}}{% endraw %}
|
|
||||||
|
|
||||||
-- check if already in whitelist cache
|
|
||||||
if use_whitelist_ip and whitelist.ip_cached_ok() then
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
if use_whitelist_reverse and whitelist.reverse_cached_ok() then
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if already in blacklist cache
|
|
||||||
if use_blacklist_ip and blacklist.ip_cached_ko() then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
if use_blacklist_reverse and blacklist.reverse_cached_ko() then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if already in dnsbl cache
|
|
||||||
if use_dnsbl and dnsbl.cached_ko() then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is whitelisted (only if not in cache)
|
|
||||||
if use_whitelist_ip and not whitelist.ip_cached() then
|
|
||||||
if whitelist.check_ip(whitelist_ip_list) then
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if reverse is whitelisted (only if not in cache)
|
|
||||||
if use_whitelist_reverse and not whitelist.reverse_cached() then
|
|
||||||
if whitelist.check_reverse(whitelist_reverse_list) then
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if URI is whitelisted
|
|
||||||
for k, v in pairs(whitelist_uri) do
|
|
||||||
if ngx.var.request_uri == v then
|
|
||||||
logger.log(ngx.NOTICE, "WHITELIST", "URI " .. v .. " is whitelisted")
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if it's certbot
|
|
||||||
if use_lets_encrypt and string.match(ngx.var.request_uri, "^/.well-known/acme-challenge/") then
|
|
||||||
logger.log(ngx.INFO, "LETSENCRYPT", "got a visit from Let's Encrypt")
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is blacklisted (only if not in cache)
|
|
||||||
if use_blacklist_ip and not blacklist.ip_cached() then
|
|
||||||
if blacklist.check_ip(blacklist_ip_list) then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if reverse is blacklisted (only if not in cache)
|
|
||||||
if use_blacklist_reverse and not blacklist.reverse_cached() then
|
|
||||||
if blacklist.check_reverse(blacklist_reverse_list, dns_resolvers) then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is banned because of "bad behavior"
|
|
||||||
if use_bad_behavior and behavior.is_banned() then
|
|
||||||
logger.log(ngx.WARN, "BEHAVIOR", "IP " .. ngx.var.remote_addr .. " is banned because of bad behavior")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is in proxies list
|
|
||||||
if use_proxies then
|
|
||||||
local value, flags = ngx.shared.proxies_data:get(iputils.ip2bin(ngx.var.remote_addr))
|
|
||||||
if value ~= nil then
|
|
||||||
logger.log(ngx.WARN, "PROXIES", "IP " .. ngx.var.remote_addr .. " is in proxies list")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is in abusers list
|
|
||||||
if use_abusers then
|
|
||||||
local value, flags = ngx.shared.abusers_data:get(iputils.ip2bin(ngx.var.remote_addr))
|
|
||||||
if value ~= nil then
|
|
||||||
logger.log(ngx.WARN, "ABUSERS", "IP " .. ngx.var.remote_addr .. " is in abusers list")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is in TOR exit nodes list
|
|
||||||
if use_tor_exit_nodes then
|
|
||||||
local value, flags = ngx.shared.tor_exit_nodes_data:get(iputils.ip2bin(ngx.var.remote_addr))
|
|
||||||
if value ~= nil then
|
|
||||||
logger.log(ngx.WARN, "TOR", "IP " .. ngx.var.remote_addr .. " is in TOR exit nodes list")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if user-agent is allowed
|
|
||||||
if use_user_agents and ngx.var.http_user_agent ~= nil then
|
|
||||||
local whitelisted = false
|
|
||||||
for k, v in pairs(whitelist_user_agent) do
|
|
||||||
if string.match(ngx.var.http_user_agent, v) then
|
|
||||||
logger.log(ngx.NOTICE, "WHITELIST", "User-Agent " .. ngx.var.http_user_agent .. " is whitelisted")
|
|
||||||
whitelisted = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not whitelisted then
|
|
||||||
local value, flags = ngx.shared.user_agents_cache:get(ngx.var.http_user_agent)
|
|
||||||
if value == nil then
|
|
||||||
local patterns = ngx.shared.user_agents_data:get_keys(0)
|
|
||||||
for i, pattern in ipairs(patterns) do
|
|
||||||
if string.match(ngx.var.http_user_agent, pattern) then
|
|
||||||
value = "ko"
|
|
||||||
ngx.shared.user_agents_cache:set(ngx.var.http_user_agent, "ko", 86400)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if value == nil then
|
|
||||||
value = "ok"
|
|
||||||
ngx.shared.user_agents_cache:set(ngx.var.http_user_agent, "ok", 86400)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if value == "ko" then
|
|
||||||
logger.log(ngx.WARN, "USER-AGENT", "User-Agent " .. ngx.var.http_user_agent .. " is blacklisted")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if referrer is allowed
|
|
||||||
if use_referrer and ngx.var.http_referer ~= nil then
|
|
||||||
local value, flags = ngx.shared.referrers_cache:get(ngx.var.http_referer)
|
|
||||||
if value == nil then
|
|
||||||
local patterns = ngx.shared.referrers_data:get_keys(0)
|
|
||||||
for i, pattern in ipairs(patterns) do
|
|
||||||
if string.match(ngx.var.http_referer, pattern) then
|
|
||||||
value = "ko"
|
|
||||||
ngx.shared.referrers_cache:set(ngx.var.http_referer, "ko", 86400)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if value == nil then
|
|
||||||
value = "ok"
|
|
||||||
ngx.shared.referrers_cache:set(ngx.var.http_referer, "ok", 86400)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if value == "ko" then
|
|
||||||
logger.log(ngx.WARN, "REFERRER", "Referrer " .. ngx.var.http_referer .. " is blacklisted")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if country is allowed
|
|
||||||
if use_country and ngx.var.allowed_country == "no" then
|
|
||||||
logger.log(ngx.WARN, "COUNTRY", "Country of " .. ngx.var.remote_addr .. " is blacklisted")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is in DNSBLs (only if not in cache)
|
|
||||||
if use_dnsbl and not dnsbl.cached() then
|
|
||||||
if dnsbl.check(dnsbl_list, dns_resolvers) then
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if IP is in CrowdSec DB
|
|
||||||
if use_crowdsec then
|
|
||||||
local ok, err = require "crowdsec.CrowdSec".allowIp(ngx.var.remote_addr)
|
|
||||||
if ok == nil then
|
|
||||||
logger.log(ngx.ERR, "CROWDSEC", err)
|
|
||||||
end
|
|
||||||
if not ok then
|
|
||||||
logger.log(ngx.WARN, "CROWDSEC", "denied " .. ngx.var.remote_addr)
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- cookie check
|
|
||||||
if use_antibot_cookie and ngx.var.uri ~= "/favicon.ico" then
|
|
||||||
if not cookie.is_set("uri") then
|
|
||||||
if ngx.var.request_uri ~= antibot_uri then
|
|
||||||
cookie.set({uri = ngx.var.request_uri})
|
|
||||||
return ngx.redirect(antibot_uri)
|
|
||||||
end
|
|
||||||
logger.log(ngx.WARN, "ANTIBOT", "cookie fail for " .. ngx.var.remote_addr)
|
|
||||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
else
|
|
||||||
if ngx.var.request_uri == antibot_uri then
|
|
||||||
return ngx.redirect(cookie.get("uri"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- javascript check
|
|
||||||
if use_antibot_javascript and ngx.var.uri ~= "/favicon.ico" then
|
|
||||||
if not cookie.is_set("javascript") then
|
|
||||||
if ngx.var.request_uri ~= antibot_uri then
|
|
||||||
cookie.set({uri = ngx.var.request_uri, challenge = javascript.get_challenge()})
|
|
||||||
return ngx.redirect(antibot_uri)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- captcha check
|
|
||||||
if use_antibot_captcha and ngx.var.uri ~= "/favicon.ico" then
|
|
||||||
if not cookie.is_set("captcha") then
|
|
||||||
if ngx.var.request_uri ~= antibot_uri then
|
|
||||||
cookie.set({uri = ngx.var.request_uri})
|
|
||||||
return ngx.redirect(antibot_uri)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- recaptcha check
|
|
||||||
if use_antibot_recaptcha and ngx.var.uri ~= "/favicon.ico" then
|
|
||||||
if not cookie.is_set("recaptcha") then
|
|
||||||
if ngx.var.request_uri ~= antibot_uri then
|
|
||||||
cookie.set({uri = ngx.var.request_uri})
|
|
||||||
return ngx.redirect(antibot_uri)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- plugins check
|
|
||||||
local plugins, flags = ngx.shared.plugins_data:get("plugins")
|
|
||||||
if plugins ~= nil then
|
|
||||||
for plugin_id in string.gmatch(plugins, "%w+") do
|
|
||||||
local plugin = require(plugin_id .. "/" .. plugin_id)
|
|
||||||
plugin.check()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
{% if USE_ANTIBOT == "javascript" %}
|
|
||||||
include {{ NGINX_PREFIX }}antibot-javascript.conf;
|
|
||||||
{% elif USE_ANTIBOT == "captcha" %}
|
|
||||||
include {{ NGINX_PREFIX }}antibot-captcha.conf;
|
|
||||||
{% elif USE_ANTIBOT == "recaptcha" %}
|
|
||||||
include {{ NGINX_PREFIX }}antibot-recaptcha.conf;
|
|
||||||
{% endif %}
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
# process rules with disruptive actions
|
|
||||||
SecRuleEngine On
|
|
||||||
|
|
||||||
# allow body checks
|
|
||||||
SecRequestBodyAccess On
|
|
||||||
|
|
||||||
# enable XML parsing
|
|
||||||
SecRule REQUEST_HEADERS:Content-Type "(?:application(?:/soap\+|/)|text/)xml" \
|
|
||||||
"id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
|
|
||||||
|
|
||||||
# enable JSON parsing
|
|
||||||
SecRule REQUEST_HEADERS:Content-Type "application/json" \
|
|
||||||
"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
|
|
||||||
|
|
||||||
# maximum data size
|
|
||||||
SecRequestBodyLimit 13107200
|
|
||||||
SecRequestBodyNoFilesLimit 131072
|
|
||||||
|
|
||||||
# reject requests if bigger than max data size
|
|
||||||
SecRequestBodyLimitAction Reject
|
|
||||||
|
|
||||||
# reject if we can't process the body
|
|
||||||
SecRule REQBODY_ERROR "!@eq 0" \
|
|
||||||
"id:'200002', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2"
|
|
||||||
|
|
||||||
# be strict with multipart/form-data body
|
|
||||||
SecRule MULTIPART_STRICT_ERROR "!@eq 0" \
|
|
||||||
"id:'200003',phase:2,t:none,log,deny,status:400, \
|
|
||||||
msg:'Multipart request body failed strict validation: \
|
|
||||||
PE %{REQBODY_PROCESSOR_ERROR}, \
|
|
||||||
BQ %{MULTIPART_BOUNDARY_QUOTED}, \
|
|
||||||
BW %{MULTIPART_BOUNDARY_WHITESPACE}, \
|
|
||||||
DB %{MULTIPART_DATA_BEFORE}, \
|
|
||||||
DA %{MULTIPART_DATA_AFTER}, \
|
|
||||||
HF %{MULTIPART_HEADER_FOLDING}, \
|
|
||||||
LF %{MULTIPART_LF_LINE}, \
|
|
||||||
SM %{MULTIPART_MISSING_SEMICOLON}, \
|
|
||||||
IQ %{MULTIPART_INVALID_QUOTING}, \
|
|
||||||
IP %{MULTIPART_INVALID_PART}, \
|
|
||||||
IH %{MULTIPART_INVALID_HEADER_FOLDING}, \
|
|
||||||
FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'"
|
|
||||||
SecRule MULTIPART_UNMATCHED_BOUNDARY "@eq 1" \
|
|
||||||
"id:'200004',phase:2,t:none,log,deny,msg:'Multipart parser detected a possible unmatched boundary.'"
|
|
||||||
|
|
||||||
# enable response body checks
|
|
||||||
SecResponseBodyAccess On
|
|
||||||
SecResponseBodyMimeType text/plain text/html text/xml application/json
|
|
||||||
SecResponseBodyLimit 524288
|
|
||||||
SecResponseBodyLimitAction ProcessPartial
|
|
||||||
|
|
||||||
# log usefull stuff
|
|
||||||
SecAuditEngine {{ MODSECURITY_SEC_AUDIT_ENGINE }}
|
|
||||||
SecAuditLogType Serial
|
|
||||||
SecAuditLog /var/log/nginx/modsec_audit.log
|
|
||||||
|
|
||||||
# include OWASP CRS configuration
|
|
||||||
{% if USE_MODSECURITY_CRS == "yes" %}
|
|
||||||
include /opt/owasp/crs.conf
|
|
||||||
|
|
||||||
# custom CRS configurations before loading rules (exclusions)
|
|
||||||
{% if is_custom_conf("/modsec-crs-confs") %}
|
|
||||||
include /modsec-crs-confs/*.conf
|
|
||||||
{% endif %}
|
|
||||||
{% if MULTISITE == "yes" and is_custom_conf("/modsec-crs-confs/" + FIRST_SERVER) %}
|
|
||||||
include /modsec-crs-confs/{{ FIRST_SERVER }}/*.conf
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
# include OWASP CRS rules
|
|
||||||
include /opt/owasp/crs/*.conf
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
# custom rules after loading the CRS
|
|
||||||
{% if is_custom_conf("/modsec-confs") %}
|
|
||||||
include /modsec-confs/*.conf
|
|
||||||
{% endif %}
|
|
||||||
{% if MULTISITE == "yes" and is_custom_conf("/modsec-confs/" + FIRST_SERVER) %}
|
|
||||||
include /modsec-confs/{{ FIRST_SERVER }}/*.conf
|
|
||||||
{% endif %}
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
modsecurity on;
|
|
||||||
modsecurity_rules_file {{ NGINX_PREFIX }}modsecurity-rules.conf;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
open_file_cache {{ OPEN_FILE_CACHE }};
|
|
||||||
open_file_cache_errors {{ OPEN_FILE_CACHE_ERRORS }};
|
|
||||||
open_file_cache_min_uses {{ OPEN_FILE_CACHE_MIN_USES }};
|
|
||||||
open_file_cache_valid {{ OPEN_FILE_CACHE_VALID }};
|
|
||||||
@ -1 +0,0 @@
|
|||||||
more_set_headers "Permissions-Policy: {{ PERMISSIONS_POLICY }}";
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
location ~ \.php$ {
|
|
||||||
fastcgi_pass {{ REMOTE_PHP }}:9000;
|
|
||||||
fastcgi_index index.php;
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
proxy_cache proxycache;
|
|
||||||
proxy_cache_methods {{ PROXY_CACHE_METHODS }};
|
|
||||||
proxy_cache_min_uses {{ PROXY_CACHE_MIN_USES }};
|
|
||||||
proxy_cache_key {{ PROXY_CACHE_KEY }};
|
|
||||||
proxy_no_cache {{ PROXY_NO_CACHE }};
|
|
||||||
proxy_cache_bypass {{ PROXY_CACHE_BYPASS }};
|
|
||||||
{% if PROXY_CACHE_VALID != "" %}
|
|
||||||
{% for element in PROXY_CACHE_VALID.split(" ") %}
|
|
||||||
proxy_cache_valid {{ element.split("=")[0] }} {{ element.split("=")[1] }};
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
{% if PROXY_REAL_IP_FROM != "" %}
|
|
||||||
{% for element in PROXY_REAL_IP_FROM.split(" ") %}
|
|
||||||
set_real_ip_from {{ element }};
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
real_ip_header {{ PROXY_REAL_IP_HEADER }};
|
|
||||||
real_ip_recursive {{ PROXY_REAL_IP_RECURSIVE }};
|
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user