TylerRick / rack_attack_admin

A Rack::Attack admin dashboard
MIT License
7 stars 9 forks source link

undefined method `keys' for #<ActiveSupport::Cache::FileStore:0x0000560ca1d37ad0> #1

Open scarroll32 opened 4 years ago

scarroll32 commented 4 years ago

Doesn't seem to work ...

Traceback

NoMethodError: undefined method `keys' for #<ActiveSupport::Cache::FileStore:0x0000560ca1d37ad0>
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack_attack_admin-0.1.2/lib/rack/attack_extensions.rb", line 11, in all_keys
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack_attack_admin-0.1.2/lib/rack/attack_extensions.rb", line 67, in prefixed_keys
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack_attack_admin-0.1.2/lib/rack/attack_extensions.rb", line 72, in keys
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack_attack_admin-0.1.2/lib/rack/attack_extensions.rb", line 88, in counters_h
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack_attack_admin-0.1.2/app/controllers/rack_attack_admin/rack_attack_controller.rb", line 8, in index
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/basic_implicit_render.rb", line 6, in send_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/base.rb", line 194, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/rendering.rb", line 30, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/callbacks.rb", line 42, in block in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 109, in block in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/ahoy_matey-3.0.1/lib/ahoy/controller.rb", line 45, in set_ahoy_request_store
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 118, in block in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/audited-4.8.0/lib/audited/sweeper.rb", line 14, in around
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 118, in block in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/audited-4.8.0/lib/audited/sweeper.rb", line 14, in around
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 118, in block in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 136, in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/callbacks.rb", line 41, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/rescue.rb", line 22, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/instrumentation.rb", line 34, in block in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb", line 168, in block in instrument
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb", line 23, in instrument
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb", line 168, in instrument
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/instrumentation.rb", line 32, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/params_wrapper.rb", line 256, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/searchkick-4.1.0/lib/searchkick/logging.rb", line 211, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/railties/controller_runtime.rb", line 24, in process_action
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/base.rb", line 134, in process
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionview-5.2.3/lib/action_view/rendering.rb", line 32, in process
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal.rb", line 191, in dispatch
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal.rb", line 252, in dispatch
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb", line 52, in dispatch
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb", line 34, in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 52, in block in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 35, in each
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 35, in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb", line 840, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/action_dispatch/routing/route_set.rb", line 14, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/fanout.rb", line 25, in instrument
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/action_dispatch/routing/route_set.rb", line 13, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb", line 524, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb", line 190, in public_send
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb", line 190, in method_missing
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb", line 19, in block in <class:Constraints>
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb", line 48, in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 52, in block in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 35, in each
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb", line 35, in serve
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb", line 840, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/action_dispatch/routing/route_set.rb", line 14, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/fanout.rb", line 25, in instrument
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/action_dispatch/routing/route_set.rb", line 13, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rollbar-2.16.4/lib/rollbar/middleware/js.rb", line 25, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-attack-6.2.2/lib/rack/attack.rb", line 170, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb", line 36, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb", line 34, in catch
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/warden-1.2.8/lib/warden/manager.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/tempfile_reaper.rb", line 17, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/etag.rb", line 27, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/conditional_get.rb", line 27, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/head.rb", line 14, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/http/content_security_policy.rb", line 18, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/session/abstract/id.rb", line 277, in context
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/session/abstract/id.rb", line 271, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/cookies.rb", line 670, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb", line 28, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb", line 98, in run_callbacks
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb", line 26, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rollbar-2.16.4/lib/rollbar/middleware/rails/rollbar.rb", line 24, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rollbar-2.16.4/lib/rollbar.rb", line 146, in scoped
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rollbar-2.16.4/lib/rollbar/middleware/rails/rollbar.rb", line 22, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/debug_exceptions.rb", line 61, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rollbar-2.16.4/lib/rollbar/middleware/rails/show_exceptions.rb", line 22, in call_with_rollbar
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/show_exceptions.rb", line 33, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/rack/logger.rb", line 38, in call_app
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/rack/logger.rb", line 26, in block in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb", line 71, in block in tagged
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb", line 28, in tagged
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb", line 71, in tagged
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/rack/logger.rb", line 26, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/ahoy_matey-3.0.1/lib/ahoy/engine.rb", line 22, in call_with_quiet_ahoy
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/remote_ip.rb", line 81, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/request_id.rb", line 27, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/action_dispatch/request_id.rb", line 12, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/method_override.rb", line 24, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/runtime.rb", line 24, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb", line 29, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb", line 14, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/static.rb", line 127, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/rack-2.1.1/lib/rack/sendfile.rb", line 113, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/ssl.rb", line 74, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/probes/middleware.rb", line 34, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/skylight-core-4.2.0/lib/skylight/core/middleware.rb", line 84, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb", line 524, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb", line 228, in call
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb", line 681, in handle_request
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb", line 472, in process_client
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/server.rb", line 328, in block in run
  File "/home/deploy/apps/immersive/shared/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/thread_pool.rb", line 134, in block in spawn_thread
Nowaker commented 4 years ago

Similar for me:

NoMethodError (undefined method `keys' for #<ActiveSupport::Cache::DalliStore:0x00007ffbfad7e3f0>)
Nowaker commented 4 years ago

I installed redis-rails gem, and configured the Rails cache store to :redis_store, and I went past it into the next problem:

NoMethodError (undefined method `without' for #<Hash:0x00007ff2776a4bb0>
Did you mean?  with_options):
  rack_attack_admin (0.1.2) app/controllers/rack_attack_admin/rack_attack_controller.rb:9:in `index'

Relevant code:

      @counters_h     = Rack::Attack.counters_h.
        without(*Rack::Attack::BannedIps.keys)
      render

Not sure where without method comes from but it's definitely not part of Ruby Hash.

Nowaker commented 4 years ago

Here's two monkey-patches to move forward:

require 'rack_attack_admin'
module RackAttackAdmin
  class RackAttackController < RackAttackAdmin::ApplicationController
    # Web version of lib/tasks/rack_attack_admin_tasks.rake
    def index
      @default_banned_ip = Rack::Attack::BannedIp.new(bantime: '60 m')
      @counters_h = Rack::Attack.counters_h.with_indifferent_access.except(*Rack::Attack::BannedIps.keys)
      render
    end
  end
end

module RackAttackAdmin
  class ApplicationController < ::ApplicationController
    helper_method \
    def is_redis?
      Rack::Attack.cache.store.to_s.match?(/Redis/)
    end
  end
end

This is all that's needed to get it working, as long as Redis Cache Store from https://github.com/redis-store/redis-rails is used. Memcached is not an option, it does not have an option to list all keys.

For Rails 4.2 specific monkey patches, see #2.