diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 2f462a4..633948d 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -630,49 +630,6 @@ define nginx::resource::vhost ( content => template('nginx/vhost/vhost_ssl_footer.erb'), order => '999', } - - #Generate ssl key/cert with provided file-locations - $cert = regsubst($name,' ','_', 'G') - - # Check if the file has been defined before creating the file to - # avoid the error when using wildcard cert on the multiple vhosts - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.crt", { - owner => $::nginx::config::daemon_user, - mode => '0444', - source => $ssl_cert, - }) - - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.client.crt", { - owner => $::nginx::config::daemon_user, - mode => '0444', - source => $ssl_client_cert, - }) - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.key", { - owner => $::nginx::config::daemon_user, - mode => '0440', - source => $ssl_key, - }) - if ($ssl_dhparam != undef) { - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.dh.pem", { - owner => $::nginx::config::daemon_user, - mode => '0440', - source => $ssl_dhparam, - }) - } - if ($ssl_stapling_file != undef) { - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.ocsp.resp", { - owner => $::nginx::config::daemon_user, - mode => '0440', - source => $ssl_stapling_file, - }) - } - if ($ssl_trusted_cert != undef) { - ensure_resource('file', "${::nginx::config::conf_dir}/${cert}.trusted.crt", { - owner => $::nginx::config::daemon_user, - mode => '0440', - source => $ssl_trusted_cert, - }) - } } file{ "${name_sanitized}.conf symlink": diff --git a/spec/defines/resource_vhost_spec.rb b/spec/defines/resource_vhost_spec.rb index 39d4327..52711cf 100644 --- a/spec/defines/resource_vhost_spec.rb +++ b/spec/defines/resource_vhost_spec.rb @@ -428,6 +428,30 @@ describe 'nginx::resource::vhost' do :value => false, :match => %r'\s+server_name\s+www.rspec.example.com;', }, + { + :title => 'should set the SSL client certificate file', + :attr => 'ssl_client_cert', + :value => '/tmp/client_certificate', + :match => %r'\s+ssl_client_certificate\s+/tmp/client_certificate;', + }, + { + :title => 'should set the SSL DH parameters file', + :attr => 'ssl_dhparam', + :value => '/tmp/dhparam', + :match => %r'\s+ssl_dhparam\s+/tmp/dhparam;', + }, + { + :title => 'should set the SSL stapling file', + :attr => 'ssl_stapling_file', + :value => '/tmp/stapling_file', + :match => %r'\s+ssl_stapling_file\s+/tmp/stapling_file;', + }, + { + :title => 'should set the SSL trusted certificate file', + :attr => 'ssl_trusted_cert', + :value => '/tmp/trusted_certificate', + :match => %r'\s+ssl_trusted_certificate\s+/tmp/trusted_certificate;', + }, { :title => 'should set the SSL cache', :attr => 'ssl_cache', @@ -816,9 +840,9 @@ describe 'nginx::resource::vhost' do it { is_expected.to contain_nginx__resource__location("#{title}-default").with_ssl_only(true) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log combined;}) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) } + it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate\s+dummy.cert;}) } + it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate_key\s+dummy.key;}) } it { is_expected.to contain_concat__fragment("#{title}-ssl-footer") } - it { is_expected.to contain_file("/etc/nginx/#{title}.crt") } - it { is_expected.to contain_file("/etc/nginx/#{title}.key") } end context 'when ssl_client_cert is set' do @@ -835,9 +859,6 @@ describe 'nginx::resource::vhost' do it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log combined;}) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_verify_client on;}) } - it { is_expected.to contain_file("/etc/nginx/#{title}.crt") } - it { is_expected.to contain_file("/etc/nginx/#{title}.client.crt") } - it { is_expected.to contain_file("/etc/nginx/#{title}.key") } end context 'when passenger_cgi_param is set' do let :params do default_params.merge({ diff --git a/templates/vhost/vhost_ssl_settings.erb b/templates/vhost/vhost_ssl_settings.erb index 89240e6..2cdd73b 100644 --- a/templates/vhost/vhost_ssl_settings.erb +++ b/templates/vhost/vhost_ssl_settings.erb @@ -1,13 +1,13 @@ ssl on; - ssl_certificate <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.crt; - ssl_certificate_key <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.key; + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; <% if defined? @ssl_client_cert -%> - ssl_client_certificate <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.client.crt; + ssl_client_certificate <%= @ssl_client_cert %>; ssl_verify_client on; <% end -%> <% if defined? @ssl_dhparam -%> - ssl_dhparam <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.dh.pem; + ssl_dhparam <%= @ssl_dhparam %>; <% end -%> ssl_session_cache <%= @ssl_cache %>; ssl_session_timeout <%= @ssl_session_timeout %>; @@ -19,7 +19,7 @@ ssl_stapling on; <%- end -%> <%- if defined? @ssl_stapling_file -%> - ssl_stapling_file <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.ocsp.resp; + ssl_stapling_file <%= @ssl_stapling_file %>; <%- end -%> <%- if defined? @ssl_stapling_responder -%> ssl_stapling_responder <%= @ssl_stapling_responder %>; @@ -28,7 +28,7 @@ ssl_stapling_verify on; <%- end -%> <%- if defined? @ssl_trusted_cert -%> - ssl_trusted_certificate <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.trusted.crt; + ssl_trusted_certificate <%= @ssl_trusted_cert %>; <%- end -%> <% end -%>