helm: reload S3 identities with a SIGHUP sidecar instead of restarting (#12945)

* helm: reload S3 identities with a SIGHUP sidecar instead of restarting

The chart restarts the filer and S3 pods when the content of
existingConfigSecret changes, so every identity change briefly takes S3
down, completely so with a single filer. SeaweedFS reloads the identities
file on SIGHUP.

filer.s3.configReloader and s3.configReloader, off by default, add an
s3-config-reloader sidecar that sends SIGHUP to SeaweedFS when kubelet
updates the mounted file, turn on shareProcessNamespace, and stop
hashing the existing Secret into checksum/s3config. The sidecar uses the
component's image and container security context, so it runs as the same
user as SeaweedFS, and it logs a warning when it cannot signal it.

* helm: address review of the S3 config reloader

- Default the configReloader map to dict, so a release upgraded with
  --reuse-values from a chart without it still renders.
- With the reloader and existingConfigSecret, leave checksum/s3config off
  the pod, so values of the Secret the chart generates cannot restart it.
- README: the restart comes from the next Helm upgrade, the timing holds
  for the kubelet's default settings, and a reload re-creates the KMS
  providers, which replaces the in-memory keys of the local provider.

* helm: describe Secret propagation as eventually consistent

Kubernetes gives no bound on when a Secret volume is updated, so the README gives typical delays instead, and says a revoked identity keeps working until then.
This commit is contained in:
Salomon Henke Andersen authored and GitHub committed 2026-11-24 15:55:11 -08:00
1 parent fe816eaac8
commit 85fcde9b0d
6 files changed
+180 -2

No files matched your search

+44
View File
@@ -162,6 +162,50 @@ jobs:
done
echo "shareProcessNamespace renders correctly"
echo "=== Testing the S3 config reloader ==="
for workload in filer.s3:templates/filer/filer-statefulset.yaml s3:templates/s3/s3-deployment.yaml; do
prefix=${workload%%:*}
template=${workload#*:}
component=${prefix%%.*}
reloader_args=(--set "$prefix.enabled=true" --set "$prefix.enableAuth=true"
--set "$prefix.existingConfigSecret=s3-identities"
--set "$component.containerSecurityContext.enabled=true"
--set "$component.containerSecurityContext.runAsUser=1000")
helm template test $CHART_DIR --show-only "$template" "${reloader_args[@]}" > /tmp/reloader-off.yaml
test "$(grep -c 's3-config-reloader\|shareProcessNamespace' /tmp/reloader-off.yaml)" -eq 0
helm template test $CHART_DIR --show-only "$template" "${reloader_args[@]}" \
--set "$prefix.configReloader.enabled=true" \
--set "$prefix.configReloader.resources.limits.memory=32Mi" > /tmp/reloader-on.yaml
python3 - /tmp/reloader-off.yaml /tmp/reloader-on.yaml <<'PYEOF'
import sys, yaml
off, on = (yaml.safe_load(open(path)) for path in sys.argv[1:])
pod = on["spec"]["template"]["spec"]
main = pod["containers"][0]
reloader = next(c for c in pod["containers"] if c["name"] == "s3-config-reloader")
assert pod["shareProcessNamespace"] is True
assert reloader["image"] == main["image"]
# It must run as the same user as SeaweedFS to signal it.
assert reloader["securityContext"] == main["securityContext"], reloader.get("securityContext")
assert {"name": "config-users", "mountPath": "/etc/sw", "readOnly": True} in reloader["volumeMounts"]
assert reloader["resources"] == {"limits": {"memory": "32Mi"}}
# Without the reloader, the checksum hashes the existing Secret, so a change to it restarts the pod.
# With it, nothing may: not the Secret, and not the values of the Secret the chart generates.
annotations = lambda d: d["spec"]["template"]["metadata"].get("annotations") or {}
assert "checksum/s3config" in annotations(off)
assert "checksum/s3config" not in annotations(on), annotations(on)
PYEOF
# A release from a chart without configReloader, upgraded with --reuse-values, has no such map.
helm template test $CHART_DIR --show-only "$template" "${reloader_args[@]}" \
--set "$prefix.configReloader=null" > /tmp/reloader-old-values.yaml
test "$(grep -c 's3-config-reloader' /tmp/reloader-old-values.yaml)" -eq 0
if helm template test $CHART_DIR --show-only "$template" \
--set "$prefix.enabled=true" --set "$prefix.configReloader.enabled=true" > /tmp/reloader-noauth.yaml 2>&1; then
echo "FAIL: $prefix.configReloader rendered without $prefix.enableAuth"; exit 1
fi
grep -q "configReloader.enabled needs" /tmp/reloader-noauth.yaml
done
echo "S3 config reloader renders correctly"
echo "=== Testing the S3 config checksum is stable across renders ==="
# s3-secret.yaml keeps its generated keys with lookup. Hashing the rendered
# Secret drew new keys for the checksum whenever lookup found nothing (on
+41
View File
@@ -330,6 +330,47 @@ applies. Rotating a key in the Secret takes effect on the next pod restart, as
with any other environment variable. The COSI driver parses the config itself
and does not resolve these references.
#### Reload identities without a restart
The chart hashes `existingConfigSecret` into the filer and S3 pod templates when it renders,
so the first Helm upgrade after the Secret's content changes restarts those pods, and every
identity change briefly takes S3 down, completely so with a single filer. SeaweedFS also
reloads the identities file on SIGHUP, which `configReloader` uses instead:
```yaml
filer:
s3:
enabled: true
enableAuth: true
existingConfigSecret: my-s3-identities
configReloader:
enabled: true
```
`s3.configReloader` does the same for the standalone S3 gateway. With it:
- An `s3-config-reloader` sidecar checks the mounted identities file every second, and
sends SIGHUP to SeaweedFS when it changes and once when it starts. Kubelet updates the
file at its next sync of the pod. Secret volumes are eventually consistent, so there is no
fixed bound: with the kubelet's default settings (a one-minute sync period and the `Watch`
Secret change detection strategy) it typically takes up to about 90 seconds, and changing
an annotation on the pod usually brings it down to seconds. Other kubelet settings can make
it slower. Until the file is updated, a revoked identity keeps working.
- Changes to the content of `existingConfigSecret` no longer restart the pod: the chart
leaves `checksum/s3config` off it. Adding, changing, disabling and deleting identities
apply without a restart. Other files in the Secret, such as an audit log config, still
need one, and so do changes to the values the chart generates its own Secret from, such
as `s3.credentials`.
- Every reload also re-creates the KMS providers configured in the identities file. The
`local` provider keeps its keys in memory, so a reload replaces them, as a restart does;
use another provider for objects that must stay readable.
- The pod shares its process namespace (see [Sharing the process namespace](#sharing-the-process-namespace)),
so the sidecar can see SeaweedFS. It uses the component's image and container security
context, because it must run as the same user as SeaweedFS to signal it. If it can't
signal SeaweedFS, it logs a warning.
The all-in-one deployment does not have this option.
## Admin Component
The admin component provides a modern web-based administration interface for managing SeaweedFS clusters. It includes:
@@ -4,6 +4,10 @@
{{- if .Values.filer.s3.enabled }}
{{- $s3PreStopSeconds = .Values.filer.s3.preStopSeconds | int }}
{{- end }}
{{- $s3ConfigReloader := (.Values.filer.s3.configReloader | default dict).enabled }}
{{- if and $s3ConfigReloader (not (and .Values.filer.s3.enabled .Values.filer.s3.enableAuth)) }}
{{- fail "filer.s3.configReloader.enabled needs filer.s3.enabled and filer.s3.enableAuth: it reloads the identities file they mount" }}
{{- end }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
@@ -50,8 +54,11 @@ spec:
{{- end }}
{{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.filer.podAnnotations | default dict) }}
{{- if .Values.filer.s3.existingConfigSecret }}
{{- /* With the config reloader, a change to the existing Secret is applied by SIGHUP, so nothing in it may restart the pod. */}}
{{- if not $s3ConfigReloader }}
{{- $configSecret := (lookup "v1" "Secret" (include "seaweedfs.namespace" .) .Values.filer.s3.existingConfigSecret) | default dict }}
{{- $_ := set $podAnnotations "checksum/s3config" ($configSecret | toYaml | sha256sum) }}
{{- end }}
{{- else }}
{{- $_ := set $podAnnotations "checksum/s3config" (include "seaweedfs.s3.configChecksum" .) }}
{{- end }}
@@ -82,7 +89,7 @@ spec:
schedulerName: {{ .Values.filer.schedulerName | quote }}
{{- end }}
enableServiceLinks: false
{{- if .Values.filer.shareProcessNamespace }}
{{- if or .Values.filer.shareProcessNamespace $s3ConfigReloader }}
shareProcessNamespace: true
{{- end }}
{{- if .Values.filer.initContainers }}
@@ -400,6 +407,9 @@ spec:
{{- if .Values.filer.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.filer.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if $s3ConfigReloader }}
{{- include "seaweedfs.s3.configReloaderContainer" (dict "root" $ "image" (include "seaweedfs.filer.image" .) "port" .Values.filer.s3.port "resources" .Values.filer.s3.configReloader.resources "securityContext" .Values.filer.containerSecurityContext) | nindent 8 }}
{{- end }}
{{- if .Values.filer.sidecars }}
{{- include "seaweedfs.tplvalues.render" (dict "value" .Values.filer.sidecars "context" $) | nindent 8 }}
{{- end }}
@@ -1,6 +1,10 @@
{{- include "seaweedfs.compat" . -}}
{{- if .Values.s3.enabled }}
{{- $preStopSeconds := .Values.s3.preStopSeconds | int }}
{{- $s3ConfigReloader := (.Values.s3.configReloader | default dict).enabled }}
{{- if and $s3ConfigReloader (not .Values.s3.enableAuth) }}
{{- fail "s3.configReloader.enabled needs s3.enableAuth: it reloads the identities file that mounts" }}
{{- end }}
{{- $minGracePeriod := add $preStopSeconds 15 }}
{{- if and (gt $preStopSeconds 0) (lt (.Values.s3.terminationGracePeriodSeconds | int) $minGracePeriod) }}
{{- fail (printf "s3.terminationGracePeriodSeconds (%v) must be at least %d: the gateway keeps serving for s3.preStopSeconds (%d) after SIGTERM, then gives in-flight requests up to 15s to finish; add the time any s3.lifecycle.preStop hook takes" .Values.s3.terminationGracePeriodSeconds $minGracePeriod $preStopSeconds) -}}
@@ -47,8 +51,11 @@ spec:
{{- end }}
{{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.s3.podAnnotations | default dict) }}
{{- if .Values.s3.existingConfigSecret }}
{{- /* With the config reloader, a change to the existing Secret is applied by SIGHUP, so nothing in it may restart the pod. */}}
{{- if not $s3ConfigReloader }}
{{- $configSecret := (lookup "v1" "Secret" (include "seaweedfs.namespace" .) .Values.s3.existingConfigSecret) | default dict }}
{{- $_ := set $podAnnotations "checksum/s3config" ($configSecret | toYaml | sha256sum) }}
{{- end }}
{{- else }}
{{- $_ := set $podAnnotations "checksum/s3config" (include "seaweedfs.s3.configChecksum" .) }}
{{- end }}
@@ -78,7 +85,7 @@ spec:
schedulerName: {{ .Values.s3.schedulerName | quote }}
{{- end }}
enableServiceLinks: false
{{- if .Values.s3.shareProcessNamespace }}
{{- if or .Values.s3.shareProcessNamespace $s3ConfigReloader }}
shareProcessNamespace: true
{{- end }}
{{- if .Values.s3.serviceAccountName }}
@@ -265,6 +272,9 @@ spec:
{{- if .Values.s3.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.s3.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if $s3ConfigReloader }}
{{- include "seaweedfs.s3.configReloaderContainer" (dict "root" $ "image" (include "seaweedfs.s3.image" .) "port" .Values.s3.port "resources" .Values.s3.configReloader.resources "securityContext" .Values.s3.containerSecurityContext) | nindent 8 }}
{{- end }}
{{- if .Values.s3.sidecars }}
{{- include "seaweedfs.tplvalues.render" (dict "value" .Values.s3.sidecars "context" $) | nindent 8 }}
{{- end }}
@@ -789,6 +789,65 @@ on install.
| toJson | sha256sum -}}
{{- end -}}
{{/*
The s3-config-reloader sidecar of the filer and S3 pods. It checks the mounted identities file every
second and sends SIGHUP to SeaweedFS when it changes, so SeaweedFS loads it again without a restart.
It only signals once SeaweedFS listens on its S3 port, because SeaweedFS registers the reload when it
starts serving S3, and it sends one SIGHUP when it starts, which catches changes made while it was not
running. It needs the pod's process namespace to see SeaweedFS, and the same user to signal it, so it
uses the component's image and container security context.
Usage: include "seaweedfs.s3.configReloaderContainer" (dict "root" $ "image" <image> "port" <S3 port>
"resources" <resources> "securityContext" <the component's containerSecurityContext>)
*/}}
{{- define "seaweedfs.s3.configReloaderContainer" -}}
- name: s3-config-reloader
image: {{ .image }}
imagePullPolicy: {{ default "IfNotPresent" .root.Values.global.seaweedfs.imagePullPolicy }}
command:
- /bin/sh
- -c
- |
config_file=/etc/sw/seaweedfs_s3_config
# /proc/net/tcp lists ports in hex, and 0A is the state LISTEN.
s3_port=$(printf '%04X' {{ .port }})
last_hash=""
warned=""
while sleep 1; do
current_hash=$(sha256sum "$config_file" 2>/dev/null | cut -d' ' -f1)
if [ -z "$current_hash" ] || [ "$current_hash" = "$last_hash" ]; then
continue
fi
if ! grep -qE ":$s3_port [0-9A-F]+:[0-9A-F]+ 0A " /proc/net/tcp /proc/net/tcp6 2>/dev/null; then
continue
fi
signalled=""
for process_dir in /proc/[0-9]*; do
if [ "$(cat "$process_dir/comm" 2>/dev/null)" = "weed" ] && kill -HUP "${process_dir#/proc/}" 2>/dev/null; then
echo "S3 config changed (sha256 $current_hash), sent SIGHUP to weed (PID ${process_dir#/proc/})"
signalled=1
fi
done
if [ -n "$signalled" ]; then
last_hash=$current_hash
warned=""
elif [ -z "$warned" ]; then
echo "S3 config changed, but no weed process is visible: the pod must share its process namespace, and the sidecar must run as the same user as SeaweedFS" >&2
warned=1
fi
done
volumeMounts:
- name: config-users
mountPath: /etc/sw
readOnly: true
{{- with .resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if .securityContext.enabled }}
securityContext: {{- omit .securityContext "enabled" | toYaml | nindent 4 }}
{{- end }}
{{- end -}}
{{/* Master ConfigMap checksum, ignoring commonLabels so labels do not roll the pods */}}
{{- define "seaweedfs.master.configChecksum" -}}
{{- $context := merge (dict "Values" (omit .Values "commonLabels")) (omit . "Values") -}}
+14
View File
@@ -1096,6 +1096,13 @@ filer:
# set to the name of an existing kubernetes Secret with the s3 json config file
# should have a secret key called seaweedfs_s3_config with an inline json configure
existingConfigSecret: null
# Reload the identities file without restarting the filer: a sidecar sends
# SIGHUP to SeaweedFS when kubelet updates the mounted config Secret, and the
# pod no longer restarts when the content of existingConfigSecret changes.
# Needs enableAuth, and turns on shareProcessNamespace. See the README.
configReloader:
enabled: false
resources: {}
# To provide explicit credentials for the S3 gateway, set them under
# the top-level s3.credentials key (not filer.s3.credentials).
# The s3-secret.yaml template only reads from .Values.s3.credentials.
@@ -1174,6 +1181,13 @@ s3:
# set to the name of an existing kubernetes Secret with the s3 json config file
# should have a secret key called seaweedfs_s3_config with an inline json config
existingConfigSecret: null
# Reload the identities file without restarting the gateway: a sidecar sends
# SIGHUP to SeaweedFS when kubelet updates the mounted config Secret, and the
# pod no longer restarts when the content of existingConfigSecret changes.
# Needs enableAuth, and turns on shareProcessNamespace. See the README.
configReloader:
enabled: false
resources: {}
# Optionally provide explicit credentials for the S3 gateway.
# When set, these are used in the generated s3 secret instead of
# auto-generating random credentials.