Skip to content
Snippets Groups Projects
Commit fd177325 authored by Chris Hines's avatar Chris Hines
Browse files

automatically expire certs from the agent

parent bd7ada78
No related branches found
No related tags found
4 merge requests!77Revert "disable agressive kill and restart",!35Dev,!24Test,!22Dev
Pipeline #10292 passed
...@@ -53,9 +53,15 @@ class SSHSession: ...@@ -53,9 +53,15 @@ class SSHSession:
certf = open(keyname+'-cert.pub',mode='w') certf = open(keyname+'-cert.pub',mode='w')
certf.write(cert) certf.write(cert)
certf.close() certf.close()
p = subprocess.Popen([self.sshkeygen,'-L','-f','-'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
keygenout,keygenerr = p.communicate(l)
# Examine the cert to determine its expiry. Use the -t flag to automatically remove from the ssh-agent when the cert expires
certcontents = SSHSession.parse_cert_contents(keygenout.decode().splitlines())
endtime = datetime.datetime.strptime(certcontents['Valid'][0].split()[3],"%Y-%m-%dT%H:%M:%S")
delta = endtime - datetime.datetime.now() # I *think* the output of ssh-keygen -L is in the current timezone even though I assume the certs validity is in UTC
env = os.environ.copy() env = os.environ.copy()
env['SSH_AUTH_SOCK'] = self.socket env['SSH_AUTH_SOCK'] = self.socket
cmd = [self.sshadd] cmd = [self.sshadd,'-t',delta.totalseconds]
cmd.append(keyname) cmd.append(keyname)
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=env) p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,env=env)
(stdout,stderr) = p.communicate() (stdout,stderr) = p.communicate()
...@@ -86,8 +92,6 @@ class SSHSession: ...@@ -86,8 +92,6 @@ class SSHSession:
keygenout,keygenerr = p.communicate(l) keygenout,keygenerr = p.communicate(l)
certcontents = SSHSession.parse_cert_contents(keygenout.decode().splitlines()) certcontents = SSHSession.parse_cert_contents(keygenout.decode().splitlines())
res.append(certcontents) res.append(certcontents)
else:
res.append({'pubkey':l.decode()})
return res return res
@staticmethod @staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment