Skip to content

Commit d73b92d

Browse files
committed
New option: puppetdb_ssl_crl
The CRL file is required by newer version of Puppet(Server)(DB).
1 parent eacd90d commit d73b92d

File tree

9 files changed

+115
-1
lines changed

9 files changed

+115
-1
lines changed

doc/configuration-puppetdb.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The following settings can be used in a [configuration file](/doc/configuration.
3232
| --- | --- |
3333
| `settings[:puppetdb_url]` | PuppetDB URL settings. If this is a string, it will set a single PuppetDB URL. If it is an array, it will set multiple URLs, which will be tried in a random order until one responds. |
3434
| `settings[:puppetdb_ssl_ca]` | Path to the certificate of the CA that signed PuppetDB's certificate. This file should contain only the public certificate, so it is safe to distribute to developer workstations or CI environments. |
35+
| `settings[:puppetdb_ssl_crl]` | Path to the Certificate Revocation List provided by Puppetserver.
3536
| `settings[:puppetdb_ssl_client_cert]` | TEXT of the certificate of the client SSL keypair used to authenticate to PuppetDB. Note: This variable is not set to a file path, which means you will likely want to use `File.read(...)` if you are configuring this to be read from a file. |
3637
| `settings[:puppetdb_ssl_client_key]` | TEXT of the private key of the client SSL keypair used to authenticate to PuppetDB. Note: This variable is not set to a file path, which means you will likely want to use means you will likely want to use `File.read(...)` if you are configuring this to be read from a file. |
3738
| `settings[:puppetdb_ssl_client_pem]` | Concatenation of the text of `puppetdb_ssl_client_key` and `puppetdb_ssl_client_cert` as previously described. This is a good alternative if your certificate chain is complex and it's easier just to put everything in a single place. Note: this option is second in precedence; if `settings[:puppetdb_ssl_client_cert]` and `settings[:puppetdb_ssl_client_key]` are both set, this will be ignored. |
@@ -46,6 +47,7 @@ The following arguments can be used on the command line.
4647
| --- | --- |
4748
| --puppetdb-url https://puppetdb.example.net:8081 | PuppetDB URL. The argument should match the `server_urls` configuration setting as described previously. Please note that only one URL is supported via the command line method, so if you have multiple `server_urls` URLs specified, you can only choose one. To use multiple URLs for failover purposes, please configure via configuration files. |
4849
| --puppetdb-ssl-ca FILENAME | Path to the certificate of the CA that signed PuppetDB's certificate. This file should contain only the public certificate, so it is safe to distribute to developer workstations or CI environments. |
50+
| --puppetdb-ssl-crl FILENAME | Path to the Certificate Revocation List of the CA that signed PuppetDB's certificate. |
4951
| --puppetdb-ssl-client-cert FILENAME | Path to the certificate of the client SSL keypair. |
5052
| --puppetdb-ssl-client-key FILENAME | Path to the private key of the client SSL keypair. |
5153
| --puppetdb-ssl-client-password PASSWORD_STRING | Plain text string containing the password to unlock the private key. For keys generated by the Puppet Master CA, this is not required. |

doc/optionsref.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Usage: octocatalog-diff [command line options]
106106
--puppetdb-token-file PATH Path containing token for PuppetDB API, relative or absolute
107107
--puppetdb-url URL PuppetDB base URL
108108
--puppetdb-ssl-ca FILENAME CA certificate that signed the PuppetDB certificate
109+
--puppetdb-ssl-crl FILENAME Certificate Revocation List of the CA that signed PuppetDB's certificate.
109110
--puppetdb-ssl-client-cert FILENAME
110111
SSL client certificate to connect to PuppetDB
111112
--puppetdb-ssl-client-key FILENAME
@@ -1440,6 +1441,19 @@ matches the name you are using to connecting. (<a href="../lib/octocatalog-diff/
14401441
</td>
14411442
</tr>
14421443

1444+
<tr>
1445+
<td valign=top>
1446+
<pre><code>--puppetdb-ssl-crl FILENAME</code></pre>
1447+
</td>
1448+
<td valign=top>
1449+
Certificate Revocation List that is supplied by Puppetserver
1450+
</td>
1451+
<td valign=top>
1452+
Specify the Certificate Revocation List file.
1453+
(<a href="../lib/octocatalog-diff/cli/options/puppetdb_ssl_crl.rb">puppetdb_ssl_crl.rb</a>)
1454+
</td>
1455+
</tr>
1456+
14431457
<tr>
14441458
<td valign=top>
14451459
<pre><code>--puppetdb-ssl-client-cert FILENAME</code></pre>

examples/octocatalog-diff.cfg.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ def self.config
9292
# If you don't specify this, SSL will still work, but the tool won't verify the certificate
9393
# of the puppetdb server it's connecting to.
9494
# More: https://github.com/github/octocatalog-diff/blob/master/doc/configuration-puppetdb.md
95+
#
9596
##############################################################################################
9697

9798
# settings[:puppetdb_ssl_ca] = '/etc/puppetlabs/puppet/ssl/certs/ca.pem'
9899

100+
##############################################################################################
101+
# puppetdb_ssl_crl
102+
# Certificate Revocation List provided by Puppetserver. You can specify an absolute path starting with `/`, or a relative path.
103+
#
104+
##############################################################################################
105+
106+
# settings[:puppetdb_ssl_crl] = '/etc/puppetlabs/puppet/ssl/crl.pem'
107+
99108
##############################################################################################
100109
# puppetdb_ssl_client_key
101110
# puppetdb_ssl_client_password

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BuildDir
3333
# :hiera_path [String] relative path to hiera data files (mutually exclusive with :hiera_path_strip)
3434
# :hiera_path_strip [String] string to strip off the beginning of :datadir
3535
# :puppetdb_ssl_ca [String] Path to SSL CA certificate
36+
# :puppetdb_ssl_crl [String] Path to Certificate Revocation List
3637
# :puppetdb_ssl_client_key [String] String representation of SSL client key
3738
# :puppetdb_ssl_client_cert [String] String representation of SSL client certificate
3839
# :puppetdb_ssl_client_password [String] Password to unlock SSL private key
@@ -273,6 +274,9 @@ def install_ssl(logger, options)
273274

274275
# SSL CA provided?
275276
install_ssl_ca(logger, options) if options[:puppetdb_ssl_ca]
277+
278+
# SSL CRL provided?
279+
install_ssl_crl(logger, options) if options[:puppetdb_ssl_crl]
276280
end
277281

278282
private
@@ -360,6 +364,18 @@ def install_ssl_ca(logger, options)
360364
logger.debug "Installed CA certificate in #{ca_outfile}"
361365
end
362366

367+
# Install SSL Certificate Revocation List
368+
# @param logger [Logger] Logger object
369+
# @param options [Hash] Options hash
370+
def install_ssl_crl(logger, options)
371+
crl_file = options[:puppetdb_ssl_crl]
372+
raise Errno::ENOENT, 'SSL CRL file does not exist' unless File.file?(crl_file)
373+
crl_content = File.read(crl_file)
374+
crl_outfile = File.join(@tempdir, 'var', 'ssl', 'crl.pem')
375+
File.open(crl_outfile, 'w') { |f| f.write(crl_content) }
376+
logger.debug "Installed Certificate Revocation List in #{crl_outfile}"
377+
end
378+
363379
# Install SSL keypair for client certificate authentication
364380
# @param logger [Logger] Logger object
365381
# @param options [Hash] Options hash
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
# Specify the Certificate Revocation List for PuppetDB SSL.
4+
# @param parser [OptionParser object] The OptionParser argument
5+
# @param options [Hash] Options hash being constructed; this is modified in this method.
6+
OctocatalogDiff::Cli::Options::Option.newoption(:puppetdb_ssl_crl) do
7+
has_weight 310
8+
order_within_weight 11
9+
10+
def parse(parser, options)
11+
parser.on('--puppetdb-ssl-crl FILENAME', 'Certificate Revocation List provided by the Puppetserver') do |x|
12+
raise Errno::ENOENT, "--puppetdb-ssl-crl #{x} does not point to a valid file" unless File.file?(x)
13+
options[:puppetdb_ssl_crl] = x
14+
end
15+
end
16+
end

lib/octocatalog-diff/puppetdb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PuppetDB
3737
# @param :puppetdb_port [Integer] Port number, defaults to 8080 (non-SSL) or 8081 (SSL)
3838
# @param :puppetdb_ssl [Boolean] defaults to true, because you should use SSL
3939
# @param :puppetdb_ssl_ca [String] Path to file containing CA certificate
40+
# @param :puppetdb_ssl_crl [String] Path to file containing CRL file
4041
# @param :puppetdb_ssl_verify [Boolean] Override the CA verification setting guessed from parameters
4142
# @param :puppetdb_ssl_client_pem [String] PEM-encoded client key and certificate
4243
# @param :puppetdb_ssl_client_p12 [String] pkcs12-encoded client key and certificate
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN X509 CRL-----
2+
MIICozCBjAIBATANBgkqhkiG9w0BAQsFADApMScwJQYDVQQDDB5QdXBwZXQgUm9v
3+
dCBDQTogMzdiZjgzODVkMzdiNjMXDTIxMDMwOTE0MTY1M1oXDTM2MDMwNjE0MTcw
4+
MVqgLzAtMB8GA1UdIwQYMBaAFEUp1Q73gDQrV1ayViXRzlDq6nbBMAoGA1UdFAQD
5+
AgEAMA0GCSqGSIb3DQEBCwUAA4ICAQBx3Nb48rbfgu2yYB2g/EClor/neBjk31s9
6+
zOVwJMbje6qNMFdMeQjvbNtofBzh/2+AMv6KZuq9DNUthM+TkgiRWhSDf/5XWRph
7+
BDC6r21DFdM8qaVsAt08u4qwlX3n+V0iOwfmeClv6EredC1ASbu91Nbk7RFQDBYh
8+
HeviHy0SQXEEf5DdOvAMmTvnHHMVjM9rPS7ZtsyubDouLBVFFfNlOBZdzAqHHvTb
9+
412ZzdQOcBsQ4+W6R3QqyNT3zMJVCG4+X3IBamtxMccEwvg1160wqb3CGtL+8IRK
10+
2f+KzZStqupRVyvtKU1P6NegwtrMznJOLdmXbA96MbHlLwQQrO8Pngz0QXqAWGvR
11+
idOgjOHJzrOkPtzyu7teHaCy/BHptwKi9zuyGoP9Q3k+qGxEFjvT3VyV+JJ3PtMQ
12+
EO6DEnPZSa77BcQ0+PQsCVN320hadt5R1zERp6isgaPR9/VRfyqos5OjY3gFxM9j
13+
pOYBCwRC32FotsCI5xwWxkaZk5L8gNbb9yCqFCixuNKd25Vsc/Ntij+XZquEpdst
14+
t1GZ9/QQFvaEkU2VQcD37Q9H4TvSVuw90MgcYConwTqOsnOag9hftyqnR5QERMzk
15+
mIWg3G31Yyu+BteM6cc4/uZ+WHXNZQNLv7osJT7yLTVm3PGedC1aqSfppzsMmr86
16+
vJiaDpccRw==
17+
-----END X509 CRL-----

spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,15 @@
857857
end
858858

859859
let(:ca) { OctocatalogDiff::Spec.fixture_path('ssl/generated/ca.crt') }
860+
let(:crl) { OctocatalogDiff::Spec.fixture_path('ssl/generated/crl.pem') }
860861
let(:cert) { File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/client.crt')) }
861862
let(:key) { File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/client.key')) }
862-
let(:ssl_opts) { { puppetdb_ssl_ca: ca, puppetdb_ssl_client_cert: cert, puppetdb_ssl_client_key: key } }
863+
let(:ssl_opts) do
864+
{
865+
puppetdb_ssl_ca: ca, puppetdb_ssl_crl: crl,
866+
puppetdb_ssl_client_cert: cert, puppetdb_ssl_client_key: key
867+
}
868+
end
863869
let(:password) { 'password' }
864870

865871
it 'should create directories when SSL setup is provided' do
@@ -885,6 +891,13 @@
885891
end.to raise_error(Errno::ENOENT, /SSL CA file does not exist/)
886892
end
887893

894+
it 'should error when CRL is specified but does not exist' do
895+
opts = default_opts.merge(puppetdb_ssl_ca: ca, puppetdb_ssl_crl: 'asldfjasdflkasdfj')
896+
expect do
897+
OctocatalogDiff::CatalogUtil::BuildDir.new(opts, @logger)
898+
end.to raise_error(Errno::ENOENT, /SSL CRL file does not exist/)
899+
end
900+
888901
it 'should install the CA file in a known place' do
889902
opts = default_opts.merge(puppetdb_ssl_ca: ca)
890903
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(opts, @logger)
@@ -893,6 +906,14 @@
893906
expect(File.read(resultfile)).to eq(File.read(ca))
894907
end
895908

909+
it 'should install the CRL file in a known place' do
910+
opts = default_opts.merge(puppetdb_ssl_ca: ca, puppetdb_ssl_crl: crl)
911+
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(opts, @logger)
912+
resultfile = File.join(testobj.tempdir, 'var', 'ssl', 'crl.pem')
913+
expect(File.file?(resultfile)).to eq(true)
914+
expect(File.read(resultfile)).to eq(File.read(crl))
915+
end
916+
896917
it 'should install the client certificate in a known place' do
897918
opts = default_opts.merge(ssl_opts)
898919
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(opts, @logger)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../options_helper'
4+
5+
describe OctocatalogDiff::Cli::Options do
6+
describe '#opt_puppetdb_ssl_crl' do
7+
it 'should handle --puppetdb-ssl-crl with a valid file' do
8+
result = run_optparse(['--puppetdb-ssl-crl', OctocatalogDiff::Spec.fixture_path('ssl/generated/crl.pem')])
9+
expect(result[:puppetdb_ssl_crl]).to eq(OctocatalogDiff::Spec.fixture_path('ssl/generated/crl.pem'))
10+
end
11+
12+
it 'should error when ssl crl file is not found' do
13+
expect do
14+
run_optparse(['--puppetdb-ssl-crl', OctocatalogDiff::Spec.fixture_path('ssl/generated/caasdfadfs.crt')])
15+
end.to raise_error(Errno::ENOENT)
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)