Skip to content

Commit ae008d1

Browse files
[rqd] Ensure logdir is owned by job user (#1742)
Failing to do so causes problems if other frames from the same job were executed on docker, which may lead to the log dir to be owned by root. This change attempts to change the logdir ownership prior to initializing `RqdLogger`. Handling this internally on the initialization logic would be preferred, but is not possible as the initialization needs to run as the job user and the chown logic needs to happen on permissionHigh mode. --------- Signed-off-by: Diego Tavares <[email protected]> Co-authored-by: Ramon Figueiredo <[email protected]>
1 parent bc16c8e commit ae008d1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rqd/rqd/rqcore.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ def setup(self):
14021402
runFrame.uid,
14031403
runFrame.gid)
14041404
if not run_on_docker:
1405+
self.ownFrameDir()
14051406
# Do everything as launching user:
14061407
runFrame.gid = rqd.rqconstants.LAUNCH_FRAME_USER_GID
14071408
rqd.rqutil.permissionsUser(runFrame.uid, runFrame.gid)
@@ -1420,6 +1421,22 @@ def setup(self):
14201421
finally:
14211422
rqd.rqutil.permissionsLow()
14221423

1424+
def ownFrameDir(self):
1425+
"""Chown the frame's log_dir"""
1426+
if not self.runFrame.loki_url:
1427+
# Ensure logdir is owned by this job user. If it doesn't exist it will get
1428+
# created under the correct user when RqdLogger is initialized
1429+
if os.path.isdir(self.runFrame.log_dir):
1430+
try:
1431+
rqd.rqutil.permissionsHigh()
1432+
os.chown(self.runFrame.log_dir, self.runFrame.uid, self.runFrame.gid)
1433+
# pylint: disable=broad-except
1434+
except Exception:
1435+
# Don't bail on this exception as rqlogging initialization might
1436+
# still work depending on the logdir permissions
1437+
log.warning("Failed to chown dir name %s", self.runFrame.log_dir)
1438+
finally:
1439+
rqd.rqutil.permissionsLow()
14231440

14241441
def runUnknown(self):
14251442
"""The steps required to handle a frame under an unknown OS."""

0 commit comments

Comments
 (0)