Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup backup::receiver on puppet01 #1930

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion puppet/manifests/site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
node /^puppet\d+\.[a-z]+\.theforeman\.org$/ {
include profiles::base
include profiles::puppetserver
include profiles::backup::receiver
class {'profiles::backup::receiver':
ensure => absent,
}
}

node /^redmine\d+\.([a-z]+\.)?theforeman\.org$/ {
Expand Down
25 changes: 16 additions & 9 deletions puppet/modules/profiles/manifests/backup/receiver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@
# The group which all targets belong to
# @param directory
# The parent directory for all targets
# @param ensure
# The backup receiver state to ensure.
class profiles::backup::receiver (
Array[String[1]] $targets = [],
String[1] $group = 'backup',
Stdlib::Absolutepath $directory = '/srv/backup',
Enum['present', 'absent'] $ensure = present,
) {
group { $group:
ensure => present,
ensure => $ensure,
}

file { $directory:
ensure => directory,
owner => 'root',
group => $group,
mode => '0750',
if $ensure == present {
file { $directory:
ensure => 'directory',
owner => 'root',
group => $group,
mode => '0750',
}
}

# Ensure $directory/.ssh is set to to ssh_home_t
if $facts['os']['selinux']['enabled'] and $directory != '/home' {
selinux::fcontext { 'backup-ssh':
ensure => $ensure,
seltype => 'ssh_home_t',
pathspec => "${directory}/[^/]+/\\.ssh(/.*)?",
}
Expand All @@ -39,19 +45,19 @@

$sshd_match = "Group ${group}"
sshd_config_match { $sshd_match:
ensure => present,
ensure => $ensure,
}

# TODO: ChrootDirectory %h

sshd_config { 'DisableForwarding':
ensure => present,
ensure => $ensure,
condition => $sshd_match,
value => 'yes',
}

sshd_config { 'ForceCommand':
ensure => present,
ensure => $ensure,
condition => $sshd_match,
value => 'internal-sftp',
}
Expand All @@ -60,6 +66,7 @@

$targets.each |$target| {
profiles::backup::receiver::target { $target:
ensure => $ensure,
require => $require,
}
}
Expand Down
17 changes: 11 additions & 6 deletions puppet/modules/profiles/manifests/backup/receiver/target.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
#
# @param username
# The remote username
# @param ensure
# The backup receiver target state to ensure.
define profiles::backup::receiver::target (
String[1] $username = "backup-${title}",
Enum['present', 'absent'] $ensure = present,
) {
include profiles::backup::receiver

$homedir = "${profiles::backup::receiver::directory}/${title}"

user { $username:
ensure => present,
ensure => $ensure,
gid => $profiles::backup::receiver::group,
home => $homedir,
managehome => true,
Expand All @@ -23,22 +26,24 @@

# Ensure authorized keys file for proper SELinux labels
file { "${homedir}/.ssh":
ensure => directory,
ensure => bool2str($ensure == present, 'directory', 'absent'),
owner => $username,
mode => '0700',
force => $ensure == absent,
seltype => 'ssh_home_t',
}

file { "${homedir}/.ssh/authorized_keys":
ensure => file,
ensure => bool2str($ensure == present, 'file', 'absent'),
owner => $username,
mode => '0600',
seltype => 'ssh_home_t',
}

ssh_authorized_key { "${username} managed by Puppet":
user => $username,
key => ssh::keygen("backup-${title}", true),
type => 'ssh-rsa',
ensure => $ensure,
user => $username,
key => ssh::keygen("backup-${title}", true),
type => 'ssh-rsa',
}
}