I thought, that the service files under /lib/systemd/system/ determine as what user a service is started. But apparently that's not (always) the case. Here's an example:
~# ps faux
...
whoopsie 1445 0.0 0.1 388420 12604 ? Ssl 08:22 0:00 /usr/bin/whoopsie -f
...
From the above output we see, that the process 'whoopsie' runs under the user 'whoopsie'
Now we look at the startupscript:
~# cat /lib/systemd/system/whoopsie.service
Description=crash report submission daemon
After=network-online.target
Wants=network-online.target
[Service]
Environment="CRASH_DB_URL=https://daisy.ubuntu.com"
ExecStart=/usr/bin/whoopsie -f
Restart=always
[Install]
WantedBy=multi-user.target
In that startup script is no user defined.
So what determines as which user a process is started?
While your observation is correct, it is not due to systemd. Whoopsie is run as root and simply drops its privileges.
Additional info, this whoopsie process changes userid from root to whoopsie after started.
Source code:
From: https://github.com/pexip/os-whoopsie-daisy/blob/master/src/whoopsie.c#L838
setresuid is the function to change user
Reference: http://man7.org/linux/man-pages/man2/setresuid.2.html
Please refer user or group if nothing is specified some defaults are applicable. The default is "root".