Skip to content

Commit

Permalink
feat (SingularityCE): propagate more env variable inside the container
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Jul 31, 2023
1 parent 3999e15 commit 5ef4042
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/DIRAC/Resources/Computing/SingularityComputingElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io
import json
import os
import re
import shutil
import sys
import tempfile
Expand Down Expand Up @@ -85,6 +86,18 @@
"""


ENV_VAR_WHITELIST = [
r"TERM",
r"VOMS_.*",
r"X509_.*",
r"XRD_.*",
r"Xrd.*",
r"DIRAC_.*",
r"BEARER_TOKEN.*",
]
ENV_VAR_WHITELIST = re.compile(r"^(" + r"|".join(ENV_VAR_WHITELIST) + r")$")


class SingularityComputingElement(ComputingElement):
"""A Computing Element for running a job within a Singularity container."""

Expand Down Expand Up @@ -311,12 +324,17 @@ def __getEnv(self):
"""Gets the environment for use within the container.
We blank almost everything to prevent contamination from the host system.
"""
payloadEnv = {}
if "TERM" in os.environ:
payloadEnv["TERM"] = os.environ["TERM"]

if not self.__installDIRACInContainer:
payloadEnv = {k: v for k, v in os.environ.items() if ENV_VAR_WHITELIST.match(k)}
else:
payloadEnv = {}

payloadEnv["TMP"] = "/tmp"
payloadEnv["TMPDIR"] = "/tmp"
payloadEnv["X509_USER_PROXY"] = os.path.join(self.__innerdir, "proxy")
payloadEnv["DIRACSYSCONFIG"] = os.path.join(self.__innerdir, "pilot.cfg")

return payloadEnv

@staticmethod
Expand Down

0 comments on commit 5ef4042

Please sign in to comment.