Wallogit.com
2017 © Pedro Peláez
A bundle for plug symfony with fail2ban security application
Inspired from https://inuits.eu/blog/getting-fail2ban-work-symfony2-proper-way, (*1)
Thank you Kalman Olah for the great article., (*2)
A bundle for plug symfony to linux fail2ban security application, (*3)
Revision 2 is for Symfony 2.x Revision 3 is for Symfony 3.x Revision 3 is merged in dev-master and in develop, (*4)
So if you are using Symfony 2.8 you must use revision 2 of this bundle., (*5)
Migration from sf 2.8 to sf 3.3 :, (*6)
If you haven't moved your log files and still let them in app/logs yopu have nothing to do. Eventually upgrade this bundle to revision 2 to ensure you dont go to 3 by error., (*7)
Start by configuring log rotate on your web server., (*8)
Create an empty file in the logrotate config directory with a pattern like this :, (*9)
$ sudo vim /etc/logrotate.d/sf2-appName
Write this in your new file (substitute with good values) :, (*10)
/var/www/appName/var/logs/prod.log {
su www-data www-data
daily
missingok
rotate 14
compress
}
Then (if your application has already started working and do logs) force first rotating :, (*11)
$ sudo logrotate --force /etc/logrotate.d/sf2_appName
Composer.json :, (*12)
"require": {
[...],
"loamok/sf2security-bundle": "^3"
And run composer update., (*13)
Add it to your kernel AppKernel.php :, (*14)
$bundles = array(
[...],
\Loamok\Sf2securityBundle\Sf2securityBundle(),
Mod your security config file, (*15)
# app/config/security.yml
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
failure_handler: sf2security.authenticationfailurehandler
logout: true
anonymous: true
Create a symbolic link from filter conf file to /etc/fail2ban/filter :, (*16)
$ sudo ln -s /var/www/appName/vendor/loamok/sf2security-bundle/Loamok/Sf2securityBundle/Resources/filter/sf2security.conf /etc/fail2ban/filter/sf2security.conf
Add the jail definition for fail2ban (/etc/fail2ban/jail.conf) (sample is in the filter file) :, (*17)
[sf2security] enabled = true filter = sf2security logpath = /var/www/appName/var/logs/prod.log port = http,https bantime = 600 banaction = iptables-multiport maxretry = 3
Restart fail2 ban service and that's it you just secure your symfony2 application against brutforce., (*18)
$ sudo service fail2ban restart