Skip to content

Commit 6fe9dac

Browse files
authored
Merge pull request #8136 from chaen/tokens_for_pilot
fix (proxy): pilot proxy are shipped with a token
2 parents 14ca988 + ae0fd4b commit 6fe9dac

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/DIRAC/Resources/Computing/PilotBundle.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
2-
Collection of Utilities to handle pilot jobs
2+
Collection of Utilities to handle pilot jobs
33
44
"""
5+
56
import os
67
import base64
78
import bz2
@@ -11,7 +12,16 @@
1112
def bundleProxy(executableFile, proxy):
1213
"""Create a self extracting archive bundling together an executable script and a proxy"""
1314

14-
compressedAndEncodedProxy = base64.b64encode(bz2.compress(proxy.dumpAllToString()["Value"])).decode()
15+
from pathlib import Path
16+
from DIRAC.Core.Security.ProxyFile import writeChainToTemporaryFile
17+
18+
retVal = writeChainToTemporaryFile(proxy)
19+
proxyLocation = Path(retVal["Value"])
20+
proxy_string = proxyLocation.read_text()
21+
proxyLocation.unlink()
22+
23+
# Note: I'd expect that to fail, as bz2.compress expects bytes, and not a string
24+
compressedAndEncodedProxy = base64.b64encode(bz2.compress(proxy_string)).decode()
1525
with open(executableFile, "rb") as fp:
1626
compressedAndEncodedExecutable = base64.b64encode(bz2.compress(fp.read(), 9)).decode()
1727

src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,6 @@ def _setupProxy(self, owner, ownerGroup):
478478

479479
proxyChain = ret["Value"]["chain"]
480480
if "groupProperties" not in ret["Value"]:
481-
print(ret["Value"])
482-
print(proxyChain.dumpAllToString())
483481
self.log.error("Invalid Proxy", "Group has no properties defined")
484482
return S_ERROR("Proxy has no group properties defined")
485483

src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ def _writePilotScript(
695695
:returns: file name of the pilot wrapper created
696696
"""
697697

698+
pilotFilesCompressedEncodedDict = None
699+
698700
try:
699701
pilotFilesCompressedEncodedDict = getPilotFilesCompressedEncodedDict([], proxy)
700702
except Exception as be:

src/DIRAC/WorkloadManagementSystem/Utilities/PilotWrapper.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
""" Module holding function(s) creating the pilot wrapper.
1+
"""Module holding function(s) creating the pilot wrapper.
22
3-
This is a DIRAC-free module, so it could possibly be used also outside of DIRAC installations.
3+
This is a DIRAC-free module, so it could possibly be used also outside of DIRAC installations.
44
5-
The main client of this module is the SiteDirector, that invokes the functions here more or less like this::
5+
The main client of this module is the SiteDirector, that invokes the functions here more or less like this::
66
7-
pilotFilesCompressedEncodedDict = getPilotFilesCompressedEncodedDict(pilotFiles)
8-
localPilot = pilotWrapperScript(pilotFilesCompressedEncodedDict,
9-
pilotOptions,
10-
pilotExecDir)
11-
_writePilotWrapperFile(localPilot=localPilot)
7+
pilotFilesCompressedEncodedDict = getPilotFilesCompressedEncodedDict(pilotFiles)
8+
localPilot = pilotWrapperScript(pilotFilesCompressedEncodedDict,
9+
pilotOptions,
10+
pilotExecDir)
11+
_writePilotWrapperFile(localPilot=localPilot)
1212
1313
"""
14+
1415
from __future__ import absolute_import, division, print_function
1516

1617
import base64
1718
import bz2
1819
import os
1920
import tempfile
2021

22+
2123
pilotWrapperContent = """#!/bin/bash
2224
# Reduce the maximum allowed number of open file descriptors as micromamba
2325
# gets stuck due to https://github.com/DaanDeMeyer/reproc/pull/103
@@ -411,7 +413,15 @@ def getPilotFilesCompressedEncodedDict(pilotFiles, proxy=None):
411413
pilotFilesCompressedEncodedDict[os.path.basename(pf)] = pfContentEncoded
412414

413415
if proxy is not None:
414-
compressedAndEncodedProxy = base64.b64encode(bz2.compress(proxy.dumpAllToString()["Value"].encode()))
416+
from pathlib import Path # pylint: disable=import-error
417+
from DIRAC.Core.Security.ProxyFile import writeChainToTemporaryFile # pylint: disable=import-error
418+
419+
retVal = writeChainToTemporaryFile(proxy)
420+
proxyLocation = Path(retVal["Value"])
421+
proxy_string = proxyLocation.read_text()
422+
proxyLocation.unlink()
423+
424+
compressedAndEncodedProxy = base64.b64encode(bz2.compress(proxy_string.encode()))
415425
pilotFilesCompressedEncodedDict["proxy"] = compressedAndEncodedProxy
416426

417427
return pilotFilesCompressedEncodedDict

0 commit comments

Comments
 (0)