Skip to content

Commit

Permalink
Arbitrary apache conf (#3293)
Browse files Browse the repository at this point in the history
Add ability to add arbitrary vhost and location directives
through 2 seperate configurations in ood_portal.yml.
  • Loading branch information
johrstrom authored Jan 17, 2024
1 parent 266a0bd commit a61aef6
Show file tree
Hide file tree
Showing 23 changed files with 674 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ood-portal-generator/lib/ood_portal_generator/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def initialize(opts = {})
@map_fail_uri = opts.fetch(:map_fail_uri, nil)
@pun_stage_cmd = opts.fetch(:pun_stage_cmd, "sudo /opt/ood/nginx_stage/sbin/nginx_stage")

# custom directives
@custom_vhost_directives = opts.fetch(:custom_vhost_directives, [])
@custom_location_directives = opts.fetch(:custom_location_directives, [])

# Maintenance configuration
@use_maintenance = opts.fetch(:use_maintenance, true)
@maintenance_ip_allowlist = Array(opts.fetch(:maintenance_ip_allowlist, nil) || opts.fetch(:maintenance_ip_whitelist, []))
Expand Down
16 changes: 16 additions & 0 deletions ood-portal-generator/share/ood_portal_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@
# - 'AuthType openid-connect'
# - 'Require valid-user'

# List of custom apache directives to apply to the entire vhost.
# Note this is an array of strings.
# Example:
# custom_vhost_directives:
# - 'SetEnv SPECIAL_ENV_VAR custom'
# Default: [] (no custom directives)
#custom_vhost_directives: []

# List of custom apache directives to apply to the Locations.
# Note this is an array of strings.
# Example:
# custom_location_directives:
# - 'SetEnv SPECIAL_ENV_VAR custom'
# Default: [] (no custom directives)
#custom_location_directives: []

# Redirect user to the following URI when accessing root URI
# Example:
# root_uri: '/my_uri'
Expand Down
12 changes: 12 additions & 0 deletions ood-portal-generator/spec/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ def test_generate(input, output)
test_generate('input/no_logs_w_log_config.yml', 'output/no_logs.conf')
end

it 'templates custom vhost directives' do
test_generate('input/custom_vhost_directives.yml', 'output/custom_vhost_directives.conf')
end

it 'templates custom location directives' do
test_generate('input/custom_location_directives.yml', 'output/custom_location_directives.conf')
end

it 'templates custom location and vhost directives' do
test_generate('input/custom_directives.yml', 'output/custom_directives.conf')
end

it 'generates full OIDC config' do
config = {
servername: 'ondemand.example.com',
Expand Down
18 changes: 18 additions & 0 deletions ood-portal-generator/spec/fixtures/input/custom_directives.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
auth:
- 'AuthType openid-connect'
- 'Require valid-user'

custom_location_directives:
- 'SetEnv SPECIAL_LOCATION_ENV_VAR custom_location'
- 'SetEnv SECOND_LOCATION_VAR custom_location2'
- ' SetEnv INDENTED_LOCATION_VAR custom_location3'

custom_vhost_directives:
- SetEnv SPECIAL_VHOST_ENV_VAR custom_vhost
- SetEnv SECOND_VHOST_VAR custom_vhost2
- ' SetEnv INDENTED_VHOST_VAR custom_vhost3'
- '<Location "/foo">'
- ' SetEnv SPECIAL_VHOST_LOCATION_ENV_VAR custom_vhost4'
- '</Location>'

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
auth:
- 'AuthType openid-connect'
- 'Require valid-user'

custom_location_directives:
- SetEnv SPECIAL_LOCATION_ENV_VAR custom_location
- SetEnv SECOND_LOCATION_VAR custom_location2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
auth:
- 'AuthType openid-connect'
- 'Require valid-user'

custom_vhost_directives:
- SetEnv SPECIAL_VHOST_ENV_VAR custom_vhost
- SetEnv SECOND_VHOST_VAR custom_vhost2

6 changes: 6 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.all
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Listen 8080

SetEnv OOD_ALLOWED_HOSTS "foo.example.com,test.proxy.name,test.server.name"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand All @@ -140,6 +141,7 @@ Listen 8080
AuthType openid-connect
Require valid-user


# ProxyPassReverse implementation
Header edit Location "^[^/]+//[^/]+" ""

Expand All @@ -162,6 +164,7 @@ Listen 8080
AuthType openid-connect
Require valid-user


# ProxyPassReverse implementation
Header edit Location "^([^/]+//[^/]+)|(?=/)|^([\./]{1,}(?<!/))" "/configured-rnode/%{MATCH_HOST}e/%{MATCH_PORT}e"

Expand All @@ -185,6 +188,7 @@ Listen 8080
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/my_pun_apps"
Expand Down Expand Up @@ -215,6 +219,7 @@ Listen 8080
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -240,6 +245,7 @@ Listen 8080
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
4 changes: 4 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.dex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -126,6 +127,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -153,6 +155,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -178,6 +181,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
4 changes: 4 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.dex-full
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

SetEnv OOD_ALLOWED_HOSTS "example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -146,6 +147,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -173,6 +175,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -198,6 +201,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
4 changes: 4 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.dex-ldap
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

SetEnv OOD_ALLOWED_HOSTS "example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -146,6 +147,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -173,6 +175,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -198,6 +201,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

SetEnv OOD_ALLOWED_HOSTS "example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -140,6 +141,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -167,6 +169,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -192,6 +195,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -108,6 +109,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -135,6 +137,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand Down
3 changes: 3 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.nomaint
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

SetEnv OOD_ALLOWED_HOSTS "8.8.8.8,example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -99,6 +100,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -126,6 +128,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand Down
4 changes: 4 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.oidc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

SetEnv OOD_ALLOWED_HOSTS "ondemand.example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -128,6 +129,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -155,6 +157,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -180,6 +183,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
4 changes: 4 additions & 0 deletions ood-portal-generator/spec/fixtures/ood-portal.conf.oidc-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@

SetEnv OOD_ALLOWED_HOSTS "ondemand.example.com"


#
# Below is used for sub-uri's this Open OnDemand portal supports
#
Expand Down Expand Up @@ -144,6 +145,7 @@
AuthType openid-connect
Require valid-user


ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassReverse "http://localhost/pun"
Expand Down Expand Up @@ -171,6 +173,7 @@
AuthType openid-connect
Require valid-user


LuaHookFixups nginx.lua nginx_handler
</Location>

Expand All @@ -196,6 +199,7 @@
<Location "/oidc">
AuthType openid-connect
Require valid-user

</Location>

# Maintenance location
Expand Down
Loading

0 comments on commit a61aef6

Please sign in to comment.