diff --git a/docs/job_managers.rst b/docs/job_managers.rst index f24ef224..7e4f9670 100644 --- a/docs/job_managers.rst +++ b/docs/job_managers.rst @@ -150,11 +150,18 @@ run DRMAA jobs via the user requested by the client (e.g. the Galaxy user). #chown_working_directory_script: scripts/chown_working_directory.bash #drmaa_kill_script: scripts/drmaa_kill.bash #drmaa_launch_script: scripts/drmaa_launch.bash + #user_mapping_script: For more information on running jobs as the real user, check out `this discussion `__ from the Galaxy mailing list. +A script that maps the user name that pulsr gets from the Galaxy server to a user name +on the target system can be configured with the optional parameter ``user_mapping_script``. +The script is supposed to get a single positional parameter and should output the +desired user name to stdout. In can a mapping is not possible a non-zero exit code +be returned and an error message should be printed on stderr. + More Options ------------------------------- diff --git a/pulsar/managers/queued_external_drmaa.py b/pulsar/managers/queued_external_drmaa.py index 1bd6a477..31bb949a 100644 --- a/pulsar/managers/queued_external_drmaa.py +++ b/pulsar/managers/queued_external_drmaa.py @@ -1,5 +1,6 @@ from getpass import getuser from json import dumps +import subprocess from .base.base_drmaa import BaseDrmaaManager from .util.sudo import sudo_popen @@ -27,6 +28,7 @@ def __init__(self, name, app, **kwds): self.chown_working_directory_script = _handle_default(kwds.get('chown_working_directory_script', None), "chown_working_directory") self.drmaa_kill_script = _handle_default(kwds.get('drmaa_kill_script', None), "drmaa_kill") self.drmaa_launch_script = _handle_default(kwds.get('drmaa_launch_script', None), "drmaa_launch") + self.user_mapping_script = kwds.get('user_mapping_script', None) self.production = str(kwds.get('production', "true")).lower() != "false" self.reclaimed = {} self.user_map = {} @@ -47,6 +49,14 @@ def launch(self, job_id, command_line, submit_params={}, dependencies_descriptio log.info("Submit as user %s" % user) if not user: raise Exception("Must specify user submit parameter with this manager.") + if self.user_mapping_script: + try: + mapped_user = subprocess.check_output([self.user_mapping_script, user], text=True).strip() + log.info("Mapped user %s to %s" % (user, mapped_user)) + user = mapped_user + except subprocess.CalledProcessError as e: + log.error(f"Could not map user {user}: {e.stderr}") + raise Exception("User mapping script failed") self.__change_ownership(job_id, user) external_id = self.__launch(job_attributes_file, user).strip() self.user_map[external_id] = user