<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=Request_Tracker_and_Fail2ban_%28Ubuntu%29</id>
	<title>Request Tracker and Fail2ban (Ubuntu) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=Request_Tracker_and_Fail2ban_%28Ubuntu%29"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=Request_Tracker_and_Fail2ban_(Ubuntu)&amp;action=history"/>
	<updated>2026-08-22T02:38:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=Request_Tracker_and_Fail2ban_(Ubuntu)&amp;diff=3155&amp;oldid=prev</id>
		<title>Admin: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=Request_Tracker_and_Fail2ban_(Ubuntu)&amp;diff=3155&amp;oldid=prev"/>
		<updated>2016-04-06T20:36:16Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[File:Placeholder|video|right|300px]] [[File:Placeholder|right|300px]] &lt;br /&gt;
Before I let RT out in the wild, our IT department wanted to have some protection against script kiddies and anyone trying to brute force their way in. They&amp;#039;ve used Fail2ban in the past, and installed it on our RT instance.&lt;br /&gt;
&lt;br /&gt;
Trying to configure Fail2ban for RT was a bit of a challenge and took me a while to sort out, so below is a summary of the steps required to get it working on Ubuntu. I haven&amp;#039;t tested this extensively, however initial results look promising. Use at your own risk.&lt;br /&gt;
&lt;br /&gt;
I won&amp;#039;t go into the installation of RT or Fail2ban, just configuration changes required to get it going.&lt;br /&gt;
&lt;br /&gt;
Request Tracker version is RT 4.2.12.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Request Tracker RT_SiteConfig.pm==&lt;br /&gt;
&lt;br /&gt;
For Fail2ban to work, first it needs to see the RT log file date/time stamps in your local time zone.&lt;br /&gt;
It won&amp;#039;t work with the RT default of GMT. As such, there is no reason pointing a Fail2ban &amp;#039;jail&amp;#039; to the RT logfile &amp;lt;code&amp;gt;/opt/rt4/var/log/rt.log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to set RT to log to the syslog file as the syslog daemon will then handle the time stamp formatting. Edit RT_SiteConfig.pm to include the following...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# Redirect RT logs to syslog for Fail2ban&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Set($LogToSyslog,       &amp;quot;warning&amp;quot;);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart the webserver for the change to take effect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Ubuntu syslog &amp;amp; RT Failed logins==&lt;br /&gt;
&lt;br /&gt;
Any login failures (indeed all RT log messages) now appear in &amp;lt;code&amp;gt;/var/log/syslog&amp;lt;/code&amp;gt;. Login failures will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Feb 15 15:12:50 myrt RT: [38319] FAILED LOGIN for user from xx.x.x.xxx&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this message will only appear each time the message changes (i.e. the user name changes), and the message will NOT appear each time a different password is used for the same user. Obviously, this is a problem as an attacker can then try many different passwords with the same username and only one message will be returned.&lt;br /&gt;
&lt;br /&gt;
When a different message is eventually sent (i.e. a login failure for a different user name), you&amp;#039;ll see something like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Feb 15 15:20:56 myrt RT: message repeated 17 times: [ [38319] FAILED LOGIN for user from xx.x.x.xxx]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Feb 15 15:22:50 myrt RT: [38319] FAILED LOGIN for test from xx.x.x.xxx&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default, the Ubuntu syslog has repeated message reduction turned on, which is the cause of the behavior seen above. To turn it off, edit &amp;lt;code&amp;gt;/etc/rsyslog.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Look for the section Filter duplicate messages and edit as per below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# Filter duplicated messages&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;#$RepeatedMsgReduction on&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# Turned repeat message reduction off so fail2ban can read every failed password attempt in syslog&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$RepeatedMsgReduction off&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After editing and saving the file, restart the syslog for changes to take effect.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sudo service rsyslog restart&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Fail2ban jail file==&lt;br /&gt;
We need to now make a new Jail in our jail file for RT specific connections over http/https.&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/etc/fail2ban/jail.local&amp;lt;/code&amp;gt; and add the following to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
[apache-rt]&lt;br /&gt;
&lt;br /&gt;
enabled   = true&lt;br /&gt;
&lt;br /&gt;
port      = http,https&lt;br /&gt;
&lt;br /&gt;
filter    = requesttracker&lt;br /&gt;
&lt;br /&gt;
logpath   = /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
maxretry  = 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above I&amp;#039;ve called my jail &amp;#039;apache-rt&amp;#039;. It references a custom filter called &amp;#039;requesttracker&amp;#039; that we will create shortly. Note above I&amp;#039;m working with jail.local and not jail.conf - read the Fail2ban installation and configuration documentation if you don&amp;#039;t understand why.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Fail2ban filter file==&lt;br /&gt;
&lt;br /&gt;
You need to create a Fail2ban filter file that is tailored to the RT message format for failed logins.&lt;br /&gt;
Create a text file called &amp;lt;code&amp;gt;requesttracker.conf&amp;lt;/code&amp;gt; in the path &amp;lt;code&amp;gt;/etc/fail2ban/filter.d/&amp;lt;/code&amp;gt; and add the following text to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# fail2Ban requesttracker filter&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;[Definition]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;failregex = myrt RT: (?:\[\d+\]) FAILED LOGIN for .* from &amp;lt;HOST&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ignoreregex =&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Important: - In the failregex line above replace &amp;#039;myrt&amp;#039; with the instance name of your RT.&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Failure to do this will result in the failregex match failing on your system. To be honest, I only just realised this oversight as I was writing this. I&amp;#039;m not great with regular expressions, but cleverer people than I will undoubtedly suggest a good way to regex &amp;#039;myrt&amp;#039; so it is fully portable.&lt;br /&gt;
&lt;br /&gt;
A possible (totally untested) example that may work...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# fail2Ban requesttracker filter&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;[Definition]&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;failregex = .* RT: (?:\[\d+\]) FAILED LOGIN for .* from &amp;lt;HOST&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ignoreregex =&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write out the file, and reload the jails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sudo fail2ban-client reload&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hopefully that should be it. Three login failures (either due to consecutive bad user names or passwords) should ban your IP Address for HTTP/HTTPS requests for 10 minutes.&lt;br /&gt;
&lt;br /&gt;
If it works, unban yourself with the following command in the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sudo fail2ban-client set apache-rt unbanip xx.x.x.xxx&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>