SELinux Systemd Access Control
Summary
We need systemd to do SELinux access checking whether or not a process is allowed to manage a unit file.
Owner
- Name: Daniel Walsh
- Email: <dwalsh@redhat.com>
Current status
- Targeted release: [Fedora 18]
- Last updated: Sep 7 2012
- Percentage of completion: 75%
selinux-policy fixes are in Fedora 18. Patch has gone through one preliminary review by systemd, Looks pretty good and working well on my machine.
Patch has been sent upstream, I have made a version available for other SELinux developers to play with, and no problems found so far.
Detailed Description
In previous versions of Fedora/RHEL we were able to control which applications/users were able to start/stop services based on the label of the SYSV Init Script. With the advent of systemd we lost this ability since systemd starts and stops all services, and users and processes talk to systemd using systemctl.
Benefit to Fedora
We can better lock down services, for example: Currently NetworkManager needs to be able to start and stop the ntpd service. Currently the only way we can allow NetworkManager to start the ntpd service is to allow it to start/stop any service including security services like iptables/firewalld. Similarly with confined administrators, I would like to define a web administrator that can only manager files in /var/www/html, and start and stop the httpd service, without this feature I have to allow the confined admin to start/stop all services.
Scope
SELinux Policy needs to be written to govern which domains are able to control which units, (completed) Systemd has to be modified to look at the label of the calling process and the label of the unit file that the caller wants to manage, and then ask SELinux whether or not the caller is allowed the access. A preliminary patch for this was sent to systemd a few months ago, but we need to follow up on it.
How To Test
We can write a test suite to setup different success and failure situations. for example cause a process to run as NetworkManager_t, and execute the systemctl start ntpd.service (Should Succeed) Another attempt would be systemd start httpd.service (Should Fail) Try out confined administrators for webadm_t, and make sure he can only start and stop the httpd service.
Normal system testing should quickly show if there are bugs in the code.
Setup a confined user as guest_u and make sure he is not able to shut the machine down.
User Experience
Since unconfined_t is normal label of the user starting and stopping services, this fix should not effect normal administration of the system.
Dependencies
Systemd accepting the patch in a release that is in F18.
Contingency Plan
We can continue allowing all access, but this is less secure then what we had in Fedora 15.
Documentation
This feature is to use SELinux to enforce Access Control to critical features like starting/stoping system services. Theoretically it should only effect the systemd developers and selinux policy writers.
Policy changes involve a new class called "service", with the following permissions
class service { start stop status reload kill load enable disable }
Since SELinux access checks and systemd access do not line up exactly, we have created a table to connect systemd (systemctl) commands with the appropriate SELinux access.
/* Define a mapping between the systemd method calls and the SELinux access to check. We define two tables, one for access checks on unit files, and one for access checks for the system in general. If we do not find a match in either table, then the "undefined" system check will be called. */
static const char *unit_methods[][2] = {{ "DisableUnitFiles", "disable" }, { "EnableUnitFiles", "enable" }, { "GetUnit", "status" }, { "GetUnitByPID", "status" }, { "GetUnitFileState", "status" }, { "Kill", "stop" }, { "KillUnit", "stop" }, { "LinkUnitFiles", "enable" }, { "ListUnits", "status" }, { "LoadUnit", "status" }, { "MaskUnitFiles", "disable" }, { "PresetUnitFiles", "enable" }, { "ReenableUnitFiles", "enable" }, { "Reexecute", "start" }, { "Reload", "reload" }, { "ReloadOrRestart", "start" }, { "ReloadOrRestartUnit", "start" }, { "ReloadOrTryRestart", "start" }, { "ReloadOrTryRestartUnit", "start" }, { "ReloadUnit", "reload" }, { "ResetFailed", "stop" }, { "ResetFailedUnit", "stop" }, { "Restart", "start" }, { "RestartUnit", "start" }, { "Start", "start" }, { "StartUnit", "start" }, { "StartUnitReplace", "start" }, { "Stop", "stop" }, { "StopUnit", "stop" }, { "TryRestart", "start" }, { "TryRestartUnit", "start" }, { "UnmaskUnitFiles", "enable" }, { NULL, NULL } };
static const char *system_methods[][2] = { { "ClearJobs", "reboot" }, { "FlushDevices", "halt" }, { "Get", "status" }, { "GetAll", "status" }, { "GetJob", "status" }, { "GetSeat", "status" }, { "GetSession", "status" }, { "GetSessionByPID", "status" }, { "GetUser", "status" }, { "Halt", "halt" }, { "Introspect", "status" }, { "KExec", "reboot" }, { "KillSession", "halt" }, { "KillUser", "halt" }, { "ListJobs", "status" }, { "ListSeats", "status" }, { "ListSessions", "status" }, { "ListUsers", "status" }, { "LockSession", "halt" }, { "PowerOff", "halt" }, { "Reboot", "reboot" }, { "SetUserLinger", "halt" }, { "TerminateSeat", "halt" }, { "TerminateSession", "halt" }, { "TerminateUser", "halt" }, { NULL, NULL } };
Policy for this would look like.
sesearch -A -s NetworkManager_t -c service Found 5 semantic av rules: allow NetworkManager_t dnsmasq_unit_file_t : service { start stop status reload kill load } ; allow NetworkManager_t nscd_unit_file_t : service { start stop status reload kill load } ; allow NetworkManager_t ntpd_unit_file_t : service { start stop status reload kill load } ; allow NetworkManager_t pppd_unit_file_t : service { start stop status reload kill load } ; allow NetworkManager_t polipo_unit_file_t : service { start stop status reload kill load } ;
sesearch -A -s webadm_t -c service Found 1 semantic av rules: allow webadm_t httpd_unit_file_t : service { start stop status reload kill load enable disable } ;
Release Notes
- Several SELinux booleans names have been changed. Mainly booleans beginning with allow_ will now begin with a domain specific name, for example allow_httpd_anon_write has been changed to httpd_anon_write. If you set or get the old boolean name, it will continue to work, but the old boolean name will no longer show up in lists of booleans.