Skip to content

Commit

Permalink
(PE-39397) Adding LDAP endpoint for 2023.8
Browse files Browse the repository at this point in the history
As rbac-api/v1/ds has been deprecated, and remove in 2023.8, we need to utilise the new endpoint.
Adding case for installs of versions 23.8 and above to use rbac-api/v1/command/ldap/create.
  • Loading branch information
ragingra committed Oct 18, 2024
1 parent 315d4ea commit ddb42a7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
13 changes: 13 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
* [`get_peadm_config`](#get_peadm_config): Run on a PE primary node to return the currently configured PEAdm parameters
* [`get_psql_version`](#get_psql_version): Run on a PE PSQL node to return the major version of the PSQL server currently installed
* [`infrastatus`](#infrastatus): Runs puppet infra status and returns the output
* [`ldapsettings`](#ldapsettings)
* [`mkdir_p_file`](#mkdir_p_file): Create a file with the specified content at the specified location
* [`mv`](#mv): Wrapper task for mv command
* [`os_identification`](#os_identification): Return the operating system runnin gon the target as a string
Expand Down Expand Up @@ -1233,6 +1234,12 @@ Data type: `Enum[json,text]`

The type of output to return

### <a name="ldapsettings"></a>`ldapsettings`

The ldapsettings task.

**Supports noop?** false

### <a name="mkdir_p_file"></a>`mkdir_p_file`

Create a file with the specified content at the specified location
Expand Down Expand Up @@ -1355,6 +1362,12 @@ Data type: `String`

The PE Main server

##### `pe_version`

Data type: `String`

The PE version

### <a name="pe_uninstall"></a>`pe_uninstall`

Uninstall Puppet Enterprise
Expand Down
5 changes: 5 additions & 0 deletions plans/subplans/configure.pp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@
}

if $ldap_config {
$pe_version = run_task('peadm::read_file', $primary_target,
path => '/opt/puppetlabs/server/pe_version',
)[0][content].chomp

# Run the task to configure ldap
$ldap_result = run_task('peadm::pe_ldap_config', $primary_target,
pe_main => $primary_target.peadm::certname(),
ldap_config => $ldap_config,
pe_version => $pe_version,
'_catch_errors' => true,
)

Expand Down
4 changes: 4 additions & 0 deletions tasks/pe_ldap_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"pe_main": {
"type": "String",
"description": "The PE Main server"
},
"pe_version": {
"type": "String",
"description": "The PE version"
}
},
"input_method": "stdin",
Expand Down
15 changes: 12 additions & 3 deletions tasks/pe_ldap_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def main
params = JSON.parse(STDIN.read)
data = params['ldap_config']
pe_main = params['pe_main']
pe_version = params['pe_version']

caf = ['/opt/puppetlabs/bin/puppet', 'config', 'print', 'localcacert']
cafout, cafstatus = Open3.capture2(*caf)
Expand All @@ -31,15 +32,23 @@ def main
raise 'Could not get the Key file path.'
end

uri = URI("https://#{pe_main}:4433/rbac-api/v1/ds")
https = Net::HTTP.new(uri.host, uri.port)
if Gem::Version.new(pe_version) < Gem::Version.new('2023.8.0')
ldap_path = URI('rbac-api/v1/ds')
uri = URI("https://#{pe_main}:4433/#{ldap_path}")
req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json')
else
ldap_path = URI('rbac-api/v1/command/ldap/create')
uri = URI("https://#{pe_main}:4433/#{ldap_path}")
req = Net::HTTP::Post.new(uri, 'Content-type' => 'application/json')
end

https = Net::HTTP.new(pe_main, '4433')
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ca_file = cafout.strip
https.cert = OpenSSL::X509::Certificate.new(File.read(certout.strip))
https.key = OpenSSL::PKey::RSA.new(File.read(keyout.strip))

req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json')
req.body = data.to_json

resp = https.request(req)
Expand Down

0 comments on commit ddb42a7

Please sign in to comment.