How To See Kubernetes Secret Data?

See Kubernetes Secret Data



Kubernetes secrets are data in key-value format stored secretly for your applications deployed in a Kubernetes system. If you have proper rights and, for debugging purposes you wish to see the secret data then this post will help you. 

To see Kubernetes secret data you must have proper rights to see its pods/deployments/secrets. This post assumes you have basic knowledge of Kubernetes and understand how to get access to a Kubernetes instance and you can run commands like kubectl get pod/deployments/secrets successfully.

Steps involved:

1. Get Kubernetes secret in details

2. Decode the secret data


Get Kubernetes Secret in Detail

You can normally get any resource list in Kubernetes by command 'kubectl get pods/deployments/secrets'. Similarly `secret` is also a resource. You get secret list by command:

>> kubectl get secrets
NAME                   TYPE                                 DATA           AGE
default-token-kctfm    kubernetes.io/service-account-token   3            634d
test-secret            Opaque                                1            258d

It will list all the secrets for the Kubernetes instance. Now choose the secret name of which you wish to see the data. Let's say in our case it's 'test-secret'. 

To get the secret data in detail, run the following command:


>> kubectl get secret test-secret -o yaml

Output:
apiVersion: v1
data:
  testKey: dGVzdEtleURhdGEK
kind: Secret
metadata:
   annotations:
     kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","data":
{"testKey":"dGVzdEtleURhdGEK"},"kind":"Secret","metadata":{"annotations":{},
"name":"test-secret","namespace":"default"}}
   creationTimestamp: "2019-04-22T08:55:50Z"
   name: test-secret
   namespace: default
   resourceVersion: "174116369"
   selfLink: /api/v1/namespaces/default/secrets/test-secret
   uid: 6d5345fd-64dc-11e9-8896-XXXXXXX
type: Opaque

The output will be in YAML file format. Notice your keys and its respective values of secrets will be under 'data' attribute i.e., testKey: dGVzdEtleURhdGEK. The value is actually base64 encoded.


Decode the Kubernetes Secret Data

To decode your key's value, either you can Google "decode base64 online". But if your secret is a corporate secret better avoid it. Make sure you have a Linux terminal open and run the following command:

base64 <encoded-data> | base64 -d

For our case it will be:

>> base64 dGVzdEtleURhdGEK | base64 -d
testKeyData

TADDDDAAAAAAAaaaaaaa your unlocked your secret data stored in your Kubernetes secret vault.


Note: To decode a string via command line in Windows try this Stackoverflow link


Comments

Popular posts from this blog

Effectively Use "cbt" command to get Google Cloud BigTable Data

Quickly Setup Golang pprof and debugging for Memory Leak

In Short: SLI, SLO and SLA (and Error Budget)