How to use the Kubernetes Secret decoder
- Get the Secret:
kubectl get secret db-credentials -n production -o yaml(or-o json). - Paste the output into the left pane. Several Secrets work too: a
List, or documents separated by---. - Read the values on the right. Choose the Output: Secret with stringData (a manifest you can apply again), JSON (keyed by namespace and name) or .env.
- Check the warnings: a value that ends with a newline, a value that is not valid base64, a value that is binary.
Example
This Secret comes from kubectl get secret db-credentials -o yaml:
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
namespace: production
type: Opaque
data:
username: YWRtaW4=
password: cGEkJHcwcmQ=
Decoded with the first output option:
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
namespace: production
type: Opaque
stringData:
username: admin
password: pa$$w0rd
What the tool checks for you
- Base64 the way the API server reads it. The standard alphabet with padding. A value written with the URL-safe alphabet (
-and_) or with the padding cut off is reported as invalid instead of being guessed. - The trailing newline.
echo "secret" | base64encodes the newline too, which is the most common reason an application cannot log in with a password that “looks right”. A single-line value that ends with a line break is flagged. Multi-line values such as a PEM certificate are expected to end with one and are not. - Binary values. A key or a certificate in DER form is not text. It stays as base64 under
dataand the warning names it. stringData. Plain values are copied as they are, and when a key appears in both blocks the tool tells you which one wins.- Other objects. A
ConfigMaporDeploymentin the same paste is skipped with a note, because only a Secret holds encoded values.
Good practice with decoded secrets
Decoding on your own machine is the safest way to look at a Secret, but the result is a plain-text secret. Do not paste it into chat, tickets or screenshots, and rotate any value that was shared by mistake. When you create a Secret, encode without the newline (printf 'value' | base64 or echo -n), or use kubectl create secret generic --from-literal and let it do the encoding. To look at the certificate inside a kubernetes.io/tls Secret, decode it here and read it with the Certificate Decoder.
For plain Base64 text and files there is the Base64 encoder and decoder; to turn the manifest into JSON for a script use YAML to JSON, and for a .env file look at .env to JSON. The background on why encoding is not protection is in Base64 is not encryption.
Frequently asked questions
Is it safe to paste a real Secret here?
The manifest is parsed and decoded in your browser and is never uploaded. The tool is also marked sensitive: your input is never kept as a draft on this device, and making a share link asks you to confirm first. Even so, treat decoded values like any secret: do not paste them into chat or tickets.
Why are the values in a Secret base64 at all?
Base64 lets a Secret hold any bytes (certificates, keys, binary tokens) in YAML or JSON. It is an encoding, not encryption: anyone who can read the object can read the values. See the article on why Base64 is not encryption.
What does the newline warning mean?
A single-line value ends with a line feed. The usual cause is encoding it with echo, which appends a newline, instead of echo -n or printf. The application then receives a password with an invisible extra character and authentication fails in a way that is hard to see.
What is the difference between data and stringData?
data holds base64 values. stringData holds plain text that the API server encodes for you when the object is created; it is write-only, so kubectl get never shows it. If a key is in both, stringData wins. The first output option writes the decoded values as stringData, so the manifest can be applied again as it is.
Why is a value shown as base64 and not as text?
It is not valid UTF-8 text, for example a binary key or a compressed blob. Showing it as text would corrupt it, so it stays in data as base64 and a warning names the key.
Last updated