Skip to content
Snippets Groups Projects
Commit c61cbb97 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

Add named_vhost TLS configuration.

To make it easier for people to configure named virtual hosts doing
HTTPS, add a parameter 'certname' to apache::named_vhost, specifying
names of the certificate files to use for that virtual host.  When
given, TLS will be enabled for the vhost, and configuration directives
pointing out the certificate files (cert, chain and private key) will
be added to the virtual host definition.

Users need to install the certificate files themselves by means of
the x509certs::hostcert::separate from the x509certs Puppet module
from NSC, though.
parent 670474cf
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2014 Thomas Bellman. # Copyright (C) 2014-2020 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information. # Licensed under the GNU LGPL v3+; see the README file for more information.
...@@ -22,6 +22,14 @@ import "nsc-puppet-utils" ...@@ -22,6 +22,14 @@ import "nsc-puppet-utils"
* into 'ServerName' and 'ServerAlias' directives. Defaults to the * into 'ServerName' and 'ServerAlias' directives. Defaults to the
* hostnames (before resolving) in the 'urls' parameter if not specified. * hostnames (before resolving) in the 'urls' parameter if not specified.
* *
* - certname
* If set, specifies the basename of server certificate files, for
* certificate, key, and chain. This is the same name as used in the
* x509certs::hostcert::separate definition in the NSC x509certs module.
* Httpd configuration to enable TLS and use those certificate files
* will be inserted in the virtual host configuration, but users needs
* to install the files themselves, using x509certs::hostcert::separate.
*
* - documentroot * - documentroot
* The document root for the virtual host. Optional (Apache will by * The document root for the virtual host. Optional (Apache will by
* default inherit this setting from the server-global setting). * default inherit this setting from the server-global setting).
...@@ -41,8 +49,11 @@ import "nsc-puppet-utils" ...@@ -41,8 +49,11 @@ import "nsc-puppet-utils"
# but we do not want to guess the protocol, or imply a preference of # but we do not want to guess the protocol, or imply a preference of
# e.g. http over https. # e.g. http over https.
define apache::named_vhost($urls, $servernames=[], define apache::named_vhost($urls,
$documentroot='', $config=undef, $servernames=[],
$certname=false,
$documentroot='',
$config=undef,
$ensure='present') $ensure='present')
{ {
include apache include apache
......
<% <%
# Copyright (C) 2014-2020 Thomas Bellman.
# Licensed under the GNU LGPL v3+; see the README file for more information.
httpd_version = scope.lookupvar('apache::standard_version') httpd_version = scope.lookupvar('apache::standard_version')
server_names = [] server_names = []
...@@ -72,6 +75,16 @@ NameVirtualHost <%= addr %> ...@@ -72,6 +75,16 @@ NameVirtualHost <%= addr %>
<% server_names[1..-1].each do |aliasname| -%> <% server_names[1..-1].each do |aliasname| -%>
ServerAlias <%= aliasname %> ServerAlias <%= aliasname %>
<% end -%> <% end -%>
<% if @certname && @certname != ''
certdir = scope.lookupvar('x509certs::pki_certdir')
keydir = scope.lookupvar('x509certs::pki_keydir')
-%>
SSLEngine on
SSLCertificateFile <%= certdir %>/<%= @certname %>-cert.pem
SSLCertificateKeyFile <%= keydir %>/<%= @certname %>-key.pem
SSLCertificateChainFile <%= certdir %>/<%= @certname %>-chain.pem
<% end -%>
<% if @documentroot && @documentroot != '' -%> <% if @documentroot && @documentroot != '' -%>
DocumentRoot <%= @documentroot %> DocumentRoot <%= @documentroot %>
<% end -%> <% end -%>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment