ssh: Backport ssh::allow from parameterize
This commit is contained in:
parent
c0ba62872b
commit
521f6c633a
2 changed files with 84 additions and 26 deletions
|
@ -180,33 +180,69 @@ class ssh::disable inherits ssh::server {
|
|||
#
|
||||
class ssh::allowgroups {
|
||||
|
||||
include ssh::server
|
||||
warning("ssh::allowgroups is deprecated, use ssh::allow")
|
||||
|
||||
$root_group = $::operatingsystem ? {
|
||||
"openbsd" => "wheel",
|
||||
default => "root",
|
||||
}
|
||||
|
||||
if $ssh_allowgroups {
|
||||
$ssh_allowgroups_real = inline_template("${root_group} <%= @ssh_allowgroups.join(' ') %>")
|
||||
} else {
|
||||
$ssh_allowgroups_real = $root_group
|
||||
}
|
||||
|
||||
exec { "ssh-allowgroups-set":
|
||||
path => "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
|
||||
cwd => "/etc/ssh",
|
||||
command => "echo 'AllowGroups ${ssh_allowgroups_real}' >> sshd_config",
|
||||
unless => "grep -q '^[^#]*AllowGroups' sshd_config",
|
||||
before => Exec["ssh-allowgroups-sub"],
|
||||
notify => Service["sshd"],
|
||||
}
|
||||
exec { "ssh-allowgroups-sub":
|
||||
path => "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
|
||||
cwd => "/etc/ssh",
|
||||
command => "ruby -pi -e 'sub(/(AllowGroups).*/, \"\\\\1 ${ssh_allowgroups_real}\")' sshd_config",
|
||||
unless => "grep -q '^[^#]*AllowGroups ${ssh_allowgroups_real}' sshd_config",
|
||||
notify => Service["sshd"],
|
||||
class { "ssh::allow":
|
||||
groups => $ssh_allowgroups,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Set AllowUsers and AllowGroups in sshd_config.
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# $root:
|
||||
# Always allow root. Defaults to true.
|
||||
# $users:
|
||||
# Array of allowed users. Allow all if undefined.
|
||||
# $groups:
|
||||
# Array of allowed groups. Allow all if undefined.
|
||||
#
|
||||
class ssh::allow(
|
||||
$root=true,
|
||||
$users=undef,
|
||||
$groups=undef,
|
||||
) {
|
||||
|
||||
include ssh::server
|
||||
|
||||
if $users {
|
||||
if $root {
|
||||
$users_real = merge('root', $users)
|
||||
} else {
|
||||
$users_real = $users
|
||||
}
|
||||
} else {
|
||||
$users_real = []
|
||||
}
|
||||
|
||||
$root_group = $::operatingsystem ? {
|
||||
'openbsd' => 'wheel',
|
||||
default => 'root',
|
||||
}
|
||||
|
||||
if $groups {
|
||||
if $root {
|
||||
$groups_real = merge($root_group, $groups)
|
||||
} else {
|
||||
$groups_real = $groups
|
||||
}
|
||||
} else {
|
||||
$groups_real = []
|
||||
}
|
||||
|
||||
augeas { 'ssh-allow-users':
|
||||
context => '/files/etc/ssh/sshd_config',
|
||||
changes => augeas_set_children('AllowUsers', $users_real),
|
||||
notify => Service['sshd'],
|
||||
}
|
||||
|
||||
augeas { 'ssh-allow-groups':
|
||||
context => '/files/etc/ssh/sshd_config',
|
||||
changes => augeas_set_children('AllowGroups', $groups_real),
|
||||
notify => Service['sshd'],
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue