53 lines
2.8 KiB
Bash
Executable File
53 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
project_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$project_root"
|
|
|
|
postgres_query() {
|
|
role=$1
|
|
password_file=$2
|
|
sql=$3
|
|
docker compose exec -T postgres sh -ec \
|
|
"export PGPASSWORD=\$(cat /run/secrets/$password_file); psql -v ON_ERROR_STOP=1 'host=postgres port=5432 dbname=messenger user=$role sslmode=verify-full sslrootcert=/run/secrets/tls_ca' -Atc '$sql'"
|
|
}
|
|
|
|
[ "$(postgres_query messenger_api postgres_api_password 'SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()')" = t ] || {
|
|
printf '%s\n' "PostgreSQL API connection is not TLS" >&2
|
|
exit 1
|
|
}
|
|
postgres_query messenger_api postgres_api_password 'SELECT 1 FROM users LIMIT 1' >/dev/null
|
|
if postgres_query messenger_worker postgres_worker_password 'SELECT 1 FROM users LIMIT 1' >/dev/null 2>&1; then
|
|
printf '%s\n' "Worker can read the users table" >&2
|
|
exit 1
|
|
fi
|
|
if postgres_query messenger_dispatcher postgres_dispatcher_password 'SELECT 1 FROM users LIMIT 1' >/dev/null 2>&1; then
|
|
printf '%s\n' "Dispatcher can read the users table" >&2
|
|
exit 1
|
|
fi
|
|
postgres_query messenger_dispatcher postgres_dispatcher_password \
|
|
'SELECT status FROM attachments WHERE false FOR UPDATE' >/dev/null
|
|
postgres_query messenger_dispatcher postgres_dispatcher_password \
|
|
'UPDATE attachments SET updated_at = updated_at WHERE false' >/dev/null
|
|
if postgres_query messenger_dispatcher postgres_dispatcher_password \
|
|
'DELETE FROM attachments WHERE false' >/dev/null 2>&1; then
|
|
printf '%s\n' "Dispatcher can delete attachment metadata" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: PostgreSQL verify-full and role GRANTs permit dispatcher recovery but deny unrelated/destructive access"
|
|
|
|
docker compose exec -T redis sh -ec '
|
|
password=$(cat /run/secrets/redis_api_password)
|
|
REDISCLI_AUTH="$password" redis-cli --user api -h 127.0.0.1 ping | grep -qx PONG
|
|
REDISCLI_AUTH="$password" redis-cli --user api -h 127.0.0.1 set chat:v2:grade4 ok | grep -qx OK
|
|
REDISCLI_AUTH="$password" redis-cli --user api -h 127.0.0.1 del chat:v2:grade4 >/dev/null
|
|
REDISCLI_AUTH="$password" redis-cli --user api -h 127.0.0.1 acl list 2>&1 | grep -q NOPERM
|
|
REDISCLI_AUTH="$password" redis-cli --user api -h 127.0.0.1 set outside:key denied 2>&1 | grep -q NOPERM
|
|
'
|
|
printf '%s\n' "PASS: Redis API ACL permits cache prefix only and denies ACL administration"
|
|
|
|
permissions=$(docker compose exec -T broker rabbitmqctl list_permissions -p / -q)
|
|
printf '%s\n' "$permissions" | awk -F '\t' '$1 == "dispatcher" && $2 == "^attachment[.]process[.]v1$" && $3 == "^amq[.]default$" && $4 == "^$" {found=1} END {exit !found}'
|
|
printf '%s\n' "$permissions" | awk -F '\t' '$1 == "worker" && $2 == "^attachment[.]process[.]v1$" && $3 == "^$" && $4 == "^attachment[.]process[.]v1$" {found=1} END {exit !found}'
|
|
printf '%s\n' "PASS: RabbitMQ dispatcher/worker permissions match the single attachment queue"
|