Skip to content

Commit 2349ba7

Browse files
committed
(maint) Allow using mod_md for managing certificates
Add a $mdomain parameter to apache::vhost. When set to true, the certifcate configuration is automatically managed by mod_md. It is also possible to use an explicit String to fully control the Subject Alternative Names of the requested certificate.
1 parent 73fe071 commit 2349ba7

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

manifests/vhost.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@
17221722
# value of the $servername parameter.
17231723
# When set to false (default), the existing behaviour of using the $name parameter
17241724
# will remain.
1725+
#
1726+
# @param $mdomain
1727+
# All the names in the list are managed as one Managed Domain (MD). mod_md will request
1728+
# one single certificate that is valid for all these names.
17251729

17261730
define apache::vhost (
17271731
Variant[Boolean,String] $docroot,
@@ -1971,6 +1975,7 @@
19711975
Hash $define = {},
19721976
Boolean $auth_oidc = false,
19731977
Optional[Apache::OIDCSettings] $oidc_settings = undef,
1978+
Optional[Variant[Boolean,String]] $mdomain = undef,
19741979
) {
19751980
# The base class must be included first because it is used by parameter defaults
19761981
if ! defined(Class['apache']) {
@@ -2771,6 +2776,10 @@
27712776
}
27722777
}
27732778

2779+
if $mdomain {
2780+
include apache::mod::md
2781+
}
2782+
27742783
# Template uses:
27752784
# - $passenger_enabled
27762785
# - $passenger_start_timeout

spec/defines/vhost_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@
484484
'RemoteUserClaim' => 'sub',
485485
'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8',
486486
'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' },
487+
'mdomain' => 'example.com example.net auto',
487488
}
488489
end
489490

@@ -1483,6 +1484,12 @@
14831484
content: %r{^\s+OIDCCryptoPassphrase\s4ad1bb46-9979-450e-ae58-c696967df3cd$},
14841485
)
14851486
}
1487+
it { is_expected.to contain_class('apache::mod::md') }
1488+
it {
1489+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
1490+
content: %r{^MDomain example\.com example\.net auto$},
1491+
)
1492+
}
14861493
end
14871494
context 'vhost with multiple ip addresses' do
14881495
let :params do
@@ -2451,6 +2458,19 @@
24512458
it { is_expected.not_to compile }
24522459
end
24532460
end
2461+
context 'mdomain' do
2462+
let :params do
2463+
default_params.merge(
2464+
'mdomain' => true,
2465+
)
2466+
end
2467+
2468+
it {
2469+
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
2470+
content: %r{^MDomain rspec.example.com$},
2471+
)
2472+
}
2473+
end
24542474
end
24552475
end
24562476
end

templates/vhost/_file_header.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
# Managed by Puppet
44
# ************************************
55
<%= [@comment].flatten.collect{|c| "# #{c}"}.join("\n") -%>
6+
<% if @mdomain -%>
7+
8+
<%- if @mdomain.is_a?(String) -%>
9+
MDomain <%= @mdomain %>
10+
<%- else -%>
11+
MDomain <%= @servername %>
12+
<%- end -%>
13+
<% end -%>
614

715
<VirtualHost <%= [@nvh_addr_port].flatten.compact.join(' ') %>>
816
<% @define.each do | k, v| -%>

templates/vhost/_ssl.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## SSL directives
44
SSLEngine on
5+
<%- unless @mdomain -%>
56
SSLCertificateFile "<%= @ssl_cert %>"
67
SSLCertificateKeyFile "<%= @ssl_key %>"
8+
<%- end -%>
79
<%- if @ssl_chain -%>
810
SSLCertificateChainFile "<%= @ssl_chain %>"
911
<%- end -%>

0 commit comments

Comments
 (0)