Problem statement
The database password, the API token and a keystore passphrase all live in a ConfigMap called secrets-for-real in namespace vault-keys - printed in full by every describe, and committed to git along with it. Move them into Secret objects, and learn what a Secret actually does with a value you hand it.
About this exercise
A Secret is a namespaced object shaped almost exactly like a ConfigMap, with one difference that runs all the way through it: every value is held base64-encoded under data. That encoding is not encryption - it is a transport rule, so that arbitrary bytes (a binary keystore, a certificate, a password ending in a newline) survive a trip through YAML and JSON intact.
Two write paths lead to the same place:
- data takes values already base64-encoded. This is the form the object is stored in and the form you read back.
- stringData takes plaintext. It is a write-only convenience: the API server encodes each value into data and the stringData field is gone from the object you read back.
The command that creates a Secret encodes for you, whether the value comes from a literal on the command line or from a file. The file path matters for byte-exactness: a file's contents go in as they are, trailing newline and all, while a literal is exactly the characters you typed.
Reading is the mirror image. kubectl describe deliberately refuses to print values - it shows each key and a byte count - so a description is safe to paste into a ticket. Getting the object with an output format shows data, and what you get there is the encoded form; turning it back into the password is a decode step you do yourself.
kubectl create secret generic --help and kubectl explain secret are the reference.
How this project is graded
The grader reads the live objects: it decodes what you stored and compares it against the expected bytes, checks the seeded ConfigMap is gone, and compares your saved answers character for character. The seeded objects are rebuilt before each run, so a Secret you never created cannot pass by accident.
What you will build
Everything lives in namespace vault-keys.
1. Secret app-credentials with three keys:
db-password not-a-real-password api-token not-a-real-token-4f21 legacy-keystore.txt the contents of credentials/legacy-keystore.txt, byte for byte
2. Secret session-signing with one key, written through the plaintext write path:
signing-key not-a-real-signing-key
3. The seeded Secret mail-relay-credentials must end up holding exactly one key:
smtp-password not-a-real-smtp-password (it currently holds a stale value) smtp-user-legacy must no longer be a key of this Secret
4. Three answers in answers/:
decoded.txt the db-password value of app-credentials as plaintext, and nothing else encoded.txt the api-token value of app-credentials exactly as it is stored, and nothing else describe.txt a rendered description of app-credentials
5. The ConfigMap secrets-for-real must no longer exist in vault-keys.
Step 1 - out of the ConfigMap, into a Secret
Create app-credentials from the two literal values and from the file on disk. The file entry has to come back byte for byte, so how you feed it in decides whether it does.
literal_values_are_stored_base64_encoded_at_rest and file_sourced_entry_round_trips_byte_exact should pass
Step 2 - the plaintext write path
Create session-signing by handing the API server plaintext instead of encoding it yourself. What is stored is the encoded form; the field you wrote through is not part of the stored object.
plaintext_write_path_is_stored_as_encoded_data should pass
Step 3 - reading a Secret back
Save the decoded password, the stored (encoded) token, and a description. The description must show what a description shows - if the password is visible in describe.txt, that file did not come from a description.
decoded_value_saved_exactly, stored_encoded_form_saved_exactly and describe_hides_the_values should pass
Step 4 - rotate and retire
Give mail-relay-credentials its current password and drop the key that is no longer used, then remove the ConfigMap that was standing in for a Secret.
seeded_secret_rotated_and_stale_key_removed and plaintext_configmap_is_retired should pass
When every test passes
You have:
- Credentials held in objects built for them instead of in a ConfigMap anyone can read
- Values that survive intact whether they came from a literal or from a file
- The difference between what you write, what is stored, and what a description will show you
- A Secret rotated in place, and the plaintext original retired
You do not have yet:
- Any of this reaching a workload. Delivering a Secret into a container as an environment variable or as files is the next exercise.
Verify
Click Test after every step.
