Skip to content

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.

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.

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.

  1. Generate a new password: openssl rand -hex 32

  2. In the chef-repo repo, run: ./bin/gkms-vault-edit <vault> <env>

  3. 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>

  4. Converge Chef on the cluster targeted for rotation.

  5. Add the new password to the running Redis on every node:

    Terminal window
    read -rs NEW_PASSWORD # paste the new password, then Enter
    for n in $(knife search node 'roles:<cluster-role>' -i 2>/dev/null | grep -v '^INFO:'); do
    printf '%s: ' "${n%%.*}"
    printf 'ACL SETUSER redis_exporter >%s\n' "$NEW_PASSWORD" | ssh "$n" 'sudo gitlab-redis-cli'
    done

    Each host should reply OK.

  6. In the chef-repo repo, run: ./bin/gkms-vault-edit redis-exporter <env>

  7. Update REDIS_PASSWORD under the cluster targeted for rotation with the new password.

  8. Converge Chef on the cluster targeted for rotation.

  9. 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.

  10. Verify that redis-exporter emits metrics correctly. It should return redis_up 1 for all hosts:

    Terminal window
    knife ssh 'roles:<cluster-role>' 'curl -s localhost:9121/metrics | grep "^redis_up "'
  11. Run ./bin/gkms-vault-edit <vault> <env> again and remove the old password (><old-password>) from the redis_exporter entry.

  12. Converge Chef on the cluster targeted for rotation.

  13. Remove the old password from the running Redis on every node:

    Terminal window
    read -rs OLD_PASSWORD # paste the old password, then Enter
    for n in $(knife search node 'roles:<cluster-role>' -i 2>/dev/null | grep -v '^INFO:'); do
    printf '%s: ' "${n%%.*}"
    printf 'ACL SETUSER redis_exporter <%s\n' "$OLD_PASSWORD" | ssh "$n" 'sudo gitlab-redis-cli'
    done
  14. Repeat the verification step above.