Skip to content

Commit ec4529e

Browse files
AriaXLijoshcooper
authored andcommitted
(PUP-11896) Send auto-renew attribute in CSR
This commit adds an auto-renew attribute to the CSR when it is generated if the agent supports auto-renewal of certificates. Agents that either do not have the hostcert_renewal_interval setting or have it set to 0 do not support auto-renewal. Originally, this was added as an auto-renew extension to the CSR (see #9076). However, in its default (FOSS) configuration, puppetserver rejects extensions so the auto-renew will be implemented as an attribute instead.
1 parent fde5713 commit ec4529e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Diff for: lib/puppet/ssl/oids.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Puppet::SSL::Oids
7171
["1.3.6.1.4.1.34380.1.3", 'ppAuthCertExt', 'Puppet Certificate Authorization Extension'],
7272

7373
["1.3.6.1.4.1.34380.1.3.1", 'pp_authorization', 'Certificate Extension Authorization'],
74-
["1.3.6.1.4.1.34380.1.3.2", 'pp_auth_auto_renew', 'Auto-Renew Certificate Extension'],
74+
["1.3.6.1.4.1.34380.1.3.2", 'pp_auth_auto_renew', 'Auto-Renew Certificate Attribute'],
7575
["1.3.6.1.4.1.34380.1.3.13", 'pp_auth_role', 'Puppet Node Role Name for Authorization'],
7676
["1.3.6.1.4.1.34380.1.3.39", 'pp_cli_auth', 'Puppetserver CA CLI Authorization'],
7777
]

Diff for: lib/puppet/x509/cert_provider.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ def create_request(name, private_key)
311311
options[:extension_requests] = csr_attributes.extension_requests
312312
end
313313

314-
# Adds auto-renew extension to CSR if the agent supports auto-renewal of
314+
# Adds auto-renew attribute to CSR if the agent supports auto-renewal of
315315
# certificates
316316
if Puppet[:hostcert_renewal_interval] && Puppet[:hostcert_renewal_interval] > 0
317-
options[:extension_requests] ||= {}
318-
options[:extension_requests].merge!({'1.3.6.1.4.1.34380.1.3.2' => 'true'})
317+
options[:csr_attributes] ||= {}
318+
options[:csr_attributes].merge!({'1.3.6.1.4.1.34380.1.3.2' => 'true'})
319319
end
320320

321321
csr = Puppet::SSL::CertificateRequest.new(name)

Diff for: spec/unit/ssl/state_machine_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def write_csr_attributes(data)
806806
state.next_state
807807
end
808808

809-
it 'includes CSR attributes' do
809+
it 'includes CSR attributes', :unless => RUBY_PLATFORM == 'java' do
810810
Puppet[:csr_attributes] = write_csr_attributes(
811811
'custom_attributes' => {
812812
'1.3.6.1.4.1.34380.1.2.1' => 'CSR specific info',
@@ -820,7 +820,8 @@ def write_csr_attributes(data)
820820
csr.custom_attributes
821821
).to contain_exactly(
822822
{'oid' => '1.3.6.1.4.1.34380.1.2.1', 'value' => 'CSR specific info'},
823-
{'oid' => '1.3.6.1.4.1.34380.1.2.2', 'value' => 'more CSR specific info'}
823+
{'oid' => '1.3.6.1.4.1.34380.1.2.2', 'value' => 'more CSR specific info'},
824+
{'oid' => 'pp_auth_auto_renew', 'value' => 'true'}
824825
)
825826
end.to_return(status: 200)
826827

@@ -843,8 +844,7 @@ def write_csr_attributes(data)
843844
csr.request_extensions
844845
).to contain_exactly(
845846
{'oid' => '1.3.6.1.4.1.34380.1.1.31415', 'value' => 'pi'},
846-
{'oid' => '1.3.6.1.4.1.34380.1.1.2718', 'value' => 'e'},
847-
{'oid' => 'pp_auth_auto_renew', 'value' => 'true'}
847+
{'oid' => '1.3.6.1.4.1.34380.1.1.2718', 'value' => 'e'}
848848
)
849849
end.to_return(status: 200)
850850

Diff for: spec/unit/x509/cert_provider_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -586,25 +586,25 @@ def expects_private_file(path)
586586
end
587587
end
588588

589-
context 'when creating' do
589+
context 'when creating', :unless => RUBY_PLATFORM == 'java' do
590590
context 'requests' do
591591
let(:name) { 'tom' }
592592
let(:requestdir) { tmpdir('cert_provider') }
593593
let(:provider) { create_provider(requestdir: requestdir) }
594594
let(:key) { OpenSSL::PKey::RSA.new(Puppet[:keylength]) }
595595

596-
it 'has the auto-renew extension by default for agents that support automatic renewal' do
596+
it 'has the auto-renew attribute by default for agents that support automatic renewal' do
597597
csr = provider.create_request(name, key)
598-
# need to create CertificateRequest instance from csr in order to use request_extensions()
598+
# need to create CertificateRequest instance from csr in order to view CSR attributes
599599
wrapped_csr = Puppet::SSL::CertificateRequest.from_instance csr
600-
expect(wrapped_csr.request_extensions).to include('oid' => 'pp_auth_auto_renew', 'value' => 'true')
600+
expect(wrapped_csr.custom_attributes).to include('oid' => 'pp_auth_auto_renew', 'value' => 'true')
601601
end
602602

603-
it 'does not have the auto-renew extension for agents that do not support automatic renewal' do
603+
it 'does not have the auto-renew attribute for agents that do not support automatic renewal' do
604604
Puppet[:hostcert_renewal_interval] = 0
605605
csr = provider.create_request(name, key)
606606
wrapped_csr = Puppet::SSL::CertificateRequest.from_instance csr
607-
expect(wrapped_csr.request_extensions.length).to eq(0)
607+
expect(wrapped_csr.custom_attributes.length).to eq(0)
608608
end
609609
end
610610
end

0 commit comments

Comments
 (0)