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

Add SELinux support for the Icinga 2 core #141

Merged
merged 1 commit into from
Aug 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
features => [],
}

# check selinux
$_selinux = if fact('os.selinux.enabled') and $facts['os']['selinux']['enabled'] and $icinga2::globals::selinux_package_name {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify it a bit. fact() will return the fact value, if the fact exists, or undef:

Suggested change
$_selinux = if fact('os.selinux.enabled') and $facts['os']['selinux']['enabled'] and $icinga2::globals::selinux_package_name {
$_selinux = if fact('os.selinux.enabled') == true and $icinga2::globals::selinux_package_name {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it the same way as in the icinga2 module. And the unit test on FreeBSD and Windows said it's required.

$icinga2::manage_selinux
} else {
false
}

# switch logging between mainlog, syslog and eventlog
if $facts['kernel'] != 'windows' {
if $logging_type == 'file' {
Expand Down Expand Up @@ -125,16 +132,20 @@

case $facts['kernel'] {
'linux': {
$icinga_user = $icinga2::globals::user
$icinga_group = $icinga2::globals::group
$icinga_package = $icinga2::globals::package_name
$icinga_service = $icinga2::globals::service_name
$icinga_user = $icinga2::globals::user
$icinga_group = $icinga2::globals::group
$icinga_service = $icinga2::globals::service_name
$icinga_packages = if $_selinux {
[$icinga2::globals::package_name, $icinga2::globals::selinux_package_name] + $extra_packages
} else {
[$icinga2::globals::package_name] + $extra_packages
}

case $facts['os']['family'] {
'redhat': {
$icinga_user_homedir = $icinga2::globals::spool_dir

package { ['nagios-common', $icinga_package] + $extra_packages:
package { ['nagios-common'] + $icinga_packages:
ensure => installed,
before => Class['icinga2'],
}
Expand All @@ -147,7 +158,7 @@
'debian': {
$icinga_user_homedir = '/var/lib/nagios'

package { [$icinga_package] + $extra_packages:
package { $icinga_packages:
ensure => installed,
before => Class['icinga2'],
}
Expand All @@ -156,7 +167,7 @@
'suse': {
$icinga_user_homedir = $icinga2::globals::spool_dir

package { [$icinga_package] + $extra_packages:
package { $icinga_packages:
ensure => installed,
before => Class['icinga2'],
}
Expand Down Expand Up @@ -191,7 +202,8 @@
ensure => file,
owner => $icinga_user,
group => $icinga_group,
require => Package[$icinga_package];
seltype => 'icinga2_spool_t',
require => Package[$icinga_packages];
["${icinga_user_homedir}/.ssh", "${icinga_user_homedir}/.ssh/controlmasters"]:
ensure => directory,
mode => '0700';
Expand Down
12 changes: 7 additions & 5 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@

($global_zones + keys($_workers) + $zone).each |String $dir| {
file { "${icinga2::globals::conf_dir}/zones.d/${dir}":
ensure => directory,
tag => 'icinga2::config::file',
owner => $icinga2::globals::user,
group => $icinga2::globals::group,
mode => '0750',
ensure => directory,
tag => 'icinga2::config::file',
owner => $icinga2::globals::user,
group => $icinga2::globals::group,
mode => '0750',
seltype => 'icinga2_etc_t',
}
}
} else {
Expand All @@ -140,6 +141,7 @@
purge => true,
recurse => true,
force => true,
seltype => 'icinga2_etc_t',
}
}
}
Loading