Skip to content

Commit 375d397

Browse files
committed
Ensure NKG has least privileges (nginx#1004)
Problem: NKG wasn't running with the least privileges necessary, which could lead to potential security issues. Solution: Remove unnecessary RBAC, and add security restrictions where necessary.
1 parent 70727d9 commit 375d397

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

conformance/provisioner/static-deployment.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ spec:
4141
imagePullPolicy: Always
4242
name: nginx-gateway
4343
securityContext:
44+
allowPrivilegeEscalation: false
4445
capabilities:
4546
add:
4647
- KILL
4748
drop:
4849
- ALL
50+
readOnlyRootFilesystem: true
4951
runAsUser: 102
5052
runAsGroup: 1001
5153
volumeMounts:
@@ -69,6 +71,7 @@ spec:
6971
- NET_BIND_SERVICE
7072
drop:
7173
- ALL
74+
readOnlyRootFilesystem: true
7275
runAsUser: 101
7376
runAsGroup: 1001
7477
volumeMounts:
@@ -78,14 +81,23 @@ spec:
7881
mountPath: /etc/nginx/secrets
7982
- name: nginx-run
8083
mountPath: /var/run/nginx
84+
- name: nginx-cache
85+
mountPath: /var/cache/nginx
86+
- name: nginx-lib
87+
mountPath: /var/lib/nginx
8188
serviceAccountName: nginx-gateway
8289
shareProcessNamespace: true
8390
securityContext:
8491
fsGroup: 1001
92+
runAsNonRoot: true
8593
volumes:
8694
- name: nginx-conf
8795
emptyDir: {}
8896
- name: nginx-secrets
8997
emptyDir: {}
9098
- name: nginx-run
9199
emptyDir: {}
100+
- name: nginx-cache
101+
emptyDir: {}
102+
- name: nginx-lib
103+
emptyDir: {}

deploy/helm-chart/templates/deployment.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ spec:
3636
imagePullPolicy: {{ .Values.nginxGateway.image.pullPolicy }}
3737
name: nginx-gateway
3838
securityContext:
39+
allowPrivilegeEscalation: false
3940
capabilities:
4041
add:
4142
- KILL
4243
drop:
4344
- ALL
45+
readOnlyRootFilesystem: true
4446
runAsUser: 102
4547
runAsGroup: 1001
4648
volumeMounts:
@@ -64,6 +66,7 @@ spec:
6466
- NET_BIND_SERVICE
6567
drop:
6668
- ALL
69+
readOnlyRootFilesystem: true
6770
runAsUser: 101
6871
runAsGroup: 1001
6972
volumeMounts:
@@ -73,15 +76,24 @@ spec:
7376
mountPath: /etc/nginx/secrets
7477
- name: nginx-run
7578
mountPath: /var/run/nginx
79+
- name: nginx-cache
80+
mountPath: /var/cache/nginx
81+
- name: nginx-lib
82+
mountPath: /var/lib/nginx
7683
serviceAccountName: {{ include "nginx-gateway.serviceAccountName" . }}
7784
shareProcessNamespace: true
7885
securityContext:
7986
fsGroup: 1001
87+
runAsNonRoot: true
8088
volumes:
8189
- name: nginx-conf
8290
emptyDir: {}
8391
- name: nginx-secrets
8492
emptyDir: {}
8593
- name: nginx-run
8694
emptyDir: {}
95+
- name: nginx-cache
96+
emptyDir: {}
97+
- name: nginx-lib
98+
emptyDir: {}
8799
{{- end }}

deploy/helm-chart/templates/rbac.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ rules:
4848
verbs:
4949
- list
5050
- watch
51-
- apiGroups:
52-
- gateway.nginx.org
53-
resources:
54-
- gatewayconfigs
55-
verbs:
56-
- list
57-
- watch
5851
- apiGroups:
5952
- gateway.networking.k8s.io
6053
resources:

deploy/manifests/nginx-gateway.yaml

+12-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ rules:
5959
verbs:
6060
- list
6161
- watch
62-
- apiGroups:
63-
- gateway.nginx.org
64-
resources:
65-
- gatewayconfigs
66-
verbs:
67-
- list
68-
- watch
6962
- apiGroups:
7063
- gateway.networking.k8s.io
7164
resources:
@@ -149,11 +142,13 @@ spec:
149142
imagePullPolicy: Always
150143
name: nginx-gateway
151144
securityContext:
145+
allowPrivilegeEscalation: false
152146
capabilities:
153147
add:
154148
- KILL
155149
drop:
156150
- ALL
151+
readOnlyRootFilesystem: true
157152
runAsUser: 102
158153
runAsGroup: 1001
159154
volumeMounts:
@@ -177,6 +172,7 @@ spec:
177172
- NET_BIND_SERVICE
178173
drop:
179174
- ALL
175+
readOnlyRootFilesystem: true
180176
runAsUser: 101
181177
runAsGroup: 1001
182178
volumeMounts:
@@ -186,17 +182,26 @@ spec:
186182
mountPath: /etc/nginx/secrets
187183
- name: nginx-run
188184
mountPath: /var/run/nginx
185+
- name: nginx-cache
186+
mountPath: /var/cache/nginx
187+
- name: nginx-lib
188+
mountPath: /var/lib/nginx
189189
serviceAccountName: nginx-gateway
190190
shareProcessNamespace: true
191191
securityContext:
192192
fsGroup: 1001
193+
runAsNonRoot: true
193194
volumes:
194195
- name: nginx-conf
195196
emptyDir: {}
196197
- name: nginx-secrets
197198
emptyDir: {}
198199
- name: nginx-run
199200
emptyDir: {}
201+
- name: nginx-cache
202+
emptyDir: {}
203+
- name: nginx-lib
204+
emptyDir: {}
200205
---
201206
# Source: nginx-kubernetes-gateway/templates/gatewayclass.yaml
202207
apiVersion: gateway.networking.k8s.io/v1beta1

0 commit comments

Comments
 (0)