feat(platform): migrate Redis and Valkey passwords to minted credentials

The converted charts stop rendering <release>-auth and point the
operator at the account Secret of the default credential. Without a
migration that Secret would be seeded with a new random password, and
every existing client, and the running servers, would lose the one they
have.

Migrations 69 (Redis) and 70 (Valkey) seed that Secret from the password
in <release>-auth before the charts switch, so the operator finds the
same password under the new name; then a finish Job per kind deletes
whatever is left of the old Secret. Each Job's ClusterRole,
ServiceAccount and binding are named for its migration, so the two
conversions in one upgrade share none.

Both hold every release of their kind, suspended, until the
redis-operator Deployment runs its new revision, and the finish Jobs,
which may read Deployments, resume them. The new chart changes the pod
template, and the old operator rolls such a change by deleting the
master, which failed client writes for up to 78 s per instance on a test
cluster before the new operator, which moves the master off first and
applies the password without a restart, had started.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
Andrei Kvapil committed 2026-12-02 20:38:26 +01:00
1 parent 5f9d6b9a87
commit 94807d93f3
6 files changed
+672 -1

No files matched your search

@@ -0,0 +1,22 @@
#!/bin/sh
# Fake credentials-migrate for hack/migration-69-70-redis-valkey-credentials.bats.
# Migrations 69 and 70 run `credentials-migrate seed` in the hook; the real binary is
# exercised by cmd/credentials-migrate's Go tests, so this fake only records the
# call and fails on demand to pin the hook's fail-closed behaviour.
#
# FAKE_CMDLOG file to append a one-line record of each call to
# FAKE_SEED_FAIL non-empty => `seed` exits 1 with this stderr
set -u
[ -n "${FAKE_CMDLOG:-}" ] && printf 'CREDMIGRATE %s\n' "$*" >> "$FAKE_CMDLOG"
case "${1:-}" in
seed)
if [ -n "${FAKE_SEED_FAIL:-}" ]; then
printf '%s\n' "$FAKE_SEED_FAIL" >&2
exit 1
fi
exit 0
;;
esac
exit 0
+119
View File
@@ -0,0 +1,119 @@
#!/bin/sh
# Fake kubectl for hack/migration-69-70-redis-valkey-credentials.bats, the
# one hack/testdata/migration-64-postgres-credentials/kubectl is with the
# migration number taken from $FAKE_MIGRATION. It serves only the calls
# migrations 69 and 70 and lib/cozystack-version.sh make, and logs each one
# to $FAKE_CMDLOG.
#
# Each migration reads its own pod's image, applies the finish Job (with its
# ServiceAccount and ClusterRoleBinding), and stamps the version. The Job
# manifest and the version stamp both arrive as `apply --filename -`, so this
# fake reads stdin and branches on the manifest's kind.
#
# FAKE_MIGRATION number of the migration under test
# FAKE_CMDLOG file to append a one-line record of each call to
# FAKE_IMAGE image the `get pod` call returns (default a test ref)
# FAKE_IMAGE_EMPTY non-empty => `get pod` returns an empty image
# FAKE_GETPOD_FAIL non-empty => `get pod` exits 1 with this stderr
# FAKE_APPLY_FAIL non-empty => applying the Job exits 1 with this stderr
set -u
log() { [ -n "${FAKE_CMDLOG:-}" ] && printf '%s\n' "$*" >> "$FAKE_CMDLOG"; }
log "KUBECTL $*"
args="$*"
IMAGE="${FAKE_IMAGE:-registry.example.org/cozystack/cozystack:v1.7.0}"
N="${FAKE_MIGRATION:?FAKE_MIGRATION is required}"
NAME="cozystack-credentials-migration-$N"
case "$args" in
*"get pod"*jsonpath*)
if [ -n "${FAKE_GETPOD_FAIL:-}" ]; then
printf '%s\n' "$FAKE_GETPOD_FAIL" >&2
exit 1
fi
[ -n "${FAKE_IMAGE_EMPTY:-}" ] || printf '%s' "$IMAGE"
exit 0
;;
*"delete job $NAME "*)
# The hook deletes a Job left by an earlier run before recreating it.
log "DELETE-JOB"
exit 0
;;
*"delete serviceaccount $NAME "*)
# The hook deletes a ServiceAccount left owned by the Job it just deleted,
# so the apply recreates a fresh, owner-less one.
log "DELETE-SA"
exit 0
;;
*"get job $NAME "*jsonpath*)
# The hook reads the Job's uid to own its ServiceAccount.
if [ -n "${FAKE_GETJOB_FAIL:-}" ]; then
printf '%s\n' "$FAKE_GETJOB_FAIL" >&2
exit 1
fi
[ -n "${FAKE_JOBUID_EMPTY:-}" ] || printf '%s' "11111111-2222-3333-4444-555555555555"
exit 0
;;
*"patch serviceaccount $NAME "*)
# The ownerReference tying the ServiceAccount to the Job.
if [ -n "${FAKE_PATCH_FAIL:-}" ]; then
printf '%s\n' "$FAKE_PATCH_FAIL" >&2
exit 1
fi
owner=$(printf '%s' "$args" | grep -c "\"name\":\"$NAME\"")
log "PATCH-SA-OWNER owner=$owner"
exit 0
;;
*"apply --filename -"*)
manifest=$(cat)
case "$manifest" in
*"kind: ConfigMap"*)
v=$(printf '%s\n' "$manifest" | sed -n 's/^ version: "\{0,1\}\([0-9]\{1,\}\)"\{0,1\}$/\1/p' | head -1)
log "STAMP ${v:-unknown}"
exit 0
;;
*"kind: Job"*)
if [ -n "${FAKE_APPLY_FAIL:-}" ]; then
printf '%s\n' "$FAKE_APPLY_FAIL" >&2
exit 1
fi
# Record the fields the Job must carry, so a copy that drops the
# ServiceAccount, names the wrong migration, or renders the wrong image
# is caught.
role=$(printf '%s\n' "$manifest" | grep -c '^kind: ClusterRole$')
sa=$(printf '%s\n' "$manifest" | grep -c '^kind: ServiceAccount$')
crb=$(printf '%s\n' "$manifest" | grep -c '^kind: ClusterRoleBinding$')
# The binding must grant the least-privilege role, never cluster-admin.
admin=$(printf '%s\n' "$manifest" | grep -c 'cluster-admin')
mig=$(printf '%s\n' "$manifest" | grep -c -- "--migration=$N\$")
# The Job finishes the kind with the same accounts the hook seeded.
fixed=$(printf '%s\n' "$manifest" | grep -c -e '- --fixed-account=default$' -e '- --source-key=password$' -e '- --enabled-flag=authEnabled$' -e '- --source-suffix=-auth$' -e '- --format=plaintext$')
actor=$(printf '%s\n' "$manifest" | grep -c "value: system:serviceaccount:.*:$NAME\$")
img=$(printf '%s\n' "$manifest" | grep -c "^ image: ${IMAGE}$")
sacc=$(printf '%s\n' "$manifest" | grep -c "^ serviceAccountName: $NAME\$")
# ClusterRole, ServiceAccount, ClusterRoleBinding and Job, each named for
# the migration, so two conversions in one upgrade do not share them.
named=$(printf '%s\n' "$manifest" | grep -c "^ name: $NAME\$")
# It reads Deployments to resume the held releases after the rollout.
deploy=$(printf '%s\n' "$manifest" | grep -c '^ resources: \["deployments"\]$')
log "APPLY-FINISH role=$role sa=$sa crb=$crb admin=$admin migration=$mig image=$img serviceaccount=$sacc fixed=$fixed actor=$actor named=$named deployments=$deploy"
exit 0
;;
*)
log "APPLY-UNKNOWN"
printf 'fake kubectl: unmodelled apply\n' >&2
exit 1
;;
esac
;;
esac
log "UNHANDLED $args"
printf 'fake kubectl: unmodelled call: %s\n' "$args" >&2
exit 1