Skip to content
Open
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`: `<fullname>-edge`
now selects the API and realtime on port 8080, and the new
`<fullname>-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.
Expand Down
25 changes: 19 additions & 6 deletions charts/appwrite/templates/networkpolicy/edge.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 8 additions & 1 deletion charts/appwrite/tests/builds_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions charts/appwrite/tests/labels_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
26 changes: 24 additions & 2 deletions charts/appwrite/tests/networkpolicy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ which carry the label `appwrite/datastore-client: "true"`.

| Policy | Selects | Allows in |
| --- | --- | --- |
| `<fullname>-edge` | API, console, realtime | `networkPolicy.ingress.from` on the HTTP port (any source when empty); pods of the release on any port |
| `<fullname>-edge` | API, realtime | `networkPolicy.ingress.from` on port 8080 (any source when empty); pods of the release on any port |
| `<fullname>-edge-console` | console | `networkPolicy.ingress.from` on port 3000 (any source when empty); pods of the release on any port |
| `<fullname>-builds-to-api` | API (`compute.enabled`) | build pods, on the HTTP port |
| `<fullname>-internal` | geo, browser, ExifTool, autogravity, embedding | pods of the release |
| `<fullname>-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` |
Expand Down
Loading