Skip to content

Commit 58de231

Browse files
committed
Allow to use the same domain multiple times with mod_md
When using mod_md to manage TLS certificates, a domain can only appear once as a parameter of a MDomain configuration. When a single node configue multiple Virtual Hosts to serve the same website on different IP Addresses or on different ports, and we want to use mod_md to manage the TLS certificate, the current code produce a MDomain entry in each virtual host, leading to configuration error and preventing apache from starting. This commit rework how the MDomain setting is emitted, and ensure it is only output once even if multiple Virtual Hosts configure the same domain.
1 parent 97449e4 commit 58de231

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

manifests/vhost.pp

+13-1
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,6 @@
22392239
$file_header_params = {
22402240
'comment' => $comment,
22412241
'nvh_addr_port' => $nvh_addr_port,
2242-
'mdomain' => $mdomain,
22432242
'servername' => $servername,
22442243
'define' => $define,
22452244
'protocols' => $protocols,
@@ -2257,6 +2256,19 @@
22572256
content => epp('apache/vhost/_file_header.epp', $file_header_params),
22582257
}
22592258

2259+
if $mdomain {
2260+
# Multiple VHosts can configure the same domain on different ports.
2261+
# Apache will fail if multile MDomain directive are set, so ensure we define it only for the first virutal host of each domain.
2262+
ensure_resource('file', "${servername}-mod_md", {
2263+
ensure => file,
2264+
path => "${apache::confd_dir}/mdomain-${servername}.conf",
2265+
mode => $apache::file_mode,
2266+
content => epp('apache/mdomain.epp', { mdomain => $mdomain, servername => $servername }),
2267+
require => File[$apache::confd_dir],
2268+
notify => Class['apache::service'],
2269+
})
2270+
}
2271+
22602272
if $docroot and $ensure == 'present' {
22612273
if $virtual_docroot {
22622274
include apache::mod::vhost_alias

spec/defines/vhost_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@
966966
it { is_expected.to contain_class('apache::mod::md') }
967967

968968
it {
969-
expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with(
969+
expect(subject).to contain_file('example.com-mod_md').with(
970970
content: %r{^MDomain example\.com example\.net auto$},
971971
)
972972
}
@@ -2166,7 +2166,7 @@
21662166
end
21672167

21682168
it {
2169-
expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with(
2169+
expect(subject).to contain_file('rspec.example.com-mod_md').with(
21702170
content: %r{^MDomain rspec.example.com$},
21712171
)
21722172
}

templates/mdomain.epp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%- |
2+
Variant[Boolean, String[1]] $mdomain,
3+
String[1] $servername,
4+
| -%>
5+
<%- if $mdomain { -%>
6+
<%- if $mdomain =~ String { -%>
7+
MDomain <%= $mdomain %>
8+
<%-} else {-%>
9+
MDomain <%= $servername %>
10+
<%- } -%>
11+
<% } -%>

templates/vhost/_file_header.epp

-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
# Managed by Puppet
44
# ************************************
55
<%= [$comment].flatten.map |$c| { "# ${c}" }.join("\n") -%>
6-
<%- if $mdomain { -%>
7-
8-
<%- if $mdomain =~ String { -%>
9-
10-
MDomain <%= $mdomain %>
11-
<%-} else {-%>
12-
MDomain <%= $servername %>
13-
<%- } -%>
14-
<% } -%>
156

167
<VirtualHost <%= [$nvh_addr_port].flatten().filter |$value| { $value }.join(' ') %>>
178
<% $define.each | $k, $v| { -%>

0 commit comments

Comments
 (0)