Skip to content

Instantly share code, notes, and snippets.

@thsutton
Last active February 23, 2022 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thsutton/a049a4c3f22704c1d8c55ef675043708 to your computer and use it in GitHub Desktop.
Save thsutton/a049a4c3f22704c1d8c55ef675043708 to your computer and use it in GitHub Desktop.
Get a Kerberos keytab from Hashicorp vault.
#!/bin/sh
# vault-get-keytab
#
# Rather than verify that it’s exactly the keytab we expect, this script checks that it is
# (or appears to be) a keytab for the required principal.
set -eu
$vault_path=“$1
$principal=“$2
$target=“$3
F=$(mktemp -s /tmp/keytab.XXXXXX)
trap ... “rm -f $F
chmod 600 $F
vault read --field token “$vault_path| base64 --decode > $F
# should we test that we CAN get a ticket? Or that we OUGHT to be able to?
kinit -kt $F$principal
kdestroy -q
# or: klist -kt “$F” | grep -q “$principal”
mv “$F” “$target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment