Files
mtusi2026lab7-fork/infra/redis/cache.sh

22 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# lab7: Redis — кэш проверок сессии. Только TLS (port 0), mTLS (tls-auth-clients yes),
# ACL вместо общего requirepass. В ACL-файле — SHA-256 пароля, не сам пароль; файл в tmpfs.
# default — отключён (без AUTH ничего нельзя)
# healthcheck — только PING (Docker healthcheck)
# messenger_api — GET/SET/DEL... только ключи sess:*, без @dangerous/@admin
set -eu
umask 077
api_hash=$(tr -d '\r\n' < /run/secrets/cache_api_password | sha256sum | cut -d' ' -f1)
cat > /tmp/users.acl <<ACL
user default off
user healthcheck on nopass -@all +ping
user messenger_api on #${api_hash} resetkeys ~sess:* resetchannels -@all +@read +@write +@connection -@dangerous -@admin -@blocking
ACL
exec redis-server \
--port 0 --tls-port 6379 \
--tls-cert-file /run/secrets/redis_crt --tls-key-file /run/secrets/redis_key \
--tls-ca-cert-file /run/secrets/ca_crt --tls-auth-clients yes \
--tls-protocols "TLSv1.2 TLSv1.3" \
--aclfile /tmp/users.acl \
--save "" --appendonly no --maxmemory 64mb --maxmemory-policy allkeys-lru