Run init script as SELinux type other than initrc_t
To run a custom init script as SELinux context other than initrc_t, you can use an SELinux policy that adds a new type for you to use.
# Filename: general-local.te
# License: CC-BY-SA 4.0
# Author: bgstack15
# Startdate: 2019-09-19 16:45
# Title: SELinux Policy for Custom Process Types from Init Scripts
# Purpose: SELinux policy to allow an init script to run a process as a selinux type other than initrc_t
# History:
# Usage:
# When installed, you can run the following command to have the daemon process transition to type unconfined_t:
# chcon -t 'local_initrc_exec_t' /etc/init.d/myscript
# Reference:
# liberal use of tail -n45000 /var/log/audit/audit.log | audit2allow
# https://selinuxproject.org/page/ObjectClassesPerms#filesystem
# http://www.cse.psu.edu/~trj1/cse543-f07/slides/03-PolicyConcepts.pdf
# http://www.billauer.co.il/selinux-policy-module-howto.html
# https://fedoraproject.org/wiki/PackagingDrafts/SELinux#Creating_new_types
# https://wiki.centos.org/HowTos/SELinux
# /posts/2018/02/13/logrotate-audit-log-selinux-cron-and-ansible/
# Improve:
# Documentation:
# Change an init script to context local_initrc_exec_t and then the process will transition to unconfined_t which of course is insecure, but it satisfies the scan that is looking for daemons running as initrc_t.
module general-local 1.0;
require {
type fs_t;
type initrc_exec_t;
type init_t;
type unconfined_t;
class file { append create entrypoint execmod execute execute_no_trans getattr ioctl link lock mounton open quotaon read relabelfrom relabelto rename setattr swapon unlink write };
class filesystem associate;
class process { unconfined transition };
class service { start status };
}
type local_initrc_exec_t;
type_transition init_t local_initrc_exec_t:process unconfined_t ;
#============= init_t ==============
allow init_t local_initrc_exec_t:file *;
allow init_t unconfined_t:process transition;
#============= local_initrc_exec_t ==============
allow local_initrc_exec_t fs_t:filesystem associate;
#============= unconfined_t ==============
allow unconfined_t local_initrc_exec_t:file *;
allow unconfined_t local_initrc_exec_t:service { start status };
To compile and install this module, you can run the following oneliner.
checkmodule -M -m -o general_local.mod general_local.te && semodule_package -m general_local.mod -o general_local.pp && semodule -v -i general_local.pp
Should you run daemons as unconfined_t? Of course not. But it's different than running it as initrc_t.
References
Weblinks
- ObjectClassesPerms - SELinux Wiki
- SELinux Policy Concepts and Overview: Security Policy Development Primer for Security Enhanced Linux
- Writing a targeted policy module for SELinux (howto tutorial slides)
- PackagingDrafts/SELinux - Fedora Project Wiki#Creating_new_types
- HowTos/SELinux - CentOS Wiki
- Logrotate, audit.log, selinux, cron, and ansible | Knowledge Base
Comments