Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Created March 3, 2023 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflansburg/7a9ebb10adbd4f70150840a8d3e8eb93 to your computer and use it in GitHub Desktop.
Save aflansburg/7a9ebb10adbd4f70150840a8d3e8eb93 to your computer and use it in GitHub Desktop.
Basic jq w/ dynamic keys example with kubectl
# want to decode the output of the `kubectl get secret secname` command
# and specifically the `auth` value
# when we maybe don't know the value of the key corresponding to a container registry
# {
# "auths": {
# "https://index.docker.io/v1/": {
# "username": "smittywerbenjagermanjensen",
# "password": "sup3rs3cr3t",
# "email": "swjmjensen12345@example.com",
# "auth": "c21pdHR5d2VyYmVuamFnZXJtYW5qZW5zZW46c3VwM3JzM2NyM3QK"
# }
# }
# }
kubectl get secret regcred \
--output="jsonpath={.data.\.dockerconfigjson}" \
| base64 --decode \
| jq '.auths \
| to_entries[] \
| select( .key | contains("http")).value.auth' \
| sed 's/"//g' \
| base64 --decode
# > smittywerbenjagermanjensen:sup3rs3cr3t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment