Skip to content

Commit f64e367

Browse files
committed
use .env file for docker-compose
1 parent ce15a8a commit f64e367

19 files changed

+164
-98
lines changed

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2
2+
WORDPRESS_VERSION=5.6
3+
WATCHER_LOGIN=watcherLogin
4+
WATCHER_PASSWORD=watcherPassword
5+
NETWORK_SUBNET=172.16.238.0/24
6+
DOCKER_HOST_IP=172.16.238.1
7+
BOUNCER_KEY=
8+
WORDPRESS_URL=
9+
DEBUG=1

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ tests/e2e/screenshots
1414
.bouncer-key
1515
.cache/
1616
*.log
17-
.vagrant
17+
.vagrant
18+
.env

docker-compose.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ services:
44
build:
55
context: .
66
dockerfile: ./docker/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
7+
networks:
8+
- wordpress_bouncer_network
79
depends_on:
810
- crowdsec
911
- mysql
@@ -24,6 +26,8 @@ services:
2426
build:
2527
context: .
2628
dockerfile: ./docker/wp5.5/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
29+
networks:
30+
- wordpress_bouncer_network
2731
depends_on:
2832
- crowdsec
2933
- mysql
@@ -44,6 +48,8 @@ services:
4448
build:
4549
context: .
4650
dockerfile: ./docker/wp5.4/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
51+
networks:
52+
- wordpress_bouncer_network
4753
depends_on:
4854
- crowdsec
4955
- mysql
@@ -64,6 +70,8 @@ services:
6470
build:
6571
context: .
6672
dockerfile: ./docker/wp5.3/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
73+
networks:
74+
- wordpress_bouncer_network
6775
depends_on:
6876
- crowdsec
6977
- mysql
@@ -84,6 +92,8 @@ services:
8492
build:
8593
context: .
8694
dockerfile: ./docker/wp5.2/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
95+
networks:
96+
- wordpress_bouncer_network
8797
depends_on:
8898
- crowdsec
8999
- mysql
@@ -104,6 +114,8 @@ services:
104114
build:
105115
context: .
106116
dockerfile: ./docker/wp5.1/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
117+
networks:
118+
- wordpress_bouncer_network
107119
depends_on:
108120
- crowdsec
109121
- mysql
@@ -124,6 +136,8 @@ services:
124136
build:
125137
context: .
126138
dockerfile: ./docker/wp5.0/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
139+
networks:
140+
- wordpress_bouncer_network
127141
depends_on:
128142
- crowdsec
129143
- mysql
@@ -144,6 +158,8 @@ services:
144158
build:
145159
context: .
146160
dockerfile: ./docker/wp4.9/php-${CS_WORDPRESS_BOUNCER_PHP_VERSION}.Dockerfile
161+
networks:
162+
- wordpress_bouncer_network
147163
depends_on:
148164
- crowdsec
149165
- mysql
@@ -162,34 +178,44 @@ services:
162178

163179
crowdsec:
164180
image: crowdsecurity/crowdsec:latest
181+
networks:
182+
- wordpress_bouncer_network
165183
environment:
166184
- DISABLE_AGENT=true
167185
ports:
168186
- "8051:8080"
169187
mysql:
170188
image: mysql:5.7
189+
networks:
190+
- wordpress_bouncer_network
171191
environment:
172192
- MYSQL_ROOT_PASSWORD=super_secret_password
173193
- MYSQL_DATABASE=wordpress
174194
redis:
175195
image: redis:6-alpine
176-
ports:
177-
- "6379:6379"
196+
networks:
197+
- wordpress_bouncer_network
178198
memcached:
179199
image: memcached:1-alpine
200+
networks:
201+
- wordpress_bouncer_network
180202
wpscan:
181203
image: wpscanteam/wpscan
204+
networks:
205+
- wordpress_bouncer_network
182206
e2e:
183207
image: mcr.microsoft.com/playwright:focal
208+
networks:
209+
- wordpress_bouncer_network
184210
environment:
211+
LAPI_URL_FROM_WP: http://crowdsec:8080
212+
LAPI_URL_FROM_E2E: http://crowdsec:8080
213+
NETWORK_IFACE: eth0
185214
WORDPRESS_VERSION: ${WORDPRESS_VERSION}
186215
WATCHER_LOGIN: ${WATCHER_LOGIN}
187216
WATCHER_PASSWORD: ${WATCHER_PASSWORD}
188217
BOUNCER_KEY: ${BOUNCER_KEY}
189-
LAPI_URL_FROM_WP: http://crowdsec:8080
190-
LAPI_URL_FROM_E2E: http://crowdsec:8080
191218
WORDPRESS_URL: ${WORDPRESS_URL}
192-
NETWORK_IFACE: eth0
193219
depends_on:
194220
- crowdsec
195221
- mysql
@@ -198,3 +224,11 @@ services:
198224
volumes:
199225
- ./tests/e2e:/var/run/tests:rw
200226
command: tail -F anything
227+
228+
networks:
229+
wordpress_bouncer_network:
230+
name: wordpress_bouncer_network
231+
enable_ipv6: false
232+
ipam:
233+
config:
234+
- subnet: ${NETWORK_SUBNET}

docs/contribute.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Contribute to this plugin
22

3-
* Before all, be sure to [get the stack installed using the docker-compose guide](install-with-docker-compose.md).
3+
> Before all, be sure to [get the stack installed using the docker-compose guide](install-with-docker-compose.md).
44
# Play with crowdsec state
55

66
```bash
7-
# Get the Docker host IP from inside the crowdsec container
8-
export CS_WP_HOST=`docker-compose exec crowdsec /sbin/ip route|awk '/default/ { printf $3 }'`
97

108
# Add captcha your own IP for 15m:
11-
docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 15m --type captcha
9+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 15m --type captcha
1210

1311
# Ban your own IP for 15 sec:
14-
docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 15s --type ban
15-
12+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 15s --type ban
1613

1714
# Remove all decisions:
1815
docker-compose exec crowdsec cscli decisions delete --all
@@ -21,6 +18,8 @@ docker-compose exec crowdsec cscli decisions delete --all
2118
docker-compose logs crowdsec
2219
```
2320

21+
> Note: The `DOCKER_HOST_IP` environnment variable is initialized via `source ./load-env-vars.sh`.
22+
2423
# WP Scan pass
2524

2625
```bash
@@ -50,15 +49,28 @@ docker-compose rm # destroy
5049
```bash
5150
docker-compose down
5251
docker images | grep wordpress-bouncer_wordpress # to get the container id
53-
docker rmi 145c1ed0e4df
54-
CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2 docker-compose up -d --build --force-recreate
52+
docker rmi <container-id>
53+
```
54+
55+
Then, in the `.env` file, replace:
56+
57+
```bash
58+
CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2
5559
```
5660

61+
with :
62+
63+
```bash
64+
CS_WORDPRESS_BOUNCER_PHP_VERSION=<the-new-php-version>
65+
```
66+
67+
Then re-run the stack.
68+
5769
### Try the plugin with another WordPress version
5870

59-
In end 2020, [more than 90% of the wordpress websites](https://wordpress.org/about/stats/) was using WordPress versions:
71+
In start of 2021, [more than 90% of the wordpress websites](https://wordpress.org/about/stats/) was using WordPress versions:
6072

61-
The plugin is tested under each of these versions: `5.6`, `5.5`, `5.4`, `5.3`, `5.2`, `5.1`, `5.0`, `4.9`.
73+
The plugin is tested under each of these WordPress versions: `5.6`, `5.5`, `5.4`, `5.3`, `5.2`, `5.1`, `5.0`, `4.9`.
6274

6375
### Plugin debug mode VS production mode
6476

@@ -79,9 +91,10 @@ You can test the Linux behaviour of this project using **Vagrant**.
7991
vagrant up
8092
vagrant ssh
8193
cd /vagrant
82-
sudo su
83-
export CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2
84-
./tests-local.sh
94+
sudo usermod -aG docker $USER
95+
sudo systemctl restart docker
96+
cp .env.example .env
97+
./run-tests.sh
8598
```
8699

87100
To destroy the vagrant instance:
@@ -101,7 +114,7 @@ docker-compose up -d wordpress<X.X> crowdsec mysql redis memcached && docker-com
101114

102115
# To display the captcha wall
103116

104-
export CS_WP_HOST=`docker-compose exec crowdsec /sbin/ip route|awk '/default/ { printf $3 }'` && docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 15m --type captcha
117+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 15m --type captcha
105118

106119
# To delete the image in order to rebuild it
107120

@@ -112,13 +125,15 @@ docker-compose down && docker rmi wordpress-bouncer_wordpress<X.X>
112125
docker-compose run wordpress<X.X> bash
113126
```
114127

128+
> Note: The `DOCKER_HOST_IP` environnment variable is initialized via `source ./load-env-vars.sh`.
129+
115130
### Display the plugin logs
116131

117132
```bash
118133
tail -f logs/debug-*
119134
```
120135

121-
#### New feature workflow
136+
### New feature workflow
122137

123138
```bash
124139
git checkout -b <branch-name>
@@ -134,7 +149,7 @@ gh pr create --fill
134149

135150
> Note: after the merge, don't forget to delete to branch.
136151
137-
#### New release workflow
152+
### New release workflow
138153

139154
```bash
140155
git checkout main && git pull && git co -

docs/full-guide.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,43 @@ docker-compose logs -f crowdsec
2828

2929
* As we don't want this delay, to take in account immediately the last unban, feel free to [clear the cache in the wp-admin](http://localhost:8050/wp-admin/admin.php?page=crowdsec_plugin).
3030

31+
The `DOCKER_HOST_IP` environnment variable is initialized via a call to:
32+
33+
```bash
34+
source ./load-env-vars.sh
35+
```
36+
3137
* In a term, ban your own IP for 4 hours:
3238

3339
```bash
34-
# Get the Docker host IP from inside the crowdsec container
35-
export CS_WP_HOST=`docker-compose exec crowdsec /sbin/ip route|awk '/default/ { printf $3 }'`
3640

3741
# Ban your own IP for 4 hours:
38-
docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 4h --type ban
42+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 4h --type ban
3943
```
4044

4145
* Immediately, the [public home](http://localhost:8050/) is now locked with a short message to explain you that you were ban.
4246

4347
### Try "captcha" remediation
4448

49+
4550
* Now, request captcha for your own IP for 15m:
4651

4752
```bash
53+
4854
# Clear all existing decisions
4955
docker-compose exec crowdsec cscli decisions delete --all
5056

5157
# Add a captcha
52-
docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 15m --type captcha
58+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 15m --type captcha
5359
```
5460

5561
* The [public home](http://localhost:8050/) now request you to fill a captcha.
5662

5763
* While you fail resolving the captcha, you'll not be able to access the website.
5864

65+
> Note: when you resolve the captcha in your browser, the associated PHP session is considered as sure.
66+
> If you remove the captcha decision with `cscli`, then you add a new captcha decision for your IP, you'll not be prompted no more for the current PHP session. To view the captcha page, You can force using a new PHP session opening the front page with incognito mode.
67+
5968
## Stream mode, for the high traffic websites
6069

6170
With live mode, as you tried it just before, each time a user arrives to the website for the first time, a called is made to LAPI. If the traffic on your website is high, the bouncer will call LAPI very often.
@@ -78,7 +87,7 @@ docker-compose exec crowdsec cscli decisions delete --all
7887
* Now, if you ban your IP for 4h:
7988

8089
```bash
81-
docker-compose exec crowdsec cscli decisions add --ip ${CS_WP_HOST} --duration 4h --type ban
90+
docker-compose exec crowdsec cscli decisions add --ip ${DOCKER_HOST_IP} --duration 4h --type ban
8291
```
8392

8493
* In less than 30 seconds your IP will be banned and the [public home](http://localhost:8050/) will be locked.

docs/install-with-docker-compose.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22

33
Follow this guide to get the development stack installed locally.
44

5+
> Prerequises:
6+
> - you should have [`docker`](https://docs.docker.com/get-docker/) installed
7+
> - `docker` should be [`runnable without sudo`](https://docs.docker.com/engine/install/linux-postinstall/).
8+
> - [`docker-compose`](https://docs.docker.com/compose/install/) installed locally.
9+
510
## Install the stack for development purpose
611

7-
Select the PHP version you want to use (7.2, 7.3, 7.4, 8.0) :
12+
Before all, create a `.env` file, using:
813

914
```bash
10-
export CS_WORDPRESS_BOUNCER_PHP_VERSION=7.2
15+
cp .env.example .env
1116
```
1217

13-
## Configure WordPress and the CrowdSec Plugin
18+
> Note about PHP 8.0: WordPress official docker image [does not officially supports PHP 8.0](https://hub.docker.com/_/wordpress?tab=tags&page=1&ordering=last_updated) at this time. However, as the CrowdSec PHP Library does support PHP 8.0, there is a good chance that the pluggin will work fine with PHP 8.0, but we can not currently test it.
1419
15-
Now there is two options:
20+
## Configure WordPress and the CrowdSec Plugin
1621

17-
### A) Automatic comfiguration
22+
Now there are two options, you can fill the Wordpress installation wizard manually OR use let the e2e tests to do it for you.
1823

19-
Install Wordpress instance and activate plugin through the e2e tests:
24+
### A) Automatic configuration
2025

21-
You can do this automatically with:
26+
Install Wordpress instance and activate plugin launching the e2e tests (limited to the installation steps):
2227

2328
```bash
24-
SETUP_ONLY=1 DEBUG=1 ./tests-local.sh
29+
SETUP_ONLY=1 ./run-tests.sh
2530
```
2631

2732
### B) Manual comfiguration
@@ -45,3 +50,12 @@ docker-compose exec crowdsec cscli bouncers add wordpress-bouncer
4550
The LAPI URL is:
4651

4752
http://crowdsec:8080
53+
54+
## Try the plugin behaviour
55+
56+
| Info | Value |
57+
|-----------------|--------------------------------------|
58+
| Public blog URL | http://localhost:8050 |
59+
| Blog admin URL | http://localhost:8050/wp-admin |
60+
| Admin username | `admin` |
61+
| Pasword | `my_very_very_secret_admin_password` |

0 commit comments

Comments
 (0)