Puppet Class: pam::access
- Defined in:
- manifests/access.pp
Overview
Class: pam::access
This module manages the pam_access.so module for PAM. It grants the ability to allow or deny certain users or groups to authenticate to the system.
If you use this class without passing an explicit access.conf configuration file via the template or source parameter, it is recommended to complement access via the define pam::access::entry
Parameters
- ensure
-
Controls the software installation Valid values:
present
,absent
,purge
- accessfile
-
Path to access.conf Valid values:
/path/to/access.conf
- debug
-
A lot of debug information is printed with syslog(3) Valid values:
true
,false
- noaudit
-
Do not report logins from disallowed hosts and ttys to the audit subsystem Valid values:
true
,false
- fieldsep
-
This option modifies the field separator character that pam_access will recognize when parsing the access configuration file Valid values:
sep character
ex:,
- listsep
-
This option modifies the list separator character that pam_access will recognize when parsing the access configuration file Valid values:
sep character
ex:,
- nodefgroup
-
User tokens which are not enclosed in parentheses will not be matched against the group database Valid values:
true
,false
- source
-
Path to static Puppet file to use Valid values:
puppet:///modules/mymodule/path/to/file.conf
- template
-
Path to ERB puppet template file to use Valid values:
mymodule/path/to/file.conf.erb
- parameters
-
Hash variable to pass to template (if used) Valid values: hash, ex:
{ 'option' => 'value' }
- restrictive
-
If a final block all users except root entry should be inserted in the end of the config file Valid values:
true
,false
Sample Usage
-
Installing with default settings class { ‘pam::access’: }
-
Uninstalling the software class { ‘pam::access’: ensure => absent }
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 |
# File 'manifests/access.pp', line 71
class pam::access (
$ensure = 'present',
$accessfile = 'UNDEF',
$debug = 'UNDEF',
$noaudit = 'UNDEF',
$fieldsep = 'UNDEF',
$listsep = 'UNDEF',
$nodefgroup = 'UNDEF',
$source = 'UNDEF',
$template = 'UNDEF',
$parameters = {},
$restrictive = 'UNDEF'
) {
include pam
include pam::params
# puppet 2.6 compatibility
$accessfile_real = $accessfile ? {
'UNDEF' => $pam::params::accessfile,
default => $accessfile
}
$debug_real = $debug ? {
'UNDEF' => $pam::params::debug,
default => $debug
}
$noaudit_real = $noaudit ? {
'UNDEF' => $pam::params::noaudit,
default => $noaudit
}
$fieldsep_real = $fieldsep ? {
'UNDEF' => $pam::params::fieldsep,
default => $fieldsep
}
$listsep_real = $listsep ? {
'UNDEF' => $pam::params::listsep,
default => $listsep
}
$nodefgroup_real = $nodefgroup ? {
'UNDEF' => $pam::params::nodefgroup,
default => $nodefgroup
}
$source_real = $source ? {
'UNDEF' => $pam::params::access_source,
default => $source,
}
$template_real = $template ? {
'UNDEF' => $pam::params::access_template,
default => $template
}
$restrictive_real = $restrictive ? {
'UNDEF' => $pam::params::access_restrictive,
default => $restrictive
}
# Input validation
$valid_ensure_values = [ 'present', 'absent' ]
validate_re($ensure, $valid_ensure_values)
validate_hash($parameters)
validate_bool($debug_real)
validate_bool($noaudit_real)
validate_bool($nodefgroup_real)
validate_bool($restrictive_real)
$manage_file_source = $source_real ? {
'' => undef,
default => $source_real,
}
$manage_file_template = $template_real ? {
'' => undef,
default => template($template_real),
}
# Sanitized string builder variables
# for pam_access.so options
$listsep_entry_real = $listsep_real ? {
undef => ' ',
default => $listsep_real
}
$accessfile_entry = $accessfile_real ? {
undef => '',
'' => '',
default => " accessfile=${accessfile_real}"
}
$debug_entry = $debug_real ? {
true => ' debug',
false => '',
}
$noaudit_entry = $noaudit_real ? {
true => ' noaudit',
false => '',
}
$fieldsep_entry = $fieldsep_real ? {
undef => '',
'' => '',
default => " fieldsep='${fieldsep_real}'"
}
$listsep_entry = $listsep_real ? {
undef => '',
'' => '',
default => " listsep='${listsep_real}'"
}
$nodefgroup_entry = $nodefgroup_real ? {
true => ' nodefgroup',
false => '',
}
$pam_access_parameters = "${accessfile_entry}${debug_entry}${noaudit_entry}${fieldsep_entry}${listsep_entry}${nodefgroup_entry}"
# Debuntu uses pam-auth-update to build pam configuration
case $::operatingsystem {
'Ubuntu', 'Debian': {
file { 'pam_auth_update_access_file':
ensure => $ensure,
path => $pam::params::pam_auth_update_access_file,
owner => root,
group => root,
mode => '0644',
content => template($pam::params::pam_auth_update_access_tmpl),
notify => Exec['pam_auth_update']
}
}
default: {
fail("Unsupported operatingsystem ${::operatingsystem}")
}
}
case $ensure {
present: {
# use fragments if file source or template not provided
if $manage_file_source == undef and $manage_file_template == undef {
concat { $accessfile_real:
path => $accessfile_real,
owner => 'root',
group => 'root',
mode => '0644'
}
concat::fragment { '00_pam_access_conf_head':
target => $accessfile_real,
content => "# MANAGED BY PUPPET\n",
order => '00'
}
if $restrictive_real == true {
pam::access::entry { 'block_all_users_except_root':
object => 'ALL',
object_type => 'ALL',
permission => 'deny',
priority => 90,
except_user => 'root'
}
}
Concat::Fragment <| tag == 'pam_access' |>
# otherwise manage file as usual
} else {
file { 'accessfile':
ensure => present,
path => $accessfile_real,
owner => 'root',
group => 'root',
mode => '0644',
content => $manage_file_template,
source => $manage_file_source
}
}
}
default: {
# Don't know how to best unmanage the access.conf file
# This section would 'reset' it in case it
# finds # MANAGED BY PUPPET in the file
exec { 'insert_blank_access_conf_file':
command => "echo '## UNMANAGED FILE' > ${accessfile_real}",
onlyif => "grep '^# MANAGED BY PUPPET' ${accessfile_real} >/dev/null",
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ]
}
}
}
}
|