Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Constraint for Rails 3 routes by IP whitelist
Ruby JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
README.md
Rakefile
firewall_constraint.gemspec

README.md

FirewallConstraint

Easy whitelist firewalling for Rails 3 route constraints

gem 'firewall_constraint'

Or:

gem install firewall_constraint

config/routes.rb:

get 'dummy/index' => 'dummy#index'
get 'dummy/blocked_by_inline' => 'dummy#blocked_by_inline', :constraints => FirewallConstraint.new

constraints FirewallConstraint.new do
  get 'dummy/blocked_by_block' => 'dummy#blocked_by_block'
end

constraints FirewallConstraint.new(['127.0.0.1']) do
  get 'dummy/blocked_by_dynamic' => 'dummy#blocked_by_dynamic'
end

constraints FirewallConstraint.new(Proc.new{['127.0.0.1']}) do
  get 'dummy/blocked_by_proc'
end

Uses a config file if ips not present in routes

config/firewall_constraint.yml:

test:
  - 10.0.0.0/8

You should be able to do DB-based whitelisting using the Proc whitelisting and an activerecord lookup or something similar to:

constraints FirewallConstraint.new(Proc.new{ValidIps.all.map{|x| x.ip}})
Something went wrong with that request. Please try again.