mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 07:03:45 +09:00
feat(redis-operator): apply a minted password without a restart
The operator reads the auth Secret on every reconcile but applies the password only through redis.conf, which a server reads at start, and everything it runs authenticated with that client password. A changed Secret therefore moved the operator, the Sentinels and any restarted pod onto the new password while every running server still required the old one, and rolling the pods to fix that deleted the master: about 30 s of failed writes per mint on Redis and Valkey alike. Platform-minted credentials rewrite that Secret, so a mint has to be cheap. Replication, the Sentinels, the probes and the shutdown hook authenticate as an internal ACL user, rf-internal, and the exporter as a user of its own, rf-exporter, both kept in the operator's own Secret. The auth Secret's password belongs to the default user alone, so a mint applies it on every running server: no restart and no failover. An existing RedisFailover gets both users live on every server and Sentinel before its ConfigMap and pod template switch to them, which rolls its pods once. The client password can read masterauth with CONFIG GET, so rf-internal has two passwords. The pod password, which the probes and the shutdown hook read from their environment at start, is on the servers only as a SHA-256 hash in the ACL, never appears in CONFIG, and stays fixed, since changing it would restart those containers. The link password, which masterauth and the Sentinels' auth-pass carry, is rotated on every change of the client password. The stages keep the old link password valid until no server, replica or Sentinel uses it, and the ConfigMap records the new client password only after that, so a completed revoke leaves the old link password valid nowhere. Each stage reads before it writes and the Secret records progress, so a pass that stops anywhere is finished by the next one. rf-internal may run only what replication, the Sentinels, the probes and the shutdown hook send, on the Sentinels' hello channel alone, and has no CONFIG GET; rf-exporter may run only what redis_exporter sends. CONFIG SET requirepass alone would leave every connection that authenticated with the old password open, and the default user may run CONFIG GET requirepass, so a holder of a leaked password could keep one connection across a mint or revoke and read the new password from it. A client password change is therefore one MULTI/EXEC per server: reset the operator's users, delete any other user, set requirepass, and kill every connection of the default and exporter users. No connection made with the old password, or with a password its holder added to an operator user, sees the new one. Replication and Sentinel links and the liveness probe stay up. A server is changed only while it still takes the old password, so a pass that stops halfway resumes on the servers left. A connection that needs no new password can still outlive a revoke: a replication stream opened as rf-internal with the link password read from masterauth, or a MONITOR, which ACL checks only when it starts. The link rotation therefore ends, before it is recorded as done, by killing every MONITOR and every operator-user connection from an address that is no pod of the RedisFailover and not loopback. For the roll that switches an existing RedisFailover, and any other, the operator moves the master role off a stale master with SENTINEL FAILOVER and relabels the pods before rolling it as a replica, so writes stop only for the failover rather than until the Sentinels notice a deleted master. The roll reports a moved master and the pass ends there, so the next pass starts from the new master instead of pointing the Sentinels back at the old one. When a quorum of Sentinels names one of two masters, the other becomes its replica; with no quorum the operator asks for a manual fix. The tenant's default user can run ACL, CONFIG and, on the unauthenticated Sentinels, SENTINEL SET, so the operator does not trust its own setup to stay. Every pass reads the operator's users with ACL GETUSER and resets one that is missing, disabled, has another password, other rules or an extra selector, checks masteruser/masterauth with CONFIG GET, and re-sends a Sentinel's auth-user/auth-pass when CLIENT LIST shows it connected as another user, since SENTINEL SET cannot be read back. Between passes a guard checks the internal user on every server every 2 s from what the last pass left in memory, with no API call, and resets it and every Sentinel's auth where it differs, well before a tenant's ACL DELUSER rf-internal on the master would make the Sentinels fail it over, about 9 s later. Every rotation and every guard run also deletes any ACL user but default, rf-internal, rf-exporter and the liveness probe's pinger, which disconnects clients authenticated as them, since such a user would keep a tenant in after a revoke. Nothing a tenant changes outlives a restart, because redis reads redis.conf from the read-only ConfigMap volume and no aclfile is configured. Every mint and revoke disconnects the tenant's clients. The redis-tls e2e reads INFO replication as REDIS_USER, since the redis container's REDIS_PASSWORD is now rf-internal's. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
2 files changed
+4597
-2
No files matched your search
@@ -523,7 +523,10 @@ spec:
|
||||
# unlinked, and a dropped link re-enters it. The topology is thus in
|
||||
# motion here and one sampling would decide on it. Wait for it to
|
||||
# settle, then assert the sentinels moved off the bootstrap address,
|
||||
# which nothing above covers at all.
|
||||
# which nothing above covers at all. The redis container's
|
||||
# REDIS_PASSWORD belongs to REDIS_USER (rf-internal), not to
|
||||
# default, so the dial names that user, as the operator's own
|
||||
# scripts do.
|
||||
link_wait=60
|
||||
started=$(date +%s)
|
||||
deadline=$(( started + link_wait ))
|
||||
@@ -534,7 +537,7 @@ spec:
|
||||
for i in 0 1; do
|
||||
rc=0
|
||||
info=$(k -n "$NAMESPACE" exec "rfr-redis-secure-$i" -c redis -- \
|
||||
sh -c 'REDISCLI_AUTH="$REDIS_PASSWORD" timeout 15 redis-cli --tls --cacert /tls/ca.crt -h localhost -p 6379 info replication' 2>&1) || rc=$?
|
||||
sh -c 'REDISCLI_AUTH="$REDIS_PASSWORD" timeout 15 redis-cli ${REDIS_USER:+--user "$REDIS_USER"} --tls --cacert /tls/ca.crt -h localhost -p 6379 info replication' 2>&1) || rc=$?
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "INFO replication on rfr-redis-secure-$i failed (exit $rc): $info" >&2
|
||||
exit 1
|
||||
|
||||
+4592
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user