Skip to content

Commit 2ef61b4

Browse files
author
Ruben Bosch
committed
Enable revocation when easyrsa version 3.0 is used
The `remote_host` parameter is set, because the expected value of `foo.example.com` is not evaluated correctly on ArchLinux.
1 parent c2b95e9 commit 2ef61b4

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

manifests/revoke.pp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,29 @@
2525

2626
$etc_directory = $openvpn::etc_directory
2727

28+
$revocation_command = $openvpn::easyrsa_version ? {
29+
'2.0' => ". ./vars && ./revoke-full ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/${name}",
30+
'3.0' => ". ./vars && ./easyrsa revoke --batch ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/${name}",
31+
}
32+
33+
$renew_command = $openvpn::easyrsa_version ? {
34+
'2.0' => ". ./vars && KEY_CN='' KEY_OU='' KEY_NAME='' KEY_ALTNAMES='' openssl ca -gencrl -out ${openvpn::etc_directory}/openvpn/${name}/crl.pem -config ${openvpn::etc_directory}/openvpn/${name}/easy-rsa/openssl.cnf",
35+
'3.0' => ". ./vars && EASYRSA_REQ_CN='' EASYRSA_REQ_OU='' openssl ca -gencrl -out ${etc_directory}/openvpn/${name}/crl.pem -config ${etc_directory}/openvpn/${name}/easy-rsa/openssl.cnf",
36+
default => fail("unexepected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 2.0 or 3.0."),
37+
}
38+
2839
exec { "revoke certificate for ${name} in context of ${server}":
29-
command => ". ./vars && ./revoke-full ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/${name}",
40+
command => $revocation_command,
3041
cwd => "${etc_directory}/openvpn/${server}/easy-rsa",
3142
creates => "${etc_directory}/openvpn/${server}/easy-rsa/revoked/${name}",
3243
provider => 'shell',
44+
notify => Exec["renew crl.pem on ${name}"],
45+
}
46+
47+
exec { "renew crl.pem on ${name}":
48+
command => $renew_command,
49+
cwd => "${openvpn::etc_directory}/openvpn/${name}/easy-rsa",
50+
provider => 'shell',
51+
schedule => "renew crl.pem schedule on ${name}",
3352
}
3453
}

spec/defines/openvpn_client_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
}
7070

7171
context 'setting the minimum parameters' do
72-
let(:params) { { 'server' => 'test_server' } }
72+
let(:params) {
73+
'server' => 'test_server',
74+
'remote_host' => 'foo.example.com'
75+
}
7376

7477
it { is_expected.to contain_file('/etc/openvpn/test_server/download-configs/test_client/test_client.conf').with_content(%r{^client$}) }
7578
it { is_expected.to contain_file('/etc/openvpn/test_server/download-configs/test_client/test_client.conf').with_content(%r{^ca\s+keys/test_client/ca\.crt$}) }

spec/defines/openvpn_revoke_spec.rb

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'openvpn::revoke', type: :define do
44
on_supported_os.each do |os, facts|
5-
context "on #{os}" do
5+
context "on #{os} with easyrsa version 2.0" do
66
let(:pre_condition) do
77
[
88
'openvpn::server { "test_server":
@@ -18,7 +18,9 @@
1818
].join
1919
end
2020
let(:facts) do
21-
facts
21+
facts.merge(
22+
easyrsa: '2.0'
23+
)
2224
end
2325
let(:title) { 'test_client' }
2426
let(:params) { { 'server' => 'test_server' } }
@@ -31,5 +33,36 @@
3133
)
3234
}
3335
end
36+
context "on #{os} with easyrsa version 3.0" do
37+
let(:pre_condition) do
38+
[
39+
'openvpn::server { "test_server":
40+
country => "CO",
41+
province => "ST",
42+
city => "Some City",
43+
organization => "example.org",
44+
email => "[email protected]"
45+
}',
46+
'openvpn::client { "test_client3":
47+
server => "test_server"
48+
}'
49+
].join
50+
end
51+
let(:facts) do
52+
facts.merge(
53+
easyrsa: '3.0'
54+
)
55+
end
56+
let(:title) { 'test_client3' }
57+
let(:params) { { 'server' => 'test_server' } }
58+
59+
it { is_expected.to compile.with_all_deps }
60+
61+
it {
62+
is_expected.to contain_exec('revoke certificate for test_client3 in context of test_server').with(
63+
'command' => ". ./vars && ./easyrsa revoke --batch test_client3; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/test_client3"
64+
)
65+
}
66+
end
3467
end
3568
end

0 commit comments

Comments
 (0)