Configure fail2ban

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

If you want to limit the number of login attempts (and avoid brute-force attacks), install fail2ban and configure it to work with the Bitnami Redmine Stack.

  • Install fail2ban:

    • Debian:

      $ sudo apt-get update
      $ sudo apt-get install fail2ban
    • CentOS:

      $ sudo yum install epel-release
      $ sudo yum install fail2ban
      $ sudo systemctl enable fail2ban
      $ sudo systemctl start fail2ban
  • Modify the installdir/apps/redmine/htdocs/config/environment.rb file to allow the Redmine logger to add timestamps to the production.log file. To do this, add the following lines:

    class Logger
      def format_message(severity, timestamp, progname, msg)
        "#{timestamp} (#{$$}) #{msg}\n"
  • Restart the Apache server.

    $ sudo installdir/ restart apache

Next, configure fail2ban following the steps below:

  • Create the /etc/fail2ban/filter.d/redmine.conf file with the following code:

    failregex = Failed [-/\w]+ for .* from <HOST>
    ignoreregex =
  • Create the /etc/fail2ban/jail.local file and add the code below:

    enabled = true
    filter = redmine
    port = http,https
    logpath = installdir/apps/redmine/htdocs/log/production.log
    maxretry = 5
    findtime = 600
    bantime = 600

    This fail2ban configuration will ban the IP of any user that tried to access five (maxretry) different times in 10 minutes (findtime) without success. Note that the ban only will affect the ports 80 and 443, and the user with the banned IP will not be able to contact the web server for 10 minutes (bantime).

  • Before applying the configuration,test if the regex configuration is correct. To test this, browse to your Bitnami Redmine login page and use a non-existent user/password to get a login error. Then, run this command:

    $ fail2ban-regex installdir/apps/redmine/htdocs/log/production.log /etc/fail2ban/filter.d/redmine.conf

    If the last two lines of the output show you at least “1 matched”, the regex is properly configured:

    Lines: 412 lines, 0 ignored, 1 matched, 397 missed
    Missed line(s):: too many to print.  Use --print-all-missed to print all 397 lines
  • Apply the configuration with this command

    • Debian:

      $ sudo /etc/init.d/fail2ban restart
    • CentOS:

      $ sudo systemctl restart fail2ban

To check if all is working, try logging in five different times with bad credentials. On the fifth unsuccessful attempt, you will be banned for 10 minutes.

Last modification September 4, 2018