Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active January 24, 2021 11:42
Show Gist options
  • Select an option

  • Save x-yuri/a927feb755e451bda2ab5ac46f3faa5a to your computer and use it in GitHub Desktop.

Select an option

Save x-yuri/a927feb755e451bda2ab5ac46f3faa5a to your computer and use it in GitHub Desktop.
#web-console #ruby #rails #docker

web-console: allow private networks

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

Alternatively:

require 'socket'
require 'ipaddr'
Rails.application.configure do
  ...
  config.web_console.permissions =  Socket.getifaddrs.select { |ifa| ifa.addr.ipv4_private? }
    .map { |ifa| '%s/%s' % [
      ifa.addr.ip_address,
      IPAddr.new(ifa.netmask.ip_address).to_i.digits(2).select{ |d| d == 1 }.length,
    ] }
  ...
end

Before web-console-4.0 the setting name is whitelisted_ips.

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