Skip to content

Harden systemd service with safe defaults - #800

Open
LaserEyess wants to merge 1 commit into
RsyncProject:masterfrom
LaserEyess:systemd-hardening
Open

Harden systemd service with safe defaults#800
LaserEyess wants to merge 1 commit into
RsyncProject:masterfrom
LaserEyess:systemd-hardening

Conversation

@LaserEyess

Copy link
Copy Markdown

See commit message for an overview, but this is an RFC, I can understand if the project does not want this. The goal here is defense in depth. If there is a bug in any access control or authentication mechanism in rsync, there should be additional protections to not compromise a system running rsync --daemon as root. This can be accomplished through systemd, so that the damage done by a hypothetical RCE is minimized as much as possible.

I have personally tested this and it does not affect file transfers for either unit. That being said, I understand a lot of the options may be confusing. I can explain why each one of these is a safe default that does not affect file transfers.

@LaserEyess
LaserEyess marked this pull request as draft August 28, 2025 13:38
@LaserEyess

Copy link
Copy Markdown
Author

@tridge I read your blog about wanting to increase defense-in-depth on rsync. I believe this PR is complementary to that goal. Further improvements could be made, such as not running rsync daemon as root. But that would be a breaking change so I left that out for this.

@LaserEyess
LaserEyess marked this pull request as ready for review August 23, 2026 13:52
@LaserEyess LaserEyess changed the title RFC: harden systemd service with safe defaults Harden systemd service with safe defaults Aug 23, 2026
@LaserEyess

Copy link
Copy Markdown
Author

Marking this as ready for review since there has been no negative feedback.

@steadytao

Copy link
Copy Markdown
Member

Just a note that drafts are ordinarily not read, they are explicitly that, drafts.

However; these cannot be described as universally safe defaults without testing representative writable modules, /tmp-backed modules/temp dirs, chroot, xattrs/ACLs, socket activation and the supported systemd versions. PrivateTmp alone can alter configured file visibility. Perhaps best as an optional hardening drop-in first.

@LaserEyess

Copy link
Copy Markdown
Author

Fair enough about PrivateTmp. I wouldn't normally consider copying to a remote system's /tmp but I suppose that's not an impossible use case.

As for the other point, the tests, it doesn't look like a systemd service test exists. I only briefly glanced at testsuite/, so maybe I'm missing something. In general testing systemd units specifically is not so easy, though with containers/VMs it's not impossible. Is there any way you would like me to approach that?

This commit adds hardening to the systemd service with a variety of
knobs designed to restrict damage that rsync can do as root, while
making sure that no file transfers are interrupted. For example,
ProtectHome= is still off, and CapabilityBoundingSet is still unlimited
to allow for chown/chmod to work unimpeded.

The rsync@.service has some additional options to restrict all network
access and only use the socket on stdin. An equivalent change was done
in rsync.service to only allow TCP, but full network isolation is not
possible for that unit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants