Lab 34 - Security review challenge
Lab 34 - Security review challenge
InfodiscoverGoal: a team asks for a security review before go-live. Find the problems, fix them, and prove each fix. Chapters: Day 4 - all of them.
The application
cd ~
cat > payments.yaml <<'YAML'
apiVersion: v1
kind: Namespace
metadata: { name: payments }
---
apiVersion: v1
kind: ServiceAccount
metadata: { name: payments-app, namespace: payments }
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata: { name: payments-app-admin }
subjects: [{ kind: ServiceAccount, name: payments-app, namespace: payments }]
roleRef: { kind: ClusterRole, name: cluster-admin, apiGroup: rbac.authorization.k8s.io }
---
apiVersion: v1
kind: ConfigMap
metadata: { name: payments-cfg, namespace: payments }
data:
DB_HOST: db
DB_PASSWORD: "Summer2026!"
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: api, namespace: payments }
spec:
replicas: 2
selector: { matchLabels: { app: api } }
template:
metadata: { labels: { app: api } }
spec:
serviceAccountName: payments-app
containers:
- name: api
image: nginx:latest
envFrom: [{ configMapRef: { name: payments-cfg } }]
securityContext: { privileged: true }
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: db, namespace: payments }
spec:
replicas: 1
selector: { matchLabels: { app: db } }
template:
metadata: { labels: { app: db } }
spec:
containers:
- name: db
image: nginx:1.27
---
apiVersion: v1
kind: Service
metadata: { name: db, namespace: payments }
spec:
selector: { app: db }
ports: [{ port: 80 }]
YAML
kubectl apply -f payments.yaml
(db is a stand-in - nginx on port 80 plays the database.)
Your review
Find at least six findings. Tools you know: kubectl auth can-i,
kubectl get ... -o yaml, trivy config, trivy image, the PSA dry run,
~/reach.sh from Lab 32.
Definition of done:
payments-appcan do nothing outsidepayments- and inside only what an API server that reads its own ConfigMaps needs.- No password in a ConfigMap.
- Namespace
paymentsenforces Pod Security baseline, warns on restricted;apiruns without warnings. - Only
apican reachdb; nothing from other namespaces reachesapiexcept Traefik. - No
latestimages. trivy configon your final manifests shows no HIGH or CRITICAL findings.
Hints
Solution
Clean up
kubectl delete ns payments
kubectl delete clusterrolebinding payments-app-admin --ignore-not-found