# Transcript for 03-config-and-storage/02-secrets.md, lab steps 0 to 9. # Tier A: a kind cluster that the lab owns. Kubernetes v1.37.0 server, kubectl # v1.37.2, gitleaks v8.30.1 (the CI pin). # Recorded by running examples/security-lab/labs/03-02.sh from full-guide/. # The section at the end, headed "the broker login", is two later runs in # another namespace. They cover the broker keys that db-credentials gained # after steps 0 to 9 were recorded, and the script above does not run them. # The lab used its own namespace, p03-02-secrets. The chapter names the # bookstore namespace and applies the same files. Lines that name the lab # namespace are kept as captured. # Step 2 applied the 03.01 Secret, db-credentials, with its demo literal. It # then applied a second Secret, db-credentials-generated, whose value was # generated when the script started and written into the manifest by sed. The # script never prints that value: where a check needs it, the transcript shows # a count, a length, a key name or a checksum. ## step 0: versions and a clean start $ kubectl version Client Version: v1.37.2 Server Version: v1.37.0 $ kubectl get namespace p03-02-secrets Error from server (NotFound): namespaces "p03-02-secrets" not found ## step 1: a namespace that enforces restricted, and three ServiceAccounts $ kubectl create namespace p03-02-secrets namespace/p03-02-secrets created $ kubectl label namespace p03-02-secrets pod-security.kubernetes.io/enforce=restricted pod-security.kubernetes.io/audit=restricted pod-security.kubernetes.io/warn=restricted namespace/p03-02-secrets labeled $ kubectl apply -f - # three ServiceAccounts in p03-02-secrets; none mounts a token serviceaccount/secret-reader created serviceaccount/secret-lister created serviceaccount/pod-creator created ## step 2: the 03.01 Secret, then a second Secret with a value generated now $ sed -e 's/namespace: bookstore/namespace: p03-02-secrets/' examples/bookstore/raw-manifests/16-db-credentials.yaml | kubectl apply -f - # 03.01's Secret, demo literal secret/db-credentials created $ kubectl get secret db-credentials -n p03-02-secrets -o name secret/db-credentials $ PW=$(openssl rand -hex 16) # generated now, never printed $ sed -e 's/devpassword/$PW/' -e 's/name: db-credentials/name: db-credentials-generated/' -e 's/namespace: bookstore/namespace: p03-02-secrets/' examples/bookstore/raw-manifests/16-db-credentials.yaml | kubectl apply -f - secret/db-credentials-generated created $ kubectl get secret db-credentials-generated -n p03-02-secrets -o jsonpath='{.data.POSTGRES_DB}'; echo Ym9va3N0b3Jl $ kubectl get secret db-credentials-generated -n p03-02-secrets -o jsonpath='{.data.POSTGRES_DB}' | base64 -d; echo bookstore $ kubectl get secret db-credentials-generated -n p03-02-secrets -o jsonpath='{.data.POSTGRES_PASSWORD}' | base64 -d | wc -c | tr -d ' ' 32 $ decoded POSTGRES_PASSWORD equals $PW (compared, not printed) yes $ kubectl get secret db-credentials-generated -n p03-02-secrets -o jsonpath='{.metadata.annotations.kubectl\.kubernetes\.io/last-applied-configuration}' | grep -c stringData 1 $ kubectl get secret db-credentials-generated -n p03-02-secrets -o jsonpath='{...last-applied-configuration}' | grep -c "$PW" # the generated value, counted not printed 1 $ grep -n 'password=$(POSTGRES_PASSWORD)' examples/bookstore/raw-manifests/10-catalog-deploy.yaml examples/bookstore/raw-manifests/14-orders-deploy.yaml examples/bookstore/raw-manifests/10-catalog-deploy.yaml:164: value: "host=postgres.bookstore.svc.cluster.local port=5432 user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) sslmode=disable" examples/bookstore/raw-manifests/14-orders-deploy.yaml:109: value: "host=postgres.bookstore.svc.cluster.local port=5432 user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) sslmode=disable" ## step 3: RBAC on one named Secret: get is named, list and create are not $ kubectl apply -f - # Role db-credentials-reader and its RoleBinding in p03-02-secrets role.rbac.authorization.k8s.io/db-credentials-reader created rolebinding.rbac.authorization.k8s.io/db-credentials-reader created $ kubectl auth can-i get secret/db-credentials-generated -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader yes $ kubectl auth can-i get secret/other-creds -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader no $ kubectl auth can-i get secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader no $ kubectl auth can-i list secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader no $ kubectl auth can-i create secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader no $ kubectl get secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader -o name Error from server (Forbidden): secrets is forbidden: User "system:serviceaccount:p03-02-secrets:secret-reader" cannot list resource "secrets" in API group "" in the namespace "p03-02-secrets" $ kubectl get secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-reader --field-selector metadata.name=db-credentials-generated -o name secret/db-credentials-generated $ kubectl create secret generic extra -n p03-02-secrets --from-literal=k=v --as=system:serviceaccount:p03-02-secrets:secret-reader error: failed to create secret secrets is forbidden: User "system:serviceaccount:p03-02-secrets:secret-reader" cannot create resource "secrets" in API group "" in the namespace "p03-02-secrets" ## step 4: a list with no names returns every value $ kubectl apply -f - # Role secret-lister (list secrets, no names) and its RoleBinding in p03-02-secrets role.rbac.authorization.k8s.io/secret-lister created rolebinding.rbac.authorization.k8s.io/secret-lister created $ kubectl get secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:secret-lister -o json | grep -o '"POSTGRES_[A-Z]*"' | sort -u "POSTGRES_DB" "POSTGRES_PASSWORD" "POSTGRES_USER" ## step 5: a subject that may only create Pods reads the Secret through a Pod $ kubectl apply -f - # Role pod-creator (create pods) and its RoleBinding in p03-02-secrets role.rbac.authorization.k8s.io/pod-creator created rolebinding.rbac.authorization.k8s.io/pod-creator created $ kubectl auth can-i create pods -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:pod-creator yes $ kubectl auth can-i get secrets -n p03-02-secrets --as=system:serviceaccount:p03-02-secrets:pod-creator no $ kubectl create -f - --as=system:serviceaccount:p03-02-secrets:pod-creator # secret-reveal: created by pod-creator, mounts db-credentials-generated, prints checksums pod/secret-reveal created $ kubectl wait pod/secret-reveal -n p03-02-secrets --for='jsonpath={.status.phase}=Succeeded' --timeout=300s pod/secret-reveal condition met $ kubectl logs secret-reveal -n p03-02-secrets 8975cb8f1ad5d41046739ae649557b8f24f4f29acacdfcf71d9cce756dfc525f /creds/POSTGRES_PASSWORD POSTGRES_DB POSTGRES_PASSWORD POSTGRES_USER $ the first checksum equals the checksum of $PW (compared, not printed) yes $ kubectl delete pod secret-reveal -n p03-02-secrets --now pod "secret-reveal" deleted from p03-02-secrets namespace ## step 6: the Secret as files, the mode an inspection Pod sees, and exec $ kubectl apply -f - # secret-files: runs as secret-reader, mounts db-credentials-generated with defaultMode 0440 and fsGroup 65532, then sleeps pod/secret-files created $ kubectl wait pod/secret-files -n p03-02-secrets --for=condition=Ready --timeout=300s pod/secret-files condition met $ kubectl logs secret-files -n p03-02-secrets uid=65532 gid=65532 groups=65532 total 12 -r--r----- 1 0 65532 9 Oct 31 02:27 POSTGRES_DB -r--r----- 1 0 65532 32 Oct 31 02:27 POSTGRES_PASSWORD -r--r----- 1 0 65532 9 Oct 31 02:27 POSTGRES_USER tmpfs /etc/creds tmpfs ro,relatime,size=65536k,inode64,noswap 0 0 $ kubectl exec secret-files -n p03-02-secrets -- sh -c 'wc -c < /etc/creds/POSTGRES_PASSWORD' 32 $ kubectl delete pod secret-files -n p03-02-secrets --now pod "secret-files" deleted from p03-02-secrets namespace ## step 7: an immutable Secret refuses an in-place change $ kubectl apply -f - # immutable-demo: Secret with immutable: true, value generated now secret/immutable-demo created $ kubectl get secret immutable-demo -n p03-02-secrets -o jsonpath='{.immutable}'; echo true $ kubectl patch secret immutable-demo -n p03-02-secrets --type merge -p "{\"stringData\":{\"token\":\"$(openssl rand -hex 16)\"}}" The Secret "immutable-demo" is invalid: data: Forbidden: field is immutable when `immutable` is set $ kubectl delete secret immutable-demo -n p03-02-secrets secret "immutable-demo" deleted from p03-02-secrets namespace ## step 8: gitleaks over the raw manifests (CI pin v8.30.1) $ gitleaks version 8.30.1 $ gitleaks dir --config ../.gitleaks.toml --no-banner --no-color --redact examples/bookstore/raw-manifests 7:27AM INF scanned ~162680 bytes (162.68 KB) in 18.8ms 7:27AM INF no leaks found ## step 9: clean up $ kubectl delete namespace p03-02-secrets --wait=true namespace "p03-02-secrets" deleted ## the broker login: two runs in a separate namespace (recorded 2026-10-31) # db-credentials gained three keys after the run above: RABBITMQ_DEFAULT_USER, # RABBITMQ_DEFAULT_PASS and AMQP_URL. rabbitmq reads the first two, and orders # and payments-worker read AMQP_URL, all by secretKeyRef. The run above did not # cover them. These two runs did, on the same kind cluster, in the namespace # p00-shared-raw. The chapter names bookstore. Lines that name the lab # namespace are kept as captured. No credential is printed: each one was # generated at apply time by openssl and the transcript shows key names only. # The orders and catalog images were rebuilt from this tree under a tag of their # own, bookstore/orders:p00-shared and bookstore/catalog:p00-shared, so the # shared :dev tags other labs use were left alone. The other images were the # :dev ones already on the node. Each manifest went through sed first: # namespace: bookstore became p00-shared-raw, the .bookstore.svc hostnames in # DB_DSN, REDIS_ADDR and the migrate Job became .p00-shared-raw.svc, and the two # image tags were replaced. The commands below show the file names only. Tabs in # rabbitmqctl output are written as spaces, which is how the evidence check reads # them. ## run A: the whole raw core applied into an empty namespace, values generated by sed $ kubectl apply -f 00-namespace.yaml -f 05-serviceaccounts-rbac.yaml -f 15-catalog-config.yaml namespace/p00-shared-raw created resourcequota/bookstore-quota created limitrange/bookstore-limits created serviceaccount/catalog-sa created serviceaccount/storefront-sa created serviceaccount/orders-sa created serviceaccount/payments-worker-sa created serviceaccount/postgres-sa created serviceaccount/redis-sa created serviceaccount/rabbitmq-sa created serviceaccount/migrate-sa created role.rbac.authorization.k8s.io/catalog-config-reader created rolebinding.rbac.authorization.k8s.io/catalog-config-reader-binding created configmap/catalog-config created $ DB="$(openssl rand -hex 16)"; MQ="$(openssl rand -hex 16)"; sed -e "s/devpassword/$DB/" -e "s/devbrokerpass/$MQ/g" 16-db-credentials.yaml | kubectl apply -f - secret/db-credentials created $ kubectl apply -f 12-redis.yaml -f 13-rabbitmq.yaml -f 20-postgres-statefulset.yaml -f 40-services.yaml deployment.apps/redis created deployment.apps/rabbitmq created service/postgres created statefulset.apps/postgres created service/catalog created service/storefront created service/orders created service/redis created service/rabbitmq created service/payments-worker created $ kubectl rollout status statefulset/postgres -n p00-shared-raw --timeout=600s Waiting for 1 pods to be ready... partitioned roll out complete: 1 new pods have been updated... $ kubectl apply -f 21-db-migrate-job.yaml job.batch/db-migrate created $ kubectl wait --for=condition=complete job/db-migrate -n p00-shared-raw --timeout=600s job.batch/db-migrate condition met $ kubectl apply -f 10-catalog-deploy.yaml -f 14-orders-deploy.yaml -f 19-payments-worker-deploy.yaml -f 11-storefront-deploy.yaml deployment.apps/catalog created deployment.apps/orders created deployment.apps/payments-worker created deployment.apps/storefront created $ kubectl rollout status deployment/rabbitmq -n p00-shared-raw --timeout=600s Waiting for deployment "rabbitmq" rollout to finish: 0 of 1 updated replicas are available... deployment "rabbitmq" successfully rolled out $ kubectl rollout status deployment/redis -n p00-shared-raw --timeout=600s deployment "redis" successfully rolled out $ kubectl rollout status deployment/catalog -n p00-shared-raw --timeout=600s deployment "catalog" successfully rolled out $ kubectl rollout status deployment/orders -n p00-shared-raw --timeout=600s deployment "orders" successfully rolled out $ kubectl rollout status deployment/payments-worker -n p00-shared-raw --timeout=600s deployment "payments-worker" successfully rolled out $ kubectl rollout status deployment/storefront -n p00-shared-raw --timeout=600s deployment "storefront" successfully rolled out ## run A: checks on the running core $ kubectl get pods -n p00-shared-raw NAME READY STATUS RESTARTS AGE catalog-7bb6855875-4lr24 1/1 Running 0 50s catalog-7bb6855875-9dzl6 1/1 Running 0 50s catalog-7bb6855875-cbgmd 1/1 Running 0 50s db-migrate-4l8nn 0/1 Completed 0 59s orders-679dd767cb-cbnl9 1/1 Running 0 50s orders-679dd767cb-vm29k 1/1 Running 0 50s payments-worker-66c9f958d9-bcqzh 1/1 Running 0 50s postgres-0 1/1 Running 0 87s rabbitmq-5bbc5c6d56-4vkj5 1/1 Running 0 87s redis-574bb544f-hz86s 1/1 Running 0 88s storefront-76cbb89847-5fvst 1/1 Running 0 50s storefront-76cbb89847-wnzb2 1/1 Running 0 50s $ kubectl get secret db-credentials -n p00-shared-raw -o go-template='{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}' AMQP_URL POSTGRES_DB POSTGRES_PASSWORD POSTGRES_USER RABBITMQ_DEFAULT_PASS RABBITMQ_DEFAULT_USER $ kubectl get deploy orders payments-worker -n p00-shared-raw -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.containers[0].env[?(@.name=="AMQP_URL")]}{"\n"}{end}' orders {"name":"AMQP_URL","valueFrom":{"secretKeyRef":{"key":"AMQP_URL","name":"db-credentials"}}} payments-worker {"name":"AMQP_URL","valueFrom":{"secretKeyRef":{"key":"AMQP_URL","name":"db-credentials"}}} $ kubectl get deploy,statefulset -n p00-shared-raw -o yaml | grep -c guest 0 $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl authenticate_user guest guest Authenticating user "guest" ... Error: Error: failed to authenticate user "guest" user 'guest' - invalid credentials command terminated with exit code 65 $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- sh -c 'rabbitmqctl authenticate_user "$RABBITMQ_DEFAULT_USER" "$RABBITMQ_DEFAULT_PASS"' Authenticating user "bookstore" ... Success $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl list_users --silent bookstore [administrator] $ kubectl exec -n p00-shared-raw postgres-0 -- sh -c 'env | cut -d= -f1 | grep -E "^(POSTGRES_|RABBITMQ_DEFAULT|AMQP_URL)" | sort' POSTGRES_DB POSTGRES_PASSWORD POSTGRES_USER $ kubectl get pods -n p00-shared-raw -o jsonpath='{range .items[*].spec.volumes[*]}{.emptyDir}{"\n"}{end}' | grep . | sort | uniq -c 1 {"sizeLimit":"256Mi"} 5 {"sizeLimit":"32Mi"} 8 {"sizeLimit":"64Mi"} 1 {"sizeLimit":"8Mi"} $ kubectl port-forward -n p00-shared-raw svc/orders 18080:80 & # stopped with kill after the orders below $ curl -s -X POST localhost:18080/orders -d '{"book_id":1,"qty":2}' {"order_id":1,"status":"accepted"} $ curl -s -X POST localhost:18080/orders -d '{"book_id":2,"qty":1}' {"order_id":2,"status":"accepted"} $ kubectl logs -n p00-shared-raw deploy/payments-worker | grep -E 'consuming queue|processed payment' | cut -d, -f2- "level":"INFO","msg":"consuming queue","queue":"orders"} "level":"INFO","msg":"processed payment for order","order_id":1} "level":"INFO","msg":"processed payment for order","order_id":2} $ for p in $(kubectl get pods -n p00-shared-raw -l app=orders -o name); do kubectl logs -n p00-shared-raw "$p"; done | grep -c 'publish order event failed' 0 $ for p in $(kubectl get pods -n p00-shared-raw -l app=orders -o name); do kubectl logs -n p00-shared-raw "$p"; done | grep -c 'AMQP_URL unset' 0 $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl list_queues name messages consumers --silent orders 0 1 ## run B: replace the broker login with a freshly generated one, as the chapter does $ kubectl get secret db-credentials -n p00-shared-raw -o go-template='{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}' AMQP_URL POSTGRES_DB POSTGRES_PASSWORD POSTGRES_USER RABBITMQ_DEFAULT_PASS RABBITMQ_DEFAULT_USER $ kubectl get deploy orders payments-worker -n p00-shared-raw -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.containers[0].env[?(@.name=="AMQP_URL")]}{"\n"}{end}' orders {"name":"AMQP_URL","valueFrom":{"secretKeyRef":{"key":"AMQP_URL","name":"db-credentials"}}} payments-worker {"name":"AMQP_URL","valueFrom":{"secretKeyRef":{"key":"AMQP_URL","name":"db-credentials"}}} $ MQ="$(openssl rand -hex 16)" $ kubectl patch secret db-credentials -n p00-shared-raw --type merge -p "{\"stringData\":{\"RABBITMQ_DEFAULT_PASS\":\"$MQ\",\"AMQP_URL\":\"amqp://bookstore:$MQ@rabbitmq:5672/\"}}" secret/db-credentials patched $ kubectl rollout restart deployment/rabbitmq -n p00-shared-raw deployment.apps/rabbitmq restarted $ kubectl rollout status deployment/rabbitmq -n p00-shared-raw --timeout=600s Waiting for deployment "rabbitmq" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "rabbitmq" rollout to finish: 1 old replicas are pending termination... deployment "rabbitmq" successfully rolled out $ kubectl rollout restart deployment/orders deployment/payments-worker -n p00-shared-raw deployment.apps/orders restarted deployment.apps/payments-worker restarted $ kubectl rollout status deployment/orders -n p00-shared-raw --timeout=600s Waiting for deployment "orders" rollout to finish: 1 out of 2 new replicas have been updated... Waiting for deployment "orders" rollout to finish: 1 out of 2 new replicas have been updated... Waiting for deployment "orders" rollout to finish: 1 out of 2 new replicas have been updated... Waiting for deployment "orders" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "orders" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "orders" rollout to finish: 1 old replicas are pending termination... deployment "orders" successfully rolled out $ kubectl rollout status deployment/payments-worker -n p00-shared-raw --timeout=600s deployment "payments-worker" successfully rolled out $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl list_users --silent bookstore [administrator] $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl authenticate_user guest guest Authenticating user "guest" ... Error: Error: failed to authenticate user "guest" user 'guest' - invalid credentials command terminated with exit code 65 $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- sh -c 'rabbitmqctl authenticate_user "$RABBITMQ_DEFAULT_USER" "$RABBITMQ_DEFAULT_PASS"' Authenticating user "bookstore" ... Success $ kubectl port-forward -n p00-shared-raw svc/orders 18080:80 & # stopped with kill after the orders below $ curl -s -X POST localhost:18080/orders -d '{"book_id":3,"qty":1}' {"order_id":3,"status":"accepted"} $ curl -s -X POST localhost:18080/orders -d '{"book_id":4,"qty":2}' {"order_id":4,"status":"accepted"} $ kubectl logs -n p00-shared-raw deploy/payments-worker | grep -E 'consuming queue|processed payment' | cut -d, -f2- "level":"INFO","msg":"consuming queue","queue":"orders"} "level":"INFO","msg":"processed payment for order","order_id":3} "level":"INFO","msg":"processed payment for order","order_id":4} $ for p in $(kubectl get pods -n p00-shared-raw -l app=orders -o name); do kubectl logs -n p00-shared-raw "$p"; done | grep -c 'publish order event failed' 0 $ kubectl exec -n p00-shared-raw deploy/rabbitmq -- rabbitmqctl list_queues name messages consumers --silent orders 0 1 $ kubectl get pods -n p00-shared-raw NAME READY STATUS RESTARTS AGE catalog-7bb6855875-4lr24 1/1 Running 0 5m25s catalog-7bb6855875-9dzl6 1/1 Running 0 5m25s catalog-7bb6855875-cbgmd 1/1 Running 0 5m25s db-migrate-4l8nn 0/1 Completed 0 5m34s orders-c469c47b-xdq7l 1/1 Running 0 32s orders-c469c47b-z94pz 1/1 Running 0 26s payments-worker-775b7994bc-8jppc 1/1 Running 0 32s postgres-0 1/1 Running 0 6m2s rabbitmq-6566455dd6-7dwfn 1/1 Running 0 63s redis-574bb544f-hz86s 1/1 Running 0 6m3s storefront-76cbb89847-5fvst 1/1 Running 0 5m25s storefront-76cbb89847-wnzb2 1/1 Running 0 5m25s ## step 8, run again over the final manifests (2026-10-31) # The scan in step 8 covered the raw manifests before db-credentials gained the # broker keys and before the other changes in this tree. Its byte count depends # on those files, so the command ran again from full-guide/ with the same pin. $ gitleaks version 8.30.1 $ gitleaks dir --config ../.gitleaks.toml --no-banner --no-color --redact examples/bookstore/raw-manifests 7:34PM INF scanned ~171179 bytes (171.18 KB) in 32ms 7:34PM INF no leaks found