Skip to content

Commit

Permalink
refactor: Split voms-proxy-init command for use with DiracX
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Jan 22, 2024
1 parent 4a5868b commit fa4c34e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/DIRAC/Core/Security/Locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def getCAsLocation():
casPath = retVal["Value"]
if os.path.isdir(casPath):
return casPath
# Other locations
return getCAsLocationNoConfig()


def getCAsLocationNoConfig():
"""Retrieve the CA's files location"""
# Look up the X509_CERT_DIR environment variable
if "X509_CERT_DIR" in os.environ:
casPath = os.environ["X509_CERT_DIR"]
Expand Down
2 changes: 2 additions & 0 deletions src/DIRAC/Core/Security/ProxyFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def multiProxyArgument(proxy=False):
return S_ERROR(DErrno.EPROXYFIND)
if isinstance(proxy, str):
proxyLoc = proxy
else:
raise NotImplementedError(f"Unknown proxy type ({type(proxy)})")
# Load proxy
proxy = X509Chain()
retVal = proxy.loadProxyFromFile(proxyLoc)
Expand Down
58 changes: 32 additions & 26 deletions src/DIRAC/Core/Security/VOMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@
VOMS_PROXY_INIT_CMD = "voms-proxy-init"


def voms_init_cmd(
vo: str, attribute: str | None, chain: X509Chain, in_fn: str, out_fn: str, vomsesPath: str | None
) -> list[str]:
secs = chain.getRemainingSecs()["Value"] - 300
if secs < 0:
return S_ERROR(DErrno.EVOMS, "Proxy length is less that 300 secs")
hours = int(secs / 3600)
mins = int((secs - hours * 3600) / 60)

bitStrength = chain.getStrength()["Value"]

cmd = [VOMS_PROXY_INIT_CMD]
if chain.isLimitedProxy()["Value"]:
cmd.append("-limited")
cmd += ["-cert", in_fn]
cmd += ["-key", in_fn]
cmd += ["-out", out_fn]
cmd += ["-voms"]
cmd += [f"{vo}:{attribute}" if attribute and attribute != "NoRole" else vo]
cmd += ["-valid", f"{hours}:{mins}"]
cmd += ["-bits", str(bitStrength)]
if vomsesPath:
cmd += ["-vomses", vomsesPath]

if chain.isRFC().get("Value"):
cmd += ["-r"]
cmd += ["-timeout", "12"]

return cmd


class VOMS:
def __init__(self, *args, **kwargs):
"""Create VOMS class, setting specific timeout for VOMS shell commands."""
Expand Down Expand Up @@ -225,38 +256,13 @@ def setVOMSAttributes(self, proxy, attribute=None, vo=None):
chain = proxyDict["chain"]
proxyLocation = proxyDict["file"]

secs = chain.getRemainingSecs()["Value"] - 300
if secs < 0:
return S_ERROR(DErrno.EVOMS, "Proxy length is less that 300 secs")
hours = int(secs / 3600)
mins = int((secs - hours * 3600) / 60)

# Ask VOMS a proxy the same strength as the one we already have
bitStrength = chain.getStrength()["Value"]

retVal = self._generateTemporalFile()
if not retVal["OK"]:
deleteMultiProxy(proxyDict)
return retVal
newProxyLocation = retVal["Value"]

cmd = [VOMS_PROXY_INIT_CMD]
if chain.isLimitedProxy()["Value"]:
cmd.append("-limited")
cmd += ["-cert", proxyLocation]
cmd += ["-key", proxyLocation]
cmd += ["-out", newProxyLocation]
cmd += ["-voms"]
cmd += [f"{vo}:{attribute}" if attribute and attribute != "NoRole" else vo]
cmd += ["-valid", f"{hours}:{mins}"]
cmd += ["-bits", str(bitStrength)]
vomsesPath = self.getVOMSESLocation()
if vomsesPath:
cmd += ["-vomses", vomsesPath]

if chain.isRFC().get("Value"):
cmd += ["-r"]
cmd += ["-timeout", "12"]
cmd = voms_init_cmd(vo, attribute, chain, proxyLocation, newProxyLocation, self.getVOMSESLocation())

result = shellCall(
self._secCmdTimeout,
Expand Down

0 comments on commit fa4c34e

Please sign in to comment.