test(postgress): lab7 add roles ACL for redis
This commit is contained in:
+9
-10
@@ -46,18 +46,16 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
image: redis:7.4-alpine
|
image: redis:7.4-alpine
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command:
|
command: ["redis-server", "/etc/redis/lab.conf"]
|
||||||
- redis-server
|
|
||||||
- --appendonly
|
|
||||||
- "yes"
|
|
||||||
- --appendfsync
|
|
||||||
- everysec
|
|
||||||
- --save
|
|
||||||
- "60 1000"
|
|
||||||
volumes:
|
volumes:
|
||||||
|
- ./infra/redis/redis.conf:/etc/redis/lab.conf:ro
|
||||||
|
- ./certs/private/ingress/ca.crt:/run/redis/ca.crt:ro
|
||||||
|
- ./certs/private/redis/server.crt:/run/redis/server.crt:ro
|
||||||
|
- ./certs/private/redis/server.key:/run/redis/server.key:ro
|
||||||
|
- ./certs/private/redis/users.acl:/run/redis/users.acl:ro
|
||||||
- redis_data:/data
|
- redis_data:/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "redis-cli", "ping"]
|
test: ["CMD-SHELL", "redis-cli -h redis --tls --cacert /run/redis/ca.crt --user health -a health --no-auth-warning ping | grep -qx PONG"]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 10
|
retries: 10
|
||||||
@@ -200,6 +198,7 @@ services:
|
|||||||
image: mtusi-messenger-api:lab3
|
image: mtusi-messenger-api:lab3
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
SSL_CERT_FILE: "/run/postgres/ca.crt"
|
||||||
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}"
|
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318}"
|
||||||
OTEL_METRIC_EXPORT_INTERVAL: "${OTEL_METRIC_EXPORT_INTERVAL:-15000}"
|
OTEL_METRIC_EXPORT_INTERVAL: "${OTEL_METRIC_EXPORT_INTERVAL:-15000}"
|
||||||
OTEL_SDK_DISABLED: "${OTEL_SDK_DISABLED:-false}"
|
OTEL_SDK_DISABLED: "${OTEL_SDK_DISABLED:-false}"
|
||||||
@@ -467,7 +466,7 @@ secrets:
|
|||||||
db_reconciler:
|
db_reconciler:
|
||||||
file: ./certs/private/postgres/reconciler.url
|
file: ./certs/private/postgres/reconciler.url
|
||||||
cache_url:
|
cache_url:
|
||||||
file: ./secrets/cache_url
|
file: ./certs/private/redis/api.url
|
||||||
minio_root_user:
|
minio_root_user:
|
||||||
file: ./secrets/minio_root_user
|
file: ./secrets/minio_root_user
|
||||||
minio_root_password:
|
minio_root_password:
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
port 0
|
||||||
|
tls-port 6379
|
||||||
|
tls-cert-file /run/redis/server.crt
|
||||||
|
tls-key-file /run/redis/server.key
|
||||||
|
tls-ca-cert-file /run/redis/ca.crt
|
||||||
|
tls-auth-clients no
|
||||||
|
aclfile /run/redis/users.acl
|
||||||
|
dir /data
|
||||||
|
appendonly yes
|
||||||
|
appendfsync everysec
|
||||||
|
save 60 1000
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
set -- redis
|
||||||
|
. "$(dirname "$0")/dependency-pki.sh"
|
||||||
|
password=$(openssl rand -hex 32)
|
||||||
|
hash=$(printf %s "$password" | openssl dgst -sha256 -r | cut -d' ' -f1)
|
||||||
|
printf 'rediss://api:%s@redis:6379/0\n' "$password" > "$tmp/api.url"
|
||||||
|
printf '%s\n' 'user default off' 'user health on nopass -@all +ping' \
|
||||||
|
"user api on #$hash ~session:* -@all +hello +ping +get +set +del +client|setinfo" > "$tmp/users.acl"
|
||||||
|
finish redis
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
umask 077
|
||||||
|
ca=certs/private/ingress
|
||||||
|
dest=certs/private/$1
|
||||||
|
if [ -d "$dest" ]; then
|
||||||
|
openssl verify -purpose sslserver -verify_hostname "$1" -CAfile "$ca/ca.crt" "$dest/server.crt"
|
||||||
|
echo "Используем существующие файлы сервиса $1"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
tmp=$(mktemp -d "certs/private/.$1.XXXXXX")
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
openssl req -new -newkey rsa:2048 -nodes -subj "/CN=$1" -keyout "$tmp/server.key" -out "$tmp/server.csr"
|
||||||
|
printf '%s\n' "subjectAltName=DNS:$1" extendedKeyUsage=serverAuth basicConstraints=CA:FALSE > "$tmp/ext"
|
||||||
|
openssl x509 -req -days 30 -sha256 -in "$tmp/server.csr" -CA "$ca/ca.crt" -CAkey "$ca/ca.key" \
|
||||||
|
-set_serial "0x$(openssl rand -hex 16)" -extfile "$tmp/ext" -out "$tmp/server.crt"
|
||||||
|
rm "$tmp/server.csr" "$tmp/ext"
|
||||||
|
# Каталог на хосте имеет права 0700. Compose монтирует файлы по отдельности.
|
||||||
|
finish() {
|
||||||
|
chmod 0444 "$tmp"/*
|
||||||
|
mv -T "$tmp" "$dest"
|
||||||
|
echo "Готовы сертификат и настройки сервиса $1"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user