Run as a non-root user

On Linux, every Mugnsoft component can run as a service under its own account instead of root, with only the capabilities it needs. This is the default procedure in the Linux installation guide. Without RunUser, the program itself still defaults to root.

At a glance

Component Service Capabilities Folders the account writes
Webserver, Webserver-Front MugnsoftWebserver, MugnsoftWebserverFront none config data dbs discovery export front_buffer ha integrator_buffer log report scripts
Integrator MugnsoftIntegrator none config data dbs log notif_buffer scripts
Monitor probe MugnsoftMonitor CAP_NET_RAW: Ping and MTR monitors clientCerts config data dbs drivers export integrator_buffer log scripts tmp
Sentinel Agent MugnsoftDiscoveryAgent CAP_NET_RAW: packet capture
CAP_SYS_PTRACE, CAP_DAC_READ_SEARCH: processes and log files of other accounts
config data dbs integrator_buffer log scripts

A port below 1024 adds CAP_NET_BIND_SERVICE; nothing else is ever granted.

Who owns what

  • Root owns the component folder, the program, install.sh, uninstall.sh, exec/ and license_MNS.dat (mode 644). A compromised component therefore cannot replace what root runs.
  • The account owns the .json file (mode 600, it holds _sharedInternal), the folders listed above, and its home folder /home/mugnsoft (mode 700).

CAP_SYS_PTRACE is close to root

It lets the Sentinel Agent read, and could let an attacker change, any process of the host. The scripts the agent starts receive none of its capabilities. If you do not need the processes of other accounts, remove it as shown in Details: those processes then appear without a name.

Install

You need root and systemd 229 or later: RHEL, Rocky Linux and AlmaLinux 8 and later, Debian, Ubuntu.

1. Create the account (or let step 3 do it):


id mugnsoft >/dev/null 2>&1 || \
  useradd --system --user-group --home-dir /home/mugnsoft \
          --create-home --shell /usr/sbin/nologin mugnsoft
chmod 700 /home/mugnsoft

2. Extract the package under /app/mugnsoft, not in a home folder, which the account cannot enter.

3. Install, from the component folder, as root:


# or webserver, integrator, discovery_agent, webserver-front
cd /app/mugnsoft/monitor
./install.sh --run-as mugnsoft 10.0.0.5:8050
install.sh --run-as output: account created, component registered, service installed

4. Start, then enable the component on the Webserver (Settings > Components) as usual:


systemctl start MugnsoftMonitor
Component menu: enable server

5. Check:


pid=$(systemctl show -p MainPID --value MugnsoftMonitor)
ps -o user= -p "$pid"                         # mugnsoft
grep -E '^(CapEff|NoNewPrivs)' /proc/$pid/status
# must fail with "Permission denied":
sudo -u mugnsoft mv /app/mugnsoft/monitor/monitor /app/mugnsoft/monitor/x
Check: runs as mugnsoft, CAP_NET_RAW only, binary cannot be replaced

CapEff is 0000000000000000 for the Webserver and Integrator, 0000000000002000 for a monitor probe and 0000000000082004 for a Sentinel Agent; NoNewPrivs is 1. Then run a Ping monitor on the probe, or look for packet capture active in the Sentinel Agent log.

install.sh --run-as creates the account if needed, writes "RunUser" into the .json file, refuses a host without systemd, installs and registers the component, and sets the ownership above. It stops with an error if the service was not created, and can be run again safely.

Switch an existing installation

Run the same command on the installed component. Do not run uninstall: it deletes the configuration and databases.


cd /app/mugnsoft/monitor && ./install.sh --run-as mugnsoft
A probe installed as root switched to the mugnsoft account

The script stops the service if it runs, adds the drop-in /etc/systemd/system/<service>.service.d/10-run-as.conf, corrects ownership (only what is not right yet) and starts the service again. It does not register the component again. It also corrects an installation converted by an earlier release, where the account owned the whole folder.

Upgrade

Replacing what root owns takes root. Nobody logs in as mugnsoft (it has no shell): use sudo.


sudo systemctl stop MugnsoftMonitor
sudo install -o root -g root -m 755 ./monitor-new /app/mugnsoft/monitor/monitor
sudo systemctl start MugnsoftMonitor

A new license goes in the same way: sudo install -o root -g root -m 644 license_MNS.dat /app/mugnsoft/webserver/. Use systemctl rather than ./monitor start|stop: it does not run the program as root at all.

Upgrades without full root

If you want admins to upgrade without full root, grant a narrow sudo rule to a dedicated admin group, for example in /etc/sudoers.d/mugnsoft (edit it with visudo -f):


%mnsadmin ALL=(root) /usr/bin/systemctl start Mugnsoft*, \
                     /usr/bin/systemctl stop Mugnsoft*, \
                     /usr/bin/systemctl restart Mugnsoft*, \
                     /app/mugnsoft/*/install.sh

Two rules to keep it safe:

  • Never put mugnsoft itself in that group.
  • Don’t make the binary group-writable for convenience.

Either one reintroduces the escalation path. The wildcards above are safe only because /app/mugnsoft and the scripts stay owned by root.

Troubleshooting

Symptom Cause and fix
RunUser "x" does not exist Create the account (step 1), or use install.sh --run-as
RunUser needs systemd The host does not use systemd: run as root (clear RunUser)
useradd: group mugnsoft exists Use --gid mugnsoft instead of --user-group, or let install.sh create the account
install.sh ends with was not installed The Webserver refused the registration (name or IP and port already known, Webserver unreachable, license): read the messages above it
ps shows root although RunUser is set The service was installed before: run ./install.sh --run-as <account>
status=203/EXEC A parent folder is closed to the account: move the component to /app/mugnsoft
permission denied in journalctl -u <service> Files created as root, or a license in mode 600: run ./install.sh --run-as <account> again
permission denied creating a folder at the top of the component folder Create it for the account (sudo install -d -o mugnsoft -g mugnsoft -m 750 <folder>) and tell Mugnsoft support
Ping or MTR fail with operation not permitted No CAP_NET_RAW: check CapEff. A setcap on the program does not help the service
Sentinel Agent: bandwidth at 0 See Packet capture
Sentinel Agent: processes of other accounts without a name CAP_SYS_PTRACE or CAP_DAC_READ_SEARCH was removed
the browser sandbox is not available on this host (Webserver log) Normal on hosts without user namespaces: PDF reports are printed without it

Details

"RunUser" does not change the identity of the program by itself. install writes it into the systemd unit, with the capabilities of the component:


[Service]
User=mugnsoft
# no setuid, no file capabilities, no sudo
NoNewPrivileges=true
# new files are not readable by other accounts
UMask=0027
# the most the process and its children can ever hold
CapabilityBoundingSet=CAP_NET_RAW
# what the process actually receives
AmbientCapabilities=CAP_NET_RAW

Consequences:

  • systemd is required: the SysV, Upstart and OpenRC scripts would start the program as root, so install refuses RunUser there.
  • Editing RunUser after the install changes nothing until install.sh --run-as converts the service.
  • ./<component> run in a terminal runs as whoever starts it, with none of the service’s settings.
  • Both capability lines are needed: CapabilityBoundingSet= alone grants nothing to a non-root account; an empty value removes every capability.
  • systemd 229 or later is needed for AmbientCapabilities=; on RHEL 7, ping, MTR and capture fail.
  • Since the account cannot rename entries of the component folder, a Webserver leaving a cluster sets its old state aside in ha/disabled-<date> instead of ha.disabled-<date>.
RHEL, Rocky, AlmaLinux Debian, Ubuntu SUSE
useradd comes from shadow-utils passwd (always installed) shadow
nologin /usr/sbin/nologin /usr/sbin/nologin /usr/sbin/nologin
Notes SELinux labels the home folder; if you create it by hand: restorecon -R /home/mugnsoft — —

Tested on AlmaLinux 8 (systemd 239) and Ubuntu 26.04 (systemd 259).

For a monitor probe; for another component, use its service, capabilities and folders from At a glance, and give license_MNS.dat back to root too.


systemctl stop MugnsoftMonitor
mkdir -p /etc/systemd/system/MugnsoftMonitor.service.d
cat > /etc/systemd/system/MugnsoftMonitor.service.d/10-run-as.conf <<'EOF'
[Service]
User=mugnsoft
Group=mugnsoft
NoNewPrivileges=true
UMask=0027
CapabilityBoundingSet=
CapabilityBoundingSet=CAP_NET_RAW
AmbientCapabilities=
AmbientCapabilities=CAP_NET_RAW
EOF
cd /app/mugnsoft/monitor
sed -i 's/"RunUser": *"[^"]*"/"RunUser": "mugnsoft"/' monitor.json
mkdir -p clientCerts config data dbs drivers export integrator_buffer log scripts tmp
chown -R mugnsoft:mugnsoft .
chown root:root . monitor install.sh uninstall.sh && chown -R root:root exec
chmod 755 . monitor && chmod 600 monitor.json
systemctl daemon-reload && systemctl start MugnsoftMonitor

The empty lines reset what the unit already had. With no capability, keep only CapabilityBoundingSet= and AmbientCapabilities=.

Add a drop-in (systemctl edit <service>), then systemctl daemon-reload and restart. Lines of the same setting add up, an empty line resets it, and CapabilityBoundingSet=~ alone restores every capability. Each block is one case:


[Service]
# Container monitors reaching the local Docker socket
SupplementaryGroups=docker

# Action scripts that call sudo
NoNewPrivileges=false
CapabilityBoundingSet=~

# A Sentinel Agent limited to packet capture
CapabilityBoundingSet=
CapabilityBoundingSet=CAP_NET_RAW
AmbientCapabilities=
AmbientCapabilities=CAP_NET_RAW

systemctl stop MugnsoftMonitor
cd /app/mugnsoft/monitor && sudo -u mugnsoft ./monitor run

The service’s capabilities do not apply here. For ping or capture in this mode, setcap cap_net_raw+ep ./monitor (ignored by the service itself, cleared when the program is replaced).

  • Scripts run as the account. A monitor probe’s scripts also get CAP_NET_RAW; a Sentinel Agent’s get no capability. sudo is refused (NoNewPrivileges).
  • Files outside the folder (an SSH key, a log file to watch) must be readable by the account; an SSH key file must be owned by it.
  • Files the service creates are not readable by other accounts (UMask=0027): read the logs with sudo.
  • Browsers: EUM journeys in Chrome or Edge always run without the browser sandbox. PDF reports keep it, and print without it on hosts that forbid user namespaces (AppArmor on Ubuntu 24.04 and later, user.max_user_namespaces=0).

See also

Translations