Skip to content

Instantly share code, notes, and snippets.

@michaelkrieg
Created November 5, 2015 14:54
Show Gist options
  • Save michaelkrieg/1b68e7d0c2ae971c1754 to your computer and use it in GitHub Desktop.
Save michaelkrieg/1b68e7d0c2ae971c1754 to your computer and use it in GitHub Desktop.
Unseal Vault Secret Storage
#!/usr/bin/env python3
import re
import random
import subprocess
initfile = "/usr/local/etc/vault/.init"
data = ""
with open(initfile, "r") as ifile:
data = ifile.read()
findkeys = re.compile(r'(?:Key\s\d+:\s)(.+)')
allkeys = findkeys.findall(data)
for x in range(0, 3):
randomkey = random.choice(allkeys)
allkeys.remove(randomkey)
print("vault unseal %s" % randomkey)
try:
out = subprocess.check_output(['vault', 'unseal', randomkey], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
emsg = e.output
ecode = e.returncode
print("exited with code %s and message: %s." % (emsg, ecode))
@michaelkrieg
Copy link
Author

and yes, of course, the above is no production Vault!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment