Disable API token automount on spawned job pods
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:
@@ -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,
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user