Skip to content

Make CSR submission version-aware #43

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

Merged
merged 1 commit into from
Jan 14, 2020
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
4 changes: 1 addition & 3 deletions plans/action/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@
)

# Ensure certificate requests have been submitted
run_command(@(HEREDOC), $agent_installer_targets)
/opt/puppetlabs/bin/puppet ssl submit_request
| HEREDOC
run_task('peadm::submit_csr', $agent_installer_targets)

# TODO: come up with an intelligent way to validate that the expected CSRs
# have been submitted and are available for signing, prior to signing them.
Expand Down
8 changes: 8 additions & 0 deletions tasks/submit_csr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"description": "Submit a certificate signing request",
"parameters": { },
"input_method": "stdin",
"implementations": [
{"name": "submit_csr.rb"}
]
}
40 changes: 40 additions & 0 deletions tasks/submit_csr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/opt/puppetlabs/puppet/bin/ruby
#
# rubocop:disable Style/GlobalVars
require 'json'
require 'open3'

def main
params = JSON.parse(STDIN.read)
majver = %x{/opt/puppetlabs/bin/puppet --version}
.chomp
.split('.')
.first
.to_i

if majver < 6
conf = %x{puppet config print dns_alt_names certname}
.chomp
.split("\n")
.map {|line| line.split(' = ') }
.to_h

cmd = ['/opt/puppetlabs/bin/puppet', 'certificate', 'generate',
'--ca-location', 'remote',
'--dns-alt-names', conf['dns_alt_names'],
conf['certname']
]
else
cmd = ['/opt/puppetlabs/bin/puppet', 'ssl', 'submit_request']
end

stdout, status = Open3.capture2(*cmd)
puts stdout
if status.success?
exit 0
else
exit 1
end
end

main