Skip to content

Commit c84b85d

Browse files
Merge pull request #89 from julienloizelet/feat/87-no-more-session
Feat/87 no more session
2 parents b45dce7 + edd10ac commit c84b85d

23 files changed

+409
-235
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.22.0] - 2022-06-02
9+
10+
### Added
11+
- Add configurations for captcha and geolocation variables cache duration
12+
### Changed
13+
- *Breaking change*: Use cache instead of session to store captcha and geolocation variables
14+
- *Breaking change*: Use symfony cache tag adapter
15+
- Change `geolocation/save_in_session` setting into `geolocation/save_result`
16+
### Fixed
17+
- Fix deleted decision count during cache update
18+
819
## [0.21.0] - 2022-04-15
920

1021
### Changed

docs/DEVELOPER.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ In most cases, you will test to bounce your current IP. As we are running on a d
177177

178178
To find it, just run:
179179

180-
```
180+
```bash
181181
ddev find-ip
182182
```
183183

@@ -186,7 +186,7 @@ You will have to know also the IP of the `ddev-router` container as it acts as a
186186

187187
To find this IP, just run:
188188

189-
```
189+
```bash
190190
ddev find-ip ddev-router
191191
```
192192

@@ -436,7 +436,7 @@ use CrowdSecBouncer\Bouncer;
436436
use Symfony\Component\Cache\Adapter\RedisAdapter;
437437

438438
// Init cache adapter
439-
$cacheAdapter = new PhpFilesAdapter('', 0, __DIR__.'/.cache');
439+
$cacheAdapter = new TagAwareAdapter(new PhpFilesAdapter('', 0, __DIR__.'/.cache'));
440440

441441
...
442442
```
@@ -453,7 +453,7 @@ use Symfony\Component\Cache\Adapter\RedisAdapter;
453453

454454
// Init cache adapter
455455

456-
$cacheAdapter = new RedisAdapter(RedisAdapter::createConnection('redis://redis:6379'));
456+
$cacheAdapter = new RedisTagAwareAdapter(RedisAdapter::createConnection('redis://redis:6379'));
457457

458458
...
459459
```
@@ -470,7 +470,8 @@ use Symfony\Component\Cache\Adapter\MemcachedAdapter;
470470

471471
// Init cache adapter
472472

473-
$cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://memcached:11211'));
473+
$cacheAdapter =
474+
new TagAwareAdapter(new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://memcached:11211')));
474475

475476
...
476477
```

docs/USER_GUIDE.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ Here is the list of available settings:
162162

163163
- `bad_ip_cache_duration`: Set the duration we keep in cache the fact that an IP is bad. In seconds. Defaults to 20.
164164

165+
- `captcha_cache_duration`: Set the duration we keep in cache the captcha flow variables for an IP. In seconds.
166+
Defaults to 86400.. In seconds. Defaults to 20.
167+
168+
- `geolocation_cache_duration`: Set the duration we keep in cache a geolocation result for an IP . In seconds.
169+
Defaults to 86400. Depends on the below `geolocation[save_result]` configuration.
170+
165171
- `stream_mode`: true to enable stream mode, false to enable the live mode. Default to false. By default, the `live mode` is enabled. The first time a stranger connects to your website, this mode means that the IP will be checked directly by the CrowdSec API. The rest of your user’s browsing will be even more transparent thanks to the fully customizable cache system. But you can also activate the `stream mode`. This mode allows you to constantly feed the bouncer with the malicious IP list via a background task (CRON), making it to be even faster when checking the IP of your visitors. Besides, if your site has a lot of unique visitors at the same time, this will not influence the traffic to the API of your CrowdSec instance.
166172

167173
##### Geolocation
@@ -170,7 +176,7 @@ Here is the list of available settings:
170176
- `geolocation[enabled]`: true to enable remediation based on country. Default to false.
171177
- `geolocation[type]`: Geolocation system. Only 'maxmind' is available for the moment. Default to `maxmind`
172178

173-
- `geolocation[save_in_session]`: true to store the geolocalized country in session. Default to true. Setting true
179+
- `geolocation[save_result]`: true to store the geolocalized country in cache. Default to true. Setting true
174180
will avoid multiple call to the geolocalized system (e.g. maxmind database)
175181
- `geolocation[maxmind]`: MaxMind settings
176182
- `geolocation[maxmind][database_type]`: Select from `country` or `city`. Default to `country`. These are the two available MaxMind database types.

scripts/auto-prepend/refresh-cache.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
$bouncer = $bounce->init($crowdSecStandaloneBouncerConfig);
2121
$bouncer->refreshBlocklistCache();
22-
echo 'Cache has been refreshed';
22+
echo 'Cache has been refreshed'.PHP_EOL;

scripts/auto-prepend/settings.example.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@
9191
// Set the duration we keep in cache the fact that an IP is clean. In seconds. Defaults to 5.
9292
'clean_ip_cache_duration'=> Constants::CACHE_EXPIRATION_FOR_CLEAN_IP,
9393

94-
// Optional. Set the duration we keep in cache the fact that an IP is bad. In seconds. Defaults to 20.
94+
// Set the duration we keep in cache the fact that an IP is bad. In seconds. Defaults to 20.
9595
'bad_ip_cache_duration'=> Constants::CACHE_EXPIRATION_FOR_BAD_IP,
9696

97+
// Set the duration we keep in cache the captcha flow variables for an IP. In seconds. Defaults to 86400.
98+
'captcha_cache_duration'=> Constants::CACHE_EXPIRATION_FOR_CAPTCHA,
99+
100+
// Set the duration we keep in cache a geolocation result for an IP . In seconds. Defaults to 86400.
101+
'geolocation_cache_duration'=> Constants::CACHE_EXPIRATION_FOR_GEO,
102+
97103
/** true to enable stream mode, false to enable the live mode. Default to false.
98104
*
99105
* By default, the `live mode` is enabled. The first time a stranger connects to your website, this mode
@@ -117,7 +123,7 @@
117123
*
118124
* Setting true will avoid multiple call to the geolocalized system (e.g. maxmind database)
119125
*/
120-
'save_in_session' => true,
126+
'save_result' => true,
121127
// MaxMind settings
122128
'maxmind' => [
123129
/**Select from 'country' or 'city'. Default to 'country'

scripts/check-ip.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CrowdSecBouncer\Bouncer;
66
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
7+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
78
use Monolog\Formatter\LineFormatter;
89
use Monolog\Handler\RotatingFileHandler;
910
use Monolog\Handler\StreamHandler;
@@ -12,7 +13,7 @@
1213

1314
// Init cache adapter
1415

15-
$cacheAdapter = new PhpFilesAdapter('', 0, __DIR__ . '/.cache');
16+
$cacheAdapter = new TagAwareAdapter(new PhpFilesAdapter('', 0, __DIR__ . '/.cache'));
1617

1718
// Parse argument
1819

scripts/clear-cache.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use Monolog\Handler\RotatingFileHandler;
88
use Monolog\Handler\StreamHandler;
99
use Monolog\Logger;
10+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
11+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
12+
13+
14+
1015

1116
// Parse arguments
1217
$bouncerApiKey = $argv[1]; // required
@@ -23,9 +28,10 @@
2328
$cachePath = __DIR__ . '/.cache';
2429

2530
// Instantiate the "PhpFilesAdapter" cache adapter
26-
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath);
27-
// Or Redis: $cacheAdapter = new RedisAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
28-
// Or Memcached: $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://your-memcached-host:11211'));
31+
$cacheAdapter = new TagAwareAdapter(new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath));
32+
// 0Or Redis: $cacheAdapter = new RedisTagAwareAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
33+
// Or Memcached: $cacheAdapter = new TagAwareAdapter(new MemcachedAdapter(MemcachedAdapter::createConnection
34+
//('memcached://your-memcached-host:11211')));
2935

3036
// Instantiate the Stream logger with info level(optional)
3137
$logger = new Logger('example');

scripts/full-example-live-mode.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Monolog\Handler\RotatingFileHandler;
88
use Monolog\Handler\StreamHandler;
99
use Monolog\Logger;
10+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
11+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1012

1113
// Parse arguments
1214
$bouncerApiKey = $argv[1]; // required
@@ -24,9 +26,10 @@
2426
$cachePath = __DIR__ . '/../.cache';
2527

2628
// Instantiate the "PhpFilesAdapter" cache adapter
27-
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath);
28-
// Or Redis: $cacheAdapter = new RedisAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
29-
// Or Memcached: $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://your-memcached-host:11211'));
29+
$cacheAdapter = new TagAwareAdapter(new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath));
30+
// 0Or Redis: $cacheAdapter = new RedisTagAwareAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
31+
// Or Memcached: $cacheAdapter = new TagAwareAdapter(new MemcachedAdapter(MemcachedAdapter::createConnection
32+
//('memcached://your-memcached-host:11211')));
3033

3134
// Instantiate the Stream logger with info level(optional)
3235
$logger = new Logger('example');

scripts/refresh-cache.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
use CrowdSecBouncer\Bouncer;
66
use Monolog\Handler\RotatingFileHandler;
77
use Monolog\Logger;
8+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
9+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
810

911
// Configure paths
1012
$logPath = __DIR__.'/.crowdsec.log';
1113
$cachePath = __DIR__ . '/.cache';
1214

1315
// Instantiate the "PhpFilesAdapter" cache adapter
14-
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath);
15-
// Or Redis: $cacheAdapter = new RedisAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
16-
// Or Memcached: $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://your-memcached-host:11211'));
17-
16+
$cacheAdapter = new TagAwareAdapter(new Symfony\Component\Cache\Adapter\PhpFilesAdapter('', 0, $cachePath));
17+
// 0Or Redis: $cacheAdapter = new RedisTagAwareAdapter(RedisAdapter::createConnection('redis://your-redis-host:6379'));
18+
// Or Memcached: $cacheAdapter = new TagAwareAdapter(new MemcachedAdapter(MemcachedAdapter::createConnection
19+
//('memcached://your-memcached-host:11211')));
1820
// Parse argument
1921

2022
$bouncerKey = $argv[1];

0 commit comments

Comments
 (0)