Disable API token automount on spawned job pods
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

Job pods only need the vault-audience projected token to log in; the
default automounted ServiceAccount token hands them the repospawner
Role's k8s API access that no job subcommand uses.
This commit is contained in:
2026-08-30 15:32:49 +10:00
parent 1b566022ac
commit 6aec05deae
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -145,6 +145,9 @@ func base(cfg *config.Config, r store.Request, t Type, args []string, deadline i
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever, RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: cfg.JobServiceAccount, ServiceAccountName: cfg.JobServiceAccount,
// Jobs never touch the k8s API; only the vault-audience
// projected token below is needed.
AutomountServiceAccountToken: ptr(false),
Containers: []corev1.Container{{ Containers: []corev1.Container{{
Name: string(t), Name: string(t),
Image: cfg.Image, Image: cfg.Image,
+4
View File
@@ -59,6 +59,10 @@ func TestPRJobSpec(t *testing.T) {
if pod.ServiceAccountName != "repospawner" { if pod.ServiceAccountName != "repospawner" {
t.Errorf("serviceAccountName = %q", pod.ServiceAccountName) t.Errorf("serviceAccountName = %q", pod.ServiceAccountName)
} }
// The job only needs the vault-audience token, not a k8s API token.
if pod.AutomountServiceAccountToken == nil || *pod.AutomountServiceAccountToken {
t.Errorf("automountServiceAccountToken = %v, want false", pod.AutomountServiceAccountToken)
}
if len(pod.Containers) != 1 || pod.Containers[0].Image != cfg.Image { if len(pod.Containers) != 1 || pod.Containers[0].Image != cfg.Image {
t.Fatalf("containers = %+v", pod.Containers) t.Fatalf("containers = %+v", pod.Containers)
} }