ldap.pp 8.5 KB
Newer Older
1
2
# Configure LDAP support for FreeRADIUS
define freeradius::module::ldap (
3
  String $basedn,
4
5
  Freeradius::Ensure $ensure                                         = 'present',
  Array[String] $server                                               = ['localhost'],
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
  Integer $port                                                       = 389,
  Optional[String] $identity                                          = undef,
  Optional[String] $password                                          = undef,
  Optional[Freeradius::Sasl] $sasl                                    = {},
  Optional[String] $valuepair_attribute                               = undef,
  Optional[Array[String]] $update                                     = undef,
  Optional[Freeradius::Boolean] $edir                                 = undef,
  Optional[Freeradius::Boolean] $edir_autz                            = undef,
  String $user_base_dn                                                = "\${..base_dn}",
  String $user_filter                                                 = '(uid=%{%{Stripped-User-Name}:-%{User-Name}})',
  Optional[Freeradius::Sasl] $user_sasl                               = {},
  Optional[Freeradius::Scope] $user_scope                             = undef,
  Optional[String] $user_sort_by                                      = undef,
  Optional[String] $user_access_attribute                             = undef,
  Optional[Freeradius::Boolean] $user_access_positive                 = undef,
  String $group_base_dn                                               = "\${..base_dn}",
  String $group_filter                                                = '(objectClass=posixGroup)',
  Optional[Freeradius::Scope] $group_scope                            = undef,
  Optional[String] $group_name_attribute                              = undef,
  Optional[String] $group_membership_filter                           = undef,
  String $group_membership_attribute                                  = 'memberOf',
  Optional[Freeradius::Boolean] $group_cacheable_name                 = undef,
  Optional[Freeradius::Boolean] $group_cacheable_dn                   = undef,
  Optional[String] $group_cache_attribute                             = undef,
  Optional[String] $group_attribute                                   = undef,
  Optional[String] $profile_filter                                    = undef,
  Optional[String] $profile_default                                   = undef,
  Optional[String] $profile_attribute                                 = undef,
  String $client_base_dn                                              = "\${..base_dn}",
  String $client_filter                                               = '(objectClass=radiusClient)',
  Optional[Freeradius::Boolean] $client_scope                         = undef,
  Optional[Freeradius::Boolean] $read_clients                         = undef,
  Optional[Enum['never','searching','finding','always']] $dereference = undef,
  Freeradius::Boolean $chase_referrals                                = 'yes',
  Freeradius::Boolean $rebind                                         = 'yes',
41
  Optional[Freeradius::Boolean] $use_referral_credentials             = undef,
42
  Optional[Freeradius::Boolean] $session_tracking                     = undef,
43
44
45
46
47
48
49
50
  Integer $timeout                                                    = 10,
  Integer $timelimit                                                  = 3,
  Integer $idle                                                       = 60,
  Integer $probes                                                     = 3,
  Integer $interval                                                   = 3,
  String $ldap_debug                                                  = '0x0028',
  Freeradius::Boolean $starttls                                       = 'no',
  Optional[String] $cafile                                            = undef,
51
  Optional[String] $capath                                            = undef,
52
53
54
55
  Optional[String] $certfile                                          = undef,
  Optional[String] $keyfile                                           = undef,
  Optional[String] $random_file                                       = undef,
  Enum['never','allow','demand','hard'] $requirecert                  = 'allow',
56
57
58
59
  Freeradius::Integer $start                                          = "\${thread[pool].start_servers}",
  Freeradius::Integer $min                                            = "\${thread[pool].min_spare_servers}",
  Freeradius::Integer $max                                            = "\${thread[pool].max_servers}",
  Freeradius::Integer $spare                                          = "\${thread[pool].max_spare_servers}",
60
61
62
63
  Integer $uses                                                       = 0,
  Integer $retry_delay                                                = 30,
  Integer $lifetime                                                   = 0,
  Integer $idle_timeout                                               = 60,
64
  Optional[Float] $connect_timeout                                    = undef,
65
66
67
68
) {
  $fr_package          = $::freeradius::params::fr_package
  $fr_service          = $::freeradius::params::fr_service
  $fr_modulepath       = $::freeradius::params::fr_modulepath
69
  $fr_basepath         = $::freeradius::params::fr_basepath
70
71
72
73
74
75
76
77
  $fr_group            = $::freeradius::params::fr_group

  # Validate our inputs
  # FR3.0 format server = 'ldap1.example.com, ldap1.example.com, ldap1.example.com'
  # FR3.1 format server = 'ldap1.example.com'
  #              server = 'ldap2.example.com'
  #              server = 'ldap3.example.com'
  $serverconcatarray = $::freeradius_version ? {
78
79
    /^3\.0\./ => any2array(join($server, ',')),
    default   => $server,
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
  # Warn if the user tries to set a FreeRADIUS 3.1.x specific parameter, and
  # we detect that they are not on (or not installing) a FreeRADIUS 3.1.x
  # then show them some errors
  # Additionally, if we are on FreeRADIUS 3.1.x then allow defaults for some
  # parameters, otherwise leave them set as specified when this define
  # is called.
  if $::freeradius::fr_3_1 {
    if $connect_timeout != undef {
      warning(@("WARN"/L)
        The `connect_timeout` parameter requires FreeRADIUS 3.1.x, i.e. the \
        experimental branch. You are running `${facts['freeradius_version']}`. \
        In the future, attempting to set it on this version may fail.
        |-WARN
      )
    }

    if $session_tracking != undef {
      warning(@("WARN"/L)
        The `session_tracking` parameter requires FreeRADIUS 3.1.x, i.e. the \
        experimental branch. You are running `${facts['freeradius_version']}`. \
        In the future, attempting to set it on this version may fail.
        |-WARN
      )
    }

    if $use_referral_credentials != undef {
      warning(@("WARN"/L)
        The `use_referral_credentials` parameter requires FreeRADIUS 3.1.x, \
        i.e. the experimental branch. You are running \
        `${facts['freeradius_version']}`. In the future, attempting to set \
        it on this version may fail.
        |-WARN
      )
    }

    $resolved_connect_timeout = $connect_timeout ? {
      undef   => 3.0,
      default => $connect_timeout,
    }

    $resolved_session_tracking = $session_tracking

    $resolved_use_referral_credentials = $use_referral_credentials ? {
      undef   => 'no',
      default => $use_referral_credentials,
    }
  } else {
    if $connect_timeout != undef {
      fail(@("FAIL"/L)
        The `connect_timeout` parameter requires FreeRADIUS 3.1.x, i.e. the \
        experimental branch. You are running `${facts['freeradius_version']}`.
        |-FAIL
      )
    }

    if $session_tracking != undef {
      fail(@("FAIL"/L)
        The `session_tracking` parameter requires FreeRADIUS 3.1.x, i.e. the \
        experimental branch. You are running `${facts['freeradius_version']}`.
        |-FAIL
      )
    }

    if $use_referral_credentials != undef {
      fail(@("FAIL"/L)
        The `use_referral_credentials` parameter requires FreeRADIUS 3.1.x, \
        i.e. the experimental branch. You are running \
        `${facts['freeradius_version']}`.
        |-FAIL
      )
    }
  }

155
  # Generate a module config, based on ldap.conf
156
  file { "${fr_basepath}/mods-available/${name}":
157
158
159
160
161
162
163
164
    ensure  => $ensure,
    mode    => '0640',
    owner   => 'root',
    group   => $fr_group,
    content => template('freeradius/ldap.erb'),
    require => [Package[$fr_package], Group[$fr_group]],
    notify  => Service[$fr_service],
  }
165
166
167
168
  file { "${fr_modulepath}/${name}":
    ensure => link,
    target => "../mods-available/${name}",
  }
169
}