What's the canonical way to have an upstart job change its userid and run the script as an unprivileged user?
Obviously one can use su or sudo, but this seems hacky (and can generate needless log lines).
migrated from stackoverflow.com Nov 21 '10 at 13:42This question came from our site for professional and enthusiast programmers. |
|||
|
|
|||
|
|
|||||||||||||||||||||
|
|
Asking on the #upstart channel on freenode, the official take on the matter is:
|
|||||||||||||||||
|
|
How about using start-stop-daemon?
From Upstart cookbook:
Note: |
|||||
|
|
There are several ways to do it, all with slightly different semantics, particularly relating to group membership:
|
||||
|
|
|
Use Documentation here: http://cr.yp.to/daemontools/setuidgid.html |
|||||||||
|
|
On an Ubuntu 10.10 instance on Amazon EC2, I had better luck with the I also struggled with some of the other upstart stanzas. I am calling a python application with a specific The following is what worked for me.
The |
|||||
|
|
I was using CentOS 6, and I could not get the recommended hack (for Upstart 0.6.5) to work for me, nor the 'su' trick because the number of forks involved (4 I think) was not tracked by 'expect fork' or 'expect daemon'. I eventually just did
(ie set the setuid bit and change the ownership). It may not be the safest method, but for an internal R&D project, it didn't matter in our case. |
|||||
|
|
There is a third possibility depending on what you are trying to accomplish. You may be able to loosen the access controls on the files/devices in question. This can allow an unprivileged user to mount or access items that they normally wouldn't be allowed to. Just be sure you aren't giving away the keys to the kingdom in the process. You can also change the timeout of the sudo password cache. But I don't recommend it unless your machine is physically secure (i.e., you believe that it's unlikely that a passer-by would attempt to gain sudo access). There's a good reason that there are very few ways to perform privileged actions and that they perform If the size of your log files is a concern then something is probably wrong. Sudo generates only one line per use under normal conditions. |
||||
|
|