Commits

YouGov, plc. committed a3cfa8e

Removed the requirement that monster_launchd must be run as root. It now only requires root when it will setuid for the apps.

  • Participants
  • Parent commits 1c74c32
  • Tags 4.1.27

Comments (0)

Files changed (3)

File docs/dev/monster_launchd.rst

 ~~~~~~~
 
 -u/--user:
-	the user that managed processes will be run as. The default is ``monster``.	
+	The user under which managed processes will be run. By default, processes will run under the current user	
 
 --debug:
 	output debugging information about managed processes

File eggmonster/client/_em_emi.py

     (entry_point, env, pkginfo), buf = get_app_info(sock)
 
     load_dependencies(pkginfo, emenv.cheeseshop)
-    os.setuid(master_uid)
+    if not master_uid == os.getuid():
+        os.setuid(master_uid)
 
     # If the below line returns (and does not raise a SystemExit), then this
     # means we are the master emi process and we communicate between the

File eggmonster/commands/monster_launchd.py

 
 def setup_parser():
     parser = OptionParser()
-    parser.add_option("-u", "--user", dest="user", default='monster',
+    current_user = pwd.getpwuid(os.getuid()).pw_name
+    parser.add_option("-u", "--user", default=current_user,
         help="setuid() to this user in application processes "
-        "(default: monster)")
+        "(default: %(current_user)s)" % vars())
     parser.add_option('--debug', action='store_true',
         help='Print debug information about launching processes.')
     return parser
 
+def get_options():
+    parser = setup_parser()
+    options, args = parser.parse_args()
+    if args:
+        parser.error("Received unexpected positional arguments")
+
+    uid = pwd.getpwnam(options.user).pw_uid
+
+    if os.getuid() and uid != os.getuid():
+        parser.error(
+            "monster_launchd must be run as root to setuid for %s" %
+            options.user)
+
+    return options
+
 def run():
-    parser = setup_parser()
-    (options, args) = parser.parse_args()
-
-    if os.getuid():
-        parser.error("monster_launchd must be run as root")
-
-    uid = pwd.getpwnam(options.user)[2]
+    options = get_options()
 
     try:
         main(options.user, options.debug)