Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP/DP Split: write configuration to agent #2999

Draft
wants to merge 7 commits into
base: change/control-data-plane-split
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FROM golang:1.23 AS ca-certs-provider
FROM scratch AS common
# CA certs are needed for telemetry report so that NGF can verify the server's certificate.
COPY --from=ca-certs-provider --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
USER 102:1001
USER 101:1001
ARG BUILD_AGENT
ENV BUILD_AGENT=${BUILD_AGENT}
ENTRYPOINT [ "/usr/bin/gateway" ]
Expand Down
1 change: 0 additions & 1 deletion charts/nginx-gateway-fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
| `nginx.image.tag` | | string | `"edge"` |
| `nginx.lifecycle` | The lifecycle of the nginx container. | object | `{}` |
| `nginx.plus` | Is NGINX Plus image being used | bool | `false` |
| `nginx.securityContext.allowPrivilegeEscalation` | Some environments may need this set to true in order for the control plane to successfully reload NGINX. | bool | `false` |
| `nginx.usage.caSecretName` | The name of the Secret containing the NGINX Instance Manager CA certificate. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `""` |
| `nginx.usage.clientSSLSecretName` | The name of the Secret containing the client certificate and key for authenticating with NGINX Instance Manager. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `""` |
| `nginx.usage.endpoint` | The endpoint of the NGINX Plus usage reporting server. Default: product.connect.nginx.com | string | `""` |
Expand Down
16 changes: 1 addition & 15 deletions charts/nginx-gateway-fabric/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,21 @@ rules:
- namespaces
- services
- secrets
- pods
{{- if .Values.nginxGateway.gwAPIExperimentalFeatures.enable }}
- configmaps
{{- end }}
verbs:
- get
- list
- watch
{{- if or .Values.nginxGateway.productTelemetry.enable .Values.nginx.plus }}
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
{{- end }}
{{- if .Values.nginx.plus }}
- apiGroups:
- apps
resources:
- replicasets
verbs:
- list
{{- end }}
{{- if or .Values.nginxGateway.productTelemetry.enable .Values.nginx.plus }}
- apiGroups:
- ""
Expand Down
3 changes: 2 additions & 1 deletion charts/nginx-gateway-fabric/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ spec:
capabilities:
drop:
- ALL
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 102
runAsUser: 101
runAsGroup: 1001
{{- with .Values.nginxGateway.extraVolumeMounts -}}
{{ toYaml . | nindent 8 }}
Expand Down
13 changes: 3 additions & 10 deletions 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" . }}
allowPrivilegeEscalation: {{ .Values.nginx.securityContext.allowPrivilegeEscalation }}
allowPrivilegeEscalation: false
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
Expand All @@ -14,7 +15,7 @@ readOnlyRootFilesystem: true
runAsUser:
type: MustRunAsRange
uidRangeMin: 101
uidRangeMax: 102
uidRangeMax: 101
fsGroup:
type: MustRunAs
ranges:
Expand All @@ -29,16 +30,8 @@ seLinuxContext:
type: MustRunAs
seccompProfiles:
- runtime/default
volumes:
- emptyDir
- secret
- configMap
- projected
users:
- {{ printf "system:serviceaccount:%s:%s" .Release.Namespace (include "nginx-gateway.serviceAccountName" .) }}
allowedCapabilities:
- NET_BIND_SERVICE
- KILL
requiredDropCapabilities:
- ALL
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ data:
- /var/run/nginx
features:
- connection
- configuration
- certificates
- metrics
{{- if .Values.nginx.plus }}
- api-action
{{- end }}
log:
level: debug
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
command:
- /usr/bin/gateway
- sleep
- --duration=15s
- --duration=5s
- name: init
image: {{ .Values.nginxGateway.image.repository }}:{{ default .Chart.AppVersion .Values.nginxGateway.image.tag }}
imagePullPolicy: {{ .Values.nginxGateway.image.pullPolicy }}
Expand Down Expand Up @@ -49,7 +49,7 @@ spec:
drop:
- ALL
readOnlyRootFilesystem: true
runAsUser: 102
runAsUser: 101
runAsGroup: 1001
volumeMounts:
- name: nginx-includes-bootstrap
Expand All @@ -72,13 +72,12 @@ spec:
securityContext:
seccompProfile:
type: RuntimeDefault
allowPrivilegeEscalation: {{ .Values.nginx.securityContext.allowPrivilegeEscalation }}
capabilities:
add:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
# readOnlyRootFilesystem: true
runAsUser: 101
runAsGroup: 1001
volumeMounts:
Expand Down
14 changes: 0 additions & 14 deletions charts/nginx-gateway-fabric/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,6 @@
"title": "plus",
"type": "boolean"
},
"securityContext": {
"properties": {
"allowPrivilegeEscalation": {
"default": false,
"description": "Some environments may need this set to true in order for the control plane to successfully reload NGINX.",
"required": [],
"title": "allowPrivilegeEscalation",
"type": "boolean"
}
},
"required": [],
"title": "securityContext",
"type": "object"
},
"usage": {
"description": "Configuration for NGINX Plus usage reporting.",
"properties": {
Expand Down
4 changes: 0 additions & 4 deletions charts/nginx-gateway-fabric/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ nginx:
# @schema
pullPolicy: Always

securityContext:
# -- Some environments may need this set to true in order for the control plane to successfully reload NGINX.
allowPrivilegeEscalation: false

# -- Is NGINX Plus image being used
plus: false

Expand Down
7 changes: 6 additions & 1 deletion cmd/gateway/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -58,7 +59,7 @@ func initialize(cfg initializeConfig) error {
return fmt.Errorf("failed to generate deployment context file: %w", err)
}

if err := file.Write(cfg.fileManager, depCtxFile); err != nil {
if err := file.Write(cfg.fileManager, file.Convert(depCtxFile)); err != nil {
return fmt.Errorf("failed to write deployment context file: %w", err)
}

Expand All @@ -84,5 +85,9 @@ func copyFile(osFileManager file.OSFileManager, src, dest string) error {
return fmt.Errorf("error copying file contents: %w", err)
}

if err := osFileManager.Chmod(destFile, os.FileMode(file.RegularFileModeInt)); err != nil {
return fmt.Errorf("error setting file permissions: %w", err)
}

return nil
}
12 changes: 11 additions & 1 deletion cmd/gateway/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestInitialize_Plus(t *testing.T) {
g.Expect(fakeGenerator.GenerateDeploymentContextArgsForCall(0)).To(Equal(test.depCtx))
g.Expect(fakeCollector.CollectCallCount()).To(Equal(1))
g.Expect(fakeFileMgr.WriteCallCount()).To(Equal(1))
g.Expect(fakeFileMgr.ChmodCallCount()).To(Equal(1))
g.Expect(fakeFileMgr.ChmodCallCount()).To(Equal(3))
})
}
}
Expand Down Expand Up @@ -161,6 +161,7 @@ func TestCopyFileErrors(t *testing.T) {
openErr := errors.New("open error")
createErr := errors.New("create error")
copyErr := errors.New("copy error")
chmodErr := errors.New("chmod error")

tests := []struct {
fileMgr *filefakes.FakeOSFileManager
Expand Down Expand Up @@ -194,6 +195,15 @@ func TestCopyFileErrors(t *testing.T) {
},
expErr: copyErr,
},
{
name: "can't set permissions",
fileMgr: &filefakes.FakeOSFileManager{
ChmodStub: func(_ *os.File, _ os.FileMode) error {
return chmodErr
},
},
expErr: chmodErr,
},
}

for _, test := range tests {
Expand Down
3 changes: 2 additions & 1 deletion config/tests/static-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ spec:
capabilities:
drop:
- ALL
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 102
runAsUser: 101
runAsGroup: 1001
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
Expand Down
20 changes: 9 additions & 11 deletions deploy/aws-nlb/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ rules:
- namespaces
- services
- secrets
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- list
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -157,6 +153,9 @@ data:
- /var/run/nginx
features:
- connection
- configuration
- certificates
- metrics
log:
level: debug
kind: ConfigMap
Expand Down Expand Up @@ -293,12 +292,13 @@ spec:
initialDelaySeconds: 3
periodSeconds: 1
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 1001
runAsUser: 102
runAsUser: 101
seccompProfile:
type: RuntimeDefault
securityContext:
Expand Down Expand Up @@ -333,13 +333,11 @@ spec:
- containerPort: 443
name: https
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 1001
runAsUser: 101
seccompProfile:
Expand All @@ -365,7 +363,7 @@ spec:
- command:
- /usr/bin/gateway
- sleep
- --duration=15s
- --duration=5s
image: ghcr.io/nginxinc/nginx-gateway-fabric:edge
imagePullPolicy: Always
name: sleep
Expand All @@ -390,7 +388,7 @@ spec:
- ALL
readOnlyRootFilesystem: true
runAsGroup: 1001
runAsUser: 102
runAsUser: 101
seccompProfile:
type: RuntimeDefault
volumeMounts:
Expand Down
Loading
Loading