Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Rack attack #1419

Merged
merged 15 commits into from
Mar 25, 2023
Merged

[feature] Rack attack #1419

merged 15 commits into from
Mar 25, 2023

Conversation

Pralish
Copy link
Contributor

@Pralish Pralish commented Feb 20, 2023

Addresses: #538

@donrestarone
Copy link
Contributor

donrestarone commented Feb 27, 2023

@Pralish please also investigate why the server is unhealthy after terminating a request from rack-timeout.

The request times out:

A Rack::Timeout::RequestTimeoutException occurred in content#show:

  Request ran for longer than 15000ms 
  config/initializers/rack_timeout.rb:21:in `call'

and the puma Server hangs, and is unable to serve subsequent requests

EDIT:

Redis connection timeouts are causing the server to crash as well:

A Redis::TimeoutError occurred in background at 2023-02-28 00:12:35 UTC :

  Connection timed out
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:58:in `block in _read_from_socket'

-------------------------------
Backtrace:
-------------------------------

  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:58:in `block in _read_from_socket'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:54:in `loop'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:54:in `_read_from_socket'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:47:in `gets'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/connection/ruby.rb:382:in `read'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:311:in `block in read'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:299:in `io'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:310:in `read'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:161:in `block in call'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:279:in `block (2 levels) in process'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:420:in `ensure_connected'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:269:in `block in process'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:356:in `logging'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:268:in `process'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:161:in `call'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:257:in `block in call_with_timeout'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:331:in `with_socket_timeout'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/client.rb:256:in `call_with_timeout'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis.rb:269:in `block in send_blocking_command'
  /home/ubuntu/.rbenv/versions/2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis.rb:268:in `send_blocking_command'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/commands/lists.rb:270:in `_bpop'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-4.6.0/lib/redis/commands/lists.rb:167:in `brpop'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-namespace-1.8.2/lib/redis/namespace.rb:476:in `call_with_namespace'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/redis-namespace-1.8.2/lib/redis/namespace.rb:352:in `block (2 levels) in <class:Namespace>'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/fetch.rb:47:in `block in retrieve_work'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq.rb:100:in `block in redis'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/connection_pool-2.2.5/lib/connection_pool.rb:63:in `block (2 levels) in with'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/connection_pool-2.2.5/lib/connection_pool.rb:62:in `handle_interrupt'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/connection_pool-2.2.5/lib/connection_pool.rb:62:in `block in with'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `handle_interrupt'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `with'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq.rb:97:in `redis'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/fetch.rb:47:in `retrieve_work'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/processor.rb:83:in `get_one'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/processor.rb:95:in `fetch'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/processor.rb:77:in `process_one'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/processor.rb:68:in `run'


  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/util.rb:56:in `watchdog'
  /var/www/violet/shared/bundle/ruby/2.6.0/gems/sidekiq-6.4.1/lib/sidekiq/util.rb:65:in `block in safe_thread'

-------------------------------
Data:
-------------------------------

  * data: {:sidekiq=>{}}

I discovered we are not aborting requests correctly, see here: #1434

donrestarone pushed a commit that referenced this pull request Mar 13, 2023
donrestarone added a commit that referenced this pull request Mar 13, 2023
Addresses: 
#1434
#1419 (comment)

Co-authored-by: Pralish Kayastha <50227291+Pralish@users.noreply.github.com>
@Pralish Pralish changed the title [WIP] rack attack Rack attack Mar 17, 2023
@@ -0,0 +1,11 @@
class RackAttackMailer < ApplicationMailer
def limit_exceeded(user, error_limit_exceeded = false)
@user = user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pralish you should CC the email to global admins as well

@Pralish Pralish marked this pull request as ready for review March 20, 2023 16:46
@github-actions
Copy link

Deployed review-app can be viewed at https://review-1419.violet-test.net

@donrestarone
Copy link
Contributor

donrestarone commented Mar 22, 2023

🧪 test plan

  1. set ERROR_PER_MINUTE=1 and REQUEST_PER_MINUTE=2 ⌛ by running dokku config:set review-1419 ERROR_PER_MINUTE=1 REQUEST_PER_MINUTE=2
  2. user should not be able to raise more than 1 error a minute ✅
  3. user should not be able to make more than 2 requests per minute ✅

Screen Shot 2023-03-22 at 1 24 04 PM

@donrestarone donrestarone changed the title Rack attack [feature] Rack attack Mar 22, 2023
@github-actions
Copy link

Deployed review-app can be viewed at https://review-1419.violet-test.net

1 similar comment
@github-actions
Copy link

Deployed review-app can be viewed at https://review-1419.violet-test.net

@@ -9,4 +9,7 @@ APP_HOST=lvh.me:5250
RECAPTCHA_SITE_KEY=6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy
RECAPTCHA_SECRET_KEY=6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx
SECRET_KEY_BASE='38c72586473e364229897f24f1892f1dc5565776878aa4d8c6bf051258622bd2e923b926ab59b40f912b661216f764d993e8d6b8bbfbc33026e5c954b6c51f9b'
REQUEST_PER_MINUTE=5
ERROR_PER_MINUTE=3
PERIOD_MULTIPLIER=2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pralish could you create a GitHub issue with documentation on how to tune this feature with these 3 variables?

@donrestarone donrestarone changed the base branch from master to rc March 25, 2023 17:55
@donrestarone donrestarone merged commit f9d84ba into rc Mar 25, 2023
@github-actions
Copy link

Deployed review-app can be viewed at https://review-1419.violet-test.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants