gitlab-org--gitlab-foss/spec
Dmitriy Zaporozhets fc4af9b197 Merge branch 'git-auth-rack-attack-improvements' into 'master'
Reduce Rack Attack false positives causing 403 errors during HTTP authentication

### What does this MR do?

This MR reduces false positives causing `403 Forbidden` messages after HTTP authentication.

A Git client may attempt to access a repository without a password. If it receives a 401 error, the client often will try again, this time supplying a password. The problem is that `grack_auth.rb` considers a blank password an authentication failure and increases a Redis counter each time this happens. With enough requests, an IP can be banned temporarily even though previous attempts may have been successful. This leads users to see `403 Forbidden` errors until the ban times out (default: 1 hour).

To reduce the chance of a false positive, this MR resets the counter upon a successful authentication from an IP.

In addition, this MR logs when a user has been banned and introduces the ability to disable Rack Attack via a config variable.

### Are there points in the code the reviewer needs to double check?

rack-attack v4.2.0 doesn't support the ability to clear counters out of the box, so `rack_attack_helpers.rb` includes a number of monkey patches to make it work. It looks like this functionality may be added in v4.3.0. I've also sent pull requests to rack-attack to add the functionality necessary to delete a key.

Each time an authentication is successful, the Redis counter for that IP is cleared. I deemed it better to clear the counter than to allow for blank passwords, since the latter seems like a security risk.

### Why was this MR needed?

It was quite difficult to figure out why users were seeing `403 Forbidden`, which is why the log message was added. Users were getting a lot of false positives when accessing repositories with HTTPS. Including the username in the HTTPS URL (e.g. `https://username@mydomain.com/account/repo.git`) caused authentication failures because while the git client provided the username, it left the password blank, leading to an authentication failure.

### What are the relevant issue numbers / [Feature requests](http://feedback.gitlab.com/)?

See Issue #1171

https://github.com/kickstarter/rack-attack/issues/113

See merge request !392
2015-03-24 21:51:40 +00:00
..
controllers Fix user controller specs 2015-03-22 11:14:42 -07:00
factories Added comment notification events to HipChat and Slack services. 2015-03-06 06:54:00 -08:00
features Merge branch 'atom-xhtml-squashed' into 'master' 2015-03-17 08:38:38 +00:00
finders Updated rspec to rspec 3.x syntax 2015-02-12 19:17:35 +01:00
fixtures Add trailing newline to all text files. 2014-06-21 11:20:22 +02:00
helpers Fix nested task lists 2015-03-21 08:45:28 -06:00
javascripts Add trailing newline to all text files. 2014-06-21 11:20:22 +02:00
lib Reduce Rack Attack false positives by clearing out auth failure count upon 2015-03-24 00:36:46 -07:00
mailers Clean up code by using keyword arguments. 2015-03-23 15:08:19 +01:00
models Merge branch 'improve-contributions-calendar' into 'master' 2015-03-23 16:40:55 +00:00
requests/api Enforce restricted visibilities for snippets 2015-03-08 17:57:08 -06:00
routing Use project_member instead of team_member. 2015-03-15 13:50:38 +01:00
services Extend push_tag event to include tag message and last commit 2015-03-21 11:25:27 +01:00
support This MR extends the commit calendar so it searches for commits made with every email address the user has associated with his account. 2015-03-09 21:43:54 -07:00
tasks/gitlab Change permissions on backup files 2015-03-17 19:04:21 -06:00
workers Prevent gitlab-shell character encoding issues by receiving its changes as raw data. 2015-03-15 16:52:22 +01:00
factories.rb Remove unneeded password_confirmation from seed. 2014-12-28 14:42:15 +01:00
factories_spec.rb Updated rspec to rspec 3.x syntax 2015-02-12 19:17:35 +01:00
spec_helper.rb Updated rspec to rspec 3.x syntax 2015-02-12 19:17:35 +01:00