I am writing a daemon in python using python-daemon . the daemon starts at boot time (init.d) and needs to access various devices. the daemon runs on the embedded system ( beaglebone ) running ubuntu.
Now my problem is that I want to run the daemon as an unprivileged user rather (like mydaemon ) than root .
To allow daemons to access devices, I added this user to the desired groups. in python code i am using daemon.DaemonContext(uid=uidofmydamon) .
a process starting with root is perfectly dismounted and belongs to the correct user, but I get permission to refuse when I try to access devices. I wrote a small test application, and it seems that the process does not inherit user group membership.
#!/usr/bin/python import logging, daemon, os if __name__ == '__main__': lh=logging.StreamHandler() logger = logging.getLogger() logger.setLevel(logging.INFO) logger.addHandler(lh) uid=1001
when I run the above code as user with uid = 1001, I get something like
$ ./testdaemon.py UID: 1001 groups: [29,107,1001]
then when I run the above code as root (or su ), I get:
$ sudo ./testdaemon.py UID: 1001 groups: [0]
How can I create a daemon process running as root, but with a different effective uid and intact group membership?
source share