92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
# File 'manifests/config/apache.pp', line 92
class foreman::config::apache (
Stdlib::Absolutepath $app_root = '/usr/share/foreman',
String $priority = '05',
Stdlib::Fqdn $servername = $facts['networking']['fqdn'],
Array[Stdlib::Fqdn] $serveraliases = [],
Stdlib::Port $server_port = 80,
Stdlib::Port $server_ssl_port = 443,
Pattern['^(https?|unix)://'] $proxy_backend = 'unix:///run/foreman.sock',
Boolean $proxy_add_headers = true,
Hash $proxy_params = { 'retry' => '0' },
Array[String] $proxy_no_proxy_uris = ['/pulp', '/pub', '/icons', '/images', '/server-status'],
Boolean $proxy_assets = false,
Boolean $ssl = false,
Optional[Stdlib::Absolutepath] $ssl_ca = undef,
Optional[Stdlib::Absolutepath] $ssl_chain = undef,
Optional[Stdlib::Absolutepath] $ssl_cert = undef,
Optional[Stdlib::Absolutepath] $ssl_key = undef,
Variant[Undef, Enum[''], Stdlib::Absolutepath] $ssl_crl = undef,
Optional[String] $ssl_protocol = undef,
Enum['none','optional','require','optional_no_ca'] $ssl_verify_client = 'optional',
Optional[String] $user = undef,
Optional[Stdlib::HTTPUrl] $foreman_url = undef,
Optional[String] $access_log_format = undef,
Boolean $ipa_authentication = false,
Hash[String, Any] $http_vhost_options = {},
Hash[String, Any] $https_vhost_options = {},
Boolean $keycloak = false,
String[1] $keycloak_app_name = 'foreman-openidc',
String[1] $keycloak_realm = 'ssl-realm',
Array[String[1]] $request_headers_to_unset = [
'REMOTE-USER',
'REMOTE_USER',
'REMOTE-USER-EMAIL',
'REMOTE-USER_EMAIL',
'REMOTE_USER-EMAIL',
'REMOTE_USER_EMAIL',
'REMOTE-USER-FIRSTNAME',
'REMOTE-USER_FIRSTNAME',
'REMOTE_USER-FIRSTNAME',
'REMOTE_USER_FIRSTNAME',
'REMOTE-USER-LASTNAME',
'REMOTE-USER_LASTNAME',
'REMOTE_USER-LASTNAME',
'REMOTE_USER_LASTNAME',
'REMOTE-USER-GROUPS',
'REMOTE-USER_GROUPS',
'REMOTE_USER-GROUPS',
'REMOTE_USER_GROUPS',
],
) {
$docroot = "${app_root}/public"
if $proxy_backend =~ 'unix://' {
$_proxy_backend = "${proxy_backend}|http://foreman/"
} else {
$_proxy_backend = regsubst($proxy_backend, 'tcp://', 'http://')
}
if $foreman_url {
$suburi_parts = split($foreman_url, '/')
$suburi_parts_count = size($suburi_parts) - 1
if $suburi_parts_count >= 3 {
$suburi_without_slash = join(values_at($suburi_parts, ["3-${suburi_parts_count}"]), '/')
if $suburi_without_slash {
$suburi = "/${suburi_without_slash}"
} else {
$suburi = undef
}
} else {
$suburi = undef
}
} else {
$suburi = undef
}
if $suburi {
$custom_fragment = undef
} else {
# mod_env, mod_expires and mod_rewrite are required by configuration in _assets.conf.erb
include apache::mod::env
include apache::mod::rewrite
# apache::mod::expires pulls in a config file we don't want, like apache::default_mods
# It uses ensure_resource to be compatible with both $apache::default_mods set to true and false
include apache
ensure_resource('apache::mod', 'expires')
$custom_fragment = file('foreman/_assets.conf.erb')
}
# This sets the headers matching what $vhost_https_internal_options sets
foreman::settings_fragment { 'reverse-proxy-headers.yaml':
content => file('foreman/settings-reverse-proxy-headers.yaml'),
order => '03',
}
$vhost_http_request_headers = [
'set X_FORWARDED_PROTO "http"',
'set SSL_CLIENT_S_DN ""',
'set SSL_CLIENT_CERT ""',
'set SSL_CLIENT_VERIFY ""',
] +
$request_headers_to_unset.map |$header| {
"unset ${header}"
}
if $proxy_assets {
$_proxy_no_proxy_uris = $proxy_no_proxy_uris
} else {
$_proxy_no_proxy_uris = $proxy_no_proxy_uris + ['/webpack', '/assets']
}
$vhost_http_internal_options = {
'proxy_preserve_host' => true,
'proxy_add_headers' => $proxy_add_headers,
'request_headers' => $vhost_http_request_headers,
'proxy_pass' => {
'no_proxy_uris' => $_proxy_no_proxy_uris,
'path' => pick($suburi, '/'),
'url' => $_proxy_backend,
'params' => $proxy_params + { 'upgrade' => 'websocket' },
},
}
$vhost_https_request_headers = [
'set X_FORWARDED_PROTO "https"',
'set SSL_CLIENT_S_DN "%{SSL_CLIENT_S_DN}s"',
'set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"',
'set SSL_CLIENT_VERIFY "%{SSL_CLIENT_VERIFY}s"',
] +
$request_headers_to_unset.map |$header| {
"unset ${header}"
}
$vhost_https_internal_options = $vhost_http_internal_options + {
'ssl_proxyengine' => true,
'request_headers' => $vhost_https_request_headers,
}
if $facts['os']['selinux']['enabled'] {
selboolean { 'httpd_can_network_connect':
persistent => true,
value => 'on',
}
}
include apache
include apache::mod::headers
if $ipa_authentication {
include apache::mod::authnz_pam
include apache::mod::auth_basic
include apache::mod::intercept_form_submit
include apache::mod::lookup_identity
include apache::mod::auth_gssapi
} elsif $keycloak {
include apache::mod::auth_openidc
# This file is generated by keycloak-httpd-client-install and that manages
# the content. The command would be:
#
# keycloak-httpd-client-install --app-name ${keycloak_app_name} --keycloak-server-url $KEYCLOAK_URL --keycloak-admin-username $KEYCLOAK_USER --keycloak-realm ${keycloak_realm} --keycloak-admin-realm master --keycloak-auth-role root-admin --client-type openidc --client-hostname ${servername} --protected-locations /users/extlogin
#
# If $suburi is used, --location-root should also be passed in
#
# By defining it here we avoid purging it and also tighten the
# permissions so the world can't read its secrets.
# This is functionally equivalent to apache::custom_config without content/source
file { "${apache::confd_dir}/${keycloak_app_name}_oidc_keycloak_${keycloak_realm}.conf":
ensure => file,
owner => 'root',
group => 'root',
mode => '0640',
}
}
file { "${apache::confd_dir}/${priority}-foreman.d":
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0644',
purge => true,
recurse => true,
}
apache::vhost { 'foreman':
add_default_charset => 'UTF-8',
docroot => $docroot,
manage_docroot => false,
options => ['SymLinksIfOwnerMatch'],
port => $server_port,
priority => $priority,
servername => $servername,
serveraliases => $serveraliases,
access_log_format => $access_log_format,
additional_includes => ["${apache::confd_dir}/${priority}-foreman.d/*.conf"],
use_optional_includes => true,
custom_fragment => $custom_fragment,
* => $vhost_http_internal_options + $http_vhost_options,
}
if $ssl {
if $ssl_crl and $ssl_crl != '' {
$ssl_crl_real = $ssl_crl
$ssl_crl_check = 'chain'
} else {
$ssl_crl_real = undef
$ssl_crl_check = undef
}
file { "${apache::confd_dir}/${priority}-foreman-ssl.d":
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0644',
purge => true,
recurse => true,
}
apache::vhost { 'foreman-ssl':
add_default_charset => 'UTF-8',
docroot => $docroot,
manage_docroot => false,
options => ['SymLinksIfOwnerMatch'],
port => $server_ssl_port,
priority => $priority,
servername => $servername,
serveraliases => $serveraliases,
ssl => true,
ssl_cert => $ssl_cert,
ssl_key => $ssl_key,
ssl_chain => $ssl_chain,
ssl_ca => $ssl_ca,
ssl_crl => $ssl_crl_real,
ssl_crl_check => $ssl_crl_check,
ssl_protocol => $ssl_protocol,
ssl_verify_client => $ssl_verify_client,
ssl_options => '+StdEnvVars +ExportCertData',
ssl_verify_depth => 3,
access_log_format => $access_log_format,
additional_includes => ["${apache::confd_dir}/${priority}-foreman-ssl.d/*.conf"],
use_optional_includes => true,
custom_fragment => $custom_fragment,
* => $vhost_https_internal_options + $https_vhost_options,
}
}
}
|