diff --git a/CHANGELOG.md b/CHANGELOG.md index 648ece4..e2b2aba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,17 @@ annotation in `charts/appwrite/Chart.yaml`. 3600 seconds by default, as before), so a lower interval frees their memory sooner. +### Changed + +- With `networkPolicy.enabled`, the entry points get one policy per port + number instead of one policy for the named port `http`: `-edge` + now selects the API and realtime on port 8080, and the new + `-edge-console` selects the console on port 3000. The same traffic + is admitted as before. This works around + [cloudnativelabs/kube-router#2226](https://github.com/cloudnativelabs/kube-router/issues/2226), + reported against the NetworkPolicy controller k3s ships: a policy that + admits a named port with two numbers can briefly reject new connections. + ### Security - Appwrite 2.7.3 (`appVersion`), rebuilt on `appwrite/base` 2.2.12, which updates libpq to 18.7 and clears the Appwrite image's high PostgreSQL findings. diff --git a/charts/appwrite/templates/networkpolicy/edge.yaml b/charts/appwrite/templates/networkpolicy/edge.yaml index 7936fc0..2c41d78 100644 --- a/charts/appwrite/templates/networkpolicy/edge.yaml +++ b/charts/appwrite/templates/networkpolicy/edge.yaml @@ -1,19 +1,32 @@ {{- if .Values.networkPolicy.enabled }} -{{- /* Entry points: reachable from the configured sources and from this release. */}} +{{- /* +Entry points: reachable from the configured sources and from this release. +One policy per port number, with the number instead of the port name "http": +that name is 8080 on the API and realtime and 3000 on the console, and +kube-router (the controller k3s ships) can briefly reject new connections +when one policy admits a named port with two numbers +(cloudnativelabs/kube-router#2226). The numbers are the containerPorts of +the three Deployments. The console comes first, so an upgrade creates its +policy before "edge" stops selecting it. +*/}} +{{- range list (dict "name" "edge-console" "components" (list "console") "port" 3000) (dict "name" "edge" "components" (list "api" "realtime") "port" 8080) }} +--- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy -{{ include "appwrite.networkPolicy.metadata" (dict "root" . "name" "edge") }} +{{ include "appwrite.networkPolicy.metadata" (dict "root" $ "name" .name) }} spec: podSelector: - {{- include "appwrite.networkPolicy.selector" (dict "root" . "components" (list "api" "console" "realtime")) | nindent 4 }} + {{- include "appwrite.networkPolicy.selector" (dict "root" $ "components" .components) | nindent 4 }} policyTypes: [Ingress] ingress: - ports: - - port: http - {{- with .Values.networkPolicy.ingress.from }} + - port: {{ .port }} + protocol: TCP + {{- with $.Values.networkPolicy.ingress.from }} from: {{- toYaml . | nindent 8 }} {{- end }} - from: - - {{- include "appwrite.networkPolicy.releasePeer" . | nindent 10 }} + - {{- include "appwrite.networkPolicy.releasePeer" $ | nindent 10 }} +{{- end }} {{- end }} diff --git a/charts/appwrite/tests/builds_test.yaml b/charts/appwrite/tests/builds_test.yaml index 0af66bf..3d8f36e 100644 --- a/charts/appwrite/tests/builds_test.yaml +++ b/charts/appwrite/tests/builds_test.yaml @@ -216,8 +216,15 @@ tests: - notContains: path: spec.ingress content: - ports: [{port: http}] + ports: [{port: 8080, protocol: TCP}] + from: [{namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: apps-builds}}}] + documentSelector: {path: metadata.name, value: aw-appwrite-edge} + - notContains: + path: spec.ingress + content: + ports: [{port: 3000, protocol: TCP}] from: [{namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: apps-builds}}}] + documentSelector: {path: metadata.name, value: aw-appwrite-edge-console} - it: lets build pods reach the API, and only the API template: templates/networkpolicy/builds-to-api.yaml diff --git a/charts/appwrite/tests/labels_test.yaml b/charts/appwrite/tests/labels_test.yaml index ca9af59..44bbbd6 100644 --- a/charts/appwrite/tests/labels_test.yaml +++ b/charts/appwrite/tests/labels_test.yaml @@ -2,6 +2,7 @@ suite: pod labels used by NetworkPolicies templates: - templates/api/deployment.yaml - templates/console/deployment.yaml + - templates/realtime/deployment.yaml release: name: aw values: @@ -27,3 +28,18 @@ tests: - contains: path: spec.template.spec.containers[0].env content: {name: VITE_EXTRA, value: "1"} + + - it: listens on the ports the edge NetworkPolicies admit by number + asserts: + - equal: + path: spec.template.spec.containers[0].ports + value: [{name: http, containerPort: 8080, protocol: TCP}] + template: templates/api/deployment.yaml + - equal: + path: spec.template.spec.containers[0].ports + value: [{name: http, containerPort: 8080, protocol: TCP}] + template: templates/realtime/deployment.yaml + - equal: + path: spec.template.spec.containers[0].ports + value: [{name: http, containerPort: 3000, protocol: TCP}] + template: templates/console/deployment.yaml diff --git a/charts/appwrite/tests/networkpolicy_test.yaml b/charts/appwrite/tests/networkpolicy_test.yaml index 7e309d8..5eb8dc4 100644 --- a/charts/appwrite/tests/networkpolicy_test.yaml +++ b/charts/appwrite/tests/networkpolicy_test.yaml @@ -33,14 +33,36 @@ tests: set: networkPolicy.enabled: true asserts: + - hasDocuments: + count: 2 - equal: path: spec.podSelector.matchExpressions[0].values - value: [api, console, realtime] + value: [api, realtime] + documentSelector: {path: metadata.name, value: aw-appwrite-edge} - equal: path: spec.ingress[0] value: ports: - - port: http + - port: 8080 + protocol: TCP + documentSelector: {path: metadata.name, value: aw-appwrite-edge} + - equal: + path: spec.podSelector.matchExpressions[0].values + value: [console] + documentSelector: {path: metadata.name, value: aw-appwrite-edge-console} + - equal: + path: spec.ingress[0] + value: + ports: + - port: 3000 + protocol: TCP + documentSelector: {path: metadata.name, value: aw-appwrite-edge-console} + - equal: + path: spec.ingress[1] + value: + from: + - podSelector: + matchLabels: {app.kubernetes.io/name: appwrite, app.kubernetes.io/instance: aw} - it: restricts the entry points to the configured sources template: templates/networkpolicy/edge.yaml diff --git a/docs/security.md b/docs/security.md index 8d63641..3c2de9e 100644 --- a/docs/security.md +++ b/docs/security.md @@ -276,7 +276,8 @@ which carry the label `appwrite/datastore-client: "true"`. | Policy | Selects | Allows in | | --- | --- | --- | -| `-edge` | API, console, realtime | `networkPolicy.ingress.from` on the HTTP port (any source when empty); pods of the release on any port | +| `-edge` | API, realtime | `networkPolicy.ingress.from` on port 8080 (any source when empty); pods of the release on any port | +| `-edge-console` | console | `networkPolicy.ingress.from` on port 3000 (any source when empty); pods of the release on any port | | `-builds-to-api` | API (`compute.enabled`) | build pods, on the HTTP port | | `-internal` | geo, browser, ExifTool, autogravity, embedding | pods of the release | | `-datastores` | PostgreSQL, Redis, ClickHouse | Appwrite pods of the release; on the metrics ports (`database.builtin.metrics.enabled` and the same under `redis` and `clickhouse`), also `networkPolicy.metrics.from` |