Skip to content

Commit 80485e5

Browse files
committed
Only output ldap_tls_client_cert_file and ldap_tls_client_key_file when set
TLSCertFile and TLSKeyFile are not always required, especially if no client certificates are used (also see the docs linked below). If they are set to empty values, the plugin throws an exception/parser error. Thus, only put them in the config file when they are actually used. References: https://github.com/threerings/openvpn-auth-ldap/wiki/Configuration Signed-off-by: Florian Pritz <[email protected]>
1 parent 433ba31 commit 80485e5

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

manifests/server.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@
175175
Boolean $ldap_tls_enable = false,
176176
String $ldap_tls_ca_cert_file = '',
177177
String $ldap_tls_ca_cert_dir = '',
178-
String $ldap_tls_client_cert_file = '',
179-
String $ldap_tls_client_key_file = '',
178+
Optional[Stdlib::Absolutepath] $ldap_tls_client_cert_file = undef,
179+
Optional[Stdlib::Absolutepath] $ldap_tls_client_key_file = undef,
180180
Integer $ca_expire = 3650,
181181
Integer $key_expire = 3650,
182182
String $key_cn = '',

spec/defines/openvpn_server_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,62 @@
233233
end
234234
end
235235

236+
case facts[:os]['family']
237+
when 'Debian'
238+
# ldap auth needs the ldap package and that is only defined for a few OSes (including debian)
239+
context 'debian' do
240+
context 'creating a server with ldap authentication enabled' do
241+
let(:params) do
242+
{
243+
'country' => 'CO',
244+
'province' => 'ST',
245+
'city' => 'Some City',
246+
'organization' => 'example.org',
247+
'email' => '[email protected]',
248+
'ldap_enabled' => true,
249+
'ldap_binddn' => 'dn=foo,ou=foo,ou=com',
250+
'ldap_bindpass' => 'ldappass123',
251+
'ldap_tls_enable' => true,
252+
'ldap_tls_ca_cert_file' => '/etc/ldap/ca.pem',
253+
'ldap_tls_ca_cert_dir' => '/etc/ldap/certs'
254+
}
255+
end
256+
257+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSEnable\s+yes$}) }
258+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertFile\s+/etc/ldap/ca.pem$}) }
259+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertDir\s+/etc/ldap/certs$}) }
260+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').without_content(%r{^\s+TLSCertFile.*$}) }
261+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').without_content(%r{^\s+TLSKeyFile.*$}) }
262+
end
263+
264+
context 'creating a server with ldap authentication enabled and using ldap client certificates' do
265+
let(:params) do
266+
{
267+
'country' => 'CO',
268+
'province' => 'ST',
269+
'city' => 'Some City',
270+
'organization' => 'example.org',
271+
'email' => '[email protected]',
272+
'ldap_enabled' => true,
273+
'ldap_binddn' => 'dn=foo,ou=foo,ou=com',
274+
'ldap_bindpass' => 'ldappass123',
275+
'ldap_tls_enable' => true,
276+
'ldap_tls_ca_cert_file' => '/etc/ldap/ca.pem',
277+
'ldap_tls_ca_cert_dir' => '/etc/ldap/certs',
278+
'ldap_tls_client_cert_file' => '/etc/ldap/client-cert.pem',
279+
'ldap_tls_client_key_file' => '/etc/ldap/client-key.pem'
280+
}
281+
end
282+
283+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSEnable\s+yes$}) }
284+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertFile\s+/etc/ldap/ca.pem$}) }
285+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertDir\s+/etc/ldap/certs$}) }
286+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCertFile\s+/etc/ldap/client-cert.pem$}) }
287+
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSKeyFile\s+/etc/ldap/client-key.pem$}) }
288+
end
289+
end
290+
end
291+
236292
context 'creating a server setting all parameters' do
237293
let(:params) do
238294
{

templates/ldap.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
TLSEnable yes
1212
TLSCACertFile <%= @ldap_tls_ca_cert_file %>
1313
TLSCACertDir <%= @ldap_tls_ca_cert_dir %>
14+
<% if @ldap_tls_client_cert_file or @ldap_tls_client_key_file -%>
1415
TLSCertFile <%= @ldap_tls_client_cert_file %>
1516
TLSKeyFile <%= @ldap_tls_client_key_file %>
17+
<% end -%>
1618
<% else %>
1719
TLSEnable no
1820
<% end -%>

0 commit comments

Comments
 (0)