|
1 | 1 | # Configure an Apache vhost |
2 | 2 | # @api private |
3 | | -class pulpcore::apache { |
| 3 | +class pulpcore::apache ( |
| 4 | + Boolean $manage_selinux_boolean = true, |
| 5 | + Stdlib::Port $http_port = 80, |
| 6 | + Stdlib::Port $https_port = 443, |
| 7 | + Hash[String, Any] $http_vhost_options = {}, |
| 8 | + Hash[String, Any] $https_vhost_options = {}, |
| 9 | + Enum['none', 'optional', 'require', 'optional_no_ca'] $ssl_verify_client = 'optional', |
| 10 | +) { |
| 11 | + $vhost_priority = $pulpcore::apache_vhost_priority |
4 | 12 | $api_path = '/pulp/api/v3' |
5 | | - $api_url = "http://${pulpcore::api_host}:${pulpcore::api_port}${api_path}" |
| 13 | + $api_base_url = "http://${pulpcore::api_host}:${pulpcore::api_port}" |
| 14 | + $api_url = "${api_base_url}${api_path}" |
6 | 15 | $content_path = '/pulp/content' |
7 | | - $content_url = "http://${pulpcore::content_host}:${pulpcore::content_port}${content_path}" |
8 | | - |
9 | | - if $pulpcore::manage_apache { |
10 | | - include apache |
11 | | - apache::vhost { 'pulpcore': |
12 | | - servername => $pulpcore::servername, |
13 | | - port => 80, |
14 | | - priority => '10', |
15 | | - docroot => $pulpcore::apache_docroot, |
16 | | - docroot_owner => $pulpcore::user, |
17 | | - docroot_group => $pulpcore::group, |
18 | | - docroot_mode => '0755', |
19 | | - manage_docroot => true, |
20 | | - proxy_pass => [ |
21 | | - { |
22 | | - 'path' => $api_path, |
23 | | - 'url' => $api_url, |
24 | | - 'reverse_urls' => [$api_url], |
25 | | - }, |
26 | | - { |
27 | | - 'path' => $content_path, |
28 | | - 'url' => $content_url, |
29 | | - 'reverse_urls' => [$content_url], |
30 | | - }, |
31 | | - ], |
| 16 | + $content_base_url = "http://${pulpcore::content_host}:${pulpcore::content_port}" |
| 17 | + $content_url = "${content_base_url}${content_path}" |
| 18 | + |
| 19 | + $docroot_directory = { |
| 20 | + 'provider' => 'Directory', |
| 21 | + 'path' => $pulpcore::apache_docroot, |
| 22 | + 'options' => ['-Indexes', '-FollowSymLinks'], |
| 23 | + 'allow_override' => ['None'], |
| 24 | + } |
| 25 | + $content_directory = { |
| 26 | + 'path' => $content_path, |
| 27 | + 'provider' => 'location', |
| 28 | + 'proxy_pass' => [ |
| 29 | + { |
| 30 | + 'url' => $content_url, |
| 31 | + }, |
| 32 | + ], |
| 33 | + 'request_headers' => [ |
| 34 | + 'unset X-CLIENT-CERT', |
| 35 | + 'set X-CLIENT-CERT "%{SSL_CLIENT_CERT}s" env=SSL_CLIENT_CERT', |
| 36 | + ], |
| 37 | + } |
| 38 | + |
| 39 | + # Pulp has a default for remote header. Here it's ensured that the end user |
| 40 | + # can't send that header to spoof users. |
| 41 | + $remote_user_environ_header = $pulpcore::remote_user_environ_name.regsubst(/^HTTP_/, '') |
| 42 | + $api_directory = { |
| 43 | + 'path' => $api_path, |
| 44 | + 'provider' => 'location', |
| 45 | + 'proxy_pass' => [ |
| 46 | + { |
| 47 | + 'url' => $api_url, |
| 48 | + }, |
| 49 | + ], |
| 50 | + 'request_headers' => [ |
| 51 | + "unset ${remote_user_environ_header}", |
| 52 | + "set ${remote_user_environ_header} \"%{SSL_CLIENT_S_DN_CN}s\" env=SSL_CLIENT_S_DN_CN", |
| 53 | + ], |
| 54 | + } |
| 55 | + |
| 56 | + # Static content is served by the whitenoise application. SELinux prevents |
| 57 | + # Apache from serving it directly |
| 58 | + $proxy_pass_static = { |
| 59 | + 'path' => $pulpcore::static_url, |
| 60 | + 'url' => "${api_base_url}${pulpcore::static_url}", |
| 61 | + } |
| 62 | + |
| 63 | + case $pulpcore::apache_http_vhost { |
| 64 | + true: { |
| 65 | + $http_vhost_name = 'pulpcore' |
| 66 | + $http_fragment = undef |
| 67 | + |
| 68 | + include apache |
| 69 | + include apache::mod::headers |
| 70 | + apache::vhost { $http_vhost_name: |
| 71 | + servername => $pulpcore::servername, |
| 72 | + port => $http_port, |
| 73 | + priority => $vhost_priority, |
| 74 | + docroot => $pulpcore::apache_docroot, |
| 75 | + manage_docroot => false, |
| 76 | + directories => [$docroot_directory, $content_directory], |
| 77 | + * => $http_vhost_options, |
| 78 | + } |
| 79 | + } |
| 80 | + false: { |
| 81 | + $http_vhost_name = undef |
| 82 | + $http_fragment = undef |
| 83 | + } |
| 84 | + default: { |
| 85 | + $http_vhost_name = $pulpcore::apache_http_vhost |
| 86 | + $http_fragment = epp('pulpcore/apache-fragment.epp', { |
| 87 | + 'directories' => [$content_directory], |
| 88 | + }) |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + case $pulpcore::apache_https_vhost { |
| 93 | + true: { |
| 94 | + $https_vhost_name = 'pulpcore-https' |
| 95 | + $https_fragment = undef |
| 96 | + |
| 97 | + include apache |
| 98 | + include apache::mod::headers |
| 99 | + apache::vhost { $https_vhost_name: |
| 100 | + servername => $pulpcore::servername, |
| 101 | + port => $https_port, |
| 102 | + ssl => true, |
| 103 | + priority => $vhost_priority, |
| 104 | + docroot => $pulpcore::apache_docroot, |
| 105 | + manage_docroot => false, |
| 106 | + directories => [$docroot_directory, $content_directory, $api_directory], |
| 107 | + proxy_pass => [$proxy_pass_static], |
| 108 | + ssl_cert => $pulpcore::apache_https_cert, |
| 109 | + ssl_key => $pulpcore::apache_https_key, |
| 110 | + ssl_chain => $pulpcore::apache_https_chain, |
| 111 | + ssl_ca => $pulpcore::apache_https_ca, |
| 112 | + ssl_verify_client => $ssl_verify_client, |
| 113 | + * => $https_vhost_options, |
| 114 | + } |
| 115 | + } |
| 116 | + false: { |
| 117 | + $https_vhost_name = undef |
| 118 | + $https_fragment = undef |
| 119 | + } |
| 120 | + default: { |
| 121 | + $https_vhost_name = $pulpcore::apache_https_vhost |
| 122 | + $https_fragment = epp('pulpcore/apache-fragment.epp', { |
| 123 | + 'directories' => [$content_directory, $api_directory], |
| 124 | + 'proxy_pass' => [$proxy_pass_static], |
| 125 | + }) |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + if $pulpcore::apache_http_vhost == true or $pulpcore::apache_https_vhost == true { |
| 130 | + file { $pulpcore::apache_docroot: |
| 131 | + ensure => directory, |
| 132 | + owner => $pulpcore::user, |
| 133 | + group => $pulpcore::group, |
| 134 | + mode => '0755', |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + if $http_fragment or $https_fragment { |
| 139 | + pulpcore::apache::fragment { 'pulpcore': |
| 140 | + http_content => $http_fragment, |
| 141 | + https_content => $https_fragment, |
32 | 142 | } |
| 143 | + } |
33 | 144 |
|
| 145 | + if $manage_selinux_boolean and ($pulpcore::apache_http_vhost or $pulpcore::apache_https_vhost) { |
| 146 | + # Doesn't use selinux::boolean since that doesn't use ensure_resource which |
| 147 | + # then conflict with the foreman module which doesn't use the selinux module. |
34 | 148 | if $facts['os']['selinux']['enabled'] { |
35 | | - selinux::boolean { 'httpd_can_network_connect': } |
| 149 | + ensure_resource('selboolean', 'httpd_can_network_connect', { |
| 150 | + value => 'on', |
| 151 | + persistent => true, |
| 152 | + }) |
36 | 153 | } |
37 | 154 | } |
38 | 155 | } |
0 commit comments