2008-10-20 22:51:27 +02:00
|
|
|
# manifests/defines.pp
|
|
|
|
|
2008-10-25 22:46:48 +02:00
|
|
|
# sshkey: have to be handed over as the classname
|
|
|
|
# containing the ssh_keys
|
|
|
|
# password: the password in cleartext or as crypted string
|
|
|
|
# which should be set. Default: absent -> no password is set.
|
2008-10-25 23:11:31 +02:00
|
|
|
# To create an encrypted password, you can use:
|
2008-12-01 23:30:22 +01:00
|
|
|
# /usr/bin/mkpasswd -H md5 --salt=$salt $password , where $salt is 8 bytes long
|
2008-11-08 22:56:52 +01:00
|
|
|
# Note: On OpenBSD systems we can only manage crypted passwords.
|
2008-10-25 22:46:48 +02:00
|
|
|
# Therefor the password_crypted option doesn't have any effect.
|
2008-11-08 22:56:52 +01:00
|
|
|
# You'll find a python script in ${module}/password/openbsd/genpwd.py
|
|
|
|
# Which will help you to create such a password
|
2008-10-25 22:46:48 +02:00
|
|
|
# password_crypted: if the supplied password is crypted or not.
|
|
|
|
# Default: true
|
|
|
|
# Note: If you'd like to use unencrypted passwords, you have to set a variable
|
|
|
|
# $password_salt to an 8 character long salt, being used for the password.
|
2008-11-22 16:12:32 +01:00
|
|
|
# gid: define the gid of the group
|
2008-12-05 15:44:27 +01:00
|
|
|
# absent: let the system take a gid
|
|
|
|
# uid: take the same as the uid has if it isn't absent (*default*)
|
2008-11-22 16:12:32 +01:00
|
|
|
# <value>: take this gid
|
2009-01-08 22:47:17 +01:00
|
|
|
# manage_group: Wether we should add a group with the same name as well, this works only
|
|
|
|
# if you supply a uid.
|
2008-12-02 01:30:12 +01:00
|
|
|
# Default: true
|
2008-12-01 23:45:57 +01:00
|
|
|
define user::managed(
|
2009-03-07 12:53:21 +01:00
|
|
|
$ensure = present,
|
|
|
|
$name_comment = 'absent',
|
|
|
|
$uid = 'absent',
|
|
|
|
$gid = 'uid',
|
2008-10-20 22:51:27 +02:00
|
|
|
$groups = [],
|
2008-12-05 18:29:47 +01:00
|
|
|
$manage_group = true,
|
2008-10-20 22:51:27 +02:00
|
|
|
$membership = 'minimum',
|
2009-03-07 12:53:21 +01:00
|
|
|
$homedir = 'absent',
|
2008-12-05 18:29:47 +01:00
|
|
|
$managehome = true,
|
2008-10-20 22:51:27 +02:00
|
|
|
$homedir_mode = '0750',
|
2009-03-07 12:53:21 +01:00
|
|
|
$sshkey = 'absent',
|
2008-10-25 22:46:48 +02:00
|
|
|
$password = 'absent',
|
2008-12-05 18:29:47 +01:00
|
|
|
$password_crypted = true,
|
2009-03-07 12:53:21 +01:00
|
|
|
$shell = 'absent'
|
2008-10-20 22:51:27 +02:00
|
|
|
){
|
|
|
|
|
|
|
|
$real_homedir = $homedir ? {
|
|
|
|
'absent' => "/home/$name",
|
|
|
|
default => $homedir
|
|
|
|
}
|
|
|
|
|
|
|
|
$real_name_comment = $name_comment ? {
|
|
|
|
'absent' => $name,
|
|
|
|
default => $name_comment,
|
|
|
|
}
|
|
|
|
|
|
|
|
$real_shell = $shell ? {
|
|
|
|
'absent' => $operatingsystem ? {
|
|
|
|
openbsd => "/usr/local/bin/bash",
|
|
|
|
default => "/bin/bash",
|
|
|
|
},
|
|
|
|
default => $shell,
|
|
|
|
}
|
|
|
|
|
2009-04-30 15:43:14 +02:00
|
|
|
if strlength($name) > 32 {
|
|
|
|
fail("Usernames can't be longer than 32 characters. ${name} is too long!")
|
|
|
|
}
|
|
|
|
|
2008-10-20 22:51:27 +02:00
|
|
|
user { $name:
|
2009-03-07 12:53:21 +01:00
|
|
|
ensure => $ensure,
|
2008-10-20 22:51:27 +02:00
|
|
|
allowdupe => false,
|
|
|
|
comment => "$real_name_comment",
|
|
|
|
home => $real_homedir,
|
|
|
|
managehome => $managehome,
|
|
|
|
shell => $real_shell,
|
|
|
|
groups => $groups,
|
|
|
|
membership => $membership,
|
|
|
|
}
|
|
|
|
|
2008-10-20 22:51:36 +02:00
|
|
|
|
2008-12-05 18:29:47 +01:00
|
|
|
if $managehome {
|
2009-03-13 00:25:54 +01:00
|
|
|
if $ensure == 'absent' {
|
2009-03-07 12:53:21 +01:00
|
|
|
file{"$real_homedir":
|
2009-03-13 00:25:54 +01:00
|
|
|
ensure => absent,
|
|
|
|
purge => true,
|
|
|
|
force => true,
|
|
|
|
recurese => true,
|
2008-10-20 22:51:36 +02:00
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
} else {
|
|
|
|
file{"$real_homedir":
|
|
|
|
ensure => directory,
|
|
|
|
require => User[$name],
|
|
|
|
owner => $name, mode => $homedir_mode;
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
2008-11-22 16:12:32 +01:00
|
|
|
case $gid {
|
2009-03-13 00:25:54 +01:00
|
|
|
'absent','uid': {
|
|
|
|
File[$real_homedir]{
|
|
|
|
group => $name,
|
2008-11-22 16:12:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
2009-03-13 00:25:54 +01:00
|
|
|
File[$real_homedir]{
|
|
|
|
group => $gid,
|
|
|
|
}
|
2008-11-22 16:12:32 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if $uid != 'absent' {
|
|
|
|
User[$name]{
|
|
|
|
uid => $uid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if $gid != 'absent' {
|
2009-03-13 00:33:08 +01:00
|
|
|
if $gid == 'uid' {
|
2009-03-13 00:25:54 +01:00
|
|
|
if $uid != 'absent' {
|
|
|
|
$real_gid = $uid
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$real_gid = $gid
|
|
|
|
}
|
|
|
|
if $real_gid {
|
|
|
|
User[$name]{
|
|
|
|
gid => $real_gid,
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 00:25:54 +01:00
|
|
|
if $name != 'root' {
|
|
|
|
if $uid == 'absent' {
|
2009-03-13 00:33:08 +01:00
|
|
|
if $manage_group and ($ensure == 'absent') {
|
2009-04-30 15:19:59 +02:00
|
|
|
case $operatingsystem {
|
|
|
|
'OpenBSD': {
|
|
|
|
group{$name:
|
2009-03-13 00:33:08 +01:00
|
|
|
ensure => absent,
|
2009-04-30 15:19:59 +02:00
|
|
|
}
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
2009-04-30 15:19:59 +02:00
|
|
|
}
|
2008-11-22 16:20:59 +01:00
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
} else {
|
|
|
|
if $manage_group {
|
|
|
|
group { $name:
|
|
|
|
allowdupe => false,
|
|
|
|
ensure => $ensure,
|
|
|
|
}
|
|
|
|
if $real_gid {
|
|
|
|
Group[$name]{
|
|
|
|
gid => $real_gid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-07 01:53:41 +01:00
|
|
|
}
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
|
|
|
|
2009-03-07 12:53:21 +01:00
|
|
|
case $ensure {
|
|
|
|
present: {
|
2009-03-13 00:25:54 +01:00
|
|
|
if $sshkey != 'absent' {
|
|
|
|
User[$name]{
|
|
|
|
before => Class[$sshkey],
|
2009-03-07 12:53:21 +01:00
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
include $sshkey
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
2008-10-25 22:31:44 +02:00
|
|
|
|
2009-03-13 00:25:54 +01:00
|
|
|
if $password != 'absent' {
|
|
|
|
case $operatingsystem {
|
|
|
|
openbsd: {
|
|
|
|
exec { "setpass ${name}":
|
|
|
|
unless => "grep -q '^${name}:${password}:' /etc/master.passwd",
|
|
|
|
command => "usermod -p '${password}' ${name}",
|
|
|
|
require => User["${name}"],
|
2009-03-07 12:53:21 +01:00
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
include ruby-libshadow
|
|
|
|
if $password_crypted {
|
|
|
|
$real_password = $password
|
|
|
|
} else {
|
|
|
|
if $password_salt {
|
|
|
|
$real_password = mkpasswd($password,$password_salt)
|
2009-03-07 12:53:21 +01:00
|
|
|
} else {
|
2009-03-13 00:25:54 +01:00
|
|
|
fail("To use unencrypted passwords you have to define a variable \$password_salt to an 8 character salt for passwords!")
|
2008-10-25 22:46:48 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 00:25:54 +01:00
|
|
|
User[$name]{
|
|
|
|
password => $real_password,
|
|
|
|
require => Package['ruby-libshadow'],
|
|
|
|
}
|
2008-10-25 22:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|
|
|
|
|
2008-11-22 16:12:32 +01:00
|
|
|
# gid: by default it will take the same as the uid
|
2008-10-20 22:51:27 +02:00
|
|
|
define user::sftp_only(
|
2009-03-07 12:53:21 +01:00
|
|
|
$ensure = present,
|
2008-12-05 18:29:47 +01:00
|
|
|
$managehome = false,
|
2008-11-09 16:16:20 +01:00
|
|
|
$uid = 'absent',
|
2008-11-22 16:12:32 +01:00
|
|
|
$gid = 'uid',
|
2008-11-07 20:38:19 +01:00
|
|
|
$homedir_mode = '0750',
|
2008-10-25 22:46:48 +02:00
|
|
|
$password = 'absent',
|
2008-12-05 18:37:24 +01:00
|
|
|
$password_crypted = true
|
2008-10-20 22:51:27 +02:00
|
|
|
) {
|
|
|
|
include user::groups::sftponly
|
2008-12-01 23:45:57 +01:00
|
|
|
user::managed{"${name}":
|
2009-03-12 23:49:51 +01:00
|
|
|
ensure => $ensure,
|
2008-11-09 16:16:20 +01:00
|
|
|
uid => $uid,
|
|
|
|
gid => $gid,
|
2008-10-20 23:02:54 +02:00
|
|
|
name_comment => "SFTP-only_user_${name}",
|
2008-10-20 22:51:36 +02:00
|
|
|
groups => [ 'sftponly' ],
|
2008-11-07 20:38:19 +01:00
|
|
|
managehome => $managehome,
|
|
|
|
homedir_mode => $homedir_mode,
|
2008-10-20 22:51:36 +02:00
|
|
|
shell => $operatingsystem ? {
|
|
|
|
debian => '/usr/sbin/nologin',
|
|
|
|
ubuntu => '/usr/sbin/nologin',
|
|
|
|
default => '/sbin/nologin'
|
|
|
|
},
|
2008-10-25 22:31:44 +02:00
|
|
|
password => $password,
|
2008-10-25 22:46:48 +02:00
|
|
|
password_crypted => $password_crypted,
|
2008-10-20 22:51:36 +02:00
|
|
|
require => Group['sftponly'],
|
|
|
|
}
|
2008-10-20 22:51:27 +02:00
|
|
|
}
|