Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions charts/nginx-gateway-fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ To use a NodePort Service instead:
helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway --set nginx.service.type=NodePort
```

To disable the creation of a Service:

```shell
helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway --set nginx.service.create=false
```

## Upgrading the Chart

> [!NOTE]
Expand Down
6 changes: 0 additions & 6 deletions charts/nginx-gateway-fabric/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ To use a NodePort Service instead:
helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway --set nginx.service.type=NodePort
```

To disable the creation of a Service:

```shell
helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway --set nginx.service.create=false
```

## Upgrading the Chart

> [!NOTE]
Expand Down
44 changes: 44 additions & 0 deletions charts/nginx-gateway-fabric/templates/certs-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,50 @@ subjects:
name: {{ include "nginx-gateway.fullname" . }}-cert-generator
namespace: {{ .Release.Namespace }}
---
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
name: {{ include "nginx-gateway.scc-name" . }}-cert-generator
labels:
{{- include "nginx-gateway.labels" . | nindent 4 }}
annotations:
"helm.sh/hook-weight": "-1"
"helm.sh/hook": pre-install
allowPrivilegeEscalation: false
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegedContainer: false
readOnlyRootFilesystem: true
runAsUser:
type: MustRunAsRange
uidRangeMin: 101
uidRangeMax: 101
fsGroup:
type: MustRunAs
ranges:
- min: 1001
max: 1001
supplementalGroups:
type: MustRunAs
ranges:
- min: 1001
max: 1001
seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
users:
- {{ printf "system:serviceaccount:%s:%s-cert-generator" .Release.Namespace (include "nginx-gateway.fullname" .) }}
requiredDropCapabilities:
- ALL
volumes:
- projected
---
{{- end }}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down
11 changes: 11 additions & 0 deletions charts/nginx-gateway-fabric/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,19 @@ rules:
- securitycontextconstraints
resourceNames:
- {{ include "nginx-gateway.scc-name" . }}
- {{ include "nginx-gateway.scc-name" . }}-nginx
verbs:
- use
- apiGroups:
- rbac.authorization.k8s.io
resources:
- roles
- rolebindings
verbs:
- create
- update
- delete
- list
- get
- watch
{{- end }}
3 changes: 3 additions & 0 deletions charts/nginx-gateway-fabric/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ spec:
{{- if .Values.nginxGateway.snippetsFilters.enable }}
- --snippets-filters
{{- end }}
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
- --nginx-scc={{ include "nginx-gateway.scc-name" . }}-nginx
{{- end}}
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
44 changes: 43 additions & 1 deletion charts/nginx-gateway-fabric/templates/scc.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# TODO(sberman): will need an SCC for nginx ServiceAccounts as well.
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
name: {{ include "nginx-gateway.scc-name" . }}
labels:
{{- include "nginx-gateway.labels" . | nindent 4 }}
allowPrivilegeEscalation: false
allowHostDirVolumePlugin: false
allowHostIPC: false
Expand Down Expand Up @@ -36,4 +37,45 @@ requiredDropCapabilities:
- ALL
volumes:
- secret
---
kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
name: {{ include "nginx-gateway.scc-name" . }}-nginx
labels:
{{- include "nginx-gateway.labels" . | nindent 4 }}
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegedContainer: false
readOnlyRootFilesystem: true
runAsUser:
type: MustRunAsRange
uidRangeMin: 101
uidRangeMax: 101
fsGroup:
type: MustRunAs
ranges:
- min: 1001
max: 1001
supplementalGroups:
type: MustRunAs
ranges:
- min: 1001
max: 1001
seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
allowedCapabilities:
- NET_BIND_SERVICE
requiredDropCapabilities:
- ALL
volumes:
- emptyDir
- secret
- configMap
- projected
{{- end }}
12 changes: 12 additions & 0 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
usageReportClientSSLSecretFlag = "usage-report-client-ssl-secret" //nolint:gosec // not credentials
usageReportCASecretFlag = "usage-report-ca-secret" //nolint:gosec // not credentials
snippetsFiltersFlag = "snippets-filters"
nginxSCCFlag = "nginx-scc"
)

// flag values
Expand All @@ -105,6 +106,9 @@
validator: validateResourceName,
value: agentTLSSecret,
}
nginxSCCName = stringValidatingValue{
validator: validateResourceName,
}
disableMetrics bool
metricsSecure bool
metricsListenPort = intValidatingValue{
Expand Down Expand Up @@ -264,6 +268,7 @@
SnippetsFilters: snippetsFilters,
NginxDockerSecretNames: nginxDockerSecrets.values,
AgentTLSSecretName: agentTLSSecretName.value,
NGINXSCCName: nginxSCCName.value,

Check warning on line 271 in cmd/gateway/commands.go

View check run for this annotation

Codecov / codecov/patch

cmd/gateway/commands.go#L271

Added line #L271 was not covered by tests
}

if err := static.StartManager(conf); err != nil {
Expand Down Expand Up @@ -457,6 +462,13 @@
"generated NGINX config for HTTPRoute and GRPCRoute resources.",
)

cmd.Flags().Var(
&nginxSCCName,
nginxSCCFlag,
`The name of the SecurityContextConstraints to be used with the NGINX data plane Pods.`+
` Only applicable in OpenShift.`,
)

return cmd
}

Expand Down
17 changes: 17 additions & 0 deletions cmd/gateway/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func TestControllerCmdFlagValidation(t *testing.T) {
"--usage-report-ca-secret=ca-secret",
"--usage-report-client-ssl-secret=client-secret",
"--snippets-filters",
"--nginx-scc=nginx-sscc-name",
},
wantErr: false,
},
Expand Down Expand Up @@ -445,6 +446,22 @@ func TestControllerCmdFlagValidation(t *testing.T) {
},
wantErr: true,
},
{
name: "nginx-scc is set to empty string",
args: []string{
"--nginx-scc=",
},
wantErr: true,
expectedErrPrefix: `invalid argument "" for "--nginx-scc" flag: must be set`,
},
{
name: "nginx-scc is invalid",
args: []string{
"--nginx-scc=!@#$",
},
wantErr: true,
expectedErrPrefix: `invalid argument "!@#$" for "--nginx-scc" flag: invalid format: `,
},
}

// common flags validation is tested separately
Expand Down
100 changes: 100 additions & 0 deletions deploy/openshift/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,22 @@ rules:
- security.openshift.io
resourceNames:
- nginx-gateway-scc
- nginx-gateway-scc-nginx
resources:
- securitycontextconstraints
verbs:
- use
- apiGroups:
- rbac.authorization.k8s.io
resources:
- roles
- rolebindings
verbs:
- create
- update
- delete
- list
- get
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -272,6 +283,7 @@ spec:
- --metrics-port=9113
- --health-port=8081
- --leader-election-lock-name=nginx-gateway-leader-election
- --nginx-scc=nginx-gateway-scc-nginx
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down Expand Up @@ -442,6 +454,10 @@ fsGroup:
type: MustRunAs
kind: SecurityContextConstraints
metadata:
labels:
app.kubernetes.io/instance: nginx-gateway
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/version: edge
name: nginx-gateway-scc
readOnlyRootFilesystem: true
requiredDropCapabilities:
Expand All @@ -463,3 +479,87 @@ users:
- system:serviceaccount:nginx-gateway:nginx-gateway
volumes:
- secret
---
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegeEscalation: false
allowPrivilegedContainer: false
apiVersion: security.openshift.io/v1
fsGroup:
ranges:
- max: 1001
min: 1001
type: MustRunAs
kind: SecurityContextConstraints
metadata:
labels:
app.kubernetes.io/instance: nginx-gateway
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/version: edge
name: nginx-gateway-scc-cert-generator
readOnlyRootFilesystem: true
requiredDropCapabilities:
- ALL
runAsUser:
type: MustRunAsRange
uidRangeMax: 101
uidRangeMin: 101
seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
supplementalGroups:
ranges:
- max: 1001
min: 1001
type: MustRunAs
users:
- system:serviceaccount:nginx-gateway:nginx-gateway-cert-generator
volumes:
- projected
---
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegedContainer: false
allowedCapabilities:
- NET_BIND_SERVICE
apiVersion: security.openshift.io/v1
fsGroup:
ranges:
- max: 1001
min: 1001
type: MustRunAs
kind: SecurityContextConstraints
metadata:
labels:
app.kubernetes.io/instance: nginx-gateway
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/version: edge
name: nginx-gateway-scc-nginx
readOnlyRootFilesystem: true
requiredDropCapabilities:
- ALL
runAsUser:
type: MustRunAsRange
uidRangeMax: 101
uidRangeMin: 101
seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
supplementalGroups:
ranges:
- max: 1001
min: 1001
type: MustRunAs
volumes:
- emptyDir
- secret
- configMap
- projected
2 changes: 2 additions & 0 deletions internal/mode/static/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Config struct {
GatewayClassName string
// AgentTLSSecretName is the name of the TLS Secret used by NGINX Agent to communicate with the control plane.
AgentTLSSecretName string
// NGINXSCCName is the name of the SecurityContextConstraints for the NGINX Pods. Only applicable in OpenShift.
NGINXSCCName string
// NginxDockerSecretNames are the names of any Docker registry Secrets for the NGINX container.
NginxDockerSecretNames []string
// LeaderElection contains the configuration for leader election.
Expand Down
3 changes: 3 additions & 0 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
authv1 "k8s.io/api/authentication/v1"
apiv1 "k8s.io/api/core/v1"
discoveryV1 "k8s.io/api/discovery/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -93,6 +94,7 @@
utilruntime.Must(apiext.AddToScheme(scheme))
utilruntime.Must(appsv1.AddToScheme(scheme))
utilruntime.Must(authv1.AddToScheme(scheme))
utilruntime.Must(rbacv1.AddToScheme(scheme))
}

func StartManager(cfg config.Config) error {
Expand Down Expand Up @@ -216,6 +218,7 @@
GatewayPodConfig: &cfg.GatewayPodConfig,
GCName: cfg.GatewayClassName,
AgentTLSSecretName: cfg.AgentTLSSecretName,
NGINXSCCName: cfg.NGINXSCCName,

Check warning on line 221 in internal/mode/static/manager.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/manager.go#L221

Added line #L221 was not covered by tests
Plus: cfg.Plus,
NginxDockerSecretNames: cfg.NginxDockerSecretNames,
PlusUsageConfig: &cfg.UsageReportConfig,
Expand Down
Loading
Loading