Skip to content

Commit 41b3b80

Browse files
authored
Add RQD_BECOME_JOB_USER config setting to disable user switching. (#847)
1 parent 4c549f6 commit 41b3b80

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

rqd/rqd/__main__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def usage():
101101
def main():
102102
setupLogging()
103103

104-
if platform.system() == 'Linux' and os.getuid() != 0:
104+
if platform.system() == 'Linux' and os.getuid() != 0 and \
105+
rqd.rqconstants.RQD_BECOME_JOB_USER:
105106
logging.critical("Please run launch as root")
106107
sys.exit(1)
107108

rqd/rqd/rqconstants.py

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
RQD_RETRY_STARTUP_CONNECT_DELAY = 30
6767
RQD_RETRY_CRITICAL_REPORT_DELAY = 30
6868
RQD_USE_IP_AS_HOSTNAME = True
69+
RQD_BECOME_JOB_USER = True
6970
RQD_CREATE_USER_IF_NOT_EXISTS = True
7071

7172
KILL_SIGNAL = 9
@@ -182,6 +183,8 @@
182183
LOAD_MODIFIER = config.getint(__section, "LOAD_MODIFIER")
183184
if config.has_option(__section, "RQD_USE_IP_AS_HOSTNAME"):
184185
RQD_USE_IP_AS_HOSTNAME = config.getboolean(__section, "RQD_USE_IP_AS_HOSTNAME")
186+
if config.has_option(__section, "RQD_BECOME_JOB_USER"):
187+
RQD_BECOME_JOB_USER = config.getboolean(__section, "RQD_BECOME_JOB_USER")
185188
if config.has_option(__section, "DEFAULT_FACILITY"):
186189
DEFAULT_FACILITY = config.get(__section, "DEFAULT_FACILITY")
187190
if config.has_option(__section, "LAUNCH_FRAME_USER_GID"):

rqd/rqd/rqcore.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ def runLinux(self):
263263

264264
rqd.rqutil.permissionsHigh()
265265
try:
266-
tempCommand += ["/bin/su", runFrame.user_name, rqd.rqconstants.SU_ARGUEMENT,
267-
'"' + self._createCommandFile(runFrame.command) + '"']
266+
if rqd.rqconstants.RQD_BECOME_JOB_USER:
267+
tempCommand += ["/bin/su", runFrame.user_name, rqd.rqconstants.SU_ARGUEMENT,
268+
'"' + self._createCommandFile(runFrame.command) + '"']
269+
else:
270+
tempCommand += [self._createCommandFile(runFrame.command)]
268271

269272
# Actual cwd is set by /shots/SHOW/home/perl/etc/qwrap.cuerun
270273
frameInfo.forkedCommand = subprocess.Popen(tempCommand,

rqd/rqd/rqutil.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def cacheGet(self, cache, key, func):
7373

7474
def permissionsHigh():
7575
"""Sets the effective gid/uid to processes original values (root)"""
76-
if platform.system() == "Windows":
76+
if platform.system() == "Windows" or not rqd.rqconstants.RQD_BECOME_JOB_USER:
7777
return
7878
PERMISSIONS.acquire()
7979
os.setegid(os.getgid())
@@ -87,7 +87,7 @@ def permissionsHigh():
8787
def permissionsLow():
8888
"""Sets the effective gid/uid to one with less permissions:
8989
RQD_GID and RQD_UID"""
90-
if platform.system() in ('Windows', 'Darwin'):
90+
if platform.system() in ('Windows', 'Darwin') or not rqd.rqconstants.RQD_BECOME_JOB_USER:
9191
return
9292
if os.getegid() != rqd.rqconstants.RQD_GID or os.geteuid() != rqd.rqconstants.RQD_UID:
9393
__becomeRoot()
@@ -100,7 +100,7 @@ def permissionsLow():
100100

101101
def permissionsUser(uid, gid):
102102
"""Sets the effective gid/uid to supplied values"""
103-
if platform.system() in ('Windows', 'Darwin'):
103+
if platform.system() in ('Windows', 'Darwin') or not rqd.rqconstants.RQD_BECOME_JOB_USER:
104104
return
105105
PERMISSIONS.acquire()
106106
__becomeRoot()
@@ -128,6 +128,8 @@ def __becomeRoot():
128128
def checkAndCreateUser(username):
129129
"""Check to see if the provided user exists, if not attempt to create it."""
130130
# TODO(gregdenton): Add Windows and Mac support here. (Issue #61)
131+
if not rqd.rqconstants.RQD_BECOME_JOB_USER:
132+
return
131133
try:
132134
pwd.getpwnam(username)
133135
return

0 commit comments

Comments
 (0)