diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-12-15 18:47:26 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-12-15 18:57:42 +0100 |
commit | 62ea02740d2fff83d636eb659eb5f80dbf1bd888 (patch) | |
tree | da939d1010ebcd376c9ad9e1bf66acfbbb7e774e /config/initializers | |
parent | 7512016d51feb6c02c3a0322325564b6b7f5ad9c (diff) | |
download | gitlab-ce-62ea02740d2fff83d636eb659eb5f80dbf1bd888.tar.gz |
Block Git HTTP Basic Auth after 10 failed attempts
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/1_settings.rb | 9 | ||||
-rw-r--r-- | config/initializers/rack_attack_git_basic_auth.rb | 10 | ||||
-rw-r--r-- | config/initializers/redis-store-fix-expiry.rb | 21 |
3 files changed, 40 insertions, 0 deletions
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 27bb83784ba..4464d9d0001 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -172,6 +172,15 @@ Settings.satellites['timeout'] ||= 30 Settings['extra'] ||= Settingslogic.new({}) # +# Rack::Attack settings +# +Settings['rack_attack'] ||= Settingslogic.new({}) +Settings.rack_attack['git_basic_auth'] ||= Settingslogic.new({}) +Settings.rack_attack.git_basic_auth['maxretry'] ||= 10 +Settings.rack_attack.git_basic_auth['findtime'] ||= 1.minute +Settings.rack_attack.git_basic_auth['bantime'] ||= 1.hour + +# # Testing settings # if Rails.env.test? diff --git a/config/initializers/rack_attack_git_basic_auth.rb b/config/initializers/rack_attack_git_basic_auth.rb new file mode 100644 index 00000000000..2348768ff16 --- /dev/null +++ b/config/initializers/rack_attack_git_basic_auth.rb @@ -0,0 +1,10 @@ +unless Rails.env.test? + Rack::Attack.blacklist('Git HTTP Basic Auth') do |req| + Rack::Attack::Allow2Ban.filter(req.ip, Gitlab.config.rack_attack.git_basic_auth) do + # This block only gets run if the IP was not already banned. + # Return false, meaning that we do not see anything wrong with the + # request at this time + false + end + end +end diff --git a/config/initializers/redis-store-fix-expiry.rb b/config/initializers/redis-store-fix-expiry.rb new file mode 100644 index 00000000000..dd27596cd0b --- /dev/null +++ b/config/initializers/redis-store-fix-expiry.rb @@ -0,0 +1,21 @@ +# Monkey-patch Redis::Store to make 'setex' and 'expire' work with namespacing + +module Gitlab + class Redis + class Store + module Namespace + def setex(key, expires_in, value, options=nil) + namespace(key) { |key| super(key, expires_in, value) } + end + + def expire(key, expires_in) + namespace(key) { |key| super(key, expires_in) } + end + end + end + end +end + +Redis::Store.class_eval do + include Gitlab::Redis::Store::Namespace +end |