Repository navigation
Conversation
b1f108a to
58de231
Compare
|
@smortex can you rebase this PR please. |
2b88951 to
47fd6e0
Compare
@amitkarsale done. Looks like SLES 15 packages are broken (does not find |
47fd6e0 to
f8a48c7
Compare
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.
f8a48c7 to
7ac56af
Compare
span786
left a comment
There was a problem hiding this comment.
Thanks @smortex, moving MDomain out of the vhost header into one ensure_resource'd file per domain is a clean way to fix the duplicate-directive error, and CI is green. I found one regression to fix before this can be approved.
1. ensure => absent vhosts now break Apache (blocking). See the inline comment. Before this change, the MDomain line was inside the vhost's concat file, so ensure => absent removed it along with the vhost. Now mdomain-<servername>.conf is written to confd_dir regardless of ensure, but apache::mod::md is still only included when $ensure == 'present' (vhost.pp ~L2771). If mod_md isn't loaded, Apache fails to start with Invalid command 'MDomain'. I confirmed this with the spec below: the absent case fails on this branch and passes with the one-line suggestion.
2. Please add a test for the actual fix. The two existing tests were only retargeted. Nothing covers two vhosts sharing a domain or the absent case. This addition to the context 'mdomain' block in spec/defines/vhost_spec.rb (after the existing it) passes locally with the fix (90 examples, 0 failures) and is rubocop-clean:
context 'when another vhost serves the same domain on a different port' do
let :pre_condition do
<<~PUPPET
class { 'apache': default_vhost => false, default_mods => false, vhost_enable_dir => '/etc/#{apache_name}/sites-enabled' }
apache::vhost { 'rspec.example.com-ssl':
servername => 'rspec.example.com',
docroot => '/rspec/docroot',
port => 443,
mdomain => true,
}
PUPPET
end
it { is_expected.to compile.with_all_deps }
it {
expect(subject).to contain_file('rspec.example.com-mod_md')
.with_content(%r{^MDomain rspec.example.com$})
}
it { is_expected.not_to contain_concat__fragment('rspec.example.com-apache-header').with_content(%r{MDomain}) }
end
context 'when the vhost is absent' do
let :params do
default_params.merge(
'mdomain' => true,
'ensure' => 'absent',
)
end
it { is_expected.not_to contain_class('apache::mod::md') }
it { is_expected.not_to contain_file('rspec.example.com-mod_md') }
end3. Non-blocking: worth documenting. ensure_resource only de-duplicates when the parameters are identical. If two vhosts share a servername but set different mdomain values (e.g. true on one and 'example.com www.example.com' on the other), the catalog fails with a duplicate declaration error. That's arguably correct, since Apache would reject it anyway, but a note in the @param mdomain doc would help users. Also, when mdomain is later removed from a vhost, the stale mdomain-*.conf is only cleaned up if purge_configs is enabled (the default).
| content => epp('apache/vhost/_file_header.epp', $file_header_params), | ||
| } | ||
|
|
||
| if $mdomain { |
There was a problem hiding this comment.
This needs the same ensure guard as the include apache::mod::md further down. Otherwise an absent vhost leaves an MDomain directive in confd_dir without mod_md loaded, and Apache refuses to start:
| if $mdomain { | |
| if $mdomain and $ensure == 'present' { |
|
|
||
| if $mdomain { | ||
| # Multiple VHosts can configure the same domain on different ports. | ||
| # Apache will fail if multile MDomain directive are set, so ensure we define it only for the first virutal host of each domain. |
There was a problem hiding this comment.
Nit, typos:
| # Apache will fail if multile MDomain directive are set, so ensure we define it only for the first virutal host of each domain. | |
| # Apache will fail if multiple MDomain directives are set, so ensure we define it only for the first virtual host of each domain. |
span786
left a comment
There was a problem hiding this comment.
Marking as changes requested for the ensure => absent regression described in my review above: mdomain-<servername>.conf is written even for absent vhosts, while apache::mod::md is only included for present ones, so Apache fails to start with Invalid command 'MDomain'. Please apply the one-line guard on manifests/vhost.pp L2257 and add the suggested specs. Happy to approve once that's in.
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.