diff --git a/manifests/revoke.pp b/manifests/revoke.pp index 67d926ef..57ed5d30 100644 --- a/manifests/revoke.pp +++ b/manifests/revoke.pp @@ -25,10 +25,33 @@ $etc_directory = $openvpn::etc_directory - exec { "revoke certificate for ${name} in context of ${server}": - command => ". ./vars && ./revoke-full ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/${name}", - cwd => "${etc_directory}/openvpn/${server}/easy-rsa", - creates => "${etc_directory}/openvpn/${server}/easy-rsa/revoked/${name}", - provider => 'shell', + case $openvpn::easyrsa_version { + '3.0': { + exec { "revoke certificate for ${name} in context of ${server}": + command => ". ./vars && ./easyrsa --batch revoke ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2|))' && touch revoked/${name}", + cwd => "${etc_directory}/openvpn/${server}/easy-rsa", + creates => "${etc_directory}/openvpn/${server}/easy-rsa/revoked/${name}", + provider => 'shell', + } + # `easyrsa gen-crl` does not work, since it will create the crl.pem + # to keys/crl.pem which is a symlinked to crl.pem in the servers etc + # directory + exec { "renew crl.pem for ${name}": + command => ". ./vars && EASYRSA_REQ_CN='' EASYRSA_REQ_OU='' openssl ca -gencrl -out ../crl.pem -config ./openssl.cnf", + cwd => "${openvpn::etc_directory}/openvpn/${server}/easy-rsa", + provider => 'shell', + } + } + '2.0': { + exec { "revoke certificate for ${name} in context of ${server}": + command => ". ./vars && ./revoke-full ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/${name}", + cwd => "${etc_directory}/openvpn/${server}/easy-rsa", + creates => "${etc_directory}/openvpn/${server}/easy-rsa/revoked/${name}", + provider => 'shell', + } + } + default: { + fail("unexepected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 2.0 or 3.0.") + } } } diff --git a/spec/acceptance/openvpn_spec.rb b/spec/acceptance/openvpn_spec.rb index c0ef64b0..9f5153ee 100644 --- a/spec/acceptance/openvpn_spec.rb +++ b/spec/acceptance/openvpn_spec.rb @@ -36,6 +36,7 @@ apply_manifest_on(hosts_as('vpnserver'), pp, catch_failures: true) apply_manifest_on(hosts_as('vpnserver'), pp, catch_changes: true) end + it 'creates openvpn client certificate idempotently' do pp = %( openvpn::server { 'test_openvpn_server': @@ -56,7 +57,18 @@ remote_host => $facts['networking']['ip'], tls_cipher => 'TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA', } - ) + + openvpn::client { 'vpnclientb' : + server => 'test_openvpn_server', + require => Openvpn::Server['test_openvpn_server'], + remote_host => $facts['networking']['ip'], + tls_cipher => 'TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA', + } + + openvpn::revoke { 'vpnclientb' : + server => 'test_openvpn_server', + } + ) apply_manifest_on(hosts_as('vpnserver'), pp, catch_failures: true) apply_manifest_on(hosts_as('vpnserver'), pp, catch_changes: true) end diff --git a/spec/defines/openvpn_revoke_spec.rb b/spec/defines/openvpn_revoke_spec.rb index 75b8eeec..da6ab5f7 100644 --- a/spec/defines/openvpn_revoke_spec.rb +++ b/spec/defines/openvpn_revoke_spec.rb @@ -24,12 +24,33 @@ let(:params) { { 'server' => 'test_server' } } it { is_expected.to compile.with_all_deps } + context 'easyrsa version 2.0' do + let(:facts) do + super().merge('easyrsa' => '2.0') + end - it { - is_expected.to contain_exec('revoke certificate for test_client in context of test_server').with( - 'command' => ". ./vars && ./revoke-full test_client; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/test_client" - ) - } + it { + is_expected.to contain_exec('revoke certificate for test_client in context of test_server').with( + 'command' => ". ./vars && ./revoke-full test_client; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))' && touch revoked/test_client" + ) + } + end + context 'easyrsa version 3.0' do + let(:facts) do + super().merge('easyrsa' => '3.0') + end + + it { + is_expected.to contain_exec('revoke certificate for test_client in context of test_server').with( + 'command' => ". ./vars && ./easyrsa --batch revoke test_client; echo \"exit $?\" | grep -qE '(error 23|exit (0|2|))' && touch revoked/test_client" + ) + } + it { + is_expected.to contain_exec('renew crl.pem for test_client').with( + 'command' => ". ./vars && EASYRSA_REQ_CN='' EASYRSA_REQ_OU='' openssl ca -gencrl -out ../crl.pem -config ./openssl.cnf" + ) + } + end end end end