UNCLASSIFIED - NO CUI

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.yaml adds console.serviceAccount, init.serviceAccount, and defender.serviceAccount with automountServiceAccountToken: false.
  • console/serviceaccount.yaml and init/serviceaccount.yaml set no-automount; the console SA gets no token (nothing consumes it), the init Job gets a projected serviceAccountToken volume mounted at /var/run/secrets/kubernetes.io/serviceaccount.
  • defender/serviceaccount.yaml and defender/daemonset.yaml (defenderOnly) get the same no-automount plus projected token volume.
  • scripts/twistlock-defenders.sh applies the same hardening to the API-returned defender manifest via yq before kubectl apply, since the chart cannot template that path.
  • defender/daemonset.yaml sets DEFENDER_CLUSTER_NAME_RESOLVING_METHOD: manual so the required defender.clusterName is honored instead of discarded.
  • init/volume-upgrade-job.yaml dedupes its name / app.kubernetes.io/name labels (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 the default upgrade / ambient upgrade jobs.
  • helm-unittest suites moved from chart/tests/ to chart/unittests/ so the helm unit tests job 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 total

bats (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

Linked Issue

issue

Merge request reports

Loading
Loading