From d4ab484dd3f1cc5966aa05123af37644066be37d Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sat, 11 Feb 2023 23:15:02 +0200 Subject: [PATCH] Fix interactive nonroot set .profile --- clearml_session/interactive_session_task.py | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/clearml_session/interactive_session_task.py b/clearml_session/interactive_session_task.py index 847d616..95d0017 100644 --- a/clearml_session/interactive_session_task.py +++ b/clearml_session/interactive_session_task.py @@ -683,12 +683,24 @@ def setup_user_env(param, task): except Exception as ex: print('Applying vault configuration failed: {}'.format(ex)) - # do not change user bash/profile + # do not change user bash/profile if we are not running inside a container if os.geteuid() != 0: - if param.get("user_key") and param.get("user_secret"): - env['CLEARML_API_ACCESS_KEY'] = param.get("user_key") - env['CLEARML_API_SECRET_KEY'] = param.get("user_secret") - return env + # check if we are inside a container + is_container = False + try: + with open("/proc/1/sched", "rt") as f: + lines = f.readlines() + if lines and lines[0].split()[0] in ("bash", "sh", "zsh"): + # this a container + is_container = True + except Exception: # noqa + pass + + if not is_container: + if param.get("user_key") and param.get("user_secret"): + env['CLEARML_API_ACCESS_KEY'] = param.get("user_key") + env['CLEARML_API_SECRET_KEY'] = param.get("user_secret") + return env # create symbolic link to the venv environment = os.path.expanduser('~/environment')