Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl add alias to decode secret data #8699

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hkiang01
Copy link

@hkiang01 hkiang01 commented Mar 5, 2020

Standards checklist:

  • The PR title is descriptive.
  • The PR doesn't replicate another PR which is already open.
  • I have read the contribution guide and followed all the instructions.
  • The code follows the code style guide detailed in the wiki.
  • The code is mine or it's from somewhere with an MIT-compatible license.
    Mine with inspiration from https://github.com/mveritym/kubedecode
  • The code is efficient, to the best of my ability, and does not waste computer resources.
  • 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. 馃榿

@ohmyzsh ohmyzsh bot added Area: plugin Issue or PR related to a plugin Topic: alias Pull Request or issue regarding aliases labels Mar 5, 2020
@hkiang01 hkiang01 changed the title kubectl add alias to decode secret values kubectl add alias to decode secret data Mar 5, 2020
@alemairebe
Copy link

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

@hkiang01
Copy link
Author

Not depending on jq is definitely a plus, nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: plugin Issue or PR related to a plugin Topic: alias Pull Request or issue regarding aliases
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

None yet

3 participants