Open almost any ~/.kube/config and you will find a line like this:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJpVENDQVMr... The same LS0tLS1CRUdJTi opening turns up in client-certificate-data, in client-key-data, and in the tls.crt field of every kubernetes.io/tls Secret. Once you know what those 14 characters mean, you can tell what a blob holds before you decode it. You can also stop decoding it the wrong way.
Two layers of Base64, not one
The kubeconfig v1 reference describes certificate-authority-data as a []byte field that "contains PEM-encoded certificate authority certificates". Kubernetes tooling is written in Go, and Go's encoding/json writes a []byte as a Base64 string. The same rule shows up in the YAML.
So the value is Base64 of a PEM file. A PEM file is also Base64: a -----BEGIN CERTIFICATE----- line, then the DER bytes of the certificate in Base64 wrapped at 64 characters (RFC 7468 says generators MUST wrap at exactly 64), then an END line.
kubeconfig value --base64 decode--> PEM text --strip BEGIN/END, base64 decode--> DER bytes LS0tLS1CRUdJTi is simply what -----BEGIN looks like after the first encoding: LS0t is --- and LS1C is --B. Because Base64 maps every 3 input bytes to 4 characters, the start of the header always encodes the same way:
| Decodes to | Stable Base64 prefix |
|---|---|
-----BEGIN CERTIFICATE----- | LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t |
-----BEGIN PRIVATE KEY----- | LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0t |
-----BEGIN RSA PRIVATE KEY----- | LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0t |
-----BEGIN EC PRIVATE KEY----- | LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0t |
-----BEGIN PUBLIC KEY----- | LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0t |
If a value starts with LS0tLS1CRUdJTiBDRVJU, it is a certificate. If you see UFJJVkFURSBLRVk near the start, it is a private key, so treat it as a password.
Worked example (illustrative, throwaway CA)
To keep real cluster data out of this post, here is a brand-new self-signed CA made only for this example:
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \ -keyout demo-ca.key -out demo-ca.crt -days 3650 -subj "/CN=demo-cluster-ca" base64 -w0 demo-ca.crt # this string is what goes into certificate-authority-data The numbers from that run:
-
demo-ca.crt(the PEM) is 595 bytes. - Base64 of the PEM is 796 characters (595 bytes → 199 groups of 3 → 796), starting
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJpVENDQVMr. - Layer 1: decoding those 796 characters gives back the PEM text exactly, starting
-----BEGIN CERTIFICATE-----followed by a newline andMIIBiTCCAS+g.... - Layer 2: decoding only the body lines (no BEGIN/END lines) gives 397 bytes of DER. As hex they start
30 82 01 89.30is an ASN.1 SEQUENCE,82means "length in the next 2 bytes", and0x0189= 393. That makes 4 header bytes + 393 = 397, so the length matches.
That 30 82 opening is also why so many certificate bodies start with MII: the bytes 30 82 01 encode to MIIB.
The mistake that wrecks layer 2: pasting the whole PEM block
It is tempting to paste the PEM, header lines included, straight into a Base64 decoder. Don't. The dashes are the problem: many decoders also accept URL-safe Base64, where - is a legal character standing in for +. So -----BEGIN CERTIFICATE----- doesn't get skipped. It gets decoded as +++++BEGINCERTIFICATE+++++.
We tested this against the browser decoder linked below (its own JavaScript, run in Node) and against Python:
- The body ends in
=(our 397-byte example ends inTw==): the padding lands in the middle of the cleaned string, so the decoder shows an error instead of output. - The body has no padding (a second throwaway cert with a 396-byte DER): no error at all. You get 433 bytes starting
FB EF BEinstead of 396 bytes starting30 82. That is silently wrong output. - Python's
base64.b64decode(pem)with default settings throws away characters that aren't Base64, including the dashes, but keeps the letters ofBEGIN CERTIFICATE. It returns 420 bytes instead of 397, with no exception. Usevalidate=Trueand you getbinascii.Error: Only base64 data is allowed, which is the behaviour you want.
The fix is easy. Remove the BEGIN/END lines before decoding layer 2, or let a PEM-aware tool like openssl handle that layer for you:
import base64 pem = open("demo-ca.crt").read() body = "".join(l for l in pem.splitlines() if not l.startswith("-----")) der = base64.b64decode(body, validate=True) print(len(der), der[:4].hex(" ")) # 397 30 82 01 89 Reading the CA from a real kubeconfig in the terminal
Plain kubectl config view will not show the data. It prints certificate-authority-data: DATA+OMITTED, and a jsonpath query for that field returns the literal text DATA+OMITTED. The kubectl config view reference documents --raw as "Display raw byte data and sensitive data". Add --minify so that clusters[0] is the cluster of your current context:
kubectl config view --minify --raw \ -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' \ | base64 -d \ | openssl x509 -noout -subject -issuer -enddate For the demo kubeconfig this printed subject=CN=demo-cluster-ca, the same issuer, and notAfter=Dec 3 10:41:38 2036 GMT (tested with kubectl v1.37.3 and OpenSSL 3.5.9). Two useful extras:
- Expiring soon? Swap the last command for
openssl x509 -noout -checkend 2592000. It prints "Certificate will not expire" and exits 0 if the cert is still valid 30 days from now. - More than one CA? The field can hold a bundle, and
openssl x509only reads the first certificate. Count them withgrep -c "BEGIN CERTIFICATE"on the decoded text, or list every one withopenssl storeutl -noout -certs file.pem.
If base64 -d isn't available on your system, openssl base64 -d -A decodes a single long line the same way.
A word on client-key-data
client-key-data uses the same two-layer format, but it holds a private key. With --raw, anyone who copies it can act as you against the cluster. Decode it in your own terminal and keep it out of chat windows, tickets and websites. The decoder below runs in the browser, but a cluster credential still doesn't belong in a paste box. Use the browser tool for CA certificates and public data.
Decoding a certificate field in the browser
- Open the Base64 Decoder and keep Decode Base64 selected.
- Paste the
certificate-authority-datavalue with Character Set: UTF-8 and click Convert (or tick Live Conversion). You should see the PEM text. - For layer 2, paste only the lines between BEGIN and END, switch Character Set to Hexadecimal, and check that the output starts
30 82.
Disclosure: this tool is from Mind vs Drive, the team behind this account.
Quick checklist
-
LS0tLS1CRUdJTi= Base64 of-----BEGIN. Two layers follow. - Layer 1 gives PEM text. Layer 2 (body lines only) gives DER starting
30 82. - Never decode layer 2 with the BEGIN/END lines still attached.
-
kubectl config viewhides the data. Use--minify --raw. - Anything containing
PRIVATE KEYstays in your terminal.
Sources (read 6 Dec 2026): kubeconfig (v1) reference, kubectl config view reference, Go encoding/json, RFC 7468. All keys and certificates above were generated for this post and thrown away afterwards.
The Mind vs Drive team

