Skip to content

Commit 1ac22b2

Browse files
authored
Merge pull request #569 from puppetlabs/sslhostconfig
Adding support for sslhostconfig options
2 parents 5222a2c + 9a02d64 commit 1ac22b2

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ tomcat::instance { 'my_tomcat_app':
125125
port => $https_port,
126126
protocol => $http_version,
127127
purge_connectors => true,
128+
cert_key_file => '/path/to/key.pem',
129+
cert_file => '/path/to/cert.pem',
130+
cert_chain_file => '/path/to/chain.pem',
131+
cert_type => 'RSA',
128132
additional_attributes => {
129133
'SSLEnabled' => bool2str($https_enabled),
130134
'maxThreads' => $https_connector_max_threads,

manifests/config/server/connector.pp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
# Specifies a server.xml file to manage. Valid options: a string containing an absolute path.
2323
# @param show_diff
2424
# Specifies display differences when augeas changes files, defaulting to true. Valid options: true or false.
25+
# @param cert_key_file
26+
# Specifies the path to the private key file. Valid options: a string containing an absolute path.
27+
# @param cert_file
28+
# Specifies the path to the certificate file. Valid options: a string containing an absolute path.
29+
# @param cert_chain_file
30+
# Specifies the path to the certificate chain file. Valid options: a string containing an absolute path.
31+
# @param cert_type
32+
# Specifies the type of certificate. Valid options: a string. 'RSA'.
2533
#
2634
define tomcat::config::server::connector (
2735
Optional[Stdlib::Absolutepath] $catalina_base = undef,
@@ -34,6 +42,10 @@
3442
Optional[Boolean] $purge_connectors = undef,
3543
Optional[Stdlib::Absolutepath] $server_config = undef,
3644
Boolean $show_diff = true,
45+
Optional[Stdlib::Absolutepath] $cert_key_file = undef,
46+
Optional[Stdlib::Absolutepath] $cert_file = undef,
47+
Optional[Stdlib::Absolutepath] $cert_chain_file = undef,
48+
String[1] $cert_type = 'RSA',
3749
) {
3850
include tomcat
3951
$_catalina_base = pick($catalina_base, $tomcat::catalina_home)
@@ -85,6 +97,21 @@
8597
} else {
8698
$_additional_attributes = undef
8799
}
100+
101+
# Add SSLHostConfig if certificate parameters are provided
102+
if $cert_key_file and $cert_file and $cert_chain_file {
103+
$sslhostconfig_path = "Server/Service/Connector[#attribute/port='${port}']"
104+
105+
$_sslhostconfig_changes = [
106+
"set ${sslhostconfig_path}/SSLHostConfig/Certificate/#attribute/certificateKeyFile ${cert_key_file}",
107+
"set ${sslhostconfig_path}/SSLHostConfig/Certificate/#attribute/certificateFile ${cert_file}",
108+
"set ${sslhostconfig_path}/SSLHostConfig/Certificate/#attribute/certificateChainFile ${cert_chain_file}",
109+
"set ${sslhostconfig_path}/SSLHostConfig/Certificate/#attribute/type ${cert_type}",
110+
]
111+
} else {
112+
$_sslhostconfig_changes = undef
113+
}
114+
88115
if ! empty(any2array($attributes_to_remove)) {
89116
$_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${base_path}/#attribute/")
90117
} else {
@@ -97,6 +124,7 @@
97124
$_protocol_change,
98125
$_additional_attributes,
99126
$_attributes_to_remove,
127+
$_sslhostconfig_changes,
100128
]))
101129
}
102130

spec/defines/config/server/connector_spec.rb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,21 @@
2929
'connectionTimeout' => '20000',
3030
'spaces' => 'foo bar'
3131
},
32-
attributes_to_remove: ['foo', 'bar', 'baz']
32+
attributes_to_remove: ['foo', 'bar', 'baz'],
33+
cert_key_file: '/path/to/cert.key',
34+
cert_file: '/path/to/cert.pem',
35+
cert_chain_file: '/path/to/chain.pem',
36+
cert_type: 'RSA'
3337
}
3438
end
3539

40+
sslhostconfig_changes = [
41+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateKeyFile /path/to/cert.key",
42+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateFile /path/to/cert.pem",
43+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateChainFile /path/to/chain.pem",
44+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/type RSA",
45+
]
46+
3647
changes = [
3748
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/port 8180',
3849
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/protocol AJP/1.3',
@@ -42,7 +53,8 @@
4253
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/foo',
4354
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/bar',
4455
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/baz',
45-
]
56+
].concat(sslhostconfig_changes)
57+
4658
it {
4759
expect(subject).to contain_augeas('server-/opt/apache-tomcat/test-Catalina2-connector-8180').with(
4860
'lens' => 'Xml.lns',
@@ -64,10 +76,21 @@
6476
'redirectPort' => '8543',
6577
'connectionTimeout' => '20000'
6678
},
67-
attributes_to_remove: ['foo', 'bar', 'baz']
79+
attributes_to_remove: ['foo', 'bar', 'baz'],
80+
cert_key_file: '/path/to/cert.key',
81+
cert_file: '/path/to/cert.pem',
82+
cert_chain_file: '/path/to/chain.pem',
83+
cert_type: 'RSA'
6884
}
6985
end
7086

87+
sslhostconfig_changes = [
88+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateKeyFile /path/to/cert.key",
89+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateFile /path/to/cert.pem",
90+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/certificateChainFile /path/to/chain.pem",
91+
"set Server/Service/Connector[#attribute/port='8180']/SSLHostConfig/Certificate/#attribute/type RSA",
92+
]
93+
7194
changes = [
7295
'rm Server//Connector[#attribute/protocol=\'AJP/1.3\'][#attribute/port!=\'8180\']',
7396
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/port 8180',
@@ -77,7 +100,8 @@
77100
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/foo',
78101
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/bar',
79102
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/baz',
80-
]
103+
].concat(sslhostconfig_changes)
104+
81105
it {
82106
expect(subject).to contain_augeas('server-/opt/apache-tomcat/test-Catalina2-connector-8180').with(
83107
'lens' => 'Xml.lns',

0 commit comments

Comments
 (0)