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

(MAINT) SSL Verification extended #504

Merged
merged 5 commits into from
Sep 23, 2024
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
5 changes: 3 additions & 2 deletions tasks/get_peadm_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ def server(role, letter, certname_array)
end

def https(port)
https = Net::HTTP.new('localhost', port)
https = Net::HTTP.new(Puppet.settings[:certname], port)
https.use_ssl = true
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ca_file = Puppet.settings[:localcacert]
https
end

Expand Down
18 changes: 11 additions & 7 deletions tasks/rbac_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
#
# rubocop:disable Style/GlobalVars
require 'net/https'
require 'uri'
require 'json'
require 'fileutils'
require 'puppet'

# Parameters expected:
# Hash
# String password
$params = JSON.parse(STDIN.read)

uri = URI.parse('https://localhost:4433/rbac-api/v1/auth/token')
Puppet.initialize_settings

body = {
'login' => 'admin',
'password' => $params['password'],
'lifetime' => $params['token_lifetime'],
'label' => 'provision-time token',
}.to_json

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

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

Expand Down
Loading