Skip to content

Commit db784cd

Browse files
committed
allow configuration of multiple ssl certificates and keys
1 parent 63b75aa commit db784cd

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

manifests/resource/server.pp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
# Pre-generated SSL Certificate file to reference for SSL Support. This is
8787
# not generated by this module. Set to `false` to inherit from the http
8888
# section, which improves performance by conserving memory.
89+
# Use an array to add multiple SSL Certificates.
8990
# @param ssl_client_cert
9091
# Pre-generated SSL Certificate file to reference for client verify SSL
9192
# Support. This is not generated by this module.
@@ -111,6 +112,7 @@
111112
# Pre-generated SSL Key file to reference for SSL Support. This is not
112113
# generated by this module. Set to `false` to inherit from the http section,
113114
# which improves performance by conserving memory.
115+
# Use an array to add multiple SSL Keys.
114116
# @param ssl_port
115117
# Default IP Port for NGINX to listen with this SSL server on.
116118
# @param ssl_protocols
@@ -294,14 +296,14 @@
294296
Hash $add_header = {},
295297
Boolean $ssl = false,
296298
Boolean $ssl_listen_option = true,
297-
Optional[Variant[String, Boolean]] $ssl_cert = undef,
299+
Optional[Variant[String, Boolean, Array[String]]] $ssl_cert = undef,
298300
Optional[String] $ssl_client_cert = undef,
299301
String $ssl_verify_client = 'on',
300302
Optional[String] $ssl_dhparam = undef,
301303
Optional[String] $ssl_ecdh_curve = undef,
302304
Boolean $ssl_redirect = false,
303305
Optional[Integer] $ssl_redirect_port = undef,
304-
Optional[Variant[String, Boolean]] $ssl_key = undef,
306+
Optional[Variant[String, Boolean, Array[String]]] $ssl_key = undef,
305307
Integer $ssl_port = 443,
306308
Optional[Enum['on', 'off']] $ssl_prefer_server_ciphers = undef,
307309
Optional[String] $ssl_protocols = undef,
@@ -592,8 +594,23 @@
592594
if $ssl {
593595
# Access and error logs are named differently in ssl template
594596

595-
File <| title == $ssl_cert or path == $ssl_cert or title == $ssl_key or path == $ssl_key |>
596-
-> concat::fragment { "${name_sanitized}-ssl-header":
597+
if $ssl_key {
598+
$ssl_key_real = $ssl_key.flatten
599+
$ssl_key_real.each | $key | {
600+
File <| title == $key or path == $key |> {
601+
before => Concat::Fragment["${name_sanitized}-ssl-header"],
602+
}
603+
}
604+
}
605+
if $ssl_cert {
606+
$ssl_cert_real = $ssl_cert.flatten
607+
$ssl_cert_real.each | $cert | {
608+
File <| title == $cert or path == $cert |> {
609+
before => Concat::Fragment["${name_sanitized}-ssl-header"],
610+
}
611+
}
612+
}
613+
concat::fragment { "${name_sanitized}-ssl-header":
597614
target => $config_file,
598615
content => template('nginx/server/server_ssl_header.erb'),
599616
order => '700',

spec/defines/resource_server_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,19 @@
12501250
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").without_content(%r{ssl_certificate_key}) }
12511251
end
12521252

1253+
context 'SSL cert and key are both an array' do
1254+
let(:params) { {
1255+
ssl: true,
1256+
ssl_cert: ['/tmp/foo1.crt', '/tmp/foo2.crt'],
1257+
ssl_key: ['/tmp/foo1.key', '/tmp/foo2.key'],
1258+
} }
1259+
1260+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate\s+/tmp/foo1.crt}) }
1261+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate_key\s+/tmp/foo1.key}) }
1262+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate\s+/tmp/foo2.crt}) }
1263+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate_key\s+/tmp/foo2.key}) }
1264+
end
1265+
12531266
context 'when use_default_location => true' do
12541267
let :params do
12551268
default_params.merge(use_default_location: true)

templates/server/server_ssl_settings.erb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<% if scope.call_function('versioncmp', [scope['nginx::nginx_version'], '1.15.0']) < 0 -%>
22
ssl on;
33
<% end -%>
4-
<% if @ssl_cert -%>
5-
ssl_certificate <%= @ssl_cert %>;
4+
<% if @ssl_cert_real -%>
5+
<% @ssl_cert_real.each do | cert | -%>
6+
ssl_certificate <%= cert %>;
7+
<% end -%>
8+
<% end -%>
9+
<% if @ssl_key_real -%>
10+
<% @ssl_key_real.each do | key | -%>
11+
ssl_certificate_key <%= key %>;
612
<% end -%>
7-
<% if @ssl_key -%>
8-
ssl_certificate_key <%= @ssl_key %>;
913
<% end -%>
1014
<% if defined? @ssl_client_cert -%>
1115
ssl_client_certificate <%= @ssl_client_cert %>;

0 commit comments

Comments
 (0)