Files
mtusi2026lab5/scripts/evidence-attachments.sh
T

43 lines
2.9 KiB
Bash
Executable File
Raw 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
set -eu
cd "$(dirname "$0")/.."
out=${EVIDENCE_DIR:-evidence}
mkdir -p "$out"
psql() { docker compose exec -T postgres psql -U messenger -d messenger -X -c "$1"; }
value() { docker compose exec -T postgres psql -U messenger -d messenger -X -tA -c "$1"; }
cli() { docker compose run --rm --no-deps -T s3-cli "$@"; }
bucket=${S3_BUCKET:-messenger-attachments}
{
echo "date: $(date -u +%FT%TZ) commit: $(git rev-parse HEAD)"
echo "\$ docker compose ps --format '{{.Service}} {{.Status}} {{.Ports}}'"
docker compose ps -a --format '{{.Service}} {{.Status}} {{.Ports}}'
for table in attachments message_attachments; do
echo "\$ psql -c '\\d $table'"
psql "\\d $table"
done
echo "\$ psql: столбцы bytea во всей схеме (хеши токенов и отпечатки, не файлы)"
psql "SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = 'public' AND data_type = 'bytea' ORDER BY 1, 2"
echo "\$ psql: вложения по статусу и максимальный размер строки attachments"
psql "SELECT status, count(*), max(pg_column_size(a.*)) AS max_row_bytes FROM attachments a GROUP BY status"
echo "\$ rc object list --recursive root/$bucket/attachments/ | count"
cli object list --recursive "root/$bucket/attachments/" --json | grep -c '"key"' || true
echo "\$ rc object list root/$bucket/ (первые 3 объекта, ключи назначены сервером)"
cli object list --recursive "root/$bucket/attachments/" | head -3
row=$(value "SELECT object_key || ' ' || sha256 || ' ' || size_bytes FROM attachments WHERE status = 'ready' ORDER BY created_at DESC LIMIT 1")
key=${row%% *}
echo "\$ сверка вне API: sha256 и размер последнего ready-вложения в PostgreSQL против байтов объекта в bucket"
echo "postgres: ${row#* }"
echo "s3: $(cli sh -c "rc object show root/$bucket/$key | sha256sum | cut -d' ' -f1") $(cli sh -c "rc object show root/$bucket/$key | wc -c" | tr -d ' ')"
echo "\$ docker inspect api: ReadonlyRootfs, tmpfs, volumes/bind mounts"
for id in $(docker compose ps -q api); do
docker inspect -f '{{.Config.Hostname}} ro={{.HostConfig.ReadonlyRootfs}} tmpfs={{json .HostConfig.Tmpfs}} mounts={{range .Mounts}}{{.Type}}:{{.Destination}} {{end}}' "$id"
done
echo "\$ docker inspect s3: volume данных"
docker inspect -f '{{range .Mounts}}{{.Type}}:{{.Name}}:{{.Destination}} {{end}}' "$(docker compose ps -q s3)"
echo "\$ секреты сервисов: root-ключи S3 только у s3/s3-init/s3-cli"
docker compose config --format json | python3 -c 'import json,sys
for name, service in sorted(json.load(sys.stdin)["services"].items()):
print(name, sorted(s["source"] for s in service.get("secrets", [])))'
} > "$out"/storage-layout.txt
cat "$out"/storage-layout.txt