-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathapache.pp
169 lines (155 loc) · 5.57 KB
/
apache.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
# Configure an Apache vhost
# @api private
class pulpcore::apache (
Boolean $manage_selinux_boolean = true,
Stdlib::Port $http_port = 80,
Stdlib::Port $https_port = 443,
Hash[String, Any] $http_vhost_options = {},
Hash[String, Any] $https_vhost_options = {},
Enum['none', 'optional', 'require', 'optional_no_ca'] $ssl_verify_client = 'optional',
Hash $content_proxy_params = {'timeout' => '600', 'disablereuse' => 'on'},
Hash $api_proxy_params = {'timeout' => '600'},
) {
include pulpcore
$vhost_priority = $pulpcore::apache_vhost_priority
$api_path = '/pulp/api/v3'
$api_base_url = "unix://${pulpcore::api_socket_path}|http://pulpcore-api"
$api_url = "${api_base_url}${api_path}"
$content_path = '/pulp/content'
$content_base_url = "unix://${pulpcore::content_socket_path}|http://pulpcore-content"
$content_url = "${content_base_url}${content_path}"
$docroot_directory = {
'provider' => 'Directory',
'path' => $pulpcore::apache_docroot,
'options' => ['-Indexes', '-FollowSymLinks'],
'allow_override' => ['None'],
}
$content_directory = {
'path' => $content_path,
'provider' => 'location',
'proxy_pass' => [
{
'url' => $content_url,
'params' => $content_proxy_params,
},
],
'request_headers' => [
'unset X-CLIENT-CERT',
'set X-CLIENT-CERT "%{SSL_CLIENT_CERT}s" env=SSL_CLIENT_CERT',
],
}
# Pulp has a default for remote header. Here it's ensured that the end user
# can't send that header to spoof users.
$remote_user_environ_header = $pulpcore::remote_user_environ_name.regsubst(/^HTTP_/, '')
$api_default_request_headers = [
"unset ${remote_user_environ_header}",
"set ${remote_user_environ_header} \"%{SSL_CLIENT_S_DN_CN}s\" env=SSL_CLIENT_S_DN_CN",
]
$api_additional_request_headers = $pulpcore::api_client_auth_cn_map.map |String $cn, String $pulp_user| {
"set ${remote_user_environ_header} \"${pulp_user}\" \"expr=%{SSL_CLIENT_S_DN_CN} == '${cn}'\""
}
$api_directory = {
'path' => $api_path,
'provider' => 'location',
'proxy_pass' => [
{
'url' => $api_url,
'params' => $api_proxy_params,
},
],
'request_headers' => $api_default_request_headers + $api_additional_request_headers,
}
# Static content is served by the whitenoise application. SELinux prevents
# Apache from serving it directly
$proxy_pass_static = {
'path' => $pulpcore::static_url,
'url' => "${api_base_url}${pulpcore::static_url}",
}
case $pulpcore::apache_http_vhost {
true: {
$http_vhost_name = 'pulpcore'
$http_fragment = undef
include apache
include apache::mod::headers
apache::vhost { $http_vhost_name:
servername => $pulpcore::servername,
port => $http_port,
priority => $vhost_priority,
docroot => $pulpcore::apache_docroot,
manage_docroot => false,
directories => [$docroot_directory, $content_directory],
* => $http_vhost_options,
}
}
false: {
$http_vhost_name = undef
$http_fragment = undef
}
default: {
$http_vhost_name = $pulpcore::apache_http_vhost
$http_fragment = epp('pulpcore/apache-fragment.epp', {
'directories' => [$content_directory],
})
}
}
case $pulpcore::apache_https_vhost {
true: {
$https_vhost_name = 'pulpcore-https'
$https_fragment = undef
include apache
include apache::mod::headers
apache::vhost { $https_vhost_name:
servername => $pulpcore::servername,
port => $https_port,
ssl => true,
priority => $vhost_priority,
docroot => $pulpcore::apache_docroot,
manage_docroot => false,
directories => [$docroot_directory, $content_directory, $api_directory],
proxy_pass => [$proxy_pass_static],
ssl_cert => $pulpcore::apache_https_cert,
ssl_key => $pulpcore::apache_https_key,
ssl_chain => $pulpcore::apache_https_chain,
ssl_ca => $pulpcore::apache_https_ca,
ssl_verify_client => $ssl_verify_client,
ssl_options => ['+StdEnvVars', '+ExportCertData'],
* => $https_vhost_options,
}
}
false: {
$https_vhost_name = undef
$https_fragment = undef
}
default: {
$https_vhost_name = $pulpcore::apache_https_vhost
$https_fragment = epp('pulpcore/apache-fragment.epp', {
'directories' => [$content_directory, $api_directory],
'proxy_pass' => [$proxy_pass_static],
})
}
}
if $pulpcore::apache_http_vhost == true or $pulpcore::apache_https_vhost == true {
file { $pulpcore::apache_docroot:
ensure => directory,
owner => $pulpcore::user,
group => $pulpcore::group,
mode => '0755',
}
}
if $http_fragment or $https_fragment {
pulpcore::apache::fragment { 'pulpcore':
http_content => $http_fragment,
https_content => $https_fragment,
}
}
if $manage_selinux_boolean and ($pulpcore::apache_http_vhost or $pulpcore::apache_https_vhost) {
# Doesn't use selinux::boolean since that doesn't use ensure_resource which
# then conflict with the foreman module which doesn't use the selinux module.
if $facts['os']['selinux']['enabled'] {
ensure_resource('selboolean', 'httpd_can_network_connect', {
value => 'on',
persistent => true,
})
}
}
}