Skip to content

Commit

Permalink
Allow ips (#2998)
Browse files Browse the repository at this point in the history
Add ip addresses to allowed_hosts if servername is nil to support sites that use ip addresses.
  • Loading branch information
johrstrom authored Sep 12, 2023
1 parent 65d958c commit af2b58f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
21 changes: 20 additions & 1 deletion ood-portal-generator/lib/ood_portal_generator/view.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "digest/sha1"
require "erb"
require 'socket'

module OodPortalGenerator
# A view class that renders an OOD portal Apache configuration file
Expand Down Expand Up @@ -131,13 +132,31 @@ def log_filename(value,log_type)

def allowed_hosts
config_hosts = []
config_hosts << @servername unless @servername.nil?

add_servername_or_ips(config_hosts)
config_hosts << @proxy_server unless @proxy_server.nil?
config_hosts.concat(@server_aliases)

return nil if config_hosts.empty?

config_hosts.sort.uniq
end

def add_servername_or_ips(config_hosts)
# if @servername is nil, they're trying to use ip addresses
if @servername.nil?
config_hosts.concat(ip_addresses)
else
config_hosts << @servername
end
end

def ip_addresses
Socket.ip_address_list.select(&:ipv4?)
.reject(&:ipv4_loopback?)
.map(&:ip_address)
end

# Helper method to escape IP for maintenance rewrite condition
def escape_ip(value)
# Value is already escaped
Expand Down
1 change: 1 addition & 0 deletions ood-portal-generator/spec/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
allow(OodPortalGenerator).to receive(:debian?).and_return(false)
allow_any_instance_of(OodPortalGenerator::Dex).to receive(:default_secret_path).and_return(dex_secret_path.path)
allow(SecureRandom).to receive(:uuid).and_return('83bc78b7-6f5e-4010-9d80-22f328aa6550')
allow(Socket).to receive(:ip_address_list).and_return([Addrinfo.ip("8.8.8.8")])
end

after(:each) do
Expand Down
2 changes: 1 addition & 1 deletion ood-portal-generator/spec/fixtures/ood-portal.conf.dex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#
SetEnv OOD_PUN_STAGE_CMD "sudo /opt/ood/nginx_stage/sbin/nginx_stage"

SetEnv OOD_ALLOWED_HOSTS "example.com"
SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"

#
# Below is used for sub-uri's this Open OnDemand portal supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
#
SetEnv OOD_PUN_STAGE_CMD "sudo /opt/ood/nginx_stage/sbin/nginx_stage"

SetEnv OOD_ALLOWED_HOSTS "example.com"
SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"

#
# Below is used for sub-uri's this Open OnDemand portal supports
Expand Down
2 changes: 1 addition & 1 deletion ood-portal-generator/spec/fixtures/ood-portal.conf.nomaint
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#
SetEnv OOD_PUN_STAGE_CMD "sudo /opt/ood/nginx_stage/sbin/nginx_stage"

SetEnv OOD_ALLOWED_HOSTS "example.com"
SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"

#
# Below is used for sub-uri's this Open OnDemand portal supports
Expand Down
2 changes: 1 addition & 1 deletion ood-portal-generator/spec/fixtures/output/auth.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#
SetEnv OOD_PUN_STAGE_CMD "sudo /opt/ood/nginx_stage/sbin/nginx_stage"

SetEnv OOD_ALLOWED_HOSTS "example.com"
SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"

#
# Below is used for sub-uri's this Open OnDemand portal supports
Expand Down
2 changes: 1 addition & 1 deletion ood-portal-generator/spec/fixtures/output/auth_deb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#
SetEnv OOD_PUN_STAGE_CMD "sudo /opt/ood/nginx_stage/sbin/nginx_stage"

SetEnv OOD_ALLOWED_HOSTS "example.com"
SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"

#
# Below is used for sub-uri's this Open OnDemand portal supports
Expand Down
1 change: 1 addition & 0 deletions ood-portal-generator/spec/update_ood_portal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
allow(OodPortalGenerator).to receive(:apache_group).and_return('apache')
allow(OodPortalGenerator).to receive(:debian?).and_return(false)
allow(OodPortalGenerator).to receive(:fqdn).and_return('example.com')
allow(Socket).to receive(:ip_address_list).and_return([Addrinfo.ip("8.8.8.8")])
end

after(:each) do
Expand Down

0 comments on commit af2b58f

Please sign in to comment.