Skip to content
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 charts/netbird/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Each component renders `repository:tag`. Set `image.digest` (`sha256:...`) to re

Each component has a `rootless` value, `false` by default. Setting it to `true` applies the `restricted` Pod Security Standard to that component: `runAsNonRoot`, the `RuntimeDefault` seccomp profile, no privilege escalation, and no capabilities. The container also moves to an unprivileged port (dashboard and management `8080`, signal `10000`; relay always uses `33080`). The Service ports do not change.

The backend images default to root, so rootless management, signal and relay run as `65532:65532` with `fsGroup: 65532`. A rootless dashboard runs the `-rootless` variant of its tag (`v2.96.0` renders `v2.96.0-rootless`; published from `v2.95.0`), which runs as `10001:0` and listens on `8080`. A tag that already ends in `-rootless` is used as is, and `image.digest` is used as given, so it must be a rootless image's digest. [`examples/rootless`](../examples/rootless) enables every component:
The backend images default to root, so rootless management, signal and relay run as `65532:65532` with `fsGroup: 65532`. Their root filesystem is read-only (`readOnlyRootFilesystem: true`): management writes only to its data directory and to an `emptyDir` on `/tmp` (the geolocation download), and signal and relay write nothing unless their log file or Let's Encrypt data directory is set to a path, which then needs a volume through `volumes` and `volumeMounts`. The dashboard image rewrites its nginx config and html at start-up, so its root filesystem stays writable until the image changes. A rootless dashboard runs the `-rootless` variant of its tag (`v2.96.0` renders `v2.96.0-rootless`; published from `v2.95.0`), which runs as `10001:0` and listens on `8080`. A tag that already ends in `-rootless` is used as is, and `image.digest` is used as given, so it must be a rootless image's digest. [`examples/rootless`](../examples/rootless) enables every component:

```yaml
dashboard:
Expand Down
12 changes: 8 additions & 4 deletions charts/netbird/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@
{{- end -}}
{{- end -}}

{{/* Restricted Pod Security Standard defaults for rootless components. Context: kind (pod, backendPod or container). */}}
{{/* Restricted Pod Security Standard defaults for rootless components. Context: kind (pod, backendPod, container or backendContainer). */}}
{{- define "netbird.rootlessSecurityContext" -}}
{{- if eq .kind "container" -}}
{{- if has .kind (list "container" "backendContainer") -}}
allowPrivilegeEscalation: false
{{- if eq .kind "backendContainer" }}
{{- /* Not the dashboard: its image rewrites the nginx config and html at start-up. */}}
readOnlyRootFilesystem: true
{{- end }}
capabilities:
drop:
- ALL
Expand All @@ -67,7 +71,7 @@ seccompProfile:
Security context: the rootless defaults when rootless is set, then each key of
securityContext replaces its default (null removes it). Pod contexts lose
runAsUser, runAsGroup and fsGroup on OpenShift.
Context: root, rootless, kind (pod, backendPod or container), securityContext.
Context: root, rootless, kind (pod, backendPod, container or backendContainer), securityContext.
*/}}
{{- define "netbird.securityContext" -}}
{{- $context := dict -}}
Expand All @@ -81,7 +85,7 @@ Context: root, rootless, kind (pod, backendPod or container), securityContext.
{{- $_ := set $context $key $value -}}
{{- end -}}
{{- end -}}
{{- if ne .kind "container" -}}
{{- if not (has .kind (list "container" "backendContainer")) -}}
{{- $mode := .root.Values.global.compatibility.openshift.adaptSecurityContext -}}
{{- if not (has $mode (list "auto" "force" "disabled")) -}}
{{- fail (printf "global.compatibility.openshift.adaptSecurityContext must be auto, force or disabled, got %q" $mode) -}}
Expand Down
11 changes: 10 additions & 1 deletion charts/netbird/templates/split/management/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "container" "securityContext" $values.container.securityContext) | nindent 12 }}
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "backendContainer" "securityContext" $values.container.securityContext) | nindent 12 }}
{{- if or (not $values.overrideConfig) $values.env $values.envRaw $values.envFromSecret }}
env:
{{- if not $values.overrideConfig }}
Expand Down Expand Up @@ -125,6 +125,10 @@ spec:
subPath: management.json
- name: data
mountPath: {{ $values.persistence.mountPath }}
{{- if $values.rootless }}
- name: tmp
mountPath: /tmp
{{- end }}
{{- with $values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
Expand All @@ -140,6 +144,11 @@ spec:
{{- /* The image's data directory is root-owned; give the non-root user a writable one. */}}
emptyDir: {}
{{- end }}
{{- if $values.rootless }}
{{- /* The root filesystem is read-only; the geolocation download goes to /tmp. */}}
- name: tmp
emptyDir: {}
{{- end }}
{{- with $values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion charts/netbird/templates/split/relay/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "container" "securityContext" $values.container.securityContext) | nindent 12 }}
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "backendContainer" "securityContext" $values.container.securityContext) | nindent 12 }}
env:
- name: NB_AUTH_SECRET
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion charts/netbird/templates/split/signal/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "container" "securityContext" $values.container.securityContext) | nindent 12 }}
{{- include "netbird.securityContext" (dict "root" . "rootless" $values.rootless "kind" "backendContainer" "securityContext" $values.container.securityContext) | nindent 12 }}
{{- if or $values.config.pprofAddress $values.env $values.envRaw $values.envFromSecret }}
env:
{{- with $values.config.pprofAddress }}
Expand Down
5 changes: 5 additions & 0 deletions charts/netbird/tests/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ lacks "nodePort" "$out"
# 20. rootless is off by default: no security context, port 80.
out="$(render "${required[@]}")"
lacks "runAsNonRoot" "$out"
lacks "readOnlyRootFilesystem" "$out"; lacks "mountPath: /tmp" "$out"
test "$(grep -c "containerPort: 80$" <<<"$out")" = 3 || { echo "FAIL: want port 80 on dashboard, management and signal"; exit 1; }
has 'image: "netbirdio/dashboard:v2.96.0"' "$out"

Expand All @@ -138,6 +139,8 @@ out="$(render "${required[@]}" "${rootless[@]}")"
test "$(grep -c "runAsNonRoot: true" <<<"$out")" = 4 || { echo "FAIL: want runAsNonRoot on 4 pods"; exit 1; }
test "$(grep -c "allowPrivilegeEscalation: false" <<<"$out")" = 4 || { echo "FAIL: want allowPrivilegeEscalation false on 4 containers"; exit 1; }
test "$(grep -c "runAsUser: 65532" <<<"$out")" = 3 || { echo "FAIL: want runAsUser on 3 backend pods"; exit 1; }
test "$(grep -c "readOnlyRootFilesystem: true" <<<"$out")" = 3 || { echo "FAIL: want a read-only root filesystem on 3 backend containers"; exit 1; }
test "$(grep -c "mountPath: /tmp$" <<<"$out")" = 1 || { echo "FAIL: want /tmp on management only"; exit 1; }
test "$(grep -c "containerPort: 8080$" <<<"$out")" = 2 || { echo "FAIL: want port 8080 on dashboard and management"; exit 1; }
has "containerPort: 10000" "$out"
has 'image: "netbirdio/dashboard:v2.96.0-rootless"' "$out"
Expand All @@ -158,6 +161,8 @@ out="$(render "${required[@]}" --set backend.split.signal.rootless=true \
--set backend.split.signal.container.port=9999 --show-only templates/split/signal/deployment.yaml)"
has "runAsUser: 1000" "$out"; has "runAsGroup: 65532" "$out"; lacks "fsGroup" "$out"
has "containerPort: 9999" "$out"; has "--port=9999" "$out"
out="$(render "${required[@]}" --set backend.split.management.rootless=true --set backend.split.management.container.securityContext.readOnlyRootFilesystem=null --show-only templates/split/management/deployment.yaml)"
lacks "readOnlyRootFilesystem" "$out"; has "allowPrivilegeEscalation: false" "$out"

# 20d. A rootless dashboard runs the -rootless tag variant; an explicit variant or a digest is kept.
out="$(render "${required[@]}" --set dashboard.rootless=true --set dashboard.image.tag=v2.96.0-rootless --show-only templates/dashboard/deployment.yaml)"
Expand Down
14 changes: 8 additions & 6 deletions charts/netbird/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dashboard:
replicaCount: 1
# Restricted Pod Security Standard defaults, merged under pod and container
# securityContext, container port 8080, and the image tag's -rootless variant
# (image.digest must already be one). See examples/rootless.
# (image.digest must already be one). The root filesystem stays writable: the
# image rewrites its nginx config and html at start-up. See examples/rootless.
rootless: false

image:
Expand Down Expand Up @@ -124,7 +125,8 @@ backend:
namespace: ""
replicaCount: 1
# Restricted Pod Security Standard defaults, merged under pod and container
# securityContext: non-root user 65532 with fsGroup, and container port 8080.
# securityContext: non-root user 65532 with fsGroup, a read-only root
# filesystem with an emptyDir on /tmp, and container port 8080.
# See examples/rootless.
rootless: false

Expand Down Expand Up @@ -339,8 +341,8 @@ backend:
namespace: ""
replicaCount: 1
# Restricted Pod Security Standard defaults, merged under pod and container
# securityContext: non-root user 65532 with fsGroup, and container port 10000.
# See examples/rootless.
# securityContext: non-root user 65532 with fsGroup, a read-only root
# filesystem, and container port 10000. See examples/rootless.
rootless: false

image:
Expand Down Expand Up @@ -439,8 +441,8 @@ backend:
namespace: ""
replicaCount: 1
# Restricted Pod Security Standard defaults, merged under pod and container
# securityContext: non-root user 65532 with fsGroup.
# See examples/rootless.
# securityContext: non-root user 65532 with fsGroup and a read-only root
# filesystem. See examples/rootless.
rootless: false

image:
Expand Down
Loading