Skip to content

Instantly share code, notes, and snippets.

@wolph
Created June 19, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wolph/a6da7b96499bdf2bc33435e7db4079e4 to your computer and use it in GitHub Desktop.
Save wolph/a6da7b96499bdf2bc33435e7db4079e4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
'''
A very simple kubernetes secrets dump tool. You can use it like this:
# kubectl get secret -o yaml -A | python decode_secrets.py
'''
import sys
import yaml
import base64
MAX_LENGTH = 120
if sys.argv[1:]:
with open(sys.argv[1]) as fh:
data = yaml.load(fh)
else:
data = yaml.load(sys.stdin)
for item in data['items']:
data = item.pop('data')
metadata = item.pop('metadata')
for key, value in data.items():
key = '{namespace}.{name}.{key}'.format(key=key, **metadata)
value = base64.b64decode(value).decode('utf-8')
if value[MAX_LENGTH:]:
value = value[:MAX_LENGTH - 3] + '...'
print(f'{key}={value}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment