Skip to content

Commit 9a8de22

Browse files
committed
Allow NGF to run on OpenShift (nginx#1976)
Add SecurityContextConstraints for NGF and documentation on additional steps when installing NGF on an OpenShift environment. Problem: NGF fails to deploy on OpenShift. Solution: Add SecurityContextConstraints for NGF, giving NGF to correct permissions to deploy on OpenShift. Testing: Manual deployment of NGF with NGINX and NGINX+. Also set up the cafe example and ensured traffic flowed.
1 parent f28f78d commit 9a8de22

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ generate-manifests: ## Generate manifests using Helm.
132132
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/loadbalancer.yaml
133133
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) --set service.annotations.'service\.beta\.kubernetes\.io\/aws-load-balancer-type'="nlb" -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/loadbalancer-aws-nlb.yaml
134134
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) --set service.type=NodePort --set service.externalTrafficPolicy="" -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/nodeport.yaml
135+
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) -n nginx-gateway --api-versions security.openshift.io/v1/SecurityContextConstraints -s templates/scc.yaml > $(strip $(MANIFEST_DIR))/scc.yaml
135136

136137
.PHONY: clean
137138
clean: ## Clean the build

charts/nginx-gateway-fabric/templates/_helpers.tpl

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Create data plane config name.
3939
{{- printf "%s-proxy-config" $name | trunc 63 | trimSuffix "-" }}
4040
{{- end }}
4141

42+
{{/*
43+
Create security context constraints name.
44+
*/}}
45+
{{- define "nginx-gateway.scc-name" -}}
46+
{{- $name := default .Release.Name .Values.nameOverride }}
47+
{{- printf "%s-scc" $name | trunc 63 | trimSuffix "-" }}
48+
{{- end }}
49+
4250
{{/*
4351
Create chart name and version as used by the chart label.
4452
*/}}

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

+10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ rules:
149149
verbs:
150150
- list
151151
- watch
152+
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
153+
- apiGroups:
154+
- security.openshift.io
155+
resources:
156+
- securitycontextconstraints
157+
resourceNames:
158+
- {{ include "nginx-gateway.scc-name" . }}
159+
verbs:
160+
- use
161+
{{- end }}
152162
---
153163
apiVersion: rbac.authorization.k8s.io/v1
154164
kind: ClusterRoleBinding
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
2+
kind: SecurityContextConstraints
3+
apiVersion: security.openshift.io/v1
4+
metadata:
5+
name: {{ include "nginx-gateway.scc-name" . }}
6+
allowPrivilegeEscalation: {{ .Values.nginxGateway.securityContext.allowPrivilegeEscalation }}
7+
allowHostDirVolumePlugin: false
8+
allowHostIPC: false
9+
allowHostNetwork: false
10+
allowHostPID: false
11+
allowHostPorts: false
12+
allowPrivilegedContainer: false
13+
readOnlyRootFilesystem: true
14+
runAsUser:
15+
type: MustRunAsRange
16+
uidRangeMin: 101
17+
uidRangeMax: 102
18+
fsGroup:
19+
type: MustRunAs
20+
ranges:
21+
- min: 1001
22+
max: 1001
23+
supplementalGroups:
24+
type: MustRunAs
25+
ranges:
26+
- min: 1001
27+
max: 1001
28+
seLinuxContext:
29+
type: MustRunAs
30+
volumes:
31+
- emptyDir
32+
- secret
33+
users:
34+
- {{ printf "system:serviceaccount:%s:%s" .Release.Namespace (include "nginx-gateway.serviceAccountName" .) }}
35+
allowedCapabilities:
36+
- NET_BIND_SERVICE
37+
- KILL
38+
requiredDropCapabilities:
39+
- ALL
40+
{{- end }}

charts/nginx-gateway-fabric/values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ terminationGracePeriodSeconds: 30
106106
## Tolerations for the NGINX Gateway Fabric pod.
107107
tolerations: []
108108

109-
## The nodeSelector of the NGINX Gateway Fabric pod.
109+
## The nodeSelector of the NGINX Gateway Fabric pod.
110110
nodeSelector: {}
111111

112112
## The affinity of the NGINX Gateway Fabric pod.

deploy/manifests/scc.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# Source: nginx-gateway-fabric/templates/scc.yaml
3+
kind: SecurityContextConstraints
4+
apiVersion: security.openshift.io/v1
5+
metadata:
6+
name: nginx-gateway-scc
7+
allowPrivilegeEscalation: false
8+
allowHostDirVolumePlugin: false
9+
allowHostIPC: false
10+
allowHostNetwork: false
11+
allowHostPID: false
12+
allowHostPorts: false
13+
allowPrivilegedContainer: false
14+
readOnlyRootFilesystem: true
15+
runAsUser:
16+
type: MustRunAsRange
17+
uidRangeMin: 101
18+
uidRangeMax: 102
19+
fsGroup:
20+
type: MustRunAs
21+
ranges:
22+
- min: 1001
23+
max: 1001
24+
supplementalGroups:
25+
type: MustRunAs
26+
ranges:
27+
- min: 1001
28+
max: 1001
29+
seLinuxContext:
30+
type: MustRunAs
31+
volumes:
32+
- emptyDir
33+
- secret
34+
users:
35+
- system:serviceaccount:nginx-gateway:nginx-gateway
36+
allowedCapabilities:
37+
- NET_BIND_SERVICE
38+
- KILL
39+
requiredDropCapabilities:
40+
- ALL

site/content/installation/installing-ngf/manifests.md

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ kubectl apply -f https://raw.githubusercontent.com/nginxinc/nginx-gateway-fabric
4545

4646
{{<note>}}By default, NGINX Gateway Fabric is installed in the **nginx-gateway** namespace. You can deploy in another namespace by modifying the manifest files.{{</note>}}
4747

48+
{{<note>}}If you are deploying NGINX Gateway Fabric on OpenShift, we've supplied a baseline [SecurityContextConstraints](https://raw.githubusercontent.com/nginxinc/nginx-gateway-fabric/v1.2.0/deploy/manifests/scc.yaml) manifest that you can download, modify if needed, and apply. You will also need to make sure the SecurityContextConstraints resource is added to the ClusterRole RBAC:
49+
50+
```yaml
51+
. . .
52+
- apiGroups:
53+
- security.openshift.io
54+
resources:
55+
- securitycontextconstraints
56+
resourceNames:
57+
- nginx-gateway-scc
58+
verbs:
59+
- use
60+
```
61+
62+
Alternatively, use [helm]({{< relref "installation/installing-ngf/helm.md" >}}), which will automatically configure the mentioned resources on OpenShift.
63+
{{</note>}}
64+
4865
#### Stable release
4966
5067
##### For NGINX

0 commit comments

Comments
 (0)