File: sudoers.pp

package info (click to toggle)
puppet-module-joshuabaird-ipaclient 2.5.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 168 kB
  • sloc: ruby: 259; sh: 10; makefile: 10
file content (192 lines) | stat: -rw-r--r-- 5,465 bytes parent folder | download | duplicates (3)
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
# == Class: ipaclient::sudoers
#
# You can use this class to configure your servers for looking up
# sudo info with FreeIPA
#
# === Parameters
#
# By default, we'll get these values from Facter.
#
# $domain::            IPA domain name
#
# $server::            Comma-separated list of servers
#
# === Examples
#
# class { 'ipaclient::sudoers': }
#
# === Authors
#
# Stephen Benjamin <stephen@bitbin.de>
#
# === Copyright
#
# Copyright 2014 Stephen Benjamin.
# Released under the MIT License. See LICENSE for more information
#
class ipaclient::sudoers (
  $server = $::ipa_server,
  $domain = $::ipa_domain,
  $automount = $ipaclient::params::automount,
) inherits ipaclient::params {

  if !empty($server) and !empty($domain) {
    $realm = upcase($domain)

    case $::osfamily {
      'RedHat': {

        if ($::operatingsystem == 'Fedora' and
          versioncmp($::operatingsystemrelease, '20') >= 0) {
            $libsss_sudo_package = []
        } elsif ($::operatingsystem != 'Fedora' and
            versioncmp($::operatingsystemrelease, '6.6') >= 0) {
            $libsss_sudo_package = []
        } else {
            $libsss_sudo_package = 'libsss_sudo'
        }

        exec { 'nisdomain':
          command => shellquote('/usr/sbin/authconfig','--nisdomain',$domain,
                                '--update'),
          unless  => shellquote('/bin/grep','-q',"NISDOMAIN=${domain}",
                                '/etc/sysconfig/network'),
        }
      }
      'Debian': {
        $libsss_sudo_package = 'libsss-sudo'
        $safe_domain = shellquote($domain)

        exec { 'nisdomain_live':
          command => "/bin/nisdomainname ${safe_domain}",
          unless  => "/bin/nisdomainname | grep -q ${safe_domain}",
        }

        # Upstart service for NIS domain
        file { '/etc/init/nisdomain.conf':
          owner   => 'root',
          group   => 'root',
          mode    => '0755',
          content => template('ipaclient/nisdomain.erb'),
        }
      }
      default: {
        fail('Unsupported OS.')
      }
    }

    package { $libsss_sudo_package:
      ensure  => installed,
    }

    service { 'sssd':
      ensure  => running,
      enable  => true,
      require => Package[$libsss_sudo_package],
    }

    augeas { 'nsswitch_sudoers':
      context => '/files/etc/nsswitch.conf',
      changes => [
        'set database[. = "sudoers"] sudoers',
        'set database[. = "sudoers"]/service[1] files',
        'set database[. = "sudoers"]/service[2] sss',
      ],
    }

    # Selecting the right provider is a PITA
    if empty($::sssd_version) {
      case $::osfamily {
        RedHat: {
          if (versioncmp($::operatingsystemrelease, '6.6') >= 0) {
            $ipa_provider = 'ipa'
          } else {
            $ipa_provider = 'ldap'
          }
        }
        Debian: {
          if (versioncmp($::operatingsystemrelease, '14.04') >= 0 and
            $::operatingsystem == 'Ubuntu') {
            $ipa_provider = 'ipa'
          } else {
            $ipa_provider = 'ldap'
          }
        }
        default: {
          $ipa_provider = 'ldap'
        }
      }
    } else {
      if (versioncmp($::sssd_version, '1.11') >= 0) {
        $ipa_provider = 'ipa'
      } else {
        $ipa_provider = 'ldap'
      }
    }

    if ($automount) {
      $sssd_with_automount = $::sssd_services ? {
        /autofs/ => $::sssd_services,
        default  => "${::sssd_services}, autofs"
      }

      $enable_sssd_services = $::sssd_services ? {
        /sudo/  => $sssd_with_automount,
        default => "${sssd_with_automount}, sudo"
      }
    } else {
      $enable_sssd_services = $::sssd_services ? {
        /sudo/  => $::sssd_services,
        default => "${::sssd_services}, sudo"
      }
    }

    if ($ipa_provider == 'ipa') {

      # SSSD versions >= 1.11 support using the IPA sudo_provider
      # which is vastly simpler to configure
      augeas { 'sssd':
        context => '/files/etc/sssd/sssd.conf',
        changes => [
          'set target[1]/sudo_provider ipa',
          "set target[2]/services \"${enable_sssd_services}\"",
        ],
        notify  => Service['sssd'],
      }
    } else {
      $krb5_server = join(values_at(split($server, ','), 0), '')
      $dn = join(prefix(split($domain, '\.'), 'dc='), ',')

      # Generate correct ldap:// uris, but _srv_ doesn't get a prefix,
      # this is all a bit tricky and ugly
      $tmp_ldap_uri = join(prefix(delete(split(regsubst($server, '\s+',
                      '', 'G'), ','), '_srv_'), 'ldap://'), ', ')

      if member(split(regsubst($server, '\s+', '', 'G') , ','), '_srv_') {
          if empty($tmp_ldap_uri) {
              $ldap_uri = '_srv_'
          } else {
              $ldap_uri = "_srv_, ${tmp_ldap_uri}"
          }
      } else {
          $ldap_uri = $tmp_ldap_uri
      }

      augeas { 'sssd':
        context => '/files/etc/sssd/sssd.conf',
        changes => [
          'set target[1]/sudo_provider ldap',
          "set target[1]/ldap_uri \"${ldap_uri}\"",
          "set target[1]/ldap_sudo_search_base ou=SUDOers,${dn}",
          'set target[1]/ldap_sasl_mech GSSAPI',
          "set target[1]/ldap_sasl_authid host/${::fqdn}",
          "set target[1]/ldap_sasl_realm ${realm}",
          "set target[1]/krb5_server ${krb5_server}",
          "set target[2]/services \"${enable_sssd_services}\"",
        ],
        notify  => Service['sssd'],
      }
    }
  }
}