Homework
Three tasks to deepen your understanding of ServiceAccounts, RBAC templating, and least-privilege design in Helm charts.
Complete the Lab Guide before starting the homework. These tasks build on the chart and skills from the lab exercises.
Task 1 — Multi-Role Chart with ClusterRole Support
Objective
Extend the lab chart to support both namespace-scoped Roles and cluster-scoped ClusterRoles, controlled through values.yaml.
Instructions
- Add a new value
rbac.clusterWide: falsetovalues.yaml. - Create a new template
templates/clusterrole.yamlthat renders a ClusterRole whenrbac.createandrbac.clusterWideare bothtrue. - Create a corresponding
templates/clusterrolebinding.yaml. - Modify
templates/role.yamlandtemplates/rolebinding.yamlto only render whenrbac.clusterWideisfalse. - Add a second set of rules in values for the cluster-wide scenario:
rbac: create: true clusterWide: false rules: - apiGroups: [""] resources: ["configmaps", "secrets"] verbs: ["get", "list", "watch"] clusterRules: - apiGroups: [""] resources: ["namespaces", "nodes"] verbs: ["get", "list"] - apiGroups: [""] resources: ["configmaps"] verbs: ["get", "list", "watch"] - Validate with
helm templateusing both--set rbac.clusterWide=trueand--set rbac.clusterWide=false.
Deliverable
The rendered output from both scenarios. Verify that:
- With
clusterWide=false: only Role + RoleBinding are rendered - With
clusterWide=true: only ClusterRole + ClusterRoleBinding are rendered
Task 2 — Image Pull Secret Automation
Objective
Configure a ServiceAccount with image pull secrets for a private container registry, and verify that pods automatically inherit the credentials.
Instructions
- Create a Docker registry secret in your cluster:
kubectl create secret docker-registry my-registry-creds \ --docker-server=https://ghcr.io \ --docker-username=YOUR_USERNAME \ --docker-password=YOUR_TOKEN \ -n rbac-lab - Update
values.yamlto include the image pull secret on the ServiceAccount:serviceAccount: create: true imagePullSecrets: - name: my-registry-creds - Deploy the chart and verify the ServiceAccount has the pull secret attached:
kubectl get serviceaccount configreader -n rbac-lab -o yaml - Verify that a pod using this ServiceAccount automatically inherits the pull secret by inspecting the pod spec:
kubectl get pod <pod-name> -n rbac-lab -o jsonpath='{.spec.imagePullSecrets}'
Deliverable
Screenshots or terminal output showing:
- The ServiceAccount YAML with
imagePullSecretspopulated - The pod spec showing the inherited pull secrets
Task 3 — Audit and Harden an Over-Permissioned Chart
Objective
Given an intentionally over-permissioned RBAC configuration, identify the security issues and produce a hardened version.
The Problematic Configuration
An application only needs to read ConfigMaps in its own namespace, but was deployed with these RBAC rules:
# INSECURE - do not use in production
rbac:
create: true
clusterWide: true
# ClusterRole with excessive permissions
clusterRules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
serviceAccount:
create: true
automount: true
Instructions
- List every security problem with the configuration above (aim for at least 5 issues).
- Write a hardened
values.yamlthat follows least-privilege for an app that only reads ConfigMaps in its namespace. - Deploy both versions (insecure and hardened) and compare the output of:
kubectl auth can-i --list \ --as=system:serviceaccount:<namespace>:<sa-name> \ -n <namespace> - Write a brief report (200-300 words) explaining the risks of the original configuration and how your hardened version addresses each one.
Deliverable
A table listing the issues found and how each was fixed:
| # | Security Issue | Risk | Fix Applied |
|---|---|---|---|
| 1 | Wildcard apiGroups | Access to all API groups including CRDs | Restrict to [""] (core API only) |
| 2 | (your finding) | (risk description) | (your fix) |
| 3 | (your finding) | (risk description) | (your fix) |
| 4 | (your finding) | (risk description) | (your fix) |
| 5 | (your finding) | (risk description) | (your fix) |
Plus the hardened values.yaml and the kubectl auth can-i --list comparison output.
Grading Rubric
| Criterion | Points | Requirements |
|---|---|---|
| Task 1 — ClusterRole templates | 30 | Both ClusterRole and ClusterRoleBinding templates render correctly; conditional logic excludes Role/RoleBinding when clusterWide is true; helm template output is valid YAML |
| Task 1 — Toggle verification | 10 | Both scenarios rendered and compared; correct resources appear in each |
| Task 2 — Pull secret on SA | 15 | Secret created; ServiceAccount YAML shows imagePullSecrets; pod inherits the secret |
| Task 2 — Documentation | 5 | Output or screenshots provided |
| Task 3 — Issue identification | 15 | At least 5 distinct security issues identified with risk explanations |
| Task 3 — Hardened values | 15 | Hardened values.yaml follows least privilege; namespace-scoped; specific verbs and resources; automount considered |
| Task 3 — Comparison report | 10 | can-i output for both versions; written report explains risks and fixes |
Submission Checklist
- Task 1: ClusterRole + ClusterRoleBinding templates created;
helm templateoutput for both scenarios - Task 2: Image pull secret configured on ServiceAccount; pod inheritance verified
- Task 3: Security issues table (5+ items); hardened values.yaml; can-i comparison; written report
- All YAML is valid and passes
helm lint