[Feature request] Support configuring the OpenWrt service user via UCI
The OpenWrt init script currently runs sing-box as root and does not expose a UCI option for selecting a different user.
My use case is transparent proxying with iptables on OpenWrt. When redirecting locally generated traffic to sing-box, its own outbound connections need to be excluded to prevent a routing loop.
Running sing-box under a dedicated user allows these connections to be identified with an iptables owner match (-m owner --uid-owner) and excluded from the redirection rules. Matching root would also exclude traffic from unrelated services running as root.
Currently, selecting a dedicated user requires modifying the init script. Could we expose an optional user setting in the main UCI section instead?
config sing-box 'main'
option enabled '1'
option user 'sing-box'
option conffile '/etc/sing-box/config.json'
option workdir '/usr/share/sing-box'
option log_stderr '1'Proposed behavior:
- When
useris set to a non-empty value, pass it to procd usingprocd_set_param user. - When
useris absent or empty, keep the current behavior of running as root. - The administrator is responsible for creating the user, granting any required permissions, and configuring the iptables exclusion rules.
I have prepared a small implementation for reference: https://github.com/eeelin/sing-box/pull/1
It passes shell syntax and diff checks, but has not yet been tested on an OpenWrt device. Would this approach be acceptable for an upstream contribution?
Source: SagerNet/sing-box