-
-
Save samholst/8e08abb5bc778d8d7a0cacaa4bfe733d to your computer and use it in GitHub Desktop.
Simple Fail2banNotifier for exception_notification (will submit a pull request and update gist when accepted).
See:
http://securityroots.com/blog/2014/01/protecting-app-rails-fail2ban/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fail2banNotifier | |
def initialize(options) | |
@default_options = options | |
@default_options[:logfile] ||= Rails.root.join('log', 'fail2ban.log') | |
# Roll over every 30M, keep 10 files | |
@logger ||= Logger.new(@default_options[:logfile], 10, 30*1024*1024) | |
end | |
def call(exception, options={}) | |
env = options[:env] | |
request = ActionDispatch::Request.new(env) | |
# <ip> : <exception class> : <method> <path> -- <params> | |
msg = "%s : %s : %s %s -- %s" % [ | |
request.remote_ip, | |
exception.class, | |
request.request_method, | |
env["PATH_INFO"], | |
request.filtered_parameters.inspect | |
] | |
@logger.error(msg) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom Rails app jail. Add to /etc/fail2ban/jail.local | |
[rails-app] | |
enabled = true | |
port = http,https | |
filter = rails-app | |
logpath = /path/to/app/log/fail2ban.log | |
bantime = 3600 | |
findtime = 600 | |
maxretry = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom Rails app filter. Place in /etc/fail2ban/filter.d/ | |
[Definition] | |
failregex = : <HOST> : | |
ignoreregex = |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment