Skip to content

Commit 1ade42d

Browse files
authored
Merge pull request #500 from yakatz/ensure_revoke
Ensure EasyRSA certificates can be properly revoked
2 parents 42e157f + c03dfcc commit 1ade42d

7 files changed

Lines changed: 86 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ openvpn::client_specific_configs:
6969
server: 'winterthur'
7070
ifconfig: '10.200.200.50 10.200.200.51'
7171

72-
openvpn::revokes:
72+
openvpn::revoke:
7373
'client3':
7474
server: 'winterthur'
7575
```

REFERENCE.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* [`openvpn::ca`](#openvpn--ca): This define creates the openvpn ca and ssl certificates
1717
* [`openvpn::client`](#openvpn--client): This define creates client certs for a specified server as well as a tarball that can be directly imported into clients
1818
* [`openvpn::client_specific_config`](#openvpn--client_specific_config): This feature is explained here: http://openvpn.net/index.php/open-source/documentation/howto.html#policy All the parameters are explained in
19-
* [`openvpn::revoke`](#openvpn--revoke): This define creates a revocation on a certificate for a specified server.
19+
* [`openvpn::revoke`](#openvpn--revoke): This define creates a revocation on a certificate for a specified server. There may not be an openvpn::client resource with the same name.
2020
* [`openvpn::server`](#openvpn--server): This define creates the openvpn server instance which can run in server or client mode.
2121

2222
## Classes
@@ -875,7 +875,7 @@ Default value: `true`
875875

876876
### <a name="openvpn--revoke"></a>`openvpn::revoke`
877877

878-
This define creates a revocation on a certificate for a specified server.
878+
This define creates a revocation on a certificate for a specified server. There may not be an openvpn::client resource with the same name.
879879

880880
#### Examples
881881

@@ -901,8 +901,17 @@ openvpn::revoke {
901901

902902
The following parameters are available in the `openvpn::revoke` defined type:
903903

904+
* [`ensure`](#-openvpn--revoke--ensure)
904905
* [`server`](#-openvpn--revoke--server)
905906

907+
##### <a name="-openvpn--revoke--ensure"></a>`ensure`
908+
909+
Data type: `Enum['present', 'absent']`
910+
911+
Revoke certificate or allow certificate to be reissued
912+
913+
Default value: `present`
914+
906915
##### <a name="-openvpn--revoke--server"></a>`server`
907916

908917
Data type: `String`

manifests/client.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
warning('Using $pam is deprecated. Use $authuserpass instead!')
8484
}
8585

86+
if defined(Openvpn::Revoke[$name]) {
87+
fail("Can't create an Openvpn::Client configuration for client '${name}' while there is an Openvpn::Revoke configuration.")
88+
}
89+
8690
Openvpn::Server[$server]
8791
-> Openvpn::Client[$name]
8892

@@ -96,6 +100,11 @@
96100

97101
$server_directory = $openvpn::server_directory
98102

103+
# If this certificate was previously revoked, remove that file.
104+
file { "${server_directory}/${server}/easy-rsa/revoked/${name}":
105+
ensure => absent,
106+
}
107+
99108
if $expire {
100109
if is_integer($expire) {
101110
case $openvpn::easyrsa_version {

manifests/revoke.pp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
2-
# @summary This define creates a revocation on a certificate for a specified server.
2+
# @summary This define creates a revocation on a certificate for a specified server. There may not be an openvpn::client resource with the same name.
33
#
4+
# @param ensure Revoke certificate or allow certificate to be reissued
45
# @param server Name of the corresponding openvpn endpoint
56
# @example
67
# openvpn::client {
@@ -15,11 +16,13 @@
1516
#
1617
define openvpn::revoke (
1718
String $server,
19+
Enum['present', 'absent'] $ensure = present,
1820
) {
19-
Openvpn::Server[$server]
20-
-> Openvpn::Revoke[$name]
21+
if defined(Openvpn::Client[$name]) and $ensure == 'present' {
22+
fail("Can't revoke certificate for client '${name}' while there is still an Openvpn::Client configuration.")
23+
}
2124

22-
Openvpn::Client[$name]
25+
Openvpn::Server[$server]
2326
-> Openvpn::Revoke[$name]
2427

2528
$server_directory = $openvpn::server_directory
@@ -34,32 +37,38 @@
3437
default => fail("unexepected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 3.0."),
3538
}
3639

37-
file { "${server_directory}/${server}/easy-rsa/revoked/${name}":
38-
ensure => file,
39-
require => Exec["revoke certificate for ${name} in context of ${server}"],
40-
}
41-
42-
exec { "revoke certificate for ${name} in context of ${server}":
43-
command => $revocation_command,
44-
cwd => "${server_directory}/${server}/easy-rsa",
45-
provider => 'shell',
46-
notify => Exec["renew crl.pem on ${server} because of revocation of ${name}"],
47-
creates => "${server_directory}/${server}/easy-rsa/revoked/${name}",
48-
}
40+
if $ensure == 'absent' {
41+
file { "${server_directory}/${server}/easy-rsa/revoked/${name}":
42+
ensure => absent,
43+
}
44+
} else {
45+
file { "${server_directory}/${server}/easy-rsa/revoked/${name}":
46+
ensure => file,
47+
require => Exec["revoke certificate for ${name} in context of ${server}"],
48+
}
4949

50-
exec { "renew crl.pem on ${server} because of revocation of ${name}":
51-
command => $renew_command,
52-
cwd => "${server_directory}/${server}/easy-rsa",
53-
provider => 'shell',
54-
refreshonly => true,
55-
}
50+
exec { "revoke certificate for ${name} in context of ${server}":
51+
command => $revocation_command,
52+
cwd => "${server_directory}/${server}/easy-rsa",
53+
provider => 'shell',
54+
notify => Exec["renew crl.pem on ${server} because of revocation of ${name}"],
55+
creates => "${server_directory}/${server}/easy-rsa/revoked/${name}",
56+
}
5657

57-
if ($openvpn::easyrsa_version == '3.0') {
58-
exec { "copy renewed crl.pem to ${server} keys directory because of revocation of ${name}":
59-
command => "cp ${server_directory}/${server}/easy-rsa/keys/crl.pem ${server_directory}/${server}/crl.pem",
60-
subscribe => Exec["renew crl.pem on ${server} because of revocation of ${name}"],
58+
exec { "renew crl.pem on ${server} because of revocation of ${name}":
59+
command => $renew_command,
60+
cwd => "${server_directory}/${server}/easy-rsa",
6161
provider => 'shell',
6262
refreshonly => true,
6363
}
64+
65+
if ($openvpn::easyrsa_version == '3.0') {
66+
exec { "copy renewed crl.pem to ${server} keys directory because of revocation of ${name}":
67+
command => "cp ${server_directory}/${server}/easy-rsa/keys/crl.pem ${server_directory}/${server}/crl.pem",
68+
subscribe => Exec["renew crl.pem on ${server} because of revocation of ${name}"],
69+
provider => 'shell',
70+
refreshonly => true,
71+
}
72+
}
6473
}
6574
}

spec/acceptance/openvpn_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
email => '[email protected]',
9494
server => '10.0.0.0 255.255.255.0',
9595
}
96-
openvpn::client { ['vpnclienta','vpnclientb'] :
96+
openvpn::client { ['vpnclienta'] :
9797
server => 'test_openvpn_server',
9898
require => Openvpn::Server['test_openvpn_server'],
9999
}

spec/defines/openvpn_client_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
'target' => "#{server_directory}/test_server/easy-rsa/keys/ca.crt"
9494
)
9595
}
96+
97+
it {
98+
is_expected.to contain_file("#{server_directory}/test_server/easy-rsa/revoked/test_client").
99+
with_ensure('absent')
100+
}
96101
end
97102

98103
context 'with remote_host' do

spec/defines/openvpn_revoke_spec.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
city => "Some City",
3131
organization => "example.org",
3232
email => "[email protected]"
33-
}',
34-
'openvpn::client { "test_client":
35-
server => "test_server"
3633
}'
3734
].join
3835
end
@@ -60,6 +57,30 @@
6057
is_expected.to contain_exec('copy renewed crl.pem to test_server keys directory because of revocation of test_client').
6158
with_command("cp #{server_directory}/test_server/easy-rsa/keys/crl.pem #{server_directory}/test_server/crl.pem")
6259
}
60+
61+
context 'with conflicting client' do
62+
let(:pre_condition) do
63+
[
64+
'openvpn::client { "test_client":
65+
server => "test_server"
66+
}'
67+
].join
68+
end
69+
70+
it {
71+
is_expected.to compile.and_raise_error(%r{Can't create an Openvpn::Client configuration for client 'test_client' while there is an Openvpn::Revoke configuration.})
72+
}
73+
end
74+
75+
context 'remove revocation' do
76+
let(:title) { 'test_client' }
77+
let(:params) { { 'ensure' => 'absent', 'server' => 'test_server' } }
78+
79+
it {
80+
is_expected.to contain_file("#{server_directory}/test_server/easy-rsa/revoked/test_client").
81+
with_ensure('absent')
82+
}
83+
end
6384
end
6485
end
6586
end

0 commit comments

Comments
 (0)