Skip to content
LF Cert Trainer

Lesson 72 · Section 7: Security

Lesson 72: TLS basics: keys, certificates and certificate authorities

How TLS protects a connection: symmetric and asymmetric encryption, key pairs, what a certificate proves, how a certificate authority signs one, and the openssl commands that create, sign and check them. · 20 min read · 4 min video

1/11TLS basics
0:00 / 3:46

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why TLS exists

Every request in a cluster crosses a network: kubectl to the API server, the API server to etcd, the kubelet to the API server. A network is a shared place. Anyone who can see the packets can read a password or a token sent in clear text, and anyone who can sit in the path can change a request or answer in the server's place.

TLS (Transport Layer Security) is the protocol that closes those three holes. It is what the "S" in HTTPS stands on, and its older versions were called SSL, which is why the tool is still named openssl. A TLS connection promises:

PromiseMeaningProvided by
ConfidentialityNobody on the path can read the trafficEncryption with a session key
IntegrityNobody can change the traffic unnoticedA check value on every record
AuthenticationThe server is the one you asked for (and, optionally, so is the client)Certificates

Kubernetes does not invent anything here. The cluster's security is ordinary TLS used very thoroughly, so every idea in this lesson returns in the next four: which certificates a cluster has, how to create them, how to read them and how to have the cluster sign new ones.

What TLS is built from

There are only four building blocks. Each one exists because the one before it leaves a problem open.

1. Symmetric encryption: one shared key

With symmetric encryption the same key encrypts and decrypts. It is fast enough to protect gigabytes of traffic, and it is what actually carries your data in every TLS connection (AES and ChaCha20 are the usual algorithms).

The open problem: both sides need the key. If the client sends the key over the network, an eavesdropper has it too, and everything encrypted with it is readable.

2. Asymmetric encryption: a key pair

Asymmetric encryption uses two keys that are generated together:

  • The private key stays with its owner and is never sent anywhere.
  • The public key is derived from the private key and can be given to anyone.
One key pair, two jobsencryptdecryptsignverifyAnyonehas the public keyEncrypted dataunreadable in transitKey ownerprivate key opens itKey ownerprivate key signsSignaturetravels with the dataAnyonepublic key checks it
One key pair, two jobs. The public key can be handed to anyone. What it locks, only the private key opens; what the private key signs, anyone with the public key can check.

Parts:

  • Anyone (has the public key)
  • Encrypted data (unreadable in transit)
  • Key owner (private key opens it)
  • Key owner (private key signs)
  • Signature (travels with the data)
  • Anyone (public key checks it)

Connections:

  • Anyone to Encrypted data: encrypt
  • Encrypted data to Key owner: decrypt
  • Key owner to Signature: sign
  • Signature to Anyone: verify

The pair does two different jobs, and TLS uses both:

JobWho uses which keyWhat it gives
EncryptAnyone encrypts with the public key; only the private key decryptsSecrecy towards the key owner
SignThe owner signs with the private key; anyone verifies with the public keyProof that the owner produced the data, and that it has not changed

You already use a key pair if you log in to servers with SSH. ssh-keygen writes id_ed25519 (private) and id_ed25519.pub (public). You copy the public key into ~/.ssh/authorized_keys on each server, and at login your client signs a challenge with the private key. The server checks the signature with the public key it has on file. No password crosses the network, and a stolen authorized_keys file is useless to an attacker.

Asymmetric operations are slow, so TLS never encrypts the traffic with them. It uses them for a few seconds at the start, to prove identity and to set up the symmetric key.

The open problem: how do you know that a public key belongs to the server you meant to reach? An attacker in the path can send you their own public key. You would then set up perfectly encrypted traffic with the attacker.

3. Certificates: a public key with a name on it

A certificate is a small public document in a standard format called X.509. It says "this public key belongs to this name", and it carries a signature from whoever vouches for that statement.

FieldExampleWhat to read from it
SubjectCN = web.example.comWho the certificate was issued to
Subject Alternative Name (SAN)DNS:web.example.com, IP Address:10.0.0.5Every hostname and IP the certificate is valid for
Public keyPublic-Key: (2048 bit)The owner's public key
IssuerCN = practice-caWho signed it
ValidityNot Before, Not AfterThe dates between which it may be used
Signaturesha256WithRSAEncryptionThe issuer's signature over all of the above

A certificate contains no secret. A server sends it to every client that connects. What makes it usable only by its owner is the matching private key, which the server keeps on its own disk and uses during the handshake to prove that the certificate is really its own.

The open problem: anyone can write a certificate that says "I am web.example.com" and sign it themselves. Such a self-signed certificate proves nothing to a stranger.

4. Certificate authorities: someone both sides trust

A certificate authority (CA) is the party whose signature clients accept. A CA is nothing more than a key pair and a certificate of its own. Its whole value is that clients have its certificate in advance, in a trust store:

  • Operating systems and browsers ship with around a hundred public CA certificates (on Linux, under /etc/ssl/certs). That is why https://kubernetes.io works without any setup.
  • An organisation can run its own private CA and hand its certificate to its own machines. This costs nothing and works for names that no public CA would sign, such as kube-apiserver or 10.96.0.1. A Kubernetes cluster does exactly this: it has its own CA, and every component is given the CA certificate.

A CA's certificate is called a root certificate. Nobody stands above the CA, so a root certificate is signed with the CA's own key: its subject and issuer are the same. A root certificate is therefore always self-signed, and it is trusted only because it was put into the trust store by hand.

How it works

Getting a certificate signed

How a certificate is issuedcreatessentchecks, then signsinstallpresentsServer adminmakes a key pairSigning requestpublic key + nameThe CAsigns with its keyCertificatesigned by the CAServercert + private keyClienthas the CA cert
How a certificate is issued. The private key never leaves the server. Only the request travels to the CA, and the CA's signature is what clients later check.

Parts:

  • Server admin (makes a key pair)
  • Signing request (public key + name)
  • The CA (signs with its key)
  • Certificate (signed by the CA)
  • Server (cert + private key)
  • Client (has the CA cert)

Connections:

  • Server admin to Signing request: creates
  • Signing request to The CA: sent
  • The CA to Certificate: checks, then signs
  • Certificate to Server: install
  • Server to Client: presents
  1. The server's admin generates a key pair. The private key stays on the server.
  2. The admin creates a certificate signing request (CSR): the public key plus the name the certificate should carry. The CSR is signed with the server's private key, which proves that the requester holds that key.
  3. The CA checks that the requester may use that name. A public CA checks that you control the domain. For a private CA, the check is whatever its owner decides.
  4. The CA signs with its private key and returns the certificate. Signing means: hash the certificate's content, then sign that hash with the CA's private key, so anyone holding the CA's public key can check it.
  5. The admin installs the certificate next to the private key and configures the server to use both.

The private key never travelled. Only the CSR and the certificate did, and both are public.

Opening a connection: the handshake

What happens when a TLS connection openssendsreceivedsigned by a CA I trust?yesencryptsServerprivate key + certCertificatename + public keyClientbrowser, curl, kubectlTrusted CA listCA certificatesSession keyagreed, never sentEncrypted trafficsymmetric and fast
What happens when a TLS connection opens. The certificate proves who the server is. A fresh session key, agreed by both sides and never sent, then encrypts the traffic.

Parts:

  • Server (private key + cert)
  • Certificate (name + public key)
  • Client (browser, curl, kubectl)
  • Trusted CA list (CA certificates)
  • Session key (agreed, never sent)
  • Encrypted traffic (symmetric and fast)

Connections:

  • Server to Certificate: sends
  • Certificate to Client: received
  • Client to Trusted CA list: signed by a CA I trust?
  • Trusted CA list to Session key: yes
  • Session key to Encrypted traffic: encrypts

When a client connects, the two sides run a short exchange called the handshake before any data flows:

  1. The client says hello and lists the TLS versions and algorithms it supports.
  2. The server answers with its certificate, and signs part of the handshake with its private key.
  3. The client verifies the certificate. All four checks must pass:
    • The signature was made by a CA in the client's trust store.
    • Today lies between Not Before and Not After.
    • The name the client connected to appears in the certificate's SANs.
    • The server's handshake signature matches the public key in the certificate, so the server really holds the private key.
  4. Both sides derive the same session key, and symmetric encryption takes over.
Under the hood · How do both sides get the session key without sending it?

There are two answers, and courses often teach only the older one.

  • The older way (RSA key exchange). The client invents the session key, encrypts it with the server's public key from the certificate, and sends it. Only the server's private key can open it. This is easy to picture, but it has a flaw: someone who records the traffic today and steals the server's private key next year can decrypt everything they recorded.
  • The current way (ephemeral Diffie-Hellman). Each side creates a throwaway key pair for this one connection and sends only the public half. From its own private half and the other side's public half, each side computes the same secret. The secret itself is never sent, and the throwaway keys are deleted afterwards, so recorded traffic stays safe even if the server's private key leaks later. This property is called forward secrecy.

TLS 1.3 allows only the second way. The server's certificate key is then used for one thing only: signing the handshake to prove identity. Kubernetes components are written in Go, whose TLS library defaults to TLS 1.2 as the minimum and prefers 1.3, so in a current cluster you can expect the modern handshake.

Chains of certificates

Public CAs keep their root key offline and sign with intermediate CAs instead. A server then sends a chain: its own certificate (the leaf) and the intermediate that signed it. The client follows the chain from the leaf upward until it reaches a certificate in its trust store. If a link is missing, verification fails even though every certificate is valid by itself.

A kubeadm cluster keeps this simple. Its CAs sign leaf certificates directly, so chains are one step long.

Client certificates: TLS in both directions

In ordinary HTTPS only the server shows a certificate; the user proves who they are later, with a password. TLS can also ask the client for a certificate. The client then proves its identity in the same way the server did, and the server reads the client's name from the certificate's subject. This is mutual TLS (mTLS).

Browsers rarely use it. Kubernetes uses it everywhere: the admin's kubectl, the kubelet, the scheduler and the controller manager all present client certificates to the API server, and the API server takes the user name from the certificate's CN and the groups from its O field. Which key a certificate may be used for is written into it: extendedKeyUsage says serverAuth, clientAuth or both.

Types and file names

Three kinds of certificate

KindHeld byProvesSigned by
Root (CA) certificateThe CA; copies go to every client's trust store"Signatures made by this CA can be trusted"Itself
Server certificateA server, with its private key"I am the server with these names"A CA
Client certificateA user or a component, with its private key"I am this user, in these groups"A CA

Reading file names

File extensions are a convention and nothing enforces them. Most files are in PEM format: Base64 text between a BEGIN and an END line. The BEGIN line is the reliable way to tell what a file holds.

Typical namesContentFirst lineSecret?
server.crt, server.pem, ca.crtCertificate-----BEGIN CERTIFICATE-----No
server.key, server-key.pem, ca.keyPrivate key-----BEGIN PRIVATE KEY----- (or RSA PRIVATE KEY, EC PRIVATE KEY)Yes
server.pubPublic key alone-----BEGIN PUBLIC KEY-----No
server.csrSigning request-----BEGIN CERTIFICATE REQUEST-----No

The rule of thumb: a file with key in its name is private. Everything else can be shown to the world.

Using it

All examples use openssl, which is installed on the exam nodes. They run on any Linux machine, with no cluster needed, so try them now: the next lessons use the same commands on real cluster files.

Example · See both jobs of a key pair

Generate a private key and extract its public key:

openssl genrsa -out web.key 2048
openssl rsa -in web.key -pubout -out web.pub

Encrypt with the public key, decrypt with the private key:

echo hello > msg.txt
openssl pkeyutl -encrypt -pubin -inkey web.pub -in msg.txt -out msg.enc
openssl pkeyutl -decrypt -inkey web.key -in msg.enc         # prints: hello

Sign with the private key, verify with the public key:

openssl dgst -sha256 -sign web.key -out msg.sig msg.txt
openssl dgst -sha256 -verify web.pub -signature msg.sig msg.txt   # prints: Verified OK

Change one character in msg.txt and verify again: the answer becomes Verification failure. That is the integrity promise at work.

Example · Create your own CA and sign a server certificate

First the CA: a private key and a self-signed root certificate.

openssl genrsa -out ca.key 2048
openssl req -x509 -new -noenc -key ca.key -subj "/CN=practice-ca" -days 365 -out ca.crt

-x509 makes req write a self-signed certificate instead of a request. -noenc leaves the key without a passphrase (OpenSSL before 3.0 spells it -nodes).

Then the server: a private key and a signing request. The name goes into the subject and, more importantly, into the SAN.

openssl genrsa -out web.key 2048
openssl req -new -key web.key -subj "/CN=web.example.com" \
  -addext "subjectAltName=DNS:web.example.com" -out web.csr

Now act as the CA and sign the request:

openssl x509 -req -in web.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -copy_extensions copy -days 90 -out web.crt
Certificate request self-signature ok
subject=CN = web.example.com

-copy_extensions copy carries the SAN from the request into the certificate. Without it the SAN is silently dropped, which is the most common reason a freshly signed certificate is rejected. On OpenSSL older than 3.0, pass the extensions in a file with -extfile instead, as the Kubernetes documentation does.

Example · Check a certificate the way a client would

Verify the signature against a CA certificate:

openssl verify -CAfile ca.crt web.crt        # web.crt: OK
openssl verify web.crt                       # without the CA: fails
CN = web.example.com
error 20 at 0 depth lookup: unable to get local issuer certificate
error web.crt: verification failed

The second command fails because practice-ca is not in the system trust store. Nothing is wrong with the certificate: the client simply does not know its CA. Read the fields that matter:

openssl x509 -in web.crt -noout -subject -issuer -dates -ext subjectAltName
subject=CN = web.example.com
issuer=CN = practice-ca
notBefore=Nov 30 11:34:24 2026 GMT
notAfter=Feb 28 11:34:24 2027 GMT
X509v3 Subject Alternative Name:
    DNS:web.example.com

For the root certificate, subject and issuer are the same, which is how you recognise a self-signed certificate:

openssl x509 -in ca.crt -noout -subject -issuer
subject=CN = practice-ca
issuer=CN = practice-ca

Example · Watch the three client checks fail and pass

Serve the certificate on a local port, then connect with curl:

openssl s_server -accept 8443 -cert web.crt -key web.key -www &
curl --resolve web.example.com:8443:127.0.0.1 https://web.example.com:8443/
curl: (60) SSL certificate problem: unable to get local issuer certificate

The CA is unknown to curl. Give it the CA certificate and the request succeeds:

curl --cacert ca.crt --resolve web.example.com:8443:127.0.0.1 https://web.example.com:8443/

Now use a name that is not in the SAN. The CA is trusted, but the certificate is for someone else:

curl --cacert ca.crt --resolve other.example.com:8443:127.0.0.1 https://other.example.com:8443/
curl: (60) SSL: no alternative certificate subject name matches target host name 'other.example.com'

These are the two messages you will meet most often in a cluster, in kubectl's words: x509: certificate signed by unknown authority and x509: certificate is valid for ..., not .... Stop the server with kill %1.

Tricks

Common mistakes

  • Sharing or copying the wrong file. The certificate (.crt) is public; the key (.key) never leaves its machine. If you are asked to send "the certificate" to someone, the key is not part of it.
  • Thinking a self-signed certificate is not encrypted. The traffic is encrypted just as well. What is missing is proof of identity, because no trusted CA stands behind the name.
  • Turning verification off to make an error go away. curl -k and kubectl --insecure-skip-tls-verify remove the identity check, and with it the protection against an impostor. Fix the trust instead: give the client the right CA certificate.
  • Putting the name only in the CN. Current clients, including everything written in Go, ignore the CN for hostnames and read only the SAN list. A server certificate without SANs is rejected.
  • Losing the SAN while signing. openssl x509 -req does not copy extensions from the request unless you ask it to. Check the result with -ext subjectAltName before you install it.
  • Blaming the certificate when the clock is wrong. "Certificate is not yet valid" or "has expired" on a new certificate usually means the machine's date is off. Compare date -u with the Not Before line.
  • Verifying against the wrong CA. A certificate is valid only relative to the CA that signed it. A cluster has more than one CA, so unable to get local issuer certificate often just means you picked the wrong ca.crt.

Recap

  • TLS gives confidentiality, integrity and authentication. Symmetric encryption carries the data; key pairs and certificates set it up.
  • A key pair: the public key encrypts and verifies, the private key decrypts and signs. The private key is never shared.
  • A certificate ties a public key to a name (subject and SANs) and is signed by a CA. A CSR is how you ask for one.
  • A client accepts a certificate when it trusts the signing CA, the dates are valid and the name matches a SAN.
  • Files with key in the name are secret; .crt, .pem, .csr and .pub are not. head -n 1 tells you which is which.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Prepare a private key and a certificate signing request for the storefront, then read the facts out of a certificate somebody else issued.

    Build · Level 1 · warm-up · target 15 min

  • Decode the certificates stored in a namespace with openssl and find the one that expired, the one about to expire, the one from the wrong CA and the one whose key does not fit.

    Investigate · Level 2 · standard · target 20 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.