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