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 support for templated SE Linux agent module #452

Merged
merged 6 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,23 @@ Many thanks for this!
### Standard usage
* Not specified as required but for working correctly, the epel repository should be available for the 'fping'|'fping6' packages.
* Make sure you have sudo installed and configured with: !requiretty.
* Make sure that selinux is permissive or disabled.

### SE Linux
Copy link
Member

Choose a reason for hiding this comment

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

please add a newline after the heading

Copy link
Member

Choose a reason for hiding this comment

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

I can recommend https://dlaa.me/markdownlint/ as a linter

Copy link
Contributor Author

@tux-o-matic tux-o-matic Sep 27, 2017

Choose a reason for hiding this comment

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

The README is full of it.

Copy link
Member

Choose a reason for hiding this comment

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

yep. github changed their parser in the past, so now we try to enforce their rules for new changes.


On systems with SE Linux active and enforcing, Zabbix agent will be limited unless given proper rights with an SE Linux module.
This Puppet module will apply some default SE Linux rules for it.
More can be provided if needed by using two class parameters, for example in Hiera YAML:

```yaml
Copy link
Member

Choose a reason for hiding this comment

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

please add a newline before the codeblock

zabbix::agent::selinux_require:
- 'type zabbix_agent_t'
- 'class process setrlimit'
zabbix::agent::selinux_rules:
zabbix_agent_t:
- 'allow zabbix_agent_t self:process setrlimit'
zabbix_script_t:
- 'allow zabbix_script_t zabbix_agent_t:process sigchld'
```

### When using exported resources

Expand Down
11 changes: 0 additions & 11 deletions files/zabbix-agent.te

This file was deleted.

8 changes: 5 additions & 3 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@
String $agent_config_owner = $zabbix::params::agent_config_owner,
String $agent_config_group = $zabbix::params::agent_config_group,
Boolean $manage_selinux = $zabbix::params::manage_selinux,
Array[String] $selinux_require = $zabbix::params::selinux_require,
Hash[String, Array] $selinux_rules = $zabbix::params::selinux_rules,
String $additional_service_params = $zabbix::params::additional_service_params,
String $service_type = $zabbix::params::service_type,
) inherits zabbix::params {
Expand Down Expand Up @@ -414,9 +416,9 @@
# https://support.zabbix.com/browse/ZBX-11631
if $facts['selinux'] == true and $manage_selinux {
selinux::module{'zabbix-agent':
ensure => 'present',
source_te => 'puppet:///modules/zabbix/zabbix-agent.te',
before => Service['zabbix-agent'],
ensure => 'present',
content_te => template('zabbix/selinux/zabbix-agent.te.erb'),
Copy link
Member

Choose a reason for hiding this comment

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

Can you switch this to an epp template instead of erb?

Copy link
Member

@juniorsysadmin juniorsysadmin Sep 29, 2017

Choose a reason for hiding this comment

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

@tux-o-matic What I meant is that zabbix/selinux/zabbix-agent.te.erb should also be the default value of a new parameter named say $selinux_content_te , so if a user doesn't want to use the selinux template included with this module, they can use their own as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The template is an empty shell, everything is doable via the new class parameters. This PR only adds flexibility.

before => Service['zabbix-agent'],
}
}
}
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@
$javagateway_pidfile = '/var/run/zabbix/zabbix_java.pid'
$javagateway_startpollers = '5'
$javagateway_timeout = '3'

# SE Linux specific params
$manage_selinux = $facts['selinux']
$selinux_require = ['type zabbix_agent_t', 'class process setrlimit', 'class unix_dgram_socket create']
$selinux_rules = { 'zabbix_agent_t' => ['allow zabbix_agent_t self:process setrlimit', 'allow zabbix_agent_t self:unix_dgram_socket create']}

# services should run foreground and as simple type
# but this only works in 3.0 and newer
Expand Down
15 changes: 15 additions & 0 deletions templates/selinux/zabbix-agent.te.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module zabbix-agent 1.0;

require {
<% @selinux_require.each do |sel_require| -%>
<%= sel_require %>;
<% end -%>
}

<% @selinux_rules.keys.each do |key| -%>
#============= <%= key %> ==============
<% @selinux_rules[key].each do |rule| -%>
<%= rule %>;
<% end -%>

<% end -%>