Skip to content

Commit 166f68e

Browse files
authored
Move automountServiceAccountToken to Pod (#3573) (#3580)
Move automountServiceToken to Pod Problem: For security reasons, it's best practice to not have `automountServiceToken` on the ServiceAccount, and instead set in directly on the workloads that need the token. Solution: Set this field on the Pods instead of the ServiceAccounts.
1 parent c3d8ba2 commit 166f68e

File tree

12 files changed

+23
-1
lines changed

12 files changed

+23
-1
lines changed

charts/nginx-gateway-fabric/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
{{- end }}
3636
{{- end }}
3737
spec:
38+
automountServiceAccountToken: true
3839
containers:
3940
- args:
4041
- controller

charts/nginx-gateway-fabric/templates/serviceaccount.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ metadata:
77
{{- include "nginx-gateway.labels" . | nindent 4 }}
88
annotations:
99
{{- toYaml .Values.nginxGateway.serviceAccount.annotations | nindent 4 }}
10+
automountServiceAccountToken: false
1011
{{- if or .Values.nginxGateway.serviceAccount.imagePullSecret .Values.nginxGateway.serviceAccount.imagePullSecrets }}
1112
imagePullSecrets:
1213
{{- if .Values.nginxGateway.serviceAccount.imagePullSecret }}

deploy/azure/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -252,6 +253,7 @@ spec:
252253
app.kubernetes.io/instance: nginx-gateway
253254
app.kubernetes.io/name: nginx-gateway
254255
spec:
256+
automountServiceAccountToken: true
255257
containers:
256258
- args:
257259
- controller

deploy/default/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -252,6 +253,7 @@ spec:
252253
app.kubernetes.io/instance: nginx-gateway
253254
app.kubernetes.io/name: nginx-gateway
254255
spec:
256+
automountServiceAccountToken: true
255257
containers:
256258
- args:
257259
- controller

deploy/experimental-nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -256,6 +257,7 @@ spec:
256257
app.kubernetes.io/instance: nginx-gateway
257258
app.kubernetes.io/name: nginx-gateway
258259
spec:
260+
automountServiceAccountToken: true
259261
containers:
260262
- args:
261263
- controller

deploy/experimental/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -256,6 +257,7 @@ spec:
256257
app.kubernetes.io/instance: nginx-gateway
257258
app.kubernetes.io/name: nginx-gateway
258259
spec:
260+
automountServiceAccountToken: true
259261
containers:
260262
- args:
261263
- controller

deploy/nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -252,6 +253,7 @@ spec:
252253
app.kubernetes.io/instance: nginx-gateway
253254
app.kubernetes.io/name: nginx-gateway
254255
spec:
256+
automountServiceAccountToken: true
255257
containers:
256258
- args:
257259
- controller

deploy/nodeport/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -252,6 +253,7 @@ spec:
252253
app.kubernetes.io/instance: nginx-gateway
253254
app.kubernetes.io/name: nginx-gateway
254255
spec:
256+
automountServiceAccountToken: true
255257
containers:
256258
- args:
257259
- controller

deploy/openshift/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -273,6 +274,7 @@ spec:
273274
app.kubernetes.io/instance: nginx-gateway
274275
app.kubernetes.io/name: nginx-gateway
275276
spec:
277+
automountServiceAccountToken: true
276278
containers:
277279
- args:
278280
- controller

deploy/snippets-filters-nginx-plus/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -254,6 +255,7 @@ spec:
254255
app.kubernetes.io/instance: nginx-gateway
255256
app.kubernetes.io/name: nginx-gateway
256257
spec:
258+
automountServiceAccountToken: true
257259
containers:
258260
- args:
259261
- controller

deploy/snippets-filters/deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: nginx-gateway
55
---
66
apiVersion: v1
7+
automountServiceAccountToken: false
78
kind: ServiceAccount
89
metadata:
910
labels:
@@ -254,6 +255,7 @@ spec:
254255
app.kubernetes.io/instance: nginx-gateway
255256
app.kubernetes.io/name: nginx-gateway
256257
spec:
258+
automountServiceAccountToken: true
257259
containers:
258260
- args:
259261
- controller

internal/controller/provisioner/objects.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ func (p *NginxProvisioner) buildNginxResourceObjects(
117117
)
118118

119119
serviceAccount := &corev1.ServiceAccount{
120-
ObjectMeta: objectMeta,
120+
ObjectMeta: objectMeta,
121+
AutomountServiceAccountToken: helpers.GetPointer(false),
121122
}
122123

123124
var openshiftObjs []client.Object
@@ -608,6 +609,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
608609
Annotations: podAnnotations,
609610
},
610611
Spec: corev1.PodSpec{
612+
AutomountServiceAccountToken: helpers.GetPointer(true),
611613
Containers: []corev1.Container{
612614
{
613615
Name: "nginx",

0 commit comments

Comments
 (0)