Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-11896) Send auto-renew extension in CSR #9076

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puppet/ssl/oids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module Puppet::SSL::Oids
["1.3.6.1.4.1.34380.1.3", 'ppAuthCertExt', 'Puppet Certificate Authorization Extension'],

["1.3.6.1.4.1.34380.1.3.1", 'pp_authorization', 'Certificate Extension Authorization'],
["1.3.6.1.4.1.34380.1.3.2", 'pp_auth_auto_renew', 'Auto-Renew Certificate Extension'],
["1.3.6.1.4.1.34380.1.3.13", 'pp_auth_role', 'Puppet Node Role Name for Authorization'],
]

Expand Down
7 changes: 7 additions & 0 deletions lib/puppet/x509/cert_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ def create_request(name, private_key)
options[:extension_requests] = csr_attributes.extension_requests
end

# Adds auto-renew extension to CSR if the agent supports auto-renewal of
# certificates
if Puppet[:hostcert_renewal_interval] && Puppet[:hostcert_renewal_interval] > 0
options[:extension_requests] ||= {}
options[:extension_requests].merge!({'1.3.6.1.4.1.34380.1.3.2' => 'true'})
end

csr = Puppet::SSL::CertificateRequest.new(name)
csr.generate(private_key, options)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/ssl/state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ def write_csr_attributes(data)
csr.request_extensions
).to contain_exactly(
{'oid' => '1.3.6.1.4.1.34380.1.1.31415', 'value' => 'pi'},
{'oid' => '1.3.6.1.4.1.34380.1.1.2718', 'value' => 'e'}
{'oid' => '1.3.6.1.4.1.34380.1.1.2718', 'value' => 'e'},
{'oid' => 'pp_auth_auto_renew', 'value' => 'true'}
)
end.to_return(status: 200)

Expand Down
23 changes: 23 additions & 0 deletions spec/unit/x509/cert_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,29 @@ def expects_private_file(path)
end
end

context 'when creating' do
context 'requests' do
let(:name) { 'tom' }
let(:requestdir) { tmpdir('cert_provider') }
let(:provider) { create_provider(requestdir: requestdir) }
let(:key) { OpenSSL::PKey::RSA.new(Puppet[:keylength]) }

it 'has the auto-renew extension by default for agents that support automatic renewal' do
csr = provider.create_request(name, key)
# need to create CertificateRequest instance from csr in order to use request_extensions()
wrapped_csr = Puppet::SSL::CertificateRequest.from_instance csr
expect(wrapped_csr.request_extensions).to include('oid' => 'pp_auth_auto_renew', 'value' => 'true')
end

it 'does not have the auto-renew extension for agents that do not support automatic renewal' do
Puppet[:hostcert_renewal_interval] = 0
csr = provider.create_request(name, key)
wrapped_csr = Puppet::SSL::CertificateRequest.from_instance csr
expect(wrapped_csr.request_extensions.length).to eq(0)
end
end
end

context 'CA last update time' do
let(:ca_path) { tmpfile('pem_ca') }

Expand Down