From a46488078f7f6685bce0303aaff73041f2cf5be5 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Tue, 9 Jul 2013 11:02:38 +0200 Subject: [PATCH] Add rack-attack, block one client who's hammering us. --- Gemfile | 1 + Gemfile.lock | 3 +++ lib/travis/api/app.rb | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/Gemfile b/Gemfile index aab78b02..80d6a333 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem 'sentry-raven', github: 'getsentry/raven-ruby' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' +gem 'rack-attack' gem 'gh' gem 'bunny' gem 'dalli' diff --git a/Gemfile.lock b/Gemfile.lock index 29c0683d..22e1cc59 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,8 @@ GEM multi_json (~> 1.0) signature (~> 0.1.6) rack (1.4.5) + rack-attack (2.2.0) + rack rack-cache (1.2) rack (>= 0.4) rack-protection (1.5.0) @@ -288,6 +290,7 @@ DEPENDENCIES mocha (~> 0.12) pry puma (= 2.3.1) + rack-attack rack-cache (~> 1.2) rack-contrib! rake (~> 0.9.2) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b23bb938..474d902d 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -4,6 +4,7 @@ require 'rack' require 'rack/protection' require 'rack/contrib' require 'rack/cache' +require 'rack/attack' require 'active_record' require 'redis' require 'gh' @@ -86,6 +87,12 @@ module Travis::Api env['travis.global_prefix'] = env['SCRIPT_NAME'] end + use Rack::Attack + + Rack::Attack.blacklist('block client requesting ruby builds') do |req| + req.ip == "130.15.4.210" + end + use Travis::Api::App::Middleware::ScopeCheck use Travis::Api::App::Middleware::Logging use Travis::Api::App::Middleware::Metriks