Redis Password Rotation
A Redis server deployed for GitLab.com can have many types of users/clients, each authenticating with a password. In the event of a password needing rotation, different actions are needed for each type of user.
This page currently covers the default and redis_exporter users. Redis
Cluster instances also define rails, replica and console users, which are
not covered yet.
default user
Section titled “default user”The default user is the one that comes with each Redis installation. Its
password is set by requirepass in the config file, and the same value is set
in masterauth, which replicas use to authenticate to the primary. Older Redis
installations use this password for many purposes; Rails authenticates with it,
and so do Sentinel, replicas and the exporters. This makes it the most involved
password to rotate.
A change request template should guide you through the necessary steps to rotate this password safely and without any downtime. You should always do these steps for staging first and then for production (if a production password is to be rotated) to verify that the steps haven’t gone stale.
redis_exporter user
Section titled “redis_exporter user”This user’s password is easy to rotate as it is used only internally. Redis ACL
users can have multiple passwords, so the new password is added alongside the
old one before the exporter switches to it. This avoids failed scrapes and
redis_up alerts during the rotation.
The server-side password lives in the redis gkms vault for Sentinel-based
instances, and in the redis-cluster vault for Redis Cluster instances. Below,
replace <env> with either gprd or gstg, and <vault> with redis or
redis-cluster.
Chef only rewrites redis.conf; it does not restart Redis or apply ACL changes
to the running server. Users defined in redis.conf are only loaded at
startup, so each ACL change is made twice: in the vault (so it survives
restarts) and live with ACL SETUSER on every node (primaries and
replicas), since ACLs are not propagated between nodes.
-
Generate a new password:
openssl rand -hex 32 -
In the
chef-reporepo, run:./bin/gkms-vault-edit <vault> <env> -
Find the
redis_exporter on ... ><old-password>entry under the cluster targeted for rotation. The password is the plaintext value after the>at the end. Add the new password next to it, keeping the old one:redis_exporter on ... ><old-password> ><new-password> -
Converge Chef on the cluster targeted for rotation.
-
Add the new password to the running Redis on every node:
Terminal window read -rs NEW_PASSWORD # paste the new password, then Enterfor n in $(knife search node 'roles:<cluster-role>' -i 2>/dev/null | grep -v '^INFO:'); doprintf '%s: ' "${n%%.*}"printf 'ACL SETUSER redis_exporter >%s\n' "$NEW_PASSWORD" | ssh "$n" 'sudo gitlab-redis-cli'doneEach host should reply
OK. -
In the
chef-reporepo, run:./bin/gkms-vault-edit redis-exporter <env> -
Update
REDIS_PASSWORDunder the cluster targeted for rotation with the new password. -
Converge Chef on the cluster targeted for rotation.
-
Restart the exporter, one node at a time. Chef only updates the exporter’s systemd unit; it does not restart the exporter, so it keeps using the old password until restarted. Each node should return
redis_up 1:Terminal window knife ssh -C 1 'roles:<cluster-role>' 'sudo systemctl restart redis_exporter; sleep 5; curl -s localhost:9121/metrics | grep "^redis_up "'On hosts that run the exporter under runit instead of systemd, use
sudo sv restart redis_exporter. -
Verify that redis-exporter emits metrics correctly. It should return
redis_up 1for all hosts:Terminal window knife ssh 'roles:<cluster-role>' 'curl -s localhost:9121/metrics | grep "^redis_up "' -
Run
./bin/gkms-vault-edit <vault> <env>again and remove the old password (><old-password>) from theredis_exporterentry. -
Converge Chef on the cluster targeted for rotation.
-
Remove the old password from the running Redis on every node:
Terminal window read -rs OLD_PASSWORD # paste the old password, then Enterfor n in $(knife search node 'roles:<cluster-role>' -i 2>/dev/null | grep -v '^INFO:'); doprintf '%s: ' "${n%%.*}"printf 'ACL SETUSER redis_exporter <%s\n' "$OLD_PASSWORD" | ssh "$n" 'sudo gitlab-redis-cli'done -
Repeat the verification step above.