HostAccess AuthProvider class – restricts access to requests coming from a list of netblocks.
You can configure which ones from the auth
section of the
config:
auth: allowed_netblocks: - 127.0.0.0/8 - 10.5.3.0/22
The default list of netblocks to allow
An Array of IPAddr objects that represent the netblocks that will be allowed access to the protected resources
Create a new Default AuthProvider.
# File lib/strelka/authprovider/hostaccess.rb, line 41
def initialize( * )
super
self.allowed_netblocks = DEFAULT_ALLOWED_NETBLOCKS
# Register this instance with Configurability
config_key :hostaccess
end
Set the list of allowed netblocks to newblocks
.
# File lib/strelka/authprovider/hostaccess.rb, line 61
def allowed_netblocks=( newblocks )
@allowed_netblocks = Array( newblocks ).map {|addr| IPAddr.new(addr) }
end
Configurability API – configure the auth provider instance.
# File lib/strelka/authprovider/hostaccess.rb, line 67
def configure( config=nil )
self.log.debug "Configuring %p with config: %p" % [ self, config ]
if config && config['allowed_netblocks']
self.allowed_netblocks = config['allowed_netblocks']
else
self.allowed_netblocks = DEFAULT_ALLOWED_NETBLOCKS
end
end
Returns true
if the given ipaddr
is in the allowed_netblocks.
# File lib/strelka/authprovider/hostaccess.rb, line 91
def in_allowed_netblocks?( ipaddr )
return self.allowed_netblocks.any? {|nb| nb.include?(ipaddr) }
end