forked from mtusi2026/mtusi2026lab7
lab7: TLS ко всем зависимостям и телеметрии; раздельные роли PostgreSQL (GRANT по коду), ACL Valkey, AMQPS, HTTPS S3, mTLS Collector/Prometheus/Loki/Tempo/Grafana
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Entry point of the compose service `valkey` (lab 7). Writes the ACL file from the Docker secret and
|
||||
# starts Valkey through the image's entrypoint (which drops root to the valkey user).
|
||||
# user default off no anonymous/shared-password access at all
|
||||
# user api SHA-256 of its password only (the plain password never lands in a file here),
|
||||
# keys session:* (sessions.py) and ratelimit:* (login limit), commands it uses:
|
||||
# GET/SET/DEL (sessions), INCR/PEXPIRE/PTTL in MULTI/EXEC (rate limit), PING
|
||||
# (readiness), CLIENT SETINFO (sent by redis-py on connect). FLUSHALL, CONFIG,
|
||||
# KEYS, DEBUG, ACL, ... are refused with NOPERM.
|
||||
set -eu
|
||||
umask 077
|
||||
mkdir -p /tmp/valkey
|
||||
hash="$(tr -d '\r\n' < /run/secrets/valkey_api_password | sha256sum | cut -d' ' -f1)"
|
||||
printf 'user default off\n' > /tmp/valkey/users.acl
|
||||
printf 'user api on #%s resetkeys ~session:* ~ratelimit:* resetchannels -@all +get +set +del +incr +pexpire +pttl +multi +exec +discard +ping +client|setinfo\n' \
|
||||
"$hash" >> /tmp/valkey/users.acl
|
||||
chown -R valkey /tmp/valkey
|
||||
exec docker-entrypoint.sh valkey-server /etc/valkey/valkey.conf
|
||||
@@ -8,10 +8,20 @@ appenddirname "appendonlydir"
|
||||
# RDB snapshots are not needed on top of AOF.
|
||||
save ""
|
||||
dir /data
|
||||
port 6379
|
||||
protected-mode yes
|
||||
# Lab 7: TLS only. The plaintext port is closed (port 0); clients verify the server certificate
|
||||
# (internal CA, SAN valkey). No client certificates at grade 3 (tls-auth-clients no): the client
|
||||
# identity is the ACL user + password below.
|
||||
port 0
|
||||
tls-port 6379
|
||||
tls-cert-file /run/secrets/valkey.crt
|
||||
tls-key-file /run/secrets/valkey.key
|
||||
tls-ca-cert-file /run/secrets/internal-ca.crt
|
||||
tls-auth-clients no
|
||||
tls-protocols "TLSv1.2 TLSv1.3"
|
||||
# Sessions are never evicted silently: if memory is full, writes fail and login returns 503.
|
||||
maxmemory 128mb
|
||||
maxmemory-policy noeviction
|
||||
# Password, generated by scripts/init_secrets.py and written here at container start.
|
||||
include /tmp/requirepass.conf
|
||||
# Lab 7: ACL users instead of one shared password (file written by infra/valkey/start.sh at start):
|
||||
# `default` is off, `api` may touch only session:* / ratelimit:* keys with the commands it uses.
|
||||
aclfile /tmp/valkey/users.acl
|
||||
|
||||
Reference in New Issue
Block a user