2 Commits

Author SHA1 Message Date
benvin 9b49170083 Merge pull request 'Disable API token automount on spawned job pods' (#2) from benvin/job-no-automount into main
ci/woodpecker/tag/docker Pipeline was successful
Reviewed-on: #2
2026-08-30 16:05:37 +10:00
unkin-agent 6aec05deae 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.
2026-08-30 15:32:49 +10:00
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{
RestartPolicy: corev1.RestartPolicyNever,
ServiceAccountName: cfg.JobServiceAccount,
// Jobs never touch the k8s API; only the vault-audience
// projected token below is needed.
AutomountServiceAccountToken: ptr(false),
Containers: []corev1.Container{{
Name: string(t),
Image: cfg.Image,
+4
View File
@@ -59,6 +59,10 @@ func TestPRJobSpec(t *testing.T) {
if pod.ServiceAccountName != "repospawner" {
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 {
t.Fatalf("containers = %+v", pod.Containers)
}