Skip to content

Commit 6923b0e

Browse files
committed
(PUP-11522) Warn if client cert or private key is missing
Warn if the caller specifies `include_client_cert: true` to `Puppet::HTTP::Client#get`, but one or both of the files are missing. If the files are invalid, e.g. mismatched key & cert, then fail the request.
1 parent e4bb473 commit 6923b0e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/puppet/ssl/ssl_provider.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ def create_system_context(cacerts:, path: Puppet[:ssl_trust_store], include_clie
7777
if include_client_cert
7878
cert_provider = Puppet::X509::CertProvider.new
7979
private_key = cert_provider.load_private_key(Puppet[:certname], required: false)
80+
unless private_key
81+
Puppet.warning("Private key for '#{Puppet[:certname]}' does not exist")
82+
end
83+
8084
client_cert = cert_provider.load_client_cert(Puppet[:certname], required: false)
85+
unless client_cert
86+
Puppet.warning("Client certificate for '#{Puppet[:certname]}' does not exist")
87+
end
8188

8289
if private_key && client_cert
8390
client_chain = resolve_client_chain(store, client_cert, private_key)

spec/unit/ssl/ssl_provider_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@
159159
expect(sslctx.private_key).to be_nil
160160
end
161161

162+
it 'warns if the client cert does not exist' do
163+
Puppet[:certname] = 'missingcert'
164+
Puppet[:hostprivkey] = fixtures('ssl/signed-key.pem')
165+
166+
expect(Puppet).to receive(:warning).with("Client certificate for 'missingcert' does not exist")
167+
subject.create_system_context(cacerts: [], include_client_cert: true)
168+
end
169+
170+
it 'warns if the private key does not exist' do
171+
Puppet[:certname] = 'missingkey'
172+
Puppet[:hostcert] = fixtures('ssl/signed.pem')
173+
174+
expect(Puppet).to receive(:warning).with("Private key for 'missingkey' does not exist")
175+
subject.create_system_context(cacerts: [], include_client_cert: true)
176+
end
177+
162178
it 'raises if client cert and private key are mismatched' do
163179
Puppet[:hostcert] = fixtures('ssl/signed.pem')
164180
Puppet[:hostprivkey] = fixtures('ssl/127.0.0.1-key.pem')

0 commit comments

Comments
 (0)