Problem statement
Namespace vault-audit was inherited with every credential in the wrong place at once: the database password is typed into the pod spec and repeated in an annotation, a ConfigMap called service-config carries the password and a keystore passphrase alongside its actual settings, the registry login and the serving certificate have no Secret at all, and one of the key files on disk does not belong to the certificate. Fix all of it, and prove it with a report.
About this exercise
This brings together the topic's three exercises:
- Storage - Secrets built from literals and from files, base64 at rest, plaintext when decoded (Secret Objects & Encoding)
- Delivery - a Secret reaching a container as an environment variable and as mounted files with a mode (Consuming Secrets)
- Types - registry and TLS Secrets in the shapes their machinery requires, and what type validation refuses (Typed Secrets)
One idea ties them together: a credential is only migrated when the plaintext copy is gone. Moving a password into a Secret and leaving it in the ConfigMap, the pod spec or an annotation buys nothing - all three are readable by anyone who can read the namespace, and all three end up in the manifests people commit. That is what the report is for: it names the surfaces where a credential must never appear and checks them.
How this project is graded
The grader decodes each Secret and compares the bytes, reads values from inside the running container, parses the typed Secrets the way the kubelet and the TLS machinery would, and re-runs the rejected creation itself against the files in certs/. It then runs your report twice: once against vault-audit, where it must find nothing, and once against a namespace the grader builds itself holding a copy of the original mess, where it must find every credential that was there. The namespace is re-seeded before each run, so anything you delete without replacing comes back.
What you will build
Everything lives in namespace vault-audit. On disk: credentials/keystore.txt, and certs/ holding edge.crt, edge.key and the leftover legacy.key.
1. Secret app-credentials
db-password not-a-real-password keystore.txt the contents of credentials/keystore.txt, byte for byte
2. Secret registry-pull of type kubernetes.io/dockerconfigjson
server registry.internal.example:5000 username deploy-bot password not-a-real-registry-password
3. Secret edge-tls of type kubernetes.io/tls, from certs/edge.crt and certs/edge.key, under the two key names that type requires. answers/rejection.txt holds what comes back when the same typed Secret is built from certs/edge.crt and certs/legacy.key - and that pair must not end up stored.
4. Pod storefront-api - container api, image busybox:1.36, staying alive, Running. The pod that is there now is the plaintext version; replace it:
env DB_PASSWORD the value of key db-password in Secret app-credentials /etc/tls/tls.crt the value of key tls.crt in Secret edge-tls /etc/tls/tls.key the value of key tls.key in Secret edge-tls, mode 0400 imagePullSecrets registry-pull
busybox:1.36 comes from a public source, so the pod runs whether or not the pull credential is usable; the reference is declared for the private registry and the grader reads it from the spec.
5. ConfigMap service-config keeps its settings and loses the credentials:
log-level info stays region eu-west-1 stays db-password must no longer be a key keystore-passphrase must no longer be a key
6. hygiene-report.sh - a scan that takes an optional namespace argument and defaults to vault-audit:
hygiene-report.sh [namespace]
The defined surfaces, in that namespace, are exactly these three:
data every value under a ConfigMap's data env every literal env value in a pod's spec (spec.containers[].env[].value) annotation every annotation value on a pod or on a ConfigMap
The credential values that must never appear on them:
not-a-real-password not-a-real-passphrase not-a-real-registry-password
The report prints one line for every object-and-surface pair where any of those values appears, and then a count of those lines:
PLAINTEXT <configmap|pod>/<name> <data|env|annotation> ... FINDINGS <n>
So a namespace still holding the original mess reports three findings - the ConfigMap's data, the pod's env, the pod's annotations - and a migrated namespace reports FINDINGS 0 with no PLAINTEXT lines at all.
The tests
- Encoding_literal_credential_stored_base64_at_rest - the migrated password decodes back to the original
- Encoding_file_sourced_entry_round_trips_byte_exact - the keystore file survives the trip unchanged
- Encoding_configmap_keeps_settings_and_drops_credentials - the ConfigMap is trimmed, not deleted
- Consumption_env_delivers_the_decoded_value_in_container - the process reads the password itself
- Consumption_mounted_tls_files_carry_content_and_mode - certificate and key on disk, key mode 0400
- Consumption_pull_secret_named_in_the_pod_spec - the pod carries its pull credential
- Typed_registry_secret_parses_as_dockerconfigjson - the registry document is the shape the kubelet reads
- Typed_tls_secret_pairs_certificate_and_key - the two halves belong together, under the required key names
- Typed_malformed_material_is_rejected - the leftover key still fails validation, and you kept what it said
- Composition_hygiene_report_finds_no_plaintext - the migrated namespace scans clean
- Composition_report_detects_the_seeded_credentials - the same scan, run against a copy of the original mess, finds all three
When every test passes
You have:
- Every credential of a namespace held in a Secret built the way its consumer needs it
- One workload reading its password from the environment and its key material from disk, with a private key mode an audit will accept
- Registry and TLS credentials that the machinery recognises, and evidence of what it refuses
- A scan that says, in one number, whether a namespace is leaking - and finds the leaks when there are any
- The next topic unlocked
Verify
Click Test.
