Bug 1380697

Summary: selinux prevents executing scripts by zabbix-agent
Product: Red Hat Enterprise Linux 7 Reporter: Eugene Peregudov <joniknsk>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: lvrabec, mgrepl, mmalik, plautrba, pvrabec, ssekidde
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.13.1-203.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-30 09:59:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eugene Peregudov 2016-09-30 11:09:53 UTC
Description of problem:

I'm trying to monitor Haproxy instance via custom script for Zabbix agent.
Default system policy contains contexts for directories with external scripts:

# semanage fcontext -l | grep zabbix | grep script
/usr/lib/zabbix/externalscripts(/.*)?              all files          system_u:object_r:zabbix_script_exec_t:s0
/var/lib/zabbix/externalscripts(/.*)?              all files          system_u:object_r:zabbix_script_exec_t:s0

SELinux prevents executing scripts by zabbix-agent with this audit message:

type=AVC msg=audit(1475181608.675:258818): avc:  denied  { execute_no_trans } for  pid=18046 comm="sh" path="/var/lib/zabbix/externalscripts/haproxy_stats.sh" dev="dm-8" ino=29564421 scontext=system_u:system_r:zabbix_agent_t:s0 tcontext=unconfined_u:object_r:zabbix_script_exec_t:s0 tclass=file

Version-Release number of selected component (if applicable):
RHEL 7.2 x86_64
selinux-policy-targeted-3.13.1-60.el7_2.9.noarch
selinux-policy-3.13.1-60.el7_2.9.noarch

How reproducible:
Always.

Steps to Reproduce:
1. Install RHEL 7.2 x86_64
2. Install zabbix-agent
3. Call custom script from /var/lib/zabbix/externalscripts/ with zabbix-agent (or call direct with source domain zabbix_agent_t)

Actual results:

SELinux prevents executing the script

Expected results:

Script will be run with zabbix_script_t domain

Additional info:

Scripts are working after installing custom module:

module zabbix_agent 1.0.1;

require {
    type zabbix_script_exec_t;
    type zabbix_script_t;
    type zabbix_agent_t;
    class file { ioctl read getattr execute open };
    class dir { ioctl read getattr lock search open };
    class process { transition sigchld };
    class fifo_file { ioctl read write getattr lock append };
    class fd use;
}

#============= zabbix_agent_t ==============
allow zabbix_agent_t zabbix_script_exec_t : file { ioctl read getattr execute open } ;
allow zabbix_agent_t zabbix_script_exec_t : dir { ioctl read getattr lock search open } ;
allow zabbix_agent_t zabbix_script_t : process transition ;
type_transition zabbix_agent_t zabbix_script_exec_t : process zabbix_script_t;

#============= zabbix_script_t =============
allow zabbix_script_t zabbix_agent_t : process sigchld ;
allow zabbix_script_t zabbix_agent_t : fd use ;
allow zabbix_script_t zabbix_agent_t : fifo_file { ioctl read write getattr lock append } ;

Please, update zabbix module in default system policy.

Comment 7 errata-xmlrpc 2018-10-30 09:59:46 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:3111