-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.pp
388 lines (360 loc) · 12.3 KB
/
init.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# This class will domain join a system to Active Directory
# The machine's hostname should be set to the FQDN
#
# @param username
# The username used to domain join
# @param sensitive_password
# The password used to domain join
# @param global_admins
# An AD group that will have full sudo access on all machines. This will also include ssh access
# @param global_ssh
# Ad AD group that will have ssh access to all machines. Sudo privileges can be specified separately
# @param local_admins
# A template for an AD group that will have full sudo access on the specific machine.
# `%HOSTNAME%` will be replaced with the machine's shortname
# @param local_ssh
# A template for an AD group that will have ssh access to the specific machine.
# `%HOSTNAME%` will be replaced with the machine's shortname
# @param global_nopasswd
# Allow sudo by global_admins without a password
# @param local_nopasswd
# Allow sudo by local_admins without a password
# @param sssd_home
# The directory where all home directories should be created. Defaults to /home
# @param override_domain
# Force the name of the domain to join. This can allow the machine's hostname to be set to the short name, but with less sucess
# @param domain_short
# The NetBIOS name for the domain
# @param dns_subdomain
# The subdomain that the dns records should be registered to. Example: for machine1.sd.example.com, sd would be the subdomain
# @param dnsupdate
# If SSSD should create the dns record for the machine. Secure updates are supported
# @param file_header
# A commented header to put on each of the managed files. A global file header can be defined using the top-level variable file_header
# @param time_servers
# A list of time servers. The domain will automatically be added to the end of the list
# @param configure_chrony
# Configures Chrony using time servers in time_servers. Time synchronization is required for kerberos to function
# @param smartcard
# Enable smartcard authentication (disabled, enabled, required, lock-on-removal)
# @param ad_trust
# Certificate chain for ad certificates (used for smartcard authentication)
# @param update_os_info
# Configures a service to update the OS information on the AD object on startup
# @param enable_smartcard_ssh
# Enable smartcard authentication for SSH (Only seems to work on RHEL 8+)
class domain_join (
String $username,
Sensitive[String] $sensitive_password,
String $global_admins,
String $global_ssh,
String $local_admins,
String $local_ssh,
Boolean $global_nopasswd = false,
Boolean $local_nopasswd = false,
String $sssd_home = '/home',
Optional[String] $override_domain = undef,
Optional[String] $domain_short = undef,
Optional[String] $dns_subdomain = undef,
Boolean $dnsupdate = true,
Optional[String] $file_header = undef,
Array $time_servers = [],
Boolean $configure_chrony = true,
Enum['disabled', 'enabled', 'required', 'lock-on-removal'] $smartcard = 'disabled',
Optional[Array[String]] $ad_trust = undef,
Boolean $update_os_info = false,
Boolean $enable_smartcard_ssh = false
) {
if $override_domain {
$currdomain = $override_domain
# This is only used if $override_domain is defined
$forced_fqdn = sprintf('%s.%s', $facts['networking']['hostname'], $currdomain)
} else {
if $dns_subdomain {
$currdomain = regsubst($facts['networking']['domain'], "${dns_subdomain}\\.", '')
} else {
$currdomain = $facts['networking']['domain']
}
}
# lint:ignore:top_scope_facts
if $file_header {
$file_header_local = $file_header
} elsif $::file_header {
$file_header_local = $::file_header
} else {
$file_header_local = 'This file is being maintained by Puppet. Do not edit.'
}
# lint:endignore
if $domain_short {
$shortdomain = split($currdomain, '[.]')[0]
} else {
$shortdomain = $domain_short
}
if $configure_chrony {
class { 'chrony':
servers => $time_servers.reduce({}) |$cumulate, $server| {
$tmp = merge($cumulate, { "${server}" => ['iburst', 'prefer'] })
$tmp
},
pools => [$currdomain].reduce({}) |$cumulate, $server| {
$tmp = merge($cumulate, { "${server}" => ['iburst'] })
$tmp
},
}
}
package { 'adcli':
ensure => installed,
}
case $facts['os']['family'] {
'RedHat': {
package { 'krb5-workstation':
ensure => installed,
}
package { 'samba-common-tools':
ensure => installed,
}
}
'Debian': {
package { 'krb5-workstation':
ensure => installed,
name => 'krb5-user',
}
package { 'samba-common-tools':
ensure => installed,
name => 'samba-common-bin',
}
}
default: {
err('Unknown OS')
}
}
package { 'oddjob-mkhomedir':
ensure => installed,
}
package { 'samba-common':
ensure => installed,
}
package { 'sssd':
ensure => installed,
}
if $ad_trust != undef {
file { '/etc/sssd/pki':
ensure => directory,
require => Package['sssd'],
}
file { '/etc/sssd/pki/sssd_auth_ca_db.pem':
ensure => file,
content => template('domain_join/sssd_auth_ca_db.pem.erb'),
require => File['/etc/sssd/pki'],
notify => [
Service['sssd'],
Exec['Trust domain ca chain']
],
}
exec { 'Trust domain ca chain':
command => 'trust anchor /etc/sssd/pki/sssd_auth_ca_db.pem',
path => $facts['path'],
require => File['/etc/sssd/pki/sssd_auth_ca_db.pem'],
refreshonly => true,
}
}
if($override_domain) {
# lint:ignore:140chars
$command = Sensitive("bash -c 'source /etc/os-release; echo -n \"${$sensitive_password.unwrap}\" | adcli join -H ${forced_fqdn} -D ${currdomain} -U \"${username}\" --stdin-password --os-name=\"\${NAME}\" --os-version=\"\${VERSION}\" --os-service-pack=\"\${VERSION_ID}\"'")
# lint:endignore
} else {
# lint:ignore:140chars
$command = Sensitive("bash -c 'source /etc/os-release; echo -n \"${$sensitive_password.unwrap}\" | adcli join -D ${currdomain} -U \"${username}\" --stdin-password --os-name=\"\${NAME}\" --os-version=\"\${VERSION}\" --os-service-pack=\"\${VERSION_ID}\"'")
# lint:endignore
}
exec { 'Join':
command => $command,
path => $facts['path'],
notify => Service['sssd'],
creates => '/etc/krb5.keytab',
require => [
Package['adcli'],
Package['krb5-workstation'],
Package['samba-common'],
Package['samba-common-tools'],
Package['sssd'],
File['/etc/krb5.conf'],
File['/etc/sssd/sssd.conf'],
],
}
file { '/etc/systemd/system/update_adcli.service':
ensure => file,
content => template('domain_join/update_adcli.service.erb'),
require => Exec['Join'],
notify => Service['update_adcli'],
}
service { 'update_adcli':
enable => true,
}
file { '/etc/krb5.conf':
ensure => file,
content => template('domain_join/krb5.conf.erb'),
notify => Service['sssd'],
require => Package['krb5-workstation'],
}
file { '/etc/sssd/sssd.conf':
ensure => file,
content => template('domain_join/sssd.conf.erb'),
owner => root,
group => root,
mode => '0400',
notify => Service['sssd'],
require => Package['sssd'],
}
service { 'oddjobd':
ensure => running,
enable => true,
require => Package['oddjob-mkhomedir'],
}
file { '/etc/sudoers.d/admins':
ensure => file,
content => template('domain_join/sudoers.erb'),
validate_cmd => '/usr/sbin/visudo -c -f %',
}
case $facts['os']['family'] {
'Debian': {
$enablesssd = 'pam-auth-update --enable mkhomedir'
Package { 'authconfig':
ensure => installed,
name => libpam-runtime,
}
package { 'libpam-sss':
ensure => installed,
before => Package['authconfig'],
}
package { 'libnss-sss':
ensure => installed,
before => Package['authconfig'],
}
}
'RedHat': {
case $facts['os']['name'] {
'Fedora': {
if Integer($facts['os']['release']['major']) >= 37 {
$enablesssd = 'authselect select sssd with-mkhomedir --force'
package { 'authconfig':
ensure => installed,
name => authselect,
}
}
}
/(RedHat|CentOS)/: {
case $facts['os']['release']['major'] {
'7': {
$enablesssd = 'authconfig --enablesssd --enablesssdauth --enablemkhomedir --update'
package { 'authconfig':
ensure => installed,
}
}
/(8|9)/: {
$enablesssd = 'authselect select sssd with-mkhomedir --force'
package { 'authconfig':
ensure => installed,
name => authselect,
}
}
default: {
err('Unknown OS')
}
}
}
default: {
fail('Unknown OS')
}
}
}
default: {
err('Unknown OS')
}
}
case $smartcard {
'disabled': {
$enable_smartcard = ''
}
'enabled': {
$enable_smartcard = 'with-smartcard'
}
'required': {
$enable_smartcard = 'with-smartcard-required'
}
'lock-on-removal': {
$enable_smartcard = 'with-smartcard-lock-on-removal'
}
default: {
err('How??')
}
}
exec { 'Enable SSSD Authentication':
command => "${enablesssd} ${enable_smartcard}",
subscribe => [
Exec['Join'],
],
path => $facts['path'],
refreshonly => true,
require => [
Package['authconfig'],
Package['oddjob-mkhomedir'],
Service['oddjobd'],
Package['sssd'],
Service['sssd'],
],
}
service { 'sssd':
ensure => running,
enable => true,
require => [
File['/etc/sssd/sssd.conf'],
Package['sssd'],
],
}
if $facts['mountpoints']['/']['device'] == 'overlay' {
file_line { 'remove systemd from system-auth':
ensure => absent,
path => '/etc/pam.d/system-auth',
line => '',
match => '.*pam_systemd\.so.*',
match_for_absence => true,
require => Exec['Enable SSSD Authentication'],
}
file_line { 'remove systemd from password-auth':
ensure => absent,
path => '/etc/pam.d/password-auth',
match => '.*pam_systemd\.so.*',
match_for_absence => true,
require => Exec['Enable SSSD Authentication'],
}
}
if $enable_smartcard_ssh {
file_line { 'Set AuthorizedKeysCommand':
ensure => present,
path => '/etc/ssh/sshd_config',
line => 'AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys',
match => '#?AuthorizedKeysCommand .*',
notify => Service['sshd'],
}
file_line { 'Set AuthorizedKeysCommandUser':
ensure => present,
path => '/etc/ssh/sshd_config',
line => 'AuthorizedKeysCommandUser nobody',
match => '#?AuthorizedKeysCommandUser .*',
notify => Service['sshd'],
}
unless defined(Package['openssh-server']) {
package { 'openssh-server':
ensure => installed,
}
}
unless defined(Service['sshd']) {
service { 'sshd':
ensure => running,
enable => true,
require => Package['openssh-server'],
}
}
}
}