Cl/defender sa hardening
Summary
Hardens the twistlock ServiceAccounts for the kyverno disallow-auto-mount-service-account-token policy (CIS Kubernetes Benchmark 5.1.6), honors defender.clusterName in defender-only mode, fixes duplicate labels on the volume upgrade job that broke the upgrade CI jobs, and moves the helm-unittest suites so the pipeline runs them. Enabling that policy flags every twistlock SA today, forcing downstream post-renderer patches; this exposes the levers to fix it at the source. Secure by default: SAs no longer auto-mount the API token, and the workloads that need it (init Job, defender DaemonSet) get it from an explicit projected volume at the standard path, so nothing they read changes.
Closes #264 (closed).
What changed
chart/values.yamladdsconsole.serviceAccount,init.serviceAccount, anddefender.serviceAccountwithautomountServiceAccountToken: false.console/serviceaccount.yamlandinit/serviceaccount.yamlset no-automount; the console SA gets no token (nothing consumes it), the init Job gets a projectedserviceAccountTokenvolume mounted at/var/run/secrets/kubernetes.io/serviceaccount.defender/serviceaccount.yamlanddefender/daemonset.yaml(defenderOnly) get the same no-automount plus projected token volume.scripts/twistlock-defenders.shapplies the same hardening to the API-returned defender manifest viayqbeforekubectl apply, since the chart cannot template that path.defender/daemonset.yamlsetsDEFENDER_CLUSTER_NAME_RESOLVING_METHOD: manualso the requireddefender.clusterNameis honored instead of discarded.init/volume-upgrade-job.yamldedupes itsname/app.kubernetes.io/namelabels (a helper already set those keys, and the template re-added them). The duplicates fail BigBang's strict post-renderer on upgrade; the job renders only on.Release.IsUpgrade, so this only showed up in thedefault upgrade/ambient upgradejobs.- helm-unittest suites moved from
chart/tests/tochart/unittests/so thehelm unit testsjob discovers them; new coverage added for the SA hardening and the resolving method.
Upgrade Notices
0.27.1-bb.0 changes ServiceAccount token mounting. SAs no longer auto-mount the token by default; the init Job and defender receive it via a projected volume at the same path, so token availability is unchanged for workloads that use it. The console SA no longer carries a token (it has no consumer). Revert per SA with console.serviceAccount.automountServiceAccountToken: true (or the init / defender equivalents). The projected volume relies on the kube-root-ca.crt ConfigMap the cluster auto-creates in every namespace.
Relevant logs/screenshots
helm-unittest (helm unittest chart -f "unittests/**/*_test.yaml", same invocation as the pipeline job):
PASS test console deployment extraEnv chart/unittests/console_deployment_test.yaml
PASS test defender-only deployment mode chart/unittests/defender_only_test.yaml
PASS test metrics user secret persistence chart/unittests/metrics_secret_test.yaml
PASS service account token hardening chart/unittests/sa_hardening_test.yaml
Charts: 1 passed, 1 total
Test Suites: 4 passed, 4 total
Tests: 21 passed, 21 totalbats (BATS_LIB_PATH=/opt/lib bats chart/tests/twistlock-defenders-hardening.bats):
1..3
ok 1 SA automount is set false in the applied manifest
ok 2 DaemonSet gets the projected token volume
ok 3 defender container gets the token mount at the standard path