Skip to content

Instantly share code, notes, and snippets.

@akagaeng
Last active January 25, 2023 07:28
Show Gist options
  • Save akagaeng/86d562447f6a41cf94953ba525a04ea8 to your computer and use it in GitHub Desktop.
Save akagaeng/86d562447f6a41cf94953ba525a04ea8 to your computer and use it in GitHub Desktop.
Decode base64-encoded Kubernetes secret

Decode base64-encoded Kubernetes secret

With jsonpath

Get secret

  • Common case: nested name with NO dot
# .data.name
k get secret <some_secret_name> -o jsonpath="{.data.name}" | base64 -d

# kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
  • nested name with dots
# .data."tls.key"
# With dot (.) in the key(name)
k get secret <some_secret_name> -o jsonpath="{.data['tls\.key']}" | base64 -d

# k get secret argocd-secret -o jsonpath="{.data['tls\.key']}" | base64 -d

With jq

Prerequisites

  • jq installed
brew install jq

Get secret

  • Common case: nested name with NO dot
# .metadata.annotations
k get secret <some_secret_name> -ojson | jq -r '.metadata.annotations'

k get secret argocd-secret -ojson | jq -r '.metadata.annotations'
  • nested name with dots
# .data."tls.key"
# With dot (.) in the key(name)
k get secret <some_secret_name> -ojson | jq -r '.data["tls.key"]' | base64 -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment