2025-02-20 13:49:00 +01:00
|
|
|
# rsyslog
|
2025-02-21 11:02:24 +01:00
|
|
|
class soc::rsyslog::server(
|
2025-02-20 13:49:00 +01:00
|
|
|
$daily_rotation = true,
|
|
|
|
$syslog_servers = lookup(syslog_servers, undef, undef, []),
|
|
|
|
$relp_syslog_servers = lookup(relp_syslog_servers, undef, undef, []),
|
|
|
|
$single_log_file = false,
|
|
|
|
$syslog_enable_remote = lookup('syslog_enable_remote', undef, undef, 'true'),
|
|
|
|
$udp_port = lookup(udp_port, undef, undef, undef),
|
|
|
|
$udp_client = lookup('udp_client', undef, undef, 'any'),
|
|
|
|
$tcp_port = lookup(tcp_port, undef, undef, undef),
|
|
|
|
$tcp_client = lookup('tcp_client', undef, undef, 'any'),
|
2025-02-20 14:20:45 +01:00
|
|
|
$relp_port = lookup(relp_port, undef, undef, undef),
|
2025-02-20 14:19:17 +01:00
|
|
|
$relp_client = lookup('relp_client', undef, undef, 'any'),
|
2025-02-20 13:49:00 +01:00
|
|
|
$traditional_file_format = false,
|
|
|
|
) {
|
|
|
|
ensure_resource('package', 'rsyslog', {
|
|
|
|
ensure => 'installed'
|
|
|
|
})
|
|
|
|
|
|
|
|
file { '/etc/rsyslog.conf':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template('soc/rsyslog/rsyslog.conf.erb'),
|
2025-02-20 13:49:00 +01:00
|
|
|
require => Package['rsyslog'],
|
|
|
|
notify => Service['rsyslog']
|
|
|
|
}
|
|
|
|
|
|
|
|
$default_template = $single_log_file ?
|
|
|
|
{
|
|
|
|
true => 'rsyslog-default-single-logfile.conf.erb',
|
|
|
|
false => 'rsyslog-default.conf.erb',
|
|
|
|
}
|
|
|
|
file { '/etc/rsyslog.d/50-default.conf':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template("soc/rsyslog/${default_template}"),
|
2025-02-20 13:49:00 +01:00
|
|
|
require => Package['rsyslog'],
|
|
|
|
notify => Service['rsyslog']
|
|
|
|
}
|
|
|
|
|
|
|
|
$do_remote = str2bool($syslog_enable_remote)
|
|
|
|
|
|
|
|
file { '/etc/rsyslog.d/60-remote.conf':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template('soc/rsyslog/rsyslog-remote.conf.erb'),
|
2025-02-20 13:49:00 +01:00
|
|
|
require => Package['rsyslog'],
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_resource('service', 'rsyslog', {
|
|
|
|
ensure => 'running',
|
|
|
|
enable => true,
|
|
|
|
subscribe => File['/etc/rsyslog.d/60-remote.conf'],
|
|
|
|
})
|
|
|
|
|
|
|
|
if $relp_syslog_servers != [] {
|
|
|
|
ensure_resource('package', 'rsyslog-relp', {
|
|
|
|
ensure => 'installed'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-02-20 14:19:17 +01:00
|
|
|
if ($tcp_port or $udp_port or $relp_port) {
|
2025-02-20 13:49:00 +01:00
|
|
|
|
|
|
|
if ($udp_port) {
|
2025-02-20 13:51:04 +01:00
|
|
|
sunet::nftables::allow { "allow-syslog-udp-${udp_port}":
|
2025-02-20 13:49:00 +01:00
|
|
|
from => $udp_client,
|
2025-02-20 13:52:13 +01:00
|
|
|
to => 'any',
|
2025-02-20 13:49:00 +01:00
|
|
|
proto => 'udp',
|
|
|
|
port => $udp_port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($tcp_port) {
|
2025-02-20 13:51:04 +01:00
|
|
|
sunet::nftables::allow { "allow-syslog-tcp-${tcp_port}":
|
2025-02-20 13:49:00 +01:00
|
|
|
from => $tcp_client,
|
2025-02-20 13:52:13 +01:00
|
|
|
to => 'any',
|
2025-02-20 13:49:00 +01:00
|
|
|
proto => 'tcp',
|
|
|
|
port => $tcp_port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-20 14:19:17 +01:00
|
|
|
if ($relp_port) {
|
|
|
|
sunet::nftables::allow { "allow-syslog-relp-${relp_port}":
|
|
|
|
from => $relp_client,
|
|
|
|
to => 'any',
|
|
|
|
proto => 'tcp',
|
|
|
|
port => $relp_port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-20 13:49:00 +01:00
|
|
|
file { '/etc/rsyslog.d/50-local.conf':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template('soc/rsyslog/rsyslog-local.conf.erb'),
|
2025-02-20 13:49:00 +01:00
|
|
|
require => Package['rsyslog'],
|
|
|
|
notify => Service['rsyslog']
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($daily_rotation == true)
|
|
|
|
{
|
|
|
|
file { '/etc/logrotate.d/rsyslog':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template('soc/rsyslog/rsyslog.logrotate.erb'),
|
2025-02-20 13:49:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($single_log_file == true and $facts['fail2ban_is_enabled'] == 'yes') {
|
|
|
|
file { '/etc/fail2ban/jail.d/sshd-rsyslog-single-logfile.conf':
|
|
|
|
ensure => file,
|
|
|
|
mode => '0644',
|
2025-02-20 14:58:38 +01:00
|
|
|
content => template('soc/rsyslog/fail2ban-ssh-syslog.conf.erb'),
|
2025-02-20 13:49:00 +01:00
|
|
|
notify => Service['fail2ban'],
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|