StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 7 · Secrets

Typed Secrets

easySecret TypesRegistry & TLS Credentials—No data yet

Problem statement

The pull from registry.internal.example:5000 fails and the TLS listener never comes up, in namespace vault-registry. Both credentials are there - shoved into ordinary opaque Secrets, under key names somebody made up. The kubelet and the ingress machinery do not read Secrets that way: they look for a declared type, and inside it, for exact keys.

About this exercise

Every Secret carries a type. Opaque is the default and it means "arbitrary key-value bytes, nobody but your own app knows what is in here". The other types are contracts: declaring one tells Kubernetes what the Secret is for, and the material is then validated - the required keys must be present and, for some types, the contents must be what they claim to be.

Two types matter here:

  • kubernetes.io/dockerconfigjson - registry credentials. It holds a single key, .dockerconfigjson, whose value is a Docker config document: an auths object keyed by registry address, each entry carrying the username, the password, and the combined user:password credential the registry client sends. A pod names such a Secret in its image pull secrets, and the kubelet uses it when pulling that pod's images.
  • kubernetes.io/tls - a serving certificate. It requires exactly two keys, tls.crt and tls.key, and they must be a real pair: material that does not check out is refused outright rather than stored and failing later at request time. That refusal is the point of the type - an opaque blob would have been accepted happily.

The commands that create typed Secrets build the required shape for you from ordinary inputs - a registry address and a login, or a certificate and a key file. kubectl create secret --help lists the subcommands.

How this project is graded

The grader reads each Secret's type and parses its contents the way the machinery would: it decodes the registry document and looks up the entry for the server, and it checks the certificate and key really belong together. It re-runs the rejected creation itself against the files in certs/ to confirm that material still fails validation, and it reads your pod's spec for the pull reference.

What you will build

Everything lives in namespace vault-registry. Three files are on disk in certs/: edge.crt and edge.key are the current pair, and legacy.key is a leftover from an earlier rotation.

1. Secret registry-pull of type kubernetes.io/dockerconfigjson:

server     registry.internal.example:5000
username   deploy-bot
password   not-a-real-registry-password

2. Secret edge-tls of type kubernetes.io/tls, holding the certificate and key from certs/edge.crt and certs/edge.key under the two key names the type requires.

3. answers/rejection.txt - what comes back when you try to build that same typed Secret out of certs/edge.crt and certs/legacy.key. Keep the message; the Secret must not end up created from that pair.

4. Pod image-puller - container puller, image busybox:1.36, staying alive, listing registry-pull as its image pull secret. busybox:1.36 comes from a public source, so this pod really does run: the pull reference is declared for the private registry and the grader reads it from the pod's spec, while the image itself pulls without it.

Step 1 - credentials the kubelet recognises

Build the registry Secret with its declared type, so the document inside it carries the server, the login and the credential the registry expects.

registry_secret_is_typed_dockerconfigjson and registry_credentials_parse_into_the_auth_entry should pass

Step 2 - a certificate the type will accept

Try the typed TLS Secret with the leftover key first and keep what comes back, then build it from the pair that belongs together.

type_validation_rejects_the_malformed_pair, tls_secret_uses_the_types_required_keys and tls_certificate_and_key_are_a_matching_pair should pass

Step 3 - wiring the pull

Create the pod that names the registry Secret as the credential to pull with.

pull_secret_named_in_the_pod_spec_and_pod_runs should pass

When every test passes

You have:

  • Registry credentials in the shape the kubelet actually reads, keyed by the registry they belong to
  • A certificate and key stored under the names the TLS machinery looks for, proven to be a pair
  • Evidence of what a declared type refuses to store, instead of a blob that fails at request time
  • A pod that carries its pull credential in its own spec

You do not have yet:

  • A namespace that is clean. Migrating every credential at once - encoding, delivery and types together - and proving no plaintext is left is the next exercise.

Verify

Click Test after every step.

More in Secrets

See the module
Secret Objects & EncodingMove credentials out of a ConfigMap into Secrets built from literals, files and the plaintext write path, and read them back in both stored and decoded form.—No data yeteasyConsuming SecretsDeliver a Secret into a container as an environment variable and as mounted files with a private-key mode, and prove what a missing reference does versus an optional one.—No data yeteasyCredential Hygiene OverhaulMigrate every credential of an inherited namespace into Secrets, deliver them by env and mounted files, mint the typed registry and TLS Secrets, and prove with a scan that no plaintext is left.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.