mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6718] [MERGED] fix(systemd): harden shipped x-ui unit files #6430
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6430
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6718
Author: @ChesterFishmansWork
Created: 10/2/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @MHSanaei
Base:
main← Head:fix/6605-systemd-hardening📝 Commits (9)
faf1e01fix(systemd): harden shipped x-ui unit files8b8c8b5fix(systemd): ship ReadWriteDirectories= alias for systemd < 231a8d3b71fix(systemd): keep root's DAC bits and regenerate the write paths11f22c9fix(systemd): keep the seccomp whitelist off old systemd, tighten the rest72c24b9fix(systemd): actually wire the read-only guard, drop the superseded drop-in3456c11fix(systemd): correct two comments and keep spaces out of the path list3536575fix(systemd): act on the independent review of the drop-in generator8f2b21dMerge branch 'main' into fix/6605-systemd-hardening395b6dcfix(systemd): name the hardening old systemd really ignores📊 Changes
6 files changed (+582 additions, -0 deletions)
View changed files
📝
install.sh(+168 -0)📝
update.sh(+180 -0)📝
x-ui.service.arch(+76 -0)📝
x-ui.service.debian(+76 -0)📝
x-ui.service.rhel(+76 -0)📝
x-ui.sh(+6 -0)📄 Description
Problem
The shipped systemd units run the panel as root with no sandboxing at all;
systemd-analyze securityrates the unit 9.6 UNSAFE (fixes #6605).Change
Adds a hardening block to
x-ui.service.debian,x-ui.service.archandx-ui.service.rhel(identical except for the pre-existingEnvironmentFile=). The panel intentionally stays root — it supervises the Xray children, edits netfilter state for the IP-limit feature and reads TLS private keys — so the settings only bound what a panel-level flaw can reach.NoNewPrivileges=yesProtectSystem=full/usrand/bootbecome read-only; the panel only needs write access to its own stores, listed inReadWritePathsbelow.ReadWritePaths=-/etc/x-ui -/usr/local/x-ui -/var/log/x-uiXUI_DB_FOLDER(DB, update status, node token),XUI_BIN_FOLDER(Xray binary/config/geo) andXUI_LOG_FOLDER. The leading-keeps the unit startable when a path does not exist yet.ProtectKernelTunables=yes,ProtectKernelModules=yes,ProtectKernelLogs=yes,ProtectClock=yes,ProtectHostname=yes,LockPersonality=yes,RestrictRealtime=yes,RestrictSUIDSGID=yes,RestrictNamespaces=yesUMask=0077RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINKip(8)child used by the AmneziaWG IPv6-alias feature).CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAWNET_ADMINforip(8)/tproxy and the IP-limit netfilter rules,NET_BIND_SERVICEfor ports below 1024,NET_RAWfor raw sockets andSO_BINDTODEVICE.SystemCallArchitectures=native,SystemCallFilter=@system-service,SystemCallErrorNumber=EPERM@system-service; violations returnEPERMinstead of killing the process, so a missed syscall degrades one operation rather than the whole panel.Deliberately absent:
PrivateTmp=yes— the web updater writes its script under/tmpand hands the absolute path to asystemd-runtransient unit, which does not share this service's private/tmp; the download would vanish and updates would break.MemoryDenyWriteExecute=yes— Xray/Go may map writable-executable memory; too risky for a proxy panel.ProtectHome=yes— kept asread-onlyinstead: installs keep TLS certificates under/root/certand the panel must read them.Notes
install.shandupdate.shdo not embed the unit — they copy it from the release tarball or fetch it from raw.githubusercontent.com — so no script changes are needed.systemd-analyzeis not available in the environment this was prepared in, so the numeric rating is not re-measured here; the directive-by-directive reasoning above is checked against the panel's code paths, not executed. Worth runningsystemd-analyze security x-ui.serviceon a test host before merging.XUI_DB_FOLDER/XUI_BIN_FOLDER/XUI_LOG_FOLDERoutside the three default paths must add them toReadWritePaths— that is called out in a comment next to the directive.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.