A simple way to create a white list of IPs that can do something. We create it to restrict some routes to work just for some IPs.
If you are using Ruby on Rails you can add our constraints
to restrict the access to sidekiq
web interface.
Add this line to your application's Gemfile:
gem 'ip_restriction'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ip_restriction
Create a yml file with the list of IPs. IPV4 or IPV6
ips:
- 10.20.30.1/24
- 192.168.1.1/22
- 2001:db8::/32
Configure the IpRestriction to load your yml file.
IpRestriction.configure do |config|
config.file_path = '/path/to/ips.yml'
end
Then in you routes add a constraint.
mount Sidekiq::Web, at: '/sidekiq', constraints: IpRestriction::AllowedIpsConstraint.new
require 'ip_restriction/middleware'
use IpRestriction::Middleware
map '/sidekiq' do
use IpRestriction::Middleware
mount Sidekiq::web
end
You can check if an IP is allowed manually.
checker = IpRestriction::IpChecker.new(['10.20.30.0/24'])
checker.allowed?('10.20.30.100')
# => true
checker.allowed?('10.10.30.100')
# => false
- André Souza (@andrerocker)
- Bruno Alvares da Costa (@brunoadacosta)
- Eron Junior
- Fabio Perrella (@fabioperrella)
- Fernando Amorim (@prodis)
- Marcio Trindade (@marciotrindade)
- Fork it ( https://github.com/locaweb/ip_restriction/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request