forked from mtusi2026/mtusi2026lab7
feat: complete lab 7 grade 3 security controls
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# Стоимость проверки хеша Argon2id на лимитах API
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`docker compose --profile test build backend-tests`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Image highload-lab7-backend-tests Building
|
||||
#1 [internal] load local bake definitions
|
||||
#1 reading from stdin 1.66kB done
|
||||
#1 DONE 0.0s
|
||||
|
||||
#2 [internal] load build definition from Dockerfile
|
||||
#2 transferring dockerfile: 816B done
|
||||
#2 DONE 0.0s
|
||||
|
||||
#3 [internal] load metadata for docker.io/library/golang:1.22.2-bookworm
|
||||
#3 DONE 1.1s
|
||||
|
||||
#4 [internal] load .dockerignore
|
||||
#4 transferring context: 327B done
|
||||
#4 DONE 0.0s
|
||||
|
||||
#5 [builder 1/7] FROM docker.io/library/golang:1.22.2-bookworm@sha256:d0902bacefdde1cf45528c098d14e55d78c107def8a22d148eabd71582d7a99f
|
||||
#5 resolve docker.io/library/golang:1.22.2-bookworm@sha256:d0902bacefdde1cf45528c098d14e55d78c107def8a22d148eabd71582d7a99f 0.0s done
|
||||
#5 DONE 0.0s
|
||||
|
||||
#6 [internal] load build context
|
||||
#6 transferring context: 13.70kB done
|
||||
#6 DONE 0.0s
|
||||
|
||||
#7 [builder 4/7] COPY go.mod go.sum ./
|
||||
#7 CACHED
|
||||
|
||||
#8 [builder 2/7] RUN apt-get update && apt-get install -y --no-install-recommends webp && rm -rf /var/lib/apt/lists/*
|
||||
#8 CACHED
|
||||
|
||||
#9 [builder 5/7] RUN go mod download
|
||||
#9 CACHED
|
||||
|
||||
#10 [builder 6/7] COPY backend ./backend
|
||||
#10 CACHED
|
||||
|
||||
#11 [builder 3/7] WORKDIR /src
|
||||
#11 CACHED
|
||||
|
||||
#12 [builder 7/7] RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/messenger ./backend
|
||||
#12 CACHED
|
||||
|
||||
#13 exporting to image
|
||||
#13 exporting layers
|
||||
#13 exporting layers 6.7s done
|
||||
#13 exporting manifest sha256:cc55619214f59b9b27ad25a2e23d1abce9f64566439be3b766526869522398f8 done
|
||||
#13 exporting config sha256:60158d0274ef38fabce1b1b41aef1dce15861f92bfe46cdd75183cc143df20f5 done
|
||||
#13 exporting attestation manifest sha256:facefdb8b90c9ec469b34788e90e8b0d663bf8c722e0e92d10cbc231bc2e6bc2 done
|
||||
#13 exporting manifest list sha256:a0ef01b3efc503922fd45a76b39ec30f5d34f2085c9a228eeb3277e39df87eab done
|
||||
#13 naming to docker.io/library/highload-lab7-backend-tests:latest done
|
||||
#13 unpacking to docker.io/library/highload-lab7-backend-tests:latest
|
||||
#13 unpacking to docker.io/library/highload-lab7-backend-tests:latest 1.2s done
|
||||
#13 DONE 7.9s
|
||||
|
||||
#14 resolving provenance for metadata file
|
||||
#14 DONE 0.0s
|
||||
Image highload-lab7-backend-tests Built
|
||||
```
|
||||
|
||||
`docker run --rm --network none --cpus 0.5 --memory 512m -e GOMAXPROCS=1 highload-lab7-backend-tests go test ./backend/services -run '^$' -bench '^BenchmarkPasswordVerification$' -benchtime=3x -count=3`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: messenger/src/backend/services
|
||||
cpu: AMD Ryzen 9 PRO 7940HS w/ Radeon 780M Graphics
|
||||
BenchmarkPasswordVerification 3 194744721 ns/op 67115832 B/op 74 allocs/op
|
||||
BenchmarkPasswordVerification 3 176595711 ns/op 67115832 B/op 74 allocs/op
|
||||
BenchmarkPasswordVerification 3 196042348 ns/op 67115832 B/op 74 allocs/op
|
||||
PASS
|
||||
ok messenger/src/backend/services 3.606s
|
||||
```
|
||||
@@ -0,0 +1,35 @@
|
||||
# TLS хранилищ, брокера и телеметрии
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_grade3_tls.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS s3:9000: verified service SAN; foreign CA rejected
|
||||
PASS broker:5671: verified service SAN; foreign CA rejected
|
||||
PASS redis:6379: verified service SAN; foreign CA rejected
|
||||
PASS db:5432: verified service SAN; foreign CA rejected
|
||||
PASS otel-collector:4318: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS otel-collector:8889: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS prometheus:9090: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS loki:3100: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS loki:3100: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS tempo:4318: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS tempo:3200: verified service SAN; foreign CA rejected; foreign client identity rejected
|
||||
PASS grafana:3000: verified service SAN; foreign CA rejected
|
||||
PASS openbao:8200: verified service SAN; foreign CA rejected
|
||||
```
|
||||
|
||||
`./scripts/check_dependency_roles.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS PostgreSQL: worker can update attachments; user table and schema creation denied
|
||||
PASS RabbitMQ: producer can publish and consumer can read attachments.v1
|
||||
PASS Redis: application role cannot read server configuration
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
@@ -0,0 +1,67 @@
|
||||
# Истечение сессии на стенде с коротким TTL
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`sleep 60`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`env SESSION_TTL_SECONDS=5 docker compose up -d --no-deps api`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Container highload-lab7-api-1 Recreate
|
||||
Container highload-lab7-api-2 Recreate
|
||||
Container highload-lab7-api-1 Recreated
|
||||
Container highload-lab7-api-2 Recreated
|
||||
Container highload-lab7-api-1 Starting
|
||||
Container highload-lab7-api-1 Started
|
||||
Container highload-lab7-api-2 Starting
|
||||
Container highload-lab7-api-2 Started
|
||||
```
|
||||
|
||||
`./scripts/wait_ingress.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`python3 scripts/check_session_expiry.py --ca-file secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS: valid session accepted before expiry and rejected after expiry
|
||||
```
|
||||
|
||||
`docker compose up -d --no-deps api`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Container highload-lab7-api-1 Recreate
|
||||
Container highload-lab7-api-2 Recreate
|
||||
Container highload-lab7-api-2 Recreated
|
||||
Container highload-lab7-api-1 Recreated
|
||||
Container highload-lab7-api-1 Starting
|
||||
Container highload-lab7-api-1 Started
|
||||
Container highload-lab7-api-2 Starting
|
||||
Container highload-lab7-api-2 Started
|
||||
```
|
||||
|
||||
`./scripts/wait_ingress.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
@@ -0,0 +1,11 @@
|
||||
# Лимиты, MIME, чужие вложения и неверный TLS hostname
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_grade3_http.py --ca-file secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS: upload size/MIME, forged identity, cross-chat attachment, wrong TLS hostname
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
# Бизнес-API, проверка CA, logout и вложения по HTTPS
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`make check`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
```
|
||||
|
||||
`make test test-security CA_FILE=secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.
|
||||
python3 tests/security.py --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
PASS: trusted HTTPS works; untrusted CA rejected. This does NOT verify internal mTLS, OpenBao or hardening.
|
||||
```
|
||||
@@ -0,0 +1,21 @@
|
||||
# Общий лимит входа по адресу клиента
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`sleep 60`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`python3 scripts/check_login_rate.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS: request 13 returned 429 with Retry-After across 2 API replicas
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
@@ -0,0 +1,12 @@
|
||||
# Допуск только роли LB на каждой реплике
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_ingress_mtls.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS d50f910b8693: LB permitted; absent, foreign CA and disallowed SAN rejected
|
||||
PASS a96f9b981475: LB permitted; absent, foreign CA and disallowed SAN rejected
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
# Сервисная аутентификация и scoped policy OpenBao
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_bao_roles.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS api: scoped read, cross-role login/read and write denied, TTL <= 900 s
|
||||
PASS worker: scoped read, cross-role login/read and write denied, TTL <= 900 s
|
||||
PASS dispatcher: scoped read, cross-role login/read and write denied, TTL <= 900 s
|
||||
PASS cleanup: scoped read, cross-role login/read and write denied, TTL <= 900 s
|
||||
```
|
||||
@@ -0,0 +1,47 @@
|
||||
# Работа HTTPS API при остановленной второй реплике
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`sleep 60`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`./scripts/check_other_replica.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Stopped API instance 50b06551b60d
|
||||
python3 tests/smoke.py --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
PASS: lab7 public API scenario; infrastructure and grading evidence remain separate.
|
||||
Container highload-lab7-redis-1 Waiting
|
||||
Container highload-lab7-db-1 Waiting
|
||||
Container highload-lab7-s3-1 Waiting
|
||||
Container highload-lab7-s3-1 Healthy
|
||||
Container highload-lab7-redis-1 Healthy
|
||||
Container highload-lab7-s3-bootstrap-1 Starting
|
||||
Container highload-lab7-db-1 Healthy
|
||||
Container highload-lab7-migrate-1 Starting
|
||||
Container highload-lab7-s3-bootstrap-1 Started
|
||||
Container highload-lab7-s3-bootstrap-1 Waiting
|
||||
Container highload-lab7-migrate-1 Started
|
||||
Container highload-lab7-migrate-1 Waiting
|
||||
Container highload-lab7-migrate-1 Exited
|
||||
Container highload-lab7-s3-bootstrap-1 Exited
|
||||
Container highload-lab7-api-2 Starting
|
||||
Container highload-lab7-api-2 Started
|
||||
```
|
||||
|
||||
`./scripts/wait_ingress.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
@@ -0,0 +1,139 @@
|
||||
# Сохранность после перезапуска хранилищ и отказ API
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`sleep 60`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`make test-persistence ACTION_SCRIPT=scripts/restart.sh CA_FILE=secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
```
|
||||
|
||||
`make test-failover ACTION_SCRIPT=scripts/stop-one.sh CA_FILE=secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 125, "failed_attempts": 2, "first_recovery_seconds": 1.538}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
```
|
||||
|
||||
`docker compose start api`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Container highload-lab7-s3-1 Waiting
|
||||
Container highload-lab7-db-1 Waiting
|
||||
Container highload-lab7-redis-1 Waiting
|
||||
Container highload-lab7-s3-1 Healthy
|
||||
Container highload-lab7-s3-bootstrap-1 Starting
|
||||
Container highload-lab7-db-1 Healthy
|
||||
Container highload-lab7-migrate-1 Starting
|
||||
Container highload-lab7-redis-1 Healthy
|
||||
Container highload-lab7-s3-bootstrap-1 Started
|
||||
Container highload-lab7-s3-bootstrap-1 Waiting
|
||||
Container highload-lab7-migrate-1 Started
|
||||
Container highload-lab7-migrate-1 Waiting
|
||||
Container highload-lab7-migrate-1 Exited
|
||||
Container highload-lab7-s3-bootstrap-1 Exited
|
||||
Container highload-lab7-api-1 Starting
|
||||
Container highload-lab7-api-1 Started
|
||||
```
|
||||
|
||||
`./scripts/wait_ingress.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`sleep 60`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
`make test-failover ACTION_SCRIPT=scripts/stop-one.sh CA_FILE=secrets/tls/lab7-ca.crt`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "https://localhost:8443" --ca-file "secrets/tls/lab7-ca.crt"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 125, "failed_attempts": 2, "first_recovery_seconds": 1.658}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
```
|
||||
|
||||
`docker compose start api`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
Container highload-lab7-db-1 Waiting
|
||||
Container highload-lab7-s3-1 Waiting
|
||||
Container highload-lab7-redis-1 Waiting
|
||||
Container highload-lab7-redis-1 Healthy
|
||||
Container highload-lab7-s3-1 Healthy
|
||||
Container highload-lab7-s3-bootstrap-1 Starting
|
||||
Container highload-lab7-db-1 Healthy
|
||||
Container highload-lab7-migrate-1 Starting
|
||||
Container highload-lab7-s3-bootstrap-1 Started
|
||||
Container highload-lab7-s3-bootstrap-1 Waiting
|
||||
Container highload-lab7-migrate-1 Started
|
||||
Container highload-lab7-migrate-1 Waiting
|
||||
Container highload-lab7-migrate-1 Exited
|
||||
Container highload-lab7-s3-bootstrap-1 Exited
|
||||
Container highload-lab7-api-1 Starting
|
||||
Container highload-lab7-api-1 Started
|
||||
```
|
||||
|
||||
`./scripts/wait_ingress.sh`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
|
||||
```
|
||||
|
||||
Состояния контейнеров (restart):
|
||||
|
||||
```text
|
||||
/highload-lab7-api-1 2026-11-14T16:56:19.970448431Z
|
||||
/highload-lab7-api-2 2026-11-14T16:56:20.135569481Z
|
||||
/highload-lab7-broker-1 2026-11-14T16:50:40.248667479Z
|
||||
/highload-lab7-db-1 2026-11-14T16:50:39.231870058Z
|
||||
/highload-lab7-redis-1 2026-11-14T16:50:39.21876659Z
|
||||
/highload-lab7-s3-1 2026-11-14T16:50:39.377104743Z
|
||||
/highload-lab7-api-1 2026-11-14T16:57:33.129069552Z
|
||||
/highload-lab7-api-2 2026-11-14T16:57:33.110951095Z
|
||||
/highload-lab7-broker-1 2026-11-14T16:57:25.694563006Z
|
||||
/highload-lab7-db-1 2026-11-14T16:57:26.301816228Z
|
||||
/highload-lab7-redis-1 2026-11-14T16:57:24.787203563Z
|
||||
/highload-lab7-s3-1 2026-11-14T16:57:24.914493761Z
|
||||
```
|
||||
|
||||
Состояния контейнеров (failover):
|
||||
|
||||
```text
|
||||
/highload-lab7-api-1 exited
|
||||
/highload-lab7-api-1 exited
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
@@ -0,0 +1,11 @@
|
||||
# Изоляция, порты, лимиты и локальное размещение секретов
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_grade3_runtime.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS: local-only ports, runtime secrets on tmpfs, non-root app roles with limits and dropped capabilities
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
# Доставка логов, метрик и трейсов по защищённым связям
|
||||
|
||||
Предпосылки: подготовленный, разблокированный учебный стенд; Docker Compose, Python и локальный CA.
|
||||
|
||||
`python3 scripts/check_grade3_signals.py`
|
||||
|
||||
Код завершения: 0.
|
||||
|
||||
```text
|
||||
PASS: Prometheus scrape up; fresh messenger API log and trace found through mTLS
|
||||
```
|
||||
|
||||
Итог: все команды завершились успешно.
|
||||
Reference in New Issue
Block a user