From F45 onwards: Fedora-maintained (self-updating) hardening for general use cases, for beginners and advanced users

Hi folks, you might have already seen the earlier topics about this:

With the release of F45, there will be a Fedora-maintained hardening, which means that once enabled, it will update and adjust itself over time, so that the user does not need to maintain it themselves like a customization.

This hardening is focused on the kernel, whereas there is also SELinux and firewalld Fedora-maintained hardening (although the latter two are not new).

Each hardening can be enabled with one command, and can be treated like “fire and forget” because when, e.g., some kernel parameter needs an update (add and/or remove something), it will be updated automatically with your updates. The hardening intentionally focuses on easy-to-maintain functions and follows the Pareto principle in the selection of functions, but with a “security for general use cases first” approach, yet with the emphasis that average stuff reliably works → this is intentionally not Secureblue or QubesOS :classic_smiley:

This is intended for average users (beginners & advanced!) with general use cases (graphics, emails, browser, etc), for GNOME and KDE (other desktop environments might work as well but not tested) . Of course keep in mind that testing this is community-based, and thus less people using+testing it means also less test coverage compared to a 100% default Fedora, but feel free to review the hardening page about how to go ahead if something seems wrong: you ain’t alone :wink:

It’s also eligible for people with other use cases if they want a security first approach. E.g., developers who want functions, which in some contexts can be exploited by malicious applications (like ptrace), to be enabled only manually and temporarily when they need them (details in the hardening pages).

If you are a user who files bug reports, it is always advised to let the assignee know that the hardening is enabled.

Minor supplement that is only relevant for KDE users who file bug reports and data: drkongi might need ptrace to work properly, so it might be necessary to temporarily disable the hardening functions around ptrace if you need make use of drkongi. Details about how to do that on demand is in the hardening pages. If you have no clue what this means, you can expect it is not relevant for you.

So, have fun, and feel free to ask questions:

→ keep in mind that this page might be refined over time, feel free to contribute if you wish, also concerning the hardening functions :classic_smiley:

7 Likes

How thos works on atomics? I will test this on cosnic atomic after i get waro xml so i can actually updste my system. Will do more reading on this to see full scope of hardening and see what it has and what still missing as I did all my hardening manually now

Thanks Chris @py0xc3 very useful…
Also a good Warning:

You have to know what you are doing and understand if and when Arch suggestions apply to Fedora, or alternatively, know of the applicable risks when testing it.
 Details:
  Hardening index : 72 [##############      ]
  Tests performed : 253
  Plugins enabled : 0

1 Like

Silverblue & Kinoite → yes. Details on the page. The hardening actually should behave the same on atomics and non-atomics → hardening features that might need separate consideration of atomics / non-atomics are intentionally avoided. Other atomics, I’d expect them to work, but cannot say for sure and did not evaluate any of them. But I’d be happy to have more feedback loops to people who use any atomic.

Not sure I understand your point, but I am not acting as single point of failure with these features if it is that what you mean. Also, we can still transfer most of Fedora QA’s guarantees while much other/external testing can be also transferred to this. That was a major criteria in the selection of hardening features.

The chosen hardening features are actually quite predictable, so I don’t expect noteworthy issues with the tested variants (and I expect they cover the realistic scenarios if users do not introduce themselves too-heavy-bad-practice-customizations and do regularly updates), but I don’t exclude people ranting about bad-practice third party applications being broke (I have also seen banking apps that need ptrace to work, likely for some tampering protection, I think that’s not likely on x86_64 though, but that would be intentionally broke by default :scream: mitigation possible though, even within the hardening → see ptrace points on the page). Yet, more testing is always better than less, so everyone is welcome to do testing and give feedback and document what might be relevant for others:

hardening (should be existing as tag [sub-tag to security-sig] here hopefully in the next days) might be used to consolidate data and experiences and ideas, and “firewall”/“filter” feedback before forwarded to feature maintainers in bug reports (like ask.fedora does for average issues). The security channel also exists, but I think most feedback (also considering audiences) is best suited at hardening. When it gets into tech details, it ends up in the devel mailing list anyway but that would be then no longer specific to our hardening.

I’d be careful with these. It’s interesting and can motivate people, and sometimes they indeed raise awareness that “something” should be checked, but it’s not really expressive → few topics can be summed up to one 0-100 number :smiley:

Thanks for the answer, Chris, and for doing this at all. I went through it properly before switching, so here is what I found, what I now run, and a few things from the Atomic side that might be useful. Both of my machines are still on 44: a Fedora COSMIC Atomic laptop (my daily machine, Secure Boot on) and a small self-hosted Fedora CoreOS server on the stable stream. So this comes from reading the docs page and the f45 99-kernel-hardening.conf (systemd 262.1, which is where 45 gets it) and from checking both live systems, not from running 45 yet.

What I took from it

All five values from the kernel file, deny_ptrace, and the public zone where it applies:

Setting Fedora default Hardening Laptop Server
net.core.bpf_jit_harden 0 2 2 2
kernel.yama.ptrace_scope 0 2 2 2
kernel.kptr_restrict 0 2 2 2
fs.protected_fifos 1 2 2 2
fs.protected_regular 1 2 2 2
SELinux deny_ptrace off on on planned
firewalld default zone FedoraWorkstation on most desktops public public (already) no firewalld

Since 44’s systemd does not ship the file yet, I put the five values into my own sysctl file for now, marked so I can delete them once I am on 45 and switch to the symlink, which is the part I like most: the values keep themselves up to date. Before, I had ptrace_scope=1 and kptr_restrict=1 on the laptop, and nothing I use has needed more than that. I have not needed a debugger on this laptop in years, so deny_ptrace was an easy yes too.

What I run on top

For context, not as a request. Some of these clearly do not belong in a general set:

  • Kernel and network: kexec_load_disabled=1 on the server (planned on the laptop), accept_redirects=0 and secure_redirects=0 for IPv4 and IPv6 on both, send_redirects=0 and log_martians=1 on the server, and init_on_free=1 as a kernel argument on the laptop.
  • Name resolution and time: LLMNR off in systemd-resolved, chrony with NTS only on the laptop.
  • Network identity: a random MAC per network in NetworkManager on the laptop.
  • Boot and disk: Secure Boot with lockdown in integrity mode, and LUKS, on both. SELinux enforcing on both.
  • Inbound: on the laptop, the public zone with ssh removed and sshd disabled. CoreOS has no firewalld, so the server uses its own default-drop nftables rules instead.

Things from the Atomic side

1. The documented revert opens ports on COSMIC Atomic. COSMIC Atomic does not install firewalld-workstation-config, so its default zone is already public, not FedoraWorkstation. Enabling the hardening changes nothing there, which is fine. But the removal step, firewall-cmd --set-default-zone=FedoraWorkstation, switches it to a zone with 1025-65535/tcp and /udp open, which that variant never had. The page does say the revert may not match a variant with a different default, but it is easy to miss. Maybe: “note your zone with firewall-cmd --get-default-zone before enabling and set that one back”, or name the variants that already default to public?

2. The kernel file is shipped as documentation. On installs without docs (tsflags=nodocs, containers, some minimal images) it is not there, and the symlink points at nothing. On both my COSMIC Atomic laptop and my CoreOS server /usr/share/doc/systemd is present (225 files on each), so it works there, and on Atomic the link in /etc simply follows the image’s copy across updates, which is nice. I have not checked whether systemd-sysctl warns about a dangling link or skips it quietly. If it is quiet, someone could believe they are hardened when they are not. Would a path that is not documentation work, say /usr/share/systemd/, with the same symlink into /etc/sysctl.d? (Not /usr/lib/sysctl.d, since everything there is applied automatically.)

3. ptrace on Atomic reaches toolbox too. On Atomic most development happens in toolbox or distrobox containers. They share the host kernel, so ptrace_scope=2 also stops gdb and strace inside them. I would guess deny_ptrace does too, but toolbox runs with SELinux labelling disabled and I have not tested it. The advice on the page works the same, but an Atomic user might not expect a host setting to reach into the container. A one-line note might save some confusion.

4. Anything beyond sysctl works differently on Atomic. This is not about the current set, since it only uses sysctl, SELinux and firewalld, which behave the same on both. But if it ever grows into kernel arguments: on Atomic they go through rpm-ostree kargs, which builds a new deployment and re-runs package layering, so it inherits whatever blocks layering at the time. Right now that includes coreos/rpm-ostree#5639 for anyone whose layered package added a group to /etc/group (Wireshark, in my case). A mutable system just uses grubby. Probably one reason the current set avoids kernel arguments.

5. CoreOS. Pieces 1 and 2 seem to apply as they are, and the file is present on CoreOS too. Piece 3 does not apply, since CoreOS has no firewalld by default. Is server or CoreOS use in scope later, or deliberately left out?

Things I run that might fit the general set

More a list to consider than a request, with the cost I know of each:

  • accept_redirects=0 and secure_redirects=0, IPv4 and IPv6. A laptop on café Wi-Fi has no reason to let another host reroute its traffic, and nothing has broken here since I set them a month ago. Were they left out for multi-homed or router setups?
  • kernel.kexec_load_disabled=1. It breaks kdump, so it only fits if kdump is not on by default on the desktop variants.
  • LLMNR off in systemd-resolved. It was on in my install, and it is a common spoofing target on shared networks. Not a sysctl, so it would be a different piece.
  • A random MAC per network in NetworkManager. Privacy rather than security, but it is one config file, and the only cost I have seen is one new device per network.
  • NTS for chrony. Authenticated time on untrusted networks, though it needs TCP 4460, which some networks block.

I would keep log_martians (log noise) and init_on_free=1 (CPU cost, the kernel help says 3 to 5% in most cases) out of a general set myself.

Thanks again. A maintained floor that updates itself is exactly what most people need, and I will switch both machines to the symlink as soon as they are on 45.

2 Likes

Actually, beginning with F45, this is no longer correct: the kernel default is always 1, but Fedora used to have a package that set it to 0 and that package was a system dependency.

However, now (F45+) that package (now renamed to yama-ptrace-enable) is no longer a system dependency, so a default F45 has the kernel default 1. However, any package maintainer can set yama-ptrace-enable as dependency and thus ensure that installing their package will again set yama to 0.

So if you have any package installed that likely needs ptrace (e.g., gdb), then you can assume your system will end up with 0. Also, KDE by default pulls that package for drkongi, but if one is not actively working with that, using yama setting 1 or 2 is no problem: I use KDE myself with 2 for several years; some KDE testers/developers might need it though, and getting new developers is harder the more they have to customize their system before something works. So I understand their emphasis given that we need more developers and packagers (and focused-but-detailed bug reporters as well).

This is a compromise that is not liked by anyone, but it was the common denominator of all stakeholders in a long discussion with many implications. What everybody agrees is that the current yama is not optimal given its rough settings (like “everything or nothing”).

However, the kernel hardening intentionally overrides yama-ptrace-enable! So if the kernel hardening is enabled, you are with 2, with and without yama-ptrace-enable → it changes the approach from usability first to security first in such matters (though average users’ use cases will behave the same as they do not need ptrace; so I see little risk for ending up with something like this :smiley: ). Both is just a compromise.

1 Like

Just be careful on any copy and paste is all it meant. :wink:

I need to state every time I test something that “I’m a Personal Tester YMMV” and if I break it I get to keep all the pieces. Is that something you would like me to add?
Tough Crowd here at times. :frowning:

2 Likes

Again, not sure I understand your point, but I did not want to urge you to add or remove anything. Just added a thought about something :classic_smiley: Sorry for the confusion!

1 Like

Update: the promised hardening sub-tag for security-sig is available now :classic_smiley:

Although it’s probably a fair amount more work, if we want this to be for everyone, it might be worth making a little gui program that lists the available options and gives a summary of what they do so people can enable/disable that way.

On the “for beginners” and advanced users, I did a general computer course at college, I have some basic knowledge of security concepts but my comprehension of that page was hit and miss. Most of the misses were on the SELinux side but then I’ve never known what SELinux does or how or why, I understand it’s some kind of security framework/system but the what and how has never entered my understanding.

I’m in favour of hardening systems, of course, I just want to understand what’s happening, how, why and if/how it’s likely to affect my use of my system.

2 Likes

On the long term, I have the goal in mind to add this to Anaconda installer, so that users are asked at the installation if they want it hardened and what hardening. But the road to that is long, and a lot of formalization is necessary before that becomes realistic, as we must be very careful with what we add to the installer by default. So far this is not a high priority target or so.

For all the functions mentioned, a lot of documentation is available: if a user really wants to understand all that before using it, incl. the underlying assumptions and implications, there is a long way to go if someone starts from scratch. A GUI would not change that. E.g., the kernel hardening file contains already rough elaborations and the upstream links to dig much deeper, but it is already mentioned in the Docs page that this is more for advanced users. firewalld and selinux also have a lot documentation available, easy to find for those who want to dig deeper: the hardening page contains sufficient terms and implications/elaborations to identify/find more detailed documentation, but deeper elaborations on that hardening page itself are intentionally avoided because for many users, that would be just scary and confusing, and not their goal.

The point is: understanding all of that is itself advanced, and not beginners level. And becoming advanced takes its time and efforts. There is no possibility to add a short summary in a GUI that allows, e.g., beginners in a few sentences to skip the road of topics like Mandatory Access Controls, inbound/outbound ports, linux security modules, ptrace, and their respective own foundations and dependencies etc. → understanding all that goes beyond the “security” topic itself.

I appreciate your goal to understand before using though, that’s the right attitude, which I wish would be exercised by everybody :wink: At some point, we all depend on the community though: nobody is an expert of every aspect of an OS. So we must ensure the community provides an environment that ensures tasks to be properly identified, allocated and stuff maintained and reviewed and tested by everyone who has the relevant knowledge & trustworthiness etc.

1 Like

Endless rabbit hole… I will follow the rabbit

I have so msby tinfoil gats and paranoia thst startet same time i moved to cyber security.

More you read more you learn more you get scared and gets paranoid…

1 Like

17 posts were split to a new topic: Rant on new kernel hardening settings

The point of number indexing is to provide clear ordering.

root@fedora:~# ll /etc/sysctl.d/
total 0
lrwxrwxrwx. 1 root root 47 Nov 9 22:18 99-kernel-hardening.conf -> /usr/share/doc/systemd/99-kernel-hardening.conf
lrwxrwxrwx. 1 root root 14 Oct 17 03:00 99-sysctl.conf -> ../sysctl.conf
root@fedora:~# rpm -qf /etc/sysctl.d/99-sysctl.conf
systemd-udev-262.1-1.fc45.x86_64

Please decide ordering, and bump either systemd-udev or hardening to 98,

1 Like

Your point is valid indeed. But it is that way intentionally. On one hand, I have seen in the past several projects using 98-, intentionally to be immediately before the 99-sysctl.conf: due to the broad audience, we cannot rely on every user knowing of the implications of the 98 (which they would be about to introduce with some applications or so) because many do not even know that these numbers are related to any ordering. If we now do that to the hardening file, it becomes arbitrary if any of these 98 configs override the kernel hardening or vice versa → 99-k ↔ 99-s → letters matter.

However, that is also the reason why the ordering is clear: the kernel hardening is as close as possible to the 99-sysctl.conf but it remains clear that the sysctl overrides the hardening if users intentionally customize this. As defaulted, 99-sysctl remains the ultimate final override, but the kernel hardening is as close as possible, not being risked by the “98s”.

There are other means to mitigate some of these issues, but the “text file only” variant makes it easy and transparent to maintain (and to allocate files to maintenance) and to explicitly/easily prove that this file does not cause any impact if not manually enabled. This file-only-approach has also a background in how Fedora’s development is organized.

So I generally agree that the “widespread practice of ordering” would look better at first glance, but the overall compromise of our result felt more useful for the majority of users and also to the devs involved in maintenance.

1 Like