Skip to content

Commit 64f2c05

Browse files
authored
Merge pull request #253 from bwilcox/ldap_setup
Add task and update configure plan to allow for ldap configuration on…
2 parents eb032d3 + 53f2887 commit 64f2c05

File tree

6 files changed

+149
-6
lines changed

6 files changed

+149
-6
lines changed

documentation/install.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,19 @@ Example params.json Bolt parameters file (shown: Extra Large with DR):
107107
}
108108
```
109109

110-
Review the [peadm::install plan](../plans/install.pp) to learn about more advanced installation options. It is possible to supply an ssh private key and git clone URL for a control-repo as part of installation, for example.
110+
Example params.json Bolt parameters file (shown: Standard):
111+
112+
```json
113+
{
114+
"primary_host": "pe-xl-core-0.lab1.puppet.vm",
115+
116+
"console_password": "puppetlabs",
117+
"dns_alt_names": [ "puppet", "puppet.lab1.puppet.vm" ],
118+
"version": "2021.5.0",
119+
}
120+
```
121+
122+
Review the [peadm::install plan](../plans/install.pp) to learn about more advanced installation options. For example, it is possible to: supply an ssh private key and git clone URL for a control-repo as part of installation; supply the LDAP configuration data for PE; and similar complete automation tie-ins.
111123

112124
## Offline usage
113125

plans/install.pp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
# specified, PEAdm will attempt to download PE installation media from its
1717
# standard public source. When specified, PEAdm will download directly from the
1818
# URL given.
19+
# @param ldap_config
20+
# If specified, configures PE RBAC DS with the supplied configuration hash.
21+
# The parameter should be set to a valid set of connection settings as
22+
# documented for the PE RBAC /ds endpoint. See:
23+
# https://puppet.com/docs/pe/latest/rbac_api_v1_directory.html#put_ds-request_format
1924
#
2025
plan peadm::install (
2126
# Standard
@@ -38,6 +43,7 @@
3843
Optional[String] $internal_compiler_a_pool_address = undef,
3944
Optional[String] $internal_compiler_b_pool_address = undef,
4045
Optional[Hash] $pe_conf_data = { },
46+
Optional[Peadm::Ldap_config] $ldap_config = undef,
4147

4248
# Code Manager
4349
Optional[String] $r10k_remote = undef,
@@ -109,6 +115,7 @@
109115
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
110116
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
111117
deploy_environment => $deploy_environment,
118+
ldap_config => $ldap_config,
112119

113120
# Other
114121
stagingdir => $stagingdir,

plans/subplans/configure.pp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# A load balancer address directing traffic to any of the "B" pool
1414
# compilers. This is used for DR configuration in large and extra large
1515
# architectures.
16+
# @param ldap_config
17+
# This hash contains the options necessary for configuring the LDAP
18+
# connection on the main server.
1619
#
1720
plan peadm::subplans::configure (
1821
# Standard
@@ -27,11 +30,12 @@
2730
Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef,
2831

2932
# Common Configuration
30-
String $compiler_pool_address = $primary_host.peadm::certname(),
31-
Optional[String] $internal_compiler_a_pool_address = undef,
32-
Optional[String] $internal_compiler_b_pool_address = undef,
33-
Optional[String] $token_file = undef,
34-
Optional[String] $deploy_environment = undef,
33+
String $compiler_pool_address = $primary_host.peadm::certname(),
34+
Optional[String] $internal_compiler_a_pool_address = undef,
35+
Optional[String] $internal_compiler_b_pool_address = undef,
36+
Optional[String] $token_file = undef,
37+
Optional[String] $deploy_environment = undef,
38+
Optional[Peadm::Ldap_config] $ldap_config = undef,
3539

3640
# Other
3741
String $stagingdir = '/tmp',
@@ -105,6 +109,21 @@
105109
)
106110
}
107111

112+
if $ldap_config {
113+
# Run the task to configure ldap
114+
$ldap_result = run_task('peadm::pe_ldap_config', $primary_target,
115+
pe_main => $primary_target.peadm::certname(),
116+
ldap_config => $ldap_config,
117+
'_catch_errors' => true,
118+
)
119+
120+
# If there was an LDAP failure, note it and continue.
121+
if $ldap_result[0].error {
122+
out::message('There was a problem with the LDAP configuration, configuration must be completed manually.')
123+
out::message($ldap_result.to_data)
124+
}
125+
}
126+
108127
# Run Puppet everywhere to pick up last remaining config tweaks
109128
run_task('peadm::puppet_runonce', peadm::flatten_compact([
110129
$primary_target,

tasks/pe_ldap_config.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"description": "Set the ldap config in the PE console",
3+
"parameters": {
4+
"ldap_config": {
5+
"type": "Peadm::Ldap_config",
6+
"description": "The hash of options for ldap."
7+
},
8+
"pe_main": {
9+
"type": "String",
10+
"description": "The PE Main server"
11+
}
12+
},
13+
"input_method": "stdin",
14+
"implementations": [
15+
{"name": "pe_ldap_config.rb"}
16+
]
17+
}

tasks/pe_ldap_config.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
# Puppet Task Name: pe_ldap_config
3+
#
4+
# Update the LDAP configuration
5+
#
6+
7+
require 'json'
8+
require 'net/http'
9+
require 'open3'
10+
11+
def main
12+
params = JSON.parse(STDIN.read)
13+
data = params['ldap_config']
14+
pe_main = params['pe_main']
15+
16+
caf = ['/opt/puppetlabs/bin/puppet', 'config', 'print', 'localcacert']
17+
cafout, cafstatus = Open3.capture2(*caf)
18+
unless cafstatus.success?
19+
raise 'Could not get the CA file path.'
20+
end
21+
22+
cert = ['/opt/puppetlabs/bin/puppet', 'config', 'print', 'hostcert']
23+
certout, certstatus = Open3.capture2(*cert)
24+
unless certstatus.success?
25+
raise 'Could not get the Cert file path.'
26+
end
27+
28+
key = ['/opt/puppetlabs/bin/puppet', 'config', 'print', 'hostprivkey']
29+
keyout, keystatus = Open3.capture2(*key)
30+
unless keystatus.success?
31+
raise 'Could not get the Key file path.'
32+
end
33+
34+
uri = URI("https://#{pe_main}:4433/rbac-api/v1/ds")
35+
http = Net::HTTP.new(uri.host, uri.port)
36+
http.use_ssl = true
37+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
38+
http.ca_file = cafout.strip
39+
http.cert = OpenSSL::X509::Certificate.new(File.read(certout.strip))
40+
http.key = OpenSSL::PKey::RSA.new(File.read(keyout.strip))
41+
42+
req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json')
43+
req.body = data.to_json
44+
45+
resp = http.request(req)
46+
47+
puts resp.body
48+
raise "API response code #{resp.code}" unless resp.code == '200'
49+
end
50+
51+
begin
52+
main
53+
rescue => e
54+
result = {
55+
'_error' => {
56+
'msg' => e.message,
57+
'kind' => 'RuntimeError',
58+
'details' => e.message,
59+
}
60+
}
61+
puts result.to_json
62+
exit(1)
63+
end

types/ldap_config.pp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
type Peadm::Ldap_config = Struct[{
2+
base_dn => String,
3+
connect_timeout => Integer,
4+
disable_ldap_matching_rule_in_chain => Boolean,
5+
display_name => String,
6+
group_lookup_attr => String,
7+
group_member_attr => String,
8+
group_name_attr => String,
9+
group_object_class => String,
10+
Optional[group_rdn] => Optional[String],
11+
Optional[help_link] => Optional[String],
12+
hostname => String,
13+
Optional[login] => Optional[String],
14+
Optional[password] => Optional[String],
15+
port => Integer,
16+
search_nested_groups => Boolean,
17+
ssl => Boolean,
18+
ssl_hostname_validation => Boolean,
19+
ssl_wildcard_validation => Boolean,
20+
start_tls => Boolean,
21+
user_display_name_attr => String,
22+
user_email_attr => String,
23+
user_lookup_attr => String,
24+
Optional[user_rdn] => Optional[String],
25+
}]

0 commit comments

Comments
 (0)