Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Why workload identity replaces shared secrets

After this lesson: I can explain why an attested, short-lived identity is safer than a shared secret.

60 min lesson3 commandsWorkload identity lab: SPIFFE and SPIRE on k3s, with mTLS between services, on a private Ubuntu VM

A password in six places

Workload identity means a running program proves what it is with an identity it is given, not a secret somebody typed. Most services still call each other with a shared secret: a password or an API key in a file.

One database password copied to six servers must be changed in six places. So it is changed rarely, and anybody who copies it once can use it for years.

By the end of this lesson

Note

I can explain why an attested, short-lived identity is safer than a shared secret.

Key words

WordWhat it meansExample
Workloada running program, such as a service or a pod
Shared secreta password or key that both sides keep
Attestationchecking what a workload really is
SPIFFEa standard for naming and proving workloads
SPIREsoftware that hands out SPIFFE identities
SVIDthe document that carries an identityan X.509 certificate

The cells students fill in are left blank in this preview.

What goes wrong with shared secrets

A shared secret proves only that the caller knows the secret. It says nothing about which program is calling.

Secrets leak through logs, backups, images and old laptops. They live a long time, because rotating one means changing every copy at once. And when one leaks, you rarely know who used it.

Worked example: a secret against an identity

QuestionShared secretSPIFFE identity
Who makes it?A person, onceSPIRE, for each running workload
How long does it last?Months or yearsAn hour in this lab
How many copies?One per server that uses itNone: each workload gets its own
What does it prove?The caller knows the secretWhat the caller is, checked by an agent
A stolen one is useful forUntil somebody noticesUntil it expires

The cells students fill in are left blank in this preview.

An identity is earned by attestation

SPIRE has two parts. The server signs identities. An agent runs on every machine and talks to the workloads there.

When a program asks the agent for an identity, the agent checks it first: which Unix user runs it, which Kubernetes pod it is in. This check is attestation. Only a workload that matches a registration gets anything.

Ask how SPIRE stands

Command
spirelab status

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

List the agents the server trusts

Command
sudo spire-server agent list

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the two Runs printed

The status says the server and the agent are healthy, and names the trust domain lab.test. The agent list shows one agent, spiffe://lab.test/spire/agent/x509pop/spire-lab, with Can re-attest : true.

Its expiry time and serial number differ in every copy of the lab, because the agent's own identity is made when it starts.

No registration, no identity

The user basket stands for a workload on this machine. Nobody has registered it yet. The next Run asks the agent for its identity as that user.

It prints rpc error: code = PermissionDenied desc = no identity issued. The agent attested the process, found no entry for it, and gave it nothing.

Ask for an identity as basket

Command
sudo -u basket spire-agent api fetch x509

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think workload identity just stores the secret somewhere safer. It does not store a secret at all. Each workload proves what it is when it asks, and receives a credential that expires within the hour.

About this lab and its source: Workload identity lab: SPIFFE and SPIRE on k3s, with mTLS between services, on a private Ubuntu VM

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.