How to disable “Cannot Render Console from…” on Rails

后端 未结 11 1283
心在旅途
心在旅途 2020-12-07 10:35

I\'m using Ubuntu/vagrant as my development environment. I\'m getting these messages on rails console:

Started GET \"/assets/home-fcec5b5a277ac7c20cc9f45a209         


        
相关标签:
11条回答
  • 2020-12-07 11:02

    Anyone on any of my private networks is welcome.

    I run in a docker container and I don't care which network it wants to use this week.

    config/environments/development.rb add line

    config.web_console.whitelisted_ips = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']
    
    0 讨论(0)
  • 2020-12-07 11:03
    class Application < Rails::Application
      config.web_console.whitelisted_ips = %w( 0.0.0.0/0 ::/0 )
    end
    
    0 讨论(0)
  • If you run your site locally (on the host) it generally works out, since 127.0.0.1 is always permitted. But if you're going to put your site into a container (not in production, locally), you might want to add this into config/environments/development.rb:

    require 'socket'
    require 'ipaddr'
    Rails.application.configure do
      ...
      config.web_console.permissions = Socket.getifaddrs
        .select { |ifa| ifa.addr.ipv4_private? }
        .map { |ifa| IPAddr.new(ifa.addr.ip_address + '/' + ifa.netmask.ip_address) }
      ...
    end
    

    P.S. Most of the time you want it to whine (don't want to do config.web_console.whiny_requests = false). Because it might mean you're running web-console in production (which you shouldn't do).

    0 讨论(0)
  • 2020-12-07 11:05

    For development environment: Detect if it's docker, then determine the IP address and whitelist it

    # config/environments/development.rb
    require 'socket'
    require 'ipaddr'
    
    Rails.application.configure do
      ...
    
      # When inside a docker container
      if File.file?('/.dockerenv')
        # Whitelist docker ip for web console
        # Cannot render console from 172.27.0.1! Allowed networks: 127.0.0.1
        Socket.ip_address_list.each do |addrinfo|
          next unless addrinfo.ipv4?
          next if addrinfo.ip_address == "127.0.0.1" # Already whitelisted
    
          ip = IPAddr.new(addrinfo.ip_address).mask(24)
    
          Logger.new(STDOUT).info "Adding #{ip.inspect} to config.web_console.whitelisted_ips"
    
          config.web_console.whitelisted_ips << ip
        end
      end
    end
    

    For me this prints the following and the warning goes away

    0 讨论(0)
  • 2020-12-07 11:05

    If you want to stop seeing this error message you can add this line in development.rb

    config.web_console.whiny_requests = false
    
    0 讨论(0)
提交回复
热议问题