-
Notifications
You must be signed in to change notification settings - Fork 13
/
kf
executable file
·42 lines (34 loc) · 1.04 KB
/
kf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# kf -- forward Kerberos TGT to remote hosts
import argparse
import gssapi
import os
import subprocess
import sys
def is_local(host):
return host.lower() == os.uname().nodename.lower()
parser = argparse.ArgumentParser()
parser.add_argument("host", nargs="+")
args = parser.parse_args()
princ = gssapi.Credentials(usage="initiate").name
realm = str(princ).rpartition("@")[-1]
# SSH will do the GSSAPI dance for delegating a ticket -- just need to copy it
# from the per-connection cache to the default cache.
print(f"Forwarding tickets for {princ}...")
cmd = f"kvno -q --out-cache FILE:/tmp/krb5cc_$(id -u) krbtgt/{realm}"
errors = 0
procs = []
for host in args.host:
if is_local(host):
print(f"{host} skipped (local)")
continue
proc = subprocess.Popen(["ssh", "-S", "none", "-K", host, cmd])
procs.append((host, proc))
for host, proc in procs:
r = proc.wait()
if r == 0:
print(f"{host} OK")
else:
print(f"{host} = {r!r}", file=sys.stderr)
errors = 1
exit(errors)