|
1 | 1 | # Configure an Apache vhost |
2 | 2 | # @api private |
3 | | -class pulpcore::apache { |
| 3 | +class pulpcore::apache ( |
| 4 | + String[1] $vhost_priority = '10', |
| 5 | + Stdlib::Port $http_port = 80, |
| 6 | + Stdlib::Port $https_port = 443, |
| 7 | +) { |
4 | 8 | $api_path = '/pulp/api/v3' |
5 | 9 | $api_url = "http://${pulpcore::api_host}:${pulpcore::api_port}${api_path}" |
6 | 10 | $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::webserver_static_dir, |
16 | | - proxy_pass => [ |
17 | | - { |
18 | | - 'path' => $api_path, |
19 | | - 'url' => $api_url, |
20 | | - 'reverse_urls' => [$api_url], |
21 | | - }, |
22 | | - { |
23 | | - 'path' => $content_path, |
24 | | - 'url' => $content_url, |
25 | | - 'reverse_urls' => [$content_url], |
26 | | - }, |
| 11 | + $content_base_url = "http://${pulpcore::content_host}:${pulpcore::content_port}" |
| 12 | + $content_url = "${content_base_url}${content_path}" |
| 13 | + |
| 14 | + $base_directories = [ |
| 15 | + { |
| 16 | + provider => 'directory', |
| 17 | + path => $pulpcore::webserver_static_dir, |
| 18 | + options => ['Indexes','FollowSymLinks'], |
| 19 | + allow_override => ['None'], |
| 20 | + }, |
| 21 | + { |
| 22 | + 'path' => $content_path, |
| 23 | + 'provider' => 'location', |
| 24 | + 'request_headers' => [ |
| 25 | + 'unset X-CLIENT-CERT', |
| 26 | + 'set X-CLIENT-CERT "%{SSL_CLIENT_CERT}s" env=SSL_CLIENT_CERT', |
27 | 27 | ], |
| 28 | + }, |
| 29 | + ] |
| 30 | + |
| 31 | + if $pulpcore::remote_user_environ_name { |
| 32 | + $remote_user_environ_header = $pulpcore::remote_user_environ_name.regsubst(/^HTTP_/, '') |
| 33 | + $api_directories = [ |
| 34 | + { |
| 35 | + 'path' => $api_path, |
| 36 | + 'provider' => 'location', |
| 37 | + 'request_headers' => [ |
| 38 | + "unset ${remote_user_environ_header}", |
| 39 | + "set ${remote_user_environ_header} \"%{SSL_CLIENT_S_DN_CN}s\" env=SSL_CLIENT_S_DN_CN", |
| 40 | + ], |
| 41 | + }, |
| 42 | + ] |
| 43 | + } else { |
| 44 | + $api_directories = [] |
| 45 | + } |
| 46 | + |
| 47 | + $proxy_pass_content = { |
| 48 | + 'path' => $content_path, |
| 49 | + 'url' => $content_url, |
| 50 | + } |
| 51 | + |
| 52 | + $proxy_pass_api = { |
| 53 | + 'path' => $api_path, |
| 54 | + 'url' => $api_url, |
| 55 | + } |
| 56 | + |
| 57 | + case $pulpcore::apache_http_vhost { |
| 58 | + true: { |
| 59 | + $http_vhost_name = 'pulpcore' |
| 60 | + $http_fragment = undef |
| 61 | + |
| 62 | + include apache |
| 63 | + include apache::mod::headers |
| 64 | + apache::vhost { $http_vhost_name: |
| 65 | + servername => $pulpcore::servername, |
| 66 | + port => $http_port, |
| 67 | + priority => $vhost_priority, |
| 68 | + docroot => $pulpcore::webserver_static_dir, |
| 69 | + directories => $base_directories, |
| 70 | + proxy_pass => [$proxy_pass_content], |
| 71 | + } |
28 | 72 | } |
| 73 | + false: { |
| 74 | + $http_vhost_name = undef |
| 75 | + $http_fragment = undef |
| 76 | + } |
| 77 | + default: { |
| 78 | + $http_vhost_name = $pulpcore::apache_http_vhost |
| 79 | + $http_fragment = epp('pulpcore/apache-fragment.epp', {'proxy_pass' => [$proxy_pass_content]}) |
29 | 80 |
|
30 | | - if $facts['os']['selinux']['enabled'] { |
31 | | - selinux::boolean { 'httpd_can_network_connect': } |
32 | 81 | } |
33 | 82 | } |
| 83 | + |
| 84 | + case $pulpcore::apache_https_vhost { |
| 85 | + true: { |
| 86 | + $https_vhost_name = 'pulpcore-https' |
| 87 | + $https_fragment = undef |
| 88 | + |
| 89 | + include apache |
| 90 | + include apache::mod::headers |
| 91 | + apache::vhost { $https_vhost_name: |
| 92 | + servername => $pulpcore::servername, |
| 93 | + port => $https_port, |
| 94 | + ssl => true, |
| 95 | + priority => $vhost_priority, |
| 96 | + docroot => $pulpcore::webserver_static_dir, |
| 97 | + directories => $base_directories + $api_directories, |
| 98 | + proxy_pass => [$proxy_pass_api, $proxy_pass_content], |
| 99 | + } |
| 100 | + } |
| 101 | + false: { |
| 102 | + $https_vhost_name = undef |
| 103 | + $https_fragment = undef |
| 104 | + } |
| 105 | + default: { |
| 106 | + $https_vhost_name = $pulpcore::apache_https_vhost |
| 107 | + $https_fragment = epp('pulpcore/apache-fragment.epp', {'proxy_pass' => [$proxy_pass_api, $proxy_pass_content]}) |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + if $http_fragment or $https_fragment { |
| 112 | + pulpcore::apache::fragment { 'pulpcore': |
| 113 | + http_content => $http_fragment, |
| 114 | + https_content => $https_fragment, |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + # TODO: should this be in the selinux policy? |
| 119 | + if $pulpcore::apache_http_vhost or $pulpcore::apache_https_vhost { |
| 120 | + selinux::boolean { 'httpd_can_network_connect': } |
| 121 | + } |
34 | 122 | } |
0 commit comments