Skip to content

Commit 7a80f00

Browse files
committed
use upgrade=websocket where possible
1 parent d5d4921 commit 7a80f00

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

manifests/config/apache.pp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,23 @@
182182
order => '03',
183183
}
184184

185-
include apache::mod::proxy_wstunnel
186-
$websockets_backend = regsubst($_proxy_backend, 'http://', 'ws://')
185+
# mod_proxy supports "ProxyPass ... upgrade=websocket" since 2.4.47
186+
# EL8: 2.4.37 / EL9: 2.4.62 / Debian11: 2.4.62 / Ubuntu20.04: 2.4.41 / Ubuntu22.04: 2.4.52
187+
$proxy_upgrade_websocket = !($facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8') and !($facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '20.04')
188+
if $proxy_upgrade_websocket {
189+
$vhost_rewrites = []
190+
$_proxy_params = $proxy_params + ['upgrade=websocket']
191+
} else {
192+
include apache::mod::proxy_wstunnel
193+
$websockets_backend = regsubst($_proxy_backend, 'http://', 'ws://')
194+
$websockets_rewrite = {
195+
'comment' => 'Upgrade Websocket connections',
196+
'rewrite_cond' => '%{HTTP:Upgrade} =websocket [NC]',
197+
'rewrite_rule' => "/(.*) ${websockets_backend}\$1 [P,L]",
198+
}
199+
$vhost_rewrites = [ $websockets_rewrite ]
200+
$_proxy_params = $proxy_params
201+
}
187202

188203
$vhost_http_request_headers = [
189204
'set X_FORWARDED_PROTO "http"',
@@ -209,15 +224,9 @@
209224
'no_proxy_uris' => $_proxy_no_proxy_uris,
210225
'path' => pick($suburi, '/'),
211226
'url' => $_proxy_backend,
212-
'params' => $proxy_params,
227+
'params' => $_proxy_params,
213228
},
214-
'rewrites' => [
215-
{
216-
'comment' => 'Upgrade Websocket connections',
217-
'rewrite_cond' => '%{HTTP:Upgrade} =websocket [NC]',
218-
'rewrite_rule' => "/(.*) ${websockets_backend}\$1 [P,L]",
219-
},
220-
],
229+
'rewrites' => $vhost_rewrites,
221230
}
222231

223232
$vhost_https_request_headers = [

manifests/plugin/remote_execution/cockpit.pp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@
7272
require => Class['foreman::database'],
7373
}
7474
} else {
75-
include apache::mod::rewrite
76-
include apache::mod::proxy_wstunnel
7775
include apache::mod::proxy_http
76+
if $foreman::config::apache::proxy_upgrade_websocket {
77+
$_apache_template = 'cockpit-apache-ssl.conf.erb'
78+
} else {
79+
include apache::mod::rewrite
80+
include apache::mod::proxy_wstunnel
81+
$_apache_template = 'cockpit-apache-ssl-rewrite.conf.erb'
82+
}
7883
foreman::config::apache::fragment { 'cockpit':
79-
ssl_content => template('foreman/cockpit-apache-ssl.conf.erb'),
84+
ssl_content => template("foreman/${_apache_template}"),
8085
}
8186

8287
foreman_config_entry { 'remote_execution_cockpit_url':
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### File managed with puppet ###
2+
3+
<Location <%= @cockpit_path %>>
4+
ProxyPreserveHost On
5+
6+
RewriteEngine On
7+
RewriteCond %{HTTP:Upgrade} =websocket [NC]
8+
RewriteRule <%= @cockpit_path %>/(.*) ws://<%= @cockpit_host %>:<%= @cockpit_port %><%= @cockpit_path %>/$1 [P]
9+
10+
ProxyPass http://<%= @cockpit_host %>:<%= @cockpit_port %><%= @cockpit_path %>
11+
</Location>

templates/cockpit-apache-ssl.conf.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22

33
<Location <%= @cockpit_path %>>
44
ProxyPreserveHost On
5-
6-
RewriteEngine On
7-
RewriteCond %{HTTP:Upgrade} =websocket [NC]
8-
RewriteRule <%= @cockpit_path %>/(.*) ws://<%= @cockpit_host %>:<%= @cockpit_port %><%= @cockpit_path %>/$1 [P]
9-
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
10-
RewriteRule <%= @cockpit_path %>/(.*) http://<%= @cockpit_host %>:<%= @cockpit_port %><%= @cockpit_path %>/$1 [P]
5+
ProxyPass http://<%= @cockpit_host %>:<%= @cockpit_port %><%= @cockpit_path %> upgrade=websocket
116
</Location>

0 commit comments

Comments
 (0)