Skip to content

Commit

Permalink
Ensure NKG has least privileges (#1004)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjberman authored Aug 29, 2023
1 parent 5e25be3 commit 3ce86fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
12 changes: 12 additions & 0 deletions conformance/provisioner/static-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ spec:
imagePullPolicy: Always
name: nginx-gateway
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- KILL
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 102
runAsGroup: 1001
volumeMounts:
Expand All @@ -69,6 +71,7 @@ spec:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 101
runAsGroup: 1001
volumeMounts:
Expand All @@ -78,14 +81,23 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-cache
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
serviceAccountName: nginx-gateway
shareProcessNamespace: true
securityContext:
fsGroup: 1001
runAsNonRoot: true
volumes:
- name: nginx-conf
emptyDir: {}
- name: nginx-secrets
emptyDir: {}
- name: nginx-run
emptyDir: {}
- name: nginx-cache
emptyDir: {}
- name: nginx-lib
emptyDir: {}
12 changes: 12 additions & 0 deletions deploy/helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ spec:
imagePullPolicy: {{ .Values.nginxGateway.image.pullPolicy }}
name: nginx-gateway
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- KILL
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 102
runAsGroup: 1001
volumeMounts:
Expand All @@ -64,6 +66,7 @@ spec:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 101
runAsGroup: 1001
volumeMounts:
Expand All @@ -73,15 +76,24 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-cache
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
serviceAccountName: {{ include "nginx-gateway.serviceAccountName" . }}
shareProcessNamespace: true
securityContext:
fsGroup: 1001
runAsNonRoot: true
volumes:
- name: nginx-conf
emptyDir: {}
- name: nginx-secrets
emptyDir: {}
- name: nginx-run
emptyDir: {}
- name: nginx-cache
emptyDir: {}
- name: nginx-lib
emptyDir: {}
{{- end }}
7 changes: 0 additions & 7 deletions deploy/helm-chart/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ rules:
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- gatewayconfigs
verbs:
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
19 changes: 12 additions & 7 deletions deploy/manifests/nginx-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ rules:
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- gatewayconfigs
verbs:
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down Expand Up @@ -149,11 +142,13 @@ spec:
imagePullPolicy: Always
name: nginx-gateway
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- KILL
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 102
runAsGroup: 1001
volumeMounts:
Expand All @@ -177,6 +172,7 @@ spec:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 101
runAsGroup: 1001
volumeMounts:
Expand All @@ -186,17 +182,26 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-cache
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
serviceAccountName: nginx-gateway
shareProcessNamespace: true
securityContext:
fsGroup: 1001
runAsNonRoot: true
volumes:
- name: nginx-conf
emptyDir: {}
- name: nginx-secrets
emptyDir: {}
- name: nginx-run
emptyDir: {}
- name: nginx-cache
emptyDir: {}
- name: nginx-lib
emptyDir: {}
---
# Source: nginx-kubernetes-gateway/templates/gatewayclass.yaml
apiVersion: gateway.networking.k8s.io/v1beta1
Expand Down

0 comments on commit 3ce86fb

Please sign in to comment.