Skip to content

Commit

Permalink
Merge pull request DIRACGrid#7135 from chaen/v8.0_fix_singularityEnv
Browse files Browse the repository at this point in the history
[v8.0]Propagate more env variable in the SingularityCE
  • Loading branch information
chaen committed Aug 2, 2023
2 parents 2bb75a6 + 5ef4042 commit 1cd52b0
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 1cd52b0

Please sign in to comment.