by bloopernova · 4y ago · 0 comments
SELinux is a policy system where policy is enforced via labels.
Labels are applied to processes which classify what the process is.
Labels are applied to files which define the what classification of process can access the file.
The application of labels happens automatically based on policy. Such policy would include the location of the file or the label of the parent process.
As an example, the default policy for httpd would prevent httpd from accessing /etc/passwd even though the process is running as (or can be) the root user. I believe you could also do interesting things like prevent httpd from opening a socket on a non-standard port if you wanted to.
SELinux is very powerful but complicated. Ideally you use this with distro packages which should have policies already configured for you.
Critically it is not one vs the other. Use both if you have it.
I would pretty much never ask a human being to write SELinux policies unless that was explicitly part of their job whereas I can pretty much point any developer to what systemd is providing and they'll be able to work with it.
So the overlap choice seems to be more around SELinux versus Capabilities. Where SELinux is more fine-grained and tunable, but more complicated also.
The overlap/comparison between capabilities, systemds features, and selinux features isn't really well defined in any meaningful way IMO. It's really like 5 different features being used in various ways.
The normal filesystem permissions of read/write/execute for user/group/other are among those known as "discretionary access controls," meaning that they can be relaxed.
The systemd unit security options are discretionary, at the control of the administrator.
The rules can also be adjusted, and there are a number of tunable parameters.
The intent is that it is never disabled.
That is, the same command that gets denied by SELinux through systemd will run fine (and unprotected) when started from a shell.
Do you write your own policies for individual end-user programs?
[Service]
ProtectSystem=strict
ReadWritePaths=/some/path
ReadOnlyPaths=/some/otherpath
InaccessiblePaths=/etc
Unlike systemd, they then apply to everything.
(and I say this based on both observation and personal experience, I have some stuff to harden later this year and I'm really hoping I'll be able to involve somebody who -has- that level of SElinux knowledge but plan B is almost certainly going to be 'mst does his best with the unit configs')
But if one can spare the time, SELinux can secure everything, not just systemd services.
It all depends on the threat vectors one faces.