Skip to content

Commit 89b6b2f

Browse files
authored
Merge pull request #363 from yakatz/feature/more-params
Add remote-random and remote-random-hostname to managed server parameters
2 parents 84ba714 + 25f6bb1 commit 89b6b2f

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

REFERENCE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,22 @@ The IP or hostname of the openvpn server service.
461461

462462
Default value: $::fqdn
463463

464+
##### `remote_random_hostname`
465+
466+
Data type: `Boolean`
467+
468+
OpenVPN will prepend a random string (6 bytes, 12 hex characters) to hostname to prevent DNS caching. For example, "foo.example.com" would be modified to "<random-chars>.foo.example.com".
469+
470+
Default value: `false`
471+
472+
##### `remote_random`
473+
474+
Data type: `Boolean`
475+
476+
When multiple ${remote} address/ports are specified, initially randomize the order of the list as a kind of basic load-balancing measure.
477+
478+
Default value: `false`
479+
464480
##### `cipher`
465481

466482
Data type: `String`
@@ -942,6 +958,22 @@ List of OpenVPN endpoints to connect to.
942958

943959
Default value: `undef`
944960

961+
##### `remote_random_hostname`
962+
963+
Data type: `Boolean`
964+
965+
OpenVPN will prepend a random string (6 bytes, 12 hex characters) to hostname to prevent DNS caching. For example, "foo.example.com" would be modified to "<random-chars>.foo.example.com".
966+
967+
Default value: `false`
968+
969+
##### `remote_random`
970+
971+
Data type: `Boolean`
972+
973+
When multiple ${remote} address/ports are specified, initially randomize the order of the list as a kind of basic load-balancing measure.
974+
975+
Default value: `false`
976+
945977
##### `common_name`
946978

947979
Data type: `String`

manifests/server.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# @param organization Organization to be used for the SSL certificate, mandatory for server mode.
88
# @param email Email address to be used for the SSL certificate, mandatory for server mode.
99
# @param remote List of OpenVPN endpoints to connect to.
10+
# @param remote_random_hostname OpenVPN will prepend a random string (6 bytes, 12 hex characters) to hostname to prevent DNS caching. For example, "foo.example.com" would be modified to "<random-chars>.foo.example.com".
11+
# @param remote_random When multiple ${remote} address/ports are specified, initially randomize the order of the list as a kind of basic load-balancing measure.
1012
# @param common_name Common name to be used for the SSL certificate
1113
# @param compression Which compression algorithim to use
1214
# @param dev TUN/TAP virtual network device
@@ -146,6 +148,8 @@
146148
Optional[String] $organization = undef,
147149
Optional[String] $email = undef,
148150
Optional[Array] $remote = undef,
151+
Boolean $remote_random_hostname = false,
152+
Boolean $remote_random = false,
149153
String $common_name = 'server',
150154
String $compression = 'comp-lzo',
151155
String $dev = 'tun0',

spec/defines/openvpn_server_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,57 @@
221221
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^key-direction 1$}) }
222222
it { is_expected.not_to contain_file('/etc/openvpn/test_client.conf').with_content(%r{nobind}) }
223223
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^port\s+\d+$}) }
224+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').without_content(%r{^remote-random-hostname$}) }
225+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').without_content(%r{^remote-random$}) }
226+
227+
it { is_expected.not_to contain_openvpn__ca('test_client') }
228+
229+
case facts[:os]['family']
230+
when 'RedHat'
231+
it {
232+
is_expected.to contain_file('/etc/openvpn/test_client/keys').
233+
with(ensure: 'directory', mode: '0750', group: 'nobody')
234+
}
235+
end
236+
end
237+
238+
context 'creating a server in client mode with multiple remotes and random' do
239+
let(:title) { 'test_client' }
240+
let(:nobind) { false }
241+
let(:params) do
242+
{
243+
'remote' => ['vpn1.example.com 12345', 'vpn2.example.com 23456'],
244+
'remote_random_hostname' => true,
245+
'remote_random' => true,
246+
'server_poll_timeout' => 1,
247+
'ping_timer_rem' => true,
248+
'tls_auth' => true,
249+
'tls_client' => true,
250+
'nobind' => nobind
251+
}
252+
end
253+
254+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^client$}) }
255+
it {
256+
is_expected.to contain_file('/etc/openvpn/test_client.conf').
257+
with_content(%r{^remote\s+vpn1.example.com\s+12345$})
258+
}
259+
it {
260+
is_expected.to contain_file('/etc/openvpn/test_client.conf').
261+
with_content(%r{^remote\s+vpn2.example.com\s+23456$})
262+
}
263+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^remote-random-hostname$}) }
264+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^remote-random$}) }
265+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^server-poll-timeout\s+1$}) }
266+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^ping-timer-rem$}) }
267+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^ns-cert-type server}) }
268+
it { is_expected.not_to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^mode\s+server$}) }
269+
it { is_expected.not_to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^client-config-dir}) }
270+
it { is_expected.not_to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^dh}) }
271+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^tls-client$}) }
272+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^key-direction 1$}) }
273+
it { is_expected.not_to contain_file('/etc/openvpn/test_client.conf').with_content(%r{nobind}) }
274+
it { is_expected.to contain_file('/etc/openvpn/test_client.conf').with_content(%r{^port\s+\d+$}) }
224275

225276
it { is_expected.not_to contain_openvpn__ca('test_client') }
226277

templates/server.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ remote-cert-tls server
1111
<% @remote.to_a.each do |rem| -%>
1212
remote <%= rem %>
1313
<% end -%>
14+
<% if @remote_random_hostname %>
15+
remote-random-hostname
16+
<% end -%>
17+
<% if @remote_random %>
18+
remote-random
19+
<% end -%>
1420
<% if @server_poll_timeout -%>
1521
server-poll-timeout <%= @server_poll_timeout %>
1622
<% end -%>

0 commit comments

Comments
 (0)