Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files. Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
90 lines
5.8 KiB
Bash
Executable File
90 lines
5.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
cli() { docker compose run --rm --no-deps -T s3-cli "$@"; }
|
|
undated() {
|
|
python3 -c 'import json, sys
|
|
def clean(value):
|
|
if isinstance(value, dict):
|
|
return {k: clean(v) for k, v in value.items() if not k.endswith("_date")}
|
|
return [clean(v) for v in value] if isinstance(value, list) else value
|
|
text, decoder, at = sys.stdin.read(), json.JSONDecoder(), 0
|
|
while text[at:].strip():
|
|
at += len(text[at:]) - len(text[at:].lstrip())
|
|
value, at = decoder.raw_decode(text, at)
|
|
print(json.dumps(clean(value), indent=2, ensure_ascii=False))'
|
|
}
|
|
snapshot() {
|
|
cli sh -s <<'EOF' | undated
|
|
ak=$(cat /run/secrets/s3_access_key_id)
|
|
rk=$(cat /run/secrets/s3_reconciler_access_key_id)
|
|
for c in "bucket list root" "bucket anonymous get root/$S3_BUCKET" "admin policy info root messenger-api" "admin policy info root messenger-reconciler" "admin user info root $ak" "admin user info root $rk" "bucket lifecycle rule export root/$S3_BUCKET"; do
|
|
rc $c --json
|
|
done | sed "s/$ak/<api-key>/g; s/$rk/<reconciler-key>/g"
|
|
EOF
|
|
}
|
|
failed=0
|
|
verdict() { if [ "$2" = "$3" ]; then echo "PASS $1: $3"; else echo "FAIL $1: ожидалось $2, получено $3"; failed=1; fi; }
|
|
echo "date: $(date -u +%FT%TZ) commit: $(git rev-parse HEAD) == S3 privacy and bootstrap checks"
|
|
verdict "s3: опубликованные host-порты" "нет" "$(docker inspect -f '{{json .NetworkSettings.Ports}}' "$(docker compose ps -q s3)" | grep -q HostPort && echo есть || echo нет)"
|
|
verdict "s3: консоль :9001 внутри контейнера" "000" "$(docker compose exec -T s3 curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:9001/ || true)"
|
|
before=$(snapshot)
|
|
first=$(docker compose run --rm --no-deps -T s3-init >/dev/null 2>&1 && echo 0 || echo 1)
|
|
second=$(docker compose run --rm --no-deps -T s3-init 2>/dev/null || echo FAILED)
|
|
after=$(snapshot)
|
|
verdict "s3-init: повторный запуск 1" "0" "$first"
|
|
verdict "s3-init: повторный запуск 2" "0" "$(echo "$second" | grep -q '^s3-init:' && echo 0 || echo 1)"
|
|
verdict "s3-init: состояние IAM/bucket не изменилось" "same" "$([ "$before" = "$after" ] && echo same || echo changed)"
|
|
cli sh -s <<'EOF' || failed=1
|
|
b=$S3_BUCKET
|
|
key="attachments/s3-check-$(date +%s)-$$"
|
|
spare="$key-reconciler"
|
|
other="s3-check-$(date +%s)-$$"
|
|
head -c 4096 /dev/urandom > /tmp/probe
|
|
result=0
|
|
expect() {
|
|
want=$1; name=$2; shift 2
|
|
if "$@" >/tmp/out 2>&1; then got=allow; elif grep -qE '403|AccessDenied|set_bucket_policy: service error|check bucket: Network error: service error' /tmp/out; then got=deny; else got=error; fi
|
|
if [ "$got" = "$want" ]; then echo "PASS $name: $got"; else echo "FAIL $name: ожидалось $want, получено $got"; result=1; fi
|
|
}
|
|
expect allow "api: PutObject" rc put /tmp/probe "api/$b/$key"
|
|
expect allow "api: HeadObject" rc object stat "api/$b/$key"
|
|
expect allow "api: GetObject" rc object show "api/$b/$key"
|
|
expect deny "api: ListBucket" rc object list "api/$b/attachments/"
|
|
rc put /tmp/probe "api/$b/$spare" >/dev/null
|
|
expect allow "reconciler: ListBucket" rc object list "reconciler/$b/attachments/"
|
|
expect allow "reconciler: HeadObject" rc object stat "reconciler/$b/$key"
|
|
expect allow "reconciler: GetObject" rc object show "reconciler/$b/$key"
|
|
expect deny "reconciler: PutObject" rc put /tmp/probe "reconciler/$b/$key-put"
|
|
expect allow "reconciler: DeleteObject" rc object remove --force "reconciler/$b/$spare"
|
|
expect deny "reconciler: CreateBucket" rc bucket create "reconciler/$other"
|
|
expect deny "reconciler: PutBucketPolicy (public)" rc bucket anonymous set public "reconciler/$b"
|
|
expect deny "reconciler: admin ListUsers" rc admin user list reconciler
|
|
expect deny "api: CreateBucket" rc bucket create "api/$other"
|
|
expect deny "api: DeleteBucket" rc bucket remove "api/$b"
|
|
expect deny "api: PutBucketPolicy (public)" rc bucket anonymous set public "api/$b"
|
|
expect deny "api: PutBucketLifecycle (HeadBucket уже 403)" rc bucket lifecycle rule import "api/$b" /s3/lifecycle.json
|
|
expect deny "api: admin ListUsers" rc admin user list api
|
|
rc bucket create --ignore-existing "root/$other" >/dev/null
|
|
expect deny "api: PutObject в чужой bucket" rc put /tmp/probe "api/$other/x"
|
|
expect deny "api: ListBucket чужого bucket" rc object list "api/$other"
|
|
rc bucket remove "root/$other" >/dev/null
|
|
expect deny "anonymous: HeadObject" rc object stat "anon/$b/$key"
|
|
expect deny "anonymous: ListBucket" rc object list "anon/$b"
|
|
expect deny "anonymous: PutObject" rc put /tmp/probe "anon/$b/attachments/anonymous"
|
|
status=$(wget -S -O /dev/null "$S3_ENDPOINT/$b/$key" 2>&1 | sed -n 's/^ *HTTP\/[0-9.]* \([0-9]*\).*/\1/p' | head -n 1)
|
|
if [ "$status" = 403 ]; then echo "PASS anonymous: прямой HTTP GET объекта из отдельного контейнера: $status"; else echo "FAIL anonymous: прямой HTTP GET: $status"; result=1; fi
|
|
permission=$(rc bucket anonymous get "root/$b" --json | sed -n 's/.*"permission": *"\([a-z]*\)".*/\1/p')
|
|
if [ "$permission" = private ]; then echo "PASS bucket: anonymous policy: $permission"; else echo "FAIL bucket: anonymous policy: $permission"; result=1; fi
|
|
expect allow "api: DeleteObject" rc object remove --force "api/$b/$key"
|
|
host=$(echo "$S3_ENDPOINT" | sed 's#^[a-z]*://##; s#:.*##')
|
|
if wget -T 2 -O /dev/null "http://$host:9001/" >/tmp/out 2>&1; then echo "FAIL s3: консоль :9001 отвечает из сети стенда"; result=1
|
|
elif grep -q refused /tmp/out; then echo "PASS s3: консоль :9001 из отдельного контейнера сети стенда: connection refused"
|
|
else echo "FAIL s3: консоль :9001 из сети стенда: $(tail -n 1 /tmp/out)"; result=1; fi
|
|
exit $result
|
|
EOF
|
|
echo "== IAM/bucket snapshot (без секретов)"
|
|
echo "$after"
|
|
if [ "$failed" != 0 ]; then echo "RESULT: FAIL"; exit 1; fi
|
|
echo "RESULT: PASS"
|