Skip to content

Commit 9cbef67

Browse files
authored
(MAINT) SSL Verification extended (#504)
* (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. * fix(rbac_token): correct syntax errors in SSL configuration - Fixed incorrect syntax in Net::HTTP initialization. - Corrected method calls for SSL setup and certificate handling. - Ensured proper request initialization for RBAC token generation. * fix(rbac_token): correct Net::HTTPSuccess class reference - Fixed incorrect reference to Net::HTTPSuccess class in token request error handling. * fix(rbac_token): correct typo in Net::HTTP::Post initialization Corrected the typo in the initialization of Net::HTTP::Post for creating the RBAC token request. This ensures the correct HTTP method is used for the request. * fix(get_peadm_config): use Puppet certname instead of localhost for HTTPS connection Changed the HTTPS connection to use Puppet's certname instead of 'localhost' to ensure proper SSL certificate validation.
1 parent cd0f5ad commit 9cbef67

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

tasks/get_peadm_config.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ def server(role, letter, certname_array)
101101
end
102102

103103
def https(port)
104-
https = Net::HTTP.new('localhost', port)
104+
https = Net::HTTP.new(Puppet.settings[:certname], 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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@
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::HTTP::Post.new('/rbac-api/v1/auth/token')
2832
request['Content-Type'] = 'application/json'
2933
request.body = body
3034

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

0 commit comments

Comments
 (0)