Skip to content

Commit 7cac8d4

Browse files
committed
(MAINT) update SSL verification and certificate handling
- Changed SSL verification mode to VERIFY_PEER for enhanced security. - Added Puppet settings initialization to load necessary certificates. - Updated HTTP request to use Puppet's certname and certificate files. - Ensured CA file is set for SSL verification.
1 parent cd0f5ad commit 7cac8d4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

tasks/get_peadm_config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def https(port)
105105
https.use_ssl = true
106106
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
107107
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
108-
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
108+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
109+
https.ca_file = Puppet.settings[:localcacert]
109110
https
110111
end
111112

tasks/rbac_token.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,36 @@
44
#
55
# rubocop:disable Style/GlobalVars
66
require 'net/https'
7-
require 'uri'
87
require 'json'
98
require 'fileutils'
9+
require 'puppet'
1010

1111
# Parameters expected:
1212
# Hash
1313
# String password
1414
$params = JSON.parse(STDIN.read)
1515

16-
uri = URI.parse('https://localhost:4433/rbac-api/v1/auth/token')
16+
Puppet.initialize_settings
17+
1718
body = {
1819
'login' => 'admin',
1920
'password' => $params['password'],
2021
'lifetime' => $params['token_lifetime'],
2122
'label' => 'provision-time token',
2223
}.to_json
2324

24-
http = Net::HTTP.new(uri.host, uri.port)
25-
http.use_ssl = true
26-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
27-
request = Net::HTTP::Post.new(uri.request_uri)
25+
https. = Net::HTTP.new(Puppet.settings[:certname], 4433)
26+
https..use_ssl = true
27+
https..cert = OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
28+
https..key = OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
29+
https..verify_mode = OpenSSL::SSL::VERIFY_PEER
30+
https..ca_file = Puppet.settings[:localcacert]
31+
request = Net::https.:Post.new('/rbac-api/v1/auth/token')
2832
request['Content-Type'] = 'application/json'
2933
request.body = body
3034

31-
response = http.request(request)
32-
raise "Error requesting token, #{response.body}" unless response.is_a? Net::HTTPSuccess
35+
response = https.request(request)
36+
raise "Error requesting token, #{response.body}" unless response.is_a? Net::https.success
3337
token = JSON.parse(response.body)['token']
3438

3539
FileUtils.mkdir_p('/root/.puppetlabs')

0 commit comments

Comments
 (0)