ohmyzsh icon indicating copy to clipboard operation
ohmyzsh copied to clipboard

kubectl add alias to decode secret data

Open hkiang01 opened this issue 4 years ago • 2 comments

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 to kubectl 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:

hkiang01 avatar Mar 05 '20 05:03 hkiang01

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

alemairebe avatar Oct 27 '22 14:10 alemairebe

Not depending on jq is definitely a plus, nice!

hkiang01 avatar Oct 27 '22 15:10 hkiang01