#!/bin/sh set -eu # Restrict usernames to a single ACL token; never interpolate raw passwords # into Redis configuration syntax or command-line arguments. case "${REDIS_USERNAME:-}" in ""|default|*[!a-zA-Z0-9_.-]*) echo "REDIS_USERNAME must contain only letters, digits, _, . or - and must not be default." >&2 exit 1 ;; esac if [ -z "${REDISCLI_AUTH:-}" ]; then echo "REDIS_PASSWORD must not be empty." >&2 exit 1 fi umask 077 password_hash="$(printf '%s' "$REDISCLI_AUTH" | sha256sum)" password_hash="${password_hash%% *}" printf 'user default off\nuser %s on #%s ~* &* +@all\n' \ "$REDIS_USERNAME" "$password_hash" > /run/redis-acl/users.acl unset password_hash exec redis-server /etc/redis/redis.conf