ohmyzsh
ohmyzsh copied to clipboard
kubectl add alias to decode secret data
Standards checklist:
- [x] The PR title is descriptive.
- [x] The PR doesn't replicate another PR which is already open.
- [x] I have read the contribution guide and followed all the instructions.
- [x] The code follows the code style guide detailed in the wiki.
- [x] The code is mine or it's from somewhere with an MIT-compatible license. Mine with inspiration from https://github.com/mveritym/kubedecode
- [x] The code is efficient, to the best of my ability, and does not waste computer resources.
- [x] The code is stable and I have tested it myself, to the best of my abilities.
Changes:
- Add
kdecsec
alias tokubectl
plugin to base64 decode kubernetes secrets
$ kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret
$ kdecsec my-secret
{
"key1": "supersecret",
"key2": "topsecret"
}
Other comments:
Kubernetes Secrets have their data encoded in base64. More often than not, when wanting to know what's in a given secret, we want the data.
The kdecsec
alias is pretty much the same thing as kubedecode, which solves the same problem. Making it part of the kubectl
plugin is just super convenient. :grin:
I think the following alias would be better/do not depends on jq alias kgsecp='kubectl get secret -o go-template='''{{range $k,$v := .data}}{{"### "}}{{$k}}{{"\n"}}{{$v|base64decode}}{{"\n\n"}}{{end}}'''' code is from https://kubernetes.io/docs/reference/kubectl/cheatsheet/#viewing-finding-resources and go-template could be edited to match a json if that's what the output should look like, but I prefer plaintext as json may need to escape some characters
Not depending on jq is definitely a plus, nice!