From Fedora Project Wiki
No edit summary
(→‎Current status: Reassign to F41)
 
(72 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{admon/important | Comments and Explanations | The page source contains comments providing guidance to fill out each section. They are invisible when viewing this page. To read it, choose the "view source" link.<br/> '''Copy the source to a ''new page'' before making changes!  DO NOT EDIT THIS TEMPLATE FOR YOUR CHANGE PROPOSAL.'''}}
= Enable systemd service hardening features for default system services =


{{admon/tip | Guidance | For details on how to fill out this form, see the [https://docs.fedoraproject.org/en-US/program_management/changes_guide/ documentation].}}
{{admon/tip | Report issues | To report an issue with this template, file an issue in the [https://pagure.io/fedora-pgm/pgm_docs pgm_docs repo].}}
<!-- The actual name of your proposed change page should look something like: Changes/Your_Change_Proposal_Name.  This keeps all change proposals in the same namespace -->
= Change Proposal Name <!-- The name of your change proposal --> =
{{Change_Proposal_Banner}}


== Summary ==
== Summary ==
<!-- A sentence or two summarizing what this change is and what it will do. This information is used for the overall changeset summary page for each release. Note that motivation for the change should be in the Benefit to Fedora section below, and this part should answer the question "What?" rather than "Why?". -->
Improve security by enabling some of the high level systemd security hardening settings that isolate and sandbox default system services.


== Owner ==
== Owner ==
<!--
 
For change proposals to qualify as self-contained, owners of all affected packages need to be included here. Alternatively, a SIG can be listed as an owner if it owns all affected packages.
* Name: [[User:Sundaram| Rahul Sundaram]]
This should link to your home wiki page so we know who you are.
* Email: metherid@gmail.com
-->
* Name: [[User:FASAcountName| Your Name]]
<!-- Include you email address that you can be reached should people want to contact you about helping with your change, status is requested, or technical issues need to be resolved. If the change proposal is owned by a SIG, please also add a primary contact person. -->
* Email: <your email address so we can contact you, invite you to meetings, etc. Please provide your Bugzilla email address if it is different from your email in FAS>
<!--- UNCOMMENT only for Changes with assigned Shepherd (by FESCo)
<!--- UNCOMMENT only for Changes with assigned Shepherd (by FESCo)
* FESCo shepherd: [[User:FASAccountName| Shehperd name]] <email address>
* FESCo shepherd: [[User:FASAccountName| Shepherd name]] <email address>
-->
-->


== Current status ==
== Current status ==
[[Category:ChangePageIncomplete]]
[[Category:ChangeAcceptedF41]]
<!-- When your change proposal page is completed and ready for review and announcement -->
<!-- When your change proposal page is completed and ready for review and announcement -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->
Line 35: Line 21:


<!-- Select proper category, default is Self Contained Change -->
<!-- Select proper category, default is Self Contained Change -->
[[Category:SelfContainedChange]]
[[Category:SystemWideChange]]
<!-- [[Category:SystemWideChange]] -->


* Targeted release: [https://docs.fedoraproject.org/en-US/releases/f<VERSION>/ Fedora Linux <VERSION>]
* Targeted release: Fedora 41
* Last updated: <!-- this is an automatic macro — you don't need to change this line -->  {{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}  
* Last updated: <!-- this is an automatic macro — you don't need to change this line -->  {{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}  
<!-- After the change proposal is accepted by FESCo, tracking bug is created in Bugzilla and linked to this page  
<!-- After the change proposal is accepted by FESCo, tracking bug is created in Bugzilla and linked to this page  
Line 46: Line 31:
ON_QA -> change is fully code complete
ON_QA -> change is fully code complete
-->
-->
* [<will be assigned by the Wrangler> devel thread]
* [https://lists.fedoraproject.org/archives/list/devel-announce@lists.fedoraproject.org/thread/ICCQ4GTH74UCR4LY3LWLOTTKW3RWKBMX/ Announced]
* FESCo issue: <will be assigned by the Wrangler>
* [https://discussion.fedoraproject.org/t/f40-change-proposal-systemd-security-hardening-system-wide/96423 Discussion thread]
* Tracker bug: <will be assigned by the Wrangler>
* FESCo issue: [https://pagure.io/fesco/issue/3117 #3117]
* Tracker bug: [https://bugzilla.redhat.com/show_bug.cgi?id=2260082 #2260082]
* Release notes tracker: <will be assigned by the Wrangler>
* Release notes tracker: <will be assigned by the Wrangler>


== Detailed Description ==
== Detailed Description ==
<!-- Expand on the summary, if appropriate.  A couple sentences suffices to explain the goal, but the more details you can provide the better. -->


== Feedback ==
systemd provides a number of settings that can harden security for services. We are selecting a few high level ones to enable by default on a service by service basis as suitable for that particular service.
<!-- Summarize the feedback from the community and address why you chose not to accept proposed alternatives. This section is optional for all change proposals but is strongly suggested. Incorporating feedback here as it is raised gives FESCo a clearer view of your proposal and leaves a good record for the future. If you get no feedback, that is useful to note in this section as well. For innovative or possibly controversial ideas, consider collecting feedback before you file the change proposal. -->
 
* `PrivateTmp=yes`
* `ProtectSystem=yes/full/strict`
* `ProtectHome=yes/read-only`
* `ProtectClock=yes`
* `ProtectHostname=yes`
* `ProtectControlGroups=yes`
* `ProtectHostname=yes`
* `ProtectKernelLogs=yes`
* `ProtectKernelModules=yes`
* `ProtectKernelTunables=yes`
* `ProtectProc=invisible`
* `PrivateDevices=yes`
* `PrivateNetwork=yes`
* `NoNewPrivileges=yes`
* `User=`


== Benefit to Fedora ==
If we want to go further, we could also consider:
<!-- What is the benefit to the distribution?  Will the software we generate be improved? How will the process of creating Fedora releases be improved?
 
      Be sure to include the following areas if relevant:
      If this is a major capability update, what has changed?
          For example: This change introduces Python 5 that runs without the Global Interpreter Lock and is fully multithreaded.
      If this is a new functionality, what capabilities does it bring?
          For example: This change allows package upgrades to be performed automatically and rolled-back at will.
      Does this improve some specific package or set of packages?
          For example: This change modifies a package to use a different language stack that reduces install size by removing dependencies.
      Does this improve specific Spins or Editions?
          For example: This change modifies the default install of Fedora Workstation to be more in line with the base install of Fedora Server.
      Does this make the distribution more efficient?
          For example: This change replaces thousands of individual %post scriptlets in packages with one script that runs at the end.
      Is this an improvement to maintainer processes?
          For example: Gating Fedora packages on automatic QA tests will make rawhide more stable and allow changes to be implemented more smoothly.
      Is this an improvement targeted as specific contributors?
          For example: Ensuring that a minimal set of tools required for contribution to Fedora are installed by default eases the onboarding of new contributors.


    When a Change has multiple benefits, it's better to list them all.
* `CapabilityBoundingSet=`
* `DevicePolicy=closed`
* `KeyringMode=private`
* `LockPersonality=yes`
* `MemoryDenyWriteExecute=yes`
* `PrivateUsers=yes`
* `RemoveIPC=yes`
* `RestrictAddressFamilies=`
* `RestrictNamespaces=yes`
* `RestrictRealtime=yes`
* `RestrictSUIDSGID=yes`
* `SystemCallFilter=`
* `SystemCallArchitectures=native`


    Consider these Change pages from previous editions as inspiration:
    https://fedoraproject.org/wiki/Changes/Annobin (low-level and technical, invisible to users)
    https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo (low-level, but visible to advanced users)
    https://fedoraproject.org/wiki/Changes/VirtualBox_Guest_Integration (primarily a UX change)
    https://fedoraproject.org/wiki/Changes/NoMoreAlpha (an improvement to distro processes)
    https://fedoraproject.org/wiki/Changes/perl5.26 (major upgrade to a popular software stack, visible to users of that stack)
-->


== Scope ==
We will aim to cover as many of the default system services as we can. We will prioritize critical or long running services. All of these settings need to be configured on a per service basis instead of using a global override to facilitate fine tuning the settings based on service requirements and limit the impact for users on upgrades. Certain services have a very targeted scope. For instance, a service that only needs to read or write from only one directory could leverage more fine grained settings to restrict access even further. We will enable as many of these as feasible for the services but not every knob is going to be applicable to every service. For example, `PrivateNetwork=yes` can only be used for services that does not need network connectivity by default.  We have to choose between `DynamicUser=yes` or `User` if either is feasible for the service to use. As a base starting point, from Fedora 39 workstation, we have the following system services installed by default which should considered within the scope of the change (excluding systemd associated ones which already have a number of these security settings enabled).
* Proposal owners:
<!-- What work do the feature owners have to accomplish to complete the feature in time for release?  Is it a large change affecting many parts of the distribution or is it a very isolated change? What are those changes?-->


* Other developers: <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
* `abrtd.service`
<!-- What work do other developers have to accomplish to complete the feature in time for release?  Is it a large change affecting many parts of the distribution or is it a very isolated change? What are those changes?-->
* `abrt-journal-core.service`
* `abrt-oops.service`
* `abrt-pstoreoops.service`
* `abrt-vmcore.service`
* `abrt-xorg.service`
* `accounts-daemon.service`
* `alsa-restore.service`
* `alsa-state.service`
* `anaconda-direct.service`
* `anaconda-fips.service`
* `anaconda-nm-config.service`
* `anaconda-nm-disable-autocons.service`
* `anaconda-noshell.service`
* `anaconda-pre.service`
* `anaconda.service`
* `anaconda-sshd.service`
* `arp-ethers.service`
* `auditd.service`
* `auth-rpcgss-module.service`
* `avahi-daemon.service`
* `blivet.service`
* `blk-availability.service`
* `bluetooth.service`
* `bolt.service`
* `brltty.service`
* `canberra-system-bootup.service`
* `canberra-system-shutdown-reboot.service`
* `canberra-system-shutdown.service`
* `chronyd-restricted.service`
* `chronyd.service`
* `chrony-wait.service`
* `colord.service`
* `console-getty.service`
* `cups-browsed.service`
* `cups.service`
* `dbus-broker.service`
* `dbus-daemon.service`
* `dbus-org.freedesktop.hostname1.service`
* `dbus-org.freedesktop.import1.service`
* `dbus-org.freedesktop.locale1.service`
* `dbus-org.freedesktop.login1.service`
* `dbus-org.freedesktop.machine1.service`
* `dbus-org.freedesktop.portable1.service`
* `dbus-org.freedesktop.timedate1.service`
* <strike>`debug-shell.service`</strike> (opens a user shell that must be able to do arbitrary stuff)
* `dm-event.service`
* `dnf-makecache.service`
* `dnf-system-upgrade-cleanup.service`
* `dnf-system-upgrade.service`
* `dnsmasq.service`
* `dracut-cmdline.service`
* `dracut-initqueue.service`
* `dracut-mount.service`
* `dracut-pre-mount.service`
* `dracut-pre-pivot.service`
* `dracut-pre-trigger.service`
* `dracut-pre-udev.service`
* `dracut-shutdown-onfailure.service`
* `dracut-shutdown.service`
* <strike>`emergency.service`</strike> (opens a user shell that must be able to do arbitrary stuff)
* `fedora-third-party-refresh.service`
* `firewalld.service`
* `flatpak-add-fedora-repos.service`
* `flatpak-system-helper.service`
* `fprintd.service`
* `fsidd.service`
* `fstrim.service`
* `fwupd-offline-update.service`
* `fwupd-refresh.service`
* `fwupd.service`
* `gdm.service`
* `geoclue.service`
* `grub-boot-indeterminate.service`
* `gssproxy.service`
* `htcacheclean.service`
* `httpd.service`
* `hypervfcopyd.service`
* `hypervkvpd.service`
* `hypervvssd.service`
* `iio-sensor-proxy.service`
* `import-state.service`
* `initrd-cleanup.service`
* `initrd-parse-etc.service`
* `initrd-switch-root.service`
* `initrd-udevadm-cleanup-db.service`
* `instperf.service`
* `ipp-usb.service`
* `iscsid.service`
* `iscsi-init.service`
* `iscsi-onboot.service`
* `iscsi.service`
* `iscsi-shutdown.service`
* `iscsi-starter.service`
* `iscsiuio.service`
* `kdump.service`
* `kmod-static-nodes.service`
* `ldconfig.service`
* `libvirtd.service`
* `libvirt-guests.service`
* <strike> `livesys-late.service`</strike> (adhoc live env config)
* <strike> `livesys.service`</strike> (adhoc live env config)
* `loadmodules.service`
* `logrotate.service`
* `low-memory-monitor.service`
* `lvm2-lvmdbusd.service`
* `lvm2-lvmpolld.service`
* `lvm2-monitor.service`
* `man-db-cache-update.service`
* `man-db-restart-cache-update.service`
* `mcelog.service`
* `mdcheck_continue.service`
* `mdcheck_start.service`
* `mdmonitor-oneshot.service`
* `mdmonitor.service`
* `ModemManager.service`
* `ndctl-monitor.service`
* `netavark-dhcp-proxy.service`
* `NetworkManager-dispatcher.service`
* `NetworkManager.service`
* `NetworkManager-wait-online.service`
* `nfs-blkmap.service`
* `nfsdcld.service`
* `nfs-idmapd.service`
* `nfs-mountd.service`
* `nfs-server.service`
* `nfs-utils.service`
* `nftables.service`
* `nis-domainname.service`
* `nm-priv-helper.service`
* `numad.service`
* `nvmefc-boot-connections.service`
* `nvmf-autoconnect.service`
* `ostree-boot-complete.service`
* `ostree-finalize-staged-hold.service`
* `ostree-finalize-staged.service`
* `ostree-prepare-root.service`
* `ostree-remount.service`
* `packagekit-offline-update.service`
* `packagekit.service`
* `pam_namespace.service`
* `pcscd.service`
* `plocate-updatedb.service`
* `plymouth-halt.service`
* `plymouth-kexec.service`
* `plymouth-poweroff.service`
* `plymouth-quit.service`
* `plymouth-quit-wait.service`
* `plymouth-read-write.service`
* `plymouth-reboot.service`
* `plymouth-start.service`
* `plymouth-switch-root-initramfs.service`
* `plymouth-switch-root.service`
* `podman-auto-update.service`
* `podman-clean-transient.service`
* `podman-restart.service`
* `podman.service`
* `polkit.service`
* `power-profiles-daemon.service`
* `psacct.service`
* `qemu-guest-agent.service`
* `qemu-pr-helper.service`
* `quotaon.service`
* `raid-check.service`
* <strike>`rc-local.service`</strike> (this can do arbitrary stuff)
* `realmd.service`
* `rescue.service`
* `rpcbind.service`
* `rpc-gssd.service`
* `rpc-statd-notify.service`
* `rpc-statd.service`
* `rpmdb-migrate.service`
* `rpmdb-rebuild.service`
* `rtkit-daemon.service`
* `saslauthd.service`
* `selinux-autorelabel-mark.service`
* `selinux-autorelabel.service`
* `selinux-check-proper-disable.service`
* `speech-dispatcherd.service`
* `spice-vdagentd.service`
* `spice-webdavd.service`
* `sshd.service`
* `ssh-host-keys-migration.service`
* `sssd-autofs.service`
* `sssd-kcm.service`
* `sssd-nss.service`
* `sssd-pac.service`
* `sssd-pam.service`
* `sssd.service`
* `sssd-ssh.service`
* `sssd-sudo.service`
* `switcheroo-control.service`
* `system-update-cleanup.service`
* `tcsd.service`
* `thermald.service`
* `udisks2.service`
* `unbound-anchor.service`
* `upower.service`
* `uresourced.service`
* `usbmuxd.service`
* `vboxclient.service`
* `vboxservice.service`
* `vgauthd.service`
* `virtinterfaced.service`
* `virtlockd.service`
* `virtlogd.service`
* `virtnetworkd.service`
* `virtnodedevd.service`
* `virtnwfilterd.service`
* `virtproxyd.service`
* `virtqemud.service`
* `virtsecretd.service`
* `virtstoraged.service`
* `vmtoolsd.service`
* `wpa_supplicant.service`
* `zfs-fuse-scrub.service`
* `zfs-fuse.service`
* `zvbid.service`


* Release engineering: [https://pagure.io/releng/issues #Releng issue number] <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
For a concrete example,  Httpd in Fedora uses only `PrivateTmp` because of https://fedoraproject.org/wiki/Features/ServicesPrivateTmp implemented in early 2012.  
<!-- Does this feature require coordination with release engineering (e.g. changes to installer image generation or update package delivery)?  Is a mass rebuild required?  include a link to the releng issue.
The issue is required to be filed prior to feature submission, to ensure that someone is on board to do any process development work and testing and that all changes make it into the pipeline; a bullet point in a change is not sufficient communication -->


* Policies and guidelines: N/A (not needed for this Change) <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
https://src.fedoraproject.org/rpms/httpd/blob/rawhide/f/httpd.service
<!-- Do the packaging guidelines or other documents need to be updated for this feature?  If so, does it need to happen before or after the implementation is done?  If a FPC ticket exists, add a link here. Please submit a pull request with the proposed changes before submitting your Change proposal. -->


* Trademark approval: N/A (not needed for this Change)
Over the decade since then, systemd has introduced a large number of additional directives.  There has been discussions about enabling more of these features in the project before (covered in https://lwn.net/Articles/709755/). It's time to move forward with this.
<!-- If your Change may require trademark approval (for example, if it is a new Spin), file a ticket ( https://pagure.io/Fedora-Council/tickets/issues ) requesting trademark approval from the Fedora Council. This approval will be done via the Council's consensus-based process. -->


* Alignment with Community Initiatives:
== Feedback ==
<!-- Does your proposal align with the current Fedora Community Initiatives: https://docs.fedoraproject.org/en-US/project/initiatives/ ? It's okay if it doesn't, but it's something to consider -->


== Upgrade/compatibility impact ==
* Updated the upstreaming guidance to take into account minimum supported version of systemd based on feedback in https://discussion.fedoraproject.org/t/96423/2.  Daniel still feels that these changes are better done upstream exclusively.  Others noted that Fedora does enable a number of compiler flags and additional security features including SELinux by default and systemd sandboxing features can follow that pattern.  Package maintainers should be encouraged to contribute these changes upstream.  IMO, however Fedora should be "First" and adopt these "Features" to be true to it's mission.  Fedora shouldn't limit itself to passively following whatever upstream happens to include as many may not even include a systemd service file and do not enable the vast majority of these features even when they do.  Fedora is better positioned to provide more comprehensive coverage of these features by default given that Fedora always included the very latest systemd releases by default and act as an integration point for newer systemd sandboxing features.
<!-- What happens to systems that have had a previous versions of Fedora installed and are updated to the version containing this change? Will anything require manual configuration or data migration? Will any existing functionality be no longer supported? -->
* Added a concrete example in the form of Httpd as part of the feedback in https://discussion.fedoraproject.org/t/96423/11 and followup at https://discussion.fedoraproject.org/t/96423/18 reiterated that all the settings will not be applicable to all the services.
* There was a suggestion to user drop-in config snippets instead of changing the service files directly to make the hardening settings readily visible at https://discussion.fedoraproject.org/t/96423/6 and another suggestion to do it in /usr/lib since Fedora already follows that pattern in https://discussion.fedoraproject.org/t/96423/8.  The current understanding is that it will impact potentially non distro services if we do this and that will be too risky. We are not going to follow this pattern.
* There was some discussions about scope and I have added my rationale at https://discussion.fedoraproject.org/t/96423/15
* There was some discussions on updating the packaging guidelines and making the changes advertised well. I have proposed some initial draft for both the packaging guidelines and release notes, both of which will evolve as we firm up our approach (drop-in vs direct service changes etc).
* Systemd does not support a general mechanism of resetting a directive back to default by setting it to an empty value. You must instead explicitly set the value depending on the setting and this was noted in https://discussion.fedoraproject.org/t/96423/17


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->


== Benefit to Fedora ==


== How To Test ==
Fedora services will get a significant security boost by default by avoiding or mitigating any unknown security vulnerabilities in default system services. Since Fedora will include the very latest version of systemd and other components and has the visibility and control of the default configuration of the services, it can go well beyond what upstream can support directly based on their minimum version of systemdSince Fedora already has the reputation of being security focused (SELinux enabled by default, system wide compiler flags that enable a number of security features etc), it is in a good position to act as a coordination and integration point.   
<!-- This does not need to be a full-fledged document. Describe the dimensions of tests that this change implementation is expected to pass when it is doneIf it needs to be tested with different hardware or software configurations, indicate themThe more specific you can be, the better the community testing can be.


Remember that you are writing this how to for interested testers to use to check out your change implementation - documenting what you do for testing is OK, but it's much better to document what *I* can do to test your change.
It can be the first mainstream distribution that enables more of these systemd hardening features by default and push that upstream wherever feasible.  This serves the first, features and friends part of the Fedora mission respectively.


A good "how to test" should answer these four questions:
== Scope ==
* Proposal owners: Individual per service pull requests to enable various security features as applicable.
* Other developers: Review PRs as needed
* Release engineering: https://pagure.io/releng/issue/11785
* Policies and guidelines:
Packaging guidelines will have to be modified to add recommendations to use more of the systemd security features by default. In particular, we should add a security settings section in https://fedoraproject.org/wiki/Packaging:Systemd.  Current the guidance only recommends a couple of settings for long running services.  Sample text:


0. What special hardware / data / etc. is needed (if any)?
Systemd services included in Fedora are recommended to use as many of the following security settings as applicable while maintaining the default functionality of the service.
1. How do I prepare my system to test this change? What packages
need to be installed, config files edited, etc.?
2. What specific actions do I perform to check that the change is
working like it's supposed to?
3. What are the expected results of those actions?
-->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
<List of enabled hardening settings>


The full list of sandboxing features are available in https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Sandboxing.  Note that if you are submitting changes to upstream as recommended in https://docs.fedoraproject.org/en-US/packaging-guidelines/PatchUpstreamStatus/, systemd will warn and ignore any of these features it doesn't support. So while the service itself won't break, these warnings can add to the support burden. Please take into account the minimum required version of systemd that upstream supports and only include those settings or provide build system logic to conditionally build the default unit file when submitting these patches upstream.  The specific version of systemd required for any of these settings is documented in the systemd exec man page.


== User Experience ==
* Trademark approval: N/A
<!-- If this change proposal is noticeable by users, how will their experiences change as a result?


  This section partially overlaps with the Benefit to Fedora section above. This section should be primarily about the User Experience, written in a way that does not assume deep technical knowledge. More detailed technical description should be left for the Benefit to Fedora section.
== Upgrade/compatibility impact ==
Packages will automatically get additional security features enabled by default transparently. In limited circumstances, they may need to override the defaults. Refer to user experience section for details.


Describe what Users will see or notice, for example:
== How To Test ==
  - Packages are compressed more efficiently, making downloads and upgrades faster by 10%.
  - Kerberos tickets can be renewed automatically. Users will now have to authenticate less and become more productive. Credential management improvements mean a user can start their work day with a single sign on and not have to pause for reauthentication during their entire day.
- Libreoffice is one of the most commonly installed applications on Fedora and it is now available by default to help users "hit the ground running".
- Green has been scientifically proven to be the most relaxing color. The move to a default background color of green with green text will result in Fedora users being the most relaxed users of any operating system.
-->


== Dependencies ==
You can use tools like `systemd-analyze security` and `systemctl cat` to verify that specific security features are enabled by default. Default services with the default features should have no adverse impact and users shouldn't have to do anything beyond using the software as intended and report any regressions. High profile services not installed by default that gain these security features would benefit from more targeting testing to spot any unintended consequences especially for niche or advanced functionality. If advanced non-default functionality requires overrides default settings, we can document those in the release notes to provide guidance.
<!-- What other packages (RPMs) depend on this package?  Are there changes outside the developers' control on which completion of this change depends? In other words, completion of another change owned by someone else and might cause you to not be able to finish on time or that you would need to coordinate? Other upstream projects like the kernel (if this is not a kernel change)? -->


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
== User Experience ==
This should be largely transparent change for users. The goal is to have the services work as expected with the default functionality but to potentially require tweaking the settings if the configuration is changed by users after installation.  For instance, if we add `ProtectHome=yes`to a web service and the user wishes to serve files out of their home directory, they will need to override the systemd setting to `ProtectHome=read-only` to allow for the service to read from the user home directory in addition to changing the service specific configuration files to enable this feature.


== Dependencies ==
None.  We are merely enabling some of systemd security features by default for default system services.


== Contingency Plan ==
== Contingency Plan ==


<!-- If you cannot complete your feature by the final development freeze, what is the backup plan?  This might be as simple as "Revert the shipped configuration".  Or it might not (e.g. rebuilding a number of dependent packages).  If you feature is not completed in time we want to assure others that other parts of Fedora will not be in jeopardy.  -->
* Contingency mechanism:  These settings can be enabled/disabled at a per service level. No wholesale reverts is necessary. If we don't finish the work for all the services, we can follow up in future releases.
* Contingency mechanism: (What to do? Who will do it?) N/A (not a System Wide Change) <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
* Contingency deadline: N/A  
<!-- When is the last time the contingency mechanism can be put in place?  This will typically be the beta freeze. -->
* Blocks release? No  
* Contingency deadline: N/A (not a System Wide Change)  <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
<!-- Does finishing this feature block the release, or can we ship with the feature in incomplete state? -->
* Blocks release? N/A (not a System Wide Change), Yes/No <!-- REQUIRED FOR SYSTEM WIDE CHANGES -->




== Documentation ==
== Documentation ==
<!-- Is there upstream documentation on this change, or notes you have written yourself?  Link to that material here so other interested developers can get involved. -->
* https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Sandboxing
* https://docs.arbitrary.ch/security/systemd.html
* https://www.redhat.com/sysadmin/systemd-secure-services
* https://www.redhat.com/sysadmin/mastering-systemd
 
== Release Notes ==


<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
systemd security hardening features are enabled for default system services. If you wish to turn off any particular settings, you can follow the standard systemd method of overriding the config.  For example,
N/A (not a System Wide Change)


== Release Notes ==
`$ cat /etc/systemd/system/httpd.service.d/override.conf
<!-- The Fedora Release Notes inform end-users about what is new in the release.  Examples of past release notes are at https://docs.fedoraproject.org/en-US/fedora/latest/release-notes/ -->
 
<!-- The release notes also help users know how to deal with platform changes such as ABIs/APIs, configuration or data file formats, or upgrade concerns. If there are any such changes involved in this change, indicate them here.  A link to upstream documentation will often satisfy this need.  This information forms the basis of the release notes edited by the documentation team and shipped with the release.  
[Service]
 
ProtectHome=no`
 
`
$ sudo systemctl daemon-reload
 
$ sudo systemctl restart httpd.service`
 
 
`$ systemctl status httpd.service


Release Notes are not required for initial draft of the Change Proposal but has to be completed by the Change Freeze.  
● httpd.service - The Apache HTTP Server
-->
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/httpd.service.d
            └─override.conf
    Active: active (running) since Mon 2023-11-15 18:29:25 EST; 3min 30s ago`

Latest revision as of 14:43, 25 March 2024

Enable systemd service hardening features for default system services

Summary

Improve security by enabling some of the high level systemd security hardening settings that isolate and sandbox default system services.

Owner

Current status

Detailed Description

systemd provides a number of settings that can harden security for services. We are selecting a few high level ones to enable by default on a service by service basis as suitable for that particular service.

  • PrivateTmp=yes
  • ProtectSystem=yes/full/strict
  • ProtectHome=yes/read-only
  • ProtectClock=yes
  • ProtectHostname=yes
  • ProtectControlGroups=yes
  • ProtectHostname=yes
  • ProtectKernelLogs=yes
  • ProtectKernelModules=yes
  • ProtectKernelTunables=yes
  • ProtectProc=invisible
  • PrivateDevices=yes
  • PrivateNetwork=yes
  • NoNewPrivileges=yes
  • User=

If we want to go further, we could also consider:

  • CapabilityBoundingSet=
  • DevicePolicy=closed
  • KeyringMode=private
  • LockPersonality=yes
  • MemoryDenyWriteExecute=yes
  • PrivateUsers=yes
  • RemoveIPC=yes
  • RestrictAddressFamilies=
  • RestrictNamespaces=yes
  • RestrictRealtime=yes
  • RestrictSUIDSGID=yes
  • SystemCallFilter=
  • SystemCallArchitectures=native


We will aim to cover as many of the default system services as we can. We will prioritize critical or long running services. All of these settings need to be configured on a per service basis instead of using a global override to facilitate fine tuning the settings based on service requirements and limit the impact for users on upgrades. Certain services have a very targeted scope. For instance, a service that only needs to read or write from only one directory could leverage more fine grained settings to restrict access even further. We will enable as many of these as feasible for the services but not every knob is going to be applicable to every service. For example, PrivateNetwork=yes can only be used for services that does not need network connectivity by default. We have to choose between DynamicUser=yes or User if either is feasible for the service to use. As a base starting point, from Fedora 39 workstation, we have the following system services installed by default which should considered within the scope of the change (excluding systemd associated ones which already have a number of these security settings enabled).

  • abrtd.service
  • abrt-journal-core.service
  • abrt-oops.service
  • abrt-pstoreoops.service
  • abrt-vmcore.service
  • abrt-xorg.service
  • accounts-daemon.service
  • alsa-restore.service
  • alsa-state.service
  • anaconda-direct.service
  • anaconda-fips.service
  • anaconda-nm-config.service
  • anaconda-nm-disable-autocons.service
  • anaconda-noshell.service
  • anaconda-pre.service
  • anaconda.service
  • anaconda-sshd.service
  • arp-ethers.service
  • auditd.service
  • auth-rpcgss-module.service
  • avahi-daemon.service
  • blivet.service
  • blk-availability.service
  • bluetooth.service
  • bolt.service
  • brltty.service
  • canberra-system-bootup.service
  • canberra-system-shutdown-reboot.service
  • canberra-system-shutdown.service
  • chronyd-restricted.service
  • chronyd.service
  • chrony-wait.service
  • colord.service
  • console-getty.service
  • cups-browsed.service
  • cups.service
  • dbus-broker.service
  • dbus-daemon.service
  • dbus-org.freedesktop.hostname1.service
  • dbus-org.freedesktop.import1.service
  • dbus-org.freedesktop.locale1.service
  • dbus-org.freedesktop.login1.service
  • dbus-org.freedesktop.machine1.service
  • dbus-org.freedesktop.portable1.service
  • dbus-org.freedesktop.timedate1.service
  • debug-shell.service (opens a user shell that must be able to do arbitrary stuff)
  • dm-event.service
  • dnf-makecache.service
  • dnf-system-upgrade-cleanup.service
  • dnf-system-upgrade.service
  • dnsmasq.service
  • dracut-cmdline.service
  • dracut-initqueue.service
  • dracut-mount.service
  • dracut-pre-mount.service
  • dracut-pre-pivot.service
  • dracut-pre-trigger.service
  • dracut-pre-udev.service
  • dracut-shutdown-onfailure.service
  • dracut-shutdown.service
  • emergency.service (opens a user shell that must be able to do arbitrary stuff)
  • fedora-third-party-refresh.service
  • firewalld.service
  • flatpak-add-fedora-repos.service
  • flatpak-system-helper.service
  • fprintd.service
  • fsidd.service
  • fstrim.service
  • fwupd-offline-update.service
  • fwupd-refresh.service
  • fwupd.service
  • gdm.service
  • geoclue.service
  • grub-boot-indeterminate.service
  • gssproxy.service
  • htcacheclean.service
  • httpd.service
  • hypervfcopyd.service
  • hypervkvpd.service
  • hypervvssd.service
  • iio-sensor-proxy.service
  • import-state.service
  • initrd-cleanup.service
  • initrd-parse-etc.service
  • initrd-switch-root.service
  • initrd-udevadm-cleanup-db.service
  • instperf.service
  • ipp-usb.service
  • iscsid.service
  • iscsi-init.service
  • iscsi-onboot.service
  • iscsi.service
  • iscsi-shutdown.service
  • iscsi-starter.service
  • iscsiuio.service
  • kdump.service
  • kmod-static-nodes.service
  • ldconfig.service
  • libvirtd.service
  • libvirt-guests.service
  • livesys-late.service (adhoc live env config)
  • livesys.service (adhoc live env config)
  • loadmodules.service
  • logrotate.service
  • low-memory-monitor.service
  • lvm2-lvmdbusd.service
  • lvm2-lvmpolld.service
  • lvm2-monitor.service
  • man-db-cache-update.service
  • man-db-restart-cache-update.service
  • mcelog.service
  • mdcheck_continue.service
  • mdcheck_start.service
  • mdmonitor-oneshot.service
  • mdmonitor.service
  • ModemManager.service
  • ndctl-monitor.service
  • netavark-dhcp-proxy.service
  • NetworkManager-dispatcher.service
  • NetworkManager.service
  • NetworkManager-wait-online.service
  • nfs-blkmap.service
  • nfsdcld.service
  • nfs-idmapd.service
  • nfs-mountd.service
  • nfs-server.service
  • nfs-utils.service
  • nftables.service
  • nis-domainname.service
  • nm-priv-helper.service
  • numad.service
  • nvmefc-boot-connections.service
  • nvmf-autoconnect.service
  • ostree-boot-complete.service
  • ostree-finalize-staged-hold.service
  • ostree-finalize-staged.service
  • ostree-prepare-root.service
  • ostree-remount.service
  • packagekit-offline-update.service
  • packagekit.service
  • pam_namespace.service
  • pcscd.service
  • plocate-updatedb.service
  • plymouth-halt.service
  • plymouth-kexec.service
  • plymouth-poweroff.service
  • plymouth-quit.service
  • plymouth-quit-wait.service
  • plymouth-read-write.service
  • plymouth-reboot.service
  • plymouth-start.service
  • plymouth-switch-root-initramfs.service
  • plymouth-switch-root.service
  • podman-auto-update.service
  • podman-clean-transient.service
  • podman-restart.service
  • podman.service
  • polkit.service
  • power-profiles-daemon.service
  • psacct.service
  • qemu-guest-agent.service
  • qemu-pr-helper.service
  • quotaon.service
  • raid-check.service
  • rc-local.service (this can do arbitrary stuff)
  • realmd.service
  • rescue.service
  • rpcbind.service
  • rpc-gssd.service
  • rpc-statd-notify.service
  • rpc-statd.service
  • rpmdb-migrate.service
  • rpmdb-rebuild.service
  • rtkit-daemon.service
  • saslauthd.service
  • selinux-autorelabel-mark.service
  • selinux-autorelabel.service
  • selinux-check-proper-disable.service
  • speech-dispatcherd.service
  • spice-vdagentd.service
  • spice-webdavd.service
  • sshd.service
  • ssh-host-keys-migration.service
  • sssd-autofs.service
  • sssd-kcm.service
  • sssd-nss.service
  • sssd-pac.service
  • sssd-pam.service
  • sssd.service
  • sssd-ssh.service
  • sssd-sudo.service
  • switcheroo-control.service
  • system-update-cleanup.service
  • tcsd.service
  • thermald.service
  • udisks2.service
  • unbound-anchor.service
  • upower.service
  • uresourced.service
  • usbmuxd.service
  • vboxclient.service
  • vboxservice.service
  • vgauthd.service
  • virtinterfaced.service
  • virtlockd.service
  • virtlogd.service
  • virtnetworkd.service
  • virtnodedevd.service
  • virtnwfilterd.service
  • virtproxyd.service
  • virtqemud.service
  • virtsecretd.service
  • virtstoraged.service
  • vmtoolsd.service
  • wpa_supplicant.service
  • zfs-fuse-scrub.service
  • zfs-fuse.service
  • zvbid.service

For a concrete example, Httpd in Fedora uses only PrivateTmp because of https://fedoraproject.org/wiki/Features/ServicesPrivateTmp implemented in early 2012.

https://src.fedoraproject.org/rpms/httpd/blob/rawhide/f/httpd.service

Over the decade since then, systemd has introduced a large number of additional directives. There has been discussions about enabling more of these features in the project before (covered in https://lwn.net/Articles/709755/). It's time to move forward with this.

Feedback

  • Updated the upstreaming guidance to take into account minimum supported version of systemd based on feedback in https://discussion.fedoraproject.org/t/96423/2. Daniel still feels that these changes are better done upstream exclusively. Others noted that Fedora does enable a number of compiler flags and additional security features including SELinux by default and systemd sandboxing features can follow that pattern. Package maintainers should be encouraged to contribute these changes upstream. IMO, however Fedora should be "First" and adopt these "Features" to be true to it's mission. Fedora shouldn't limit itself to passively following whatever upstream happens to include as many may not even include a systemd service file and do not enable the vast majority of these features even when they do. Fedora is better positioned to provide more comprehensive coverage of these features by default given that Fedora always included the very latest systemd releases by default and act as an integration point for newer systemd sandboxing features.
  • Added a concrete example in the form of Httpd as part of the feedback in https://discussion.fedoraproject.org/t/96423/11 and followup at https://discussion.fedoraproject.org/t/96423/18 reiterated that all the settings will not be applicable to all the services.
  • There was a suggestion to user drop-in config snippets instead of changing the service files directly to make the hardening settings readily visible at https://discussion.fedoraproject.org/t/96423/6 and another suggestion to do it in /usr/lib since Fedora already follows that pattern in https://discussion.fedoraproject.org/t/96423/8. The current understanding is that it will impact potentially non distro services if we do this and that will be too risky. We are not going to follow this pattern.
  • There was some discussions about scope and I have added my rationale at https://discussion.fedoraproject.org/t/96423/15
  • There was some discussions on updating the packaging guidelines and making the changes advertised well. I have proposed some initial draft for both the packaging guidelines and release notes, both of which will evolve as we firm up our approach (drop-in vs direct service changes etc).
  • Systemd does not support a general mechanism of resetting a directive back to default by setting it to an empty value. You must instead explicitly set the value depending on the setting and this was noted in https://discussion.fedoraproject.org/t/96423/17


Benefit to Fedora

Fedora services will get a significant security boost by default by avoiding or mitigating any unknown security vulnerabilities in default system services. Since Fedora will include the very latest version of systemd and other components and has the visibility and control of the default configuration of the services, it can go well beyond what upstream can support directly based on their minimum version of systemd. Since Fedora already has the reputation of being security focused (SELinux enabled by default, system wide compiler flags that enable a number of security features etc), it is in a good position to act as a coordination and integration point.

It can be the first mainstream distribution that enables more of these systemd hardening features by default and push that upstream wherever feasible. This serves the first, features and friends part of the Fedora mission respectively.

Scope

  • Proposal owners: Individual per service pull requests to enable various security features as applicable.
  • Other developers: Review PRs as needed
  • Release engineering: https://pagure.io/releng/issue/11785
  • Policies and guidelines:

Packaging guidelines will have to be modified to add recommendations to use more of the systemd security features by default. In particular, we should add a security settings section in https://fedoraproject.org/wiki/Packaging:Systemd. Current the guidance only recommends a couple of settings for long running services. Sample text:

Systemd services included in Fedora are recommended to use as many of the following security settings as applicable while maintaining the default functionality of the service.

<List of enabled hardening settings>

The full list of sandboxing features are available in https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Sandboxing. Note that if you are submitting changes to upstream as recommended in https://docs.fedoraproject.org/en-US/packaging-guidelines/PatchUpstreamStatus/, systemd will warn and ignore any of these features it doesn't support. So while the service itself won't break, these warnings can add to the support burden. Please take into account the minimum required version of systemd that upstream supports and only include those settings or provide build system logic to conditionally build the default unit file when submitting these patches upstream. The specific version of systemd required for any of these settings is documented in the systemd exec man page.

  • Trademark approval: N/A

Upgrade/compatibility impact

Packages will automatically get additional security features enabled by default transparently. In limited circumstances, they may need to override the defaults. Refer to user experience section for details.

How To Test

You can use tools like systemd-analyze security and systemctl cat to verify that specific security features are enabled by default. Default services with the default features should have no adverse impact and users shouldn't have to do anything beyond using the software as intended and report any regressions. High profile services not installed by default that gain these security features would benefit from more targeting testing to spot any unintended consequences especially for niche or advanced functionality. If advanced non-default functionality requires overrides default settings, we can document those in the release notes to provide guidance.

User Experience

This should be largely transparent change for users. The goal is to have the services work as expected with the default functionality but to potentially require tweaking the settings if the configuration is changed by users after installation. For instance, if we add ProtectHome=yesto a web service and the user wishes to serve files out of their home directory, they will need to override the systemd setting to ProtectHome=read-only to allow for the service to read from the user home directory in addition to changing the service specific configuration files to enable this feature.

Dependencies

None. We are merely enabling some of systemd security features by default for default system services.

Contingency Plan

  • Contingency mechanism: These settings can be enabled/disabled at a per service level. No wholesale reverts is necessary. If we don't finish the work for all the services, we can follow up in future releases.
  • Contingency deadline: N/A
  • Blocks release? No


Documentation

Release Notes

systemd security hardening features are enabled for default system services. If you wish to turn off any particular settings, you can follow the standard systemd method of overriding the config. For example,

$ cat /etc/systemd/system/httpd.service.d/override.conf

[Service]

ProtectHome=no

$ sudo systemctl daemon-reload

$ sudo systemctl restart httpd.service


$ systemctl status httpd.service

● httpd.service - The Apache HTTP Server

    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Drop-In: /etc/systemd/system/httpd.service.d
            └─override.conf
    Active: active (running) since Mon 2023-11-15 18:29:25 EST; 3min 30s ago