Skip to content

Commit 5ef4042

Browse files
committed
feat (SingularityCE): propagate more env variable inside the container
1 parent 3999e15 commit 5ef4042

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/DIRAC/Resources/Computing/SingularityComputingElement.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io
1515
import json
1616
import os
17+
import re
1718
import shutil
1819
import sys
1920
import tempfile
@@ -85,6 +86,18 @@
8586
"""
8687

8788

89+
ENV_VAR_WHITELIST = [
90+
r"TERM",
91+
r"VOMS_.*",
92+
r"X509_.*",
93+
r"XRD_.*",
94+
r"Xrd.*",
95+
r"DIRAC_.*",
96+
r"BEARER_TOKEN.*",
97+
]
98+
ENV_VAR_WHITELIST = re.compile(r"^(" + r"|".join(ENV_VAR_WHITELIST) + r")$")
99+
100+
88101
class SingularityComputingElement(ComputingElement):
89102
"""A Computing Element for running a job within a Singularity container."""
90103

@@ -311,12 +324,17 @@ def __getEnv(self):
311324
"""Gets the environment for use within the container.
312325
We blank almost everything to prevent contamination from the host system.
313326
"""
314-
payloadEnv = {}
315-
if "TERM" in os.environ:
316-
payloadEnv["TERM"] = os.environ["TERM"]
327+
328+
if not self.__installDIRACInContainer:
329+
payloadEnv = {k: v for k, v in os.environ.items() if ENV_VAR_WHITELIST.match(k)}
330+
else:
331+
payloadEnv = {}
332+
317333
payloadEnv["TMP"] = "/tmp"
318334
payloadEnv["TMPDIR"] = "/tmp"
319335
payloadEnv["X509_USER_PROXY"] = os.path.join(self.__innerdir, "proxy")
336+
payloadEnv["DIRACSYSCONFIG"] = os.path.join(self.__innerdir, "pilot.cfg")
337+
320338
return payloadEnv
321339

322340
@staticmethod

0 commit comments

Comments
 (0)