forked from mtusi2026/mtusi2026lab7
fix: address container-hardening verify findings
Loki gets a /tmp tmpfs for its retention marks (the compactor failed on the read-only root), hardening_check reads each container's log since start for write errors, the fast test covers override mounts and the driver and bench overrides, s3-bootstrap /data is narrowed to its user, spec wording and docs are corrected, Tempo's exit 137 on stop is recorded as a known issue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
- Код: commit `157b878` (снято на рабочем дереве поверх `1f45bfe` с правками apply до коммита, 2026-11-27; рабочее
|
||||
дерево и commit совпадают); стенд «до» — код `3ef21c2` (compose рабочего дерева до первой правки apply совпадал с
|
||||
ним).
|
||||
ним). Раздел 14 — правки verify, рабочее дерево поверх `8fc5bbf`.
|
||||
- Docker Desktop 29.9.2 (arm64, cgroup v2), Compose 5.6.1, ВМ 12 CPU; параллельно на машине работал стенд другого
|
||||
агента (CPU общий).
|
||||
- Спеки: `container-security` (все требования), `container-image` («Работа с корнем только на чтение»),
|
||||
@@ -190,9 +190,12 @@ openbao-outage: exit 0 PASS: running stand served without OpenBao; new p
|
||||
hardening_check: exit 0 PASS: 631 checks
|
||||
```
|
||||
|
||||
Журналы всех 22 сервисов после этих прогонов: `Read-only file system`, `Operation not permitted`, `EACCES`, `can't
|
||||
start new thread`, `failed to create new OS thread` — 0; Grafana `plugin init error` — 0. Строки `permission denied`
|
||||
в журналах PostgreSQL и OpenBao — отказы, которые сами вызывают `storage_roles_check` (42501) и `bao_check` (403).
|
||||
~~Журналы всех 22 сервисов после этих прогонов: `Read-only file system`, `Operation not permitted`, `EACCES`, `can't
|
||||
start new thread`, `failed to create new OS thread` — 0~~ — **неверно** (найдено verify): в журнале `loki` после
|
||||
прогонов apply было 24 строки `marker.go:218 … failed to process marks … open /tmp/…: read-only file system`
|
||||
(compactor раз в минуту, начиная через ~10 мин работы); почему поиск apply их не нашёл, не установлено (журнал того
|
||||
контейнера не сохранился). Исправление и пересъёмка — раздел 14. Остальное верно: Grafana `plugin init error` — 0; строки `permission denied` в журналах
|
||||
PostgreSQL и OpenBao — отказы, которые сами вызывают `storage_roles_check` (42501) и `bao_check` (403).
|
||||
|
||||
## 7. Контроли `make hardening_check` (задача 7.3)
|
||||
|
||||
@@ -371,3 +374,102 @@ make hardening_check PASS: 631 checks
|
||||
не читались.
|
||||
- В конце рабочий стенд остановлен (`make stop`); контейнеров проб, временных проектов, сетей, volumes и временных
|
||||
каталогов прогона не осталось.
|
||||
|
||||
## 14. Правки verify (рабочее дерево поверх `8fc5bbf`, 2026-11-27)
|
||||
|
||||
Снято на незакоммиченном рабочем дереве поверх `8fc5bbf` (правки verify, design, «Уточнения verify»; commit — основная
|
||||
сессия). Роль оператора OpenBao (`make bao_unseal`) — агент.
|
||||
|
||||
**C1, Loki.** Источник `pkg/compactor/retention/marker.go` Loki 3.7.9: файл меток retention пишется через
|
||||
`os.TempDir()` (`filepath.Join(os.TempDir(), …)`), а при обработке каждый копируется в `os.CreateTemp("", name)` и
|
||||
открывается как boltdb — обоим нужен записываемый `/tmp`; без него — `failed to process marks … open /tmp/…:
|
||||
read-only file system` раз в минуту, метки не удаляются, чанки старше срока остаются. Правка — tmpfs
|
||||
`/tmp:size=32m,mode=1777` у `loki`. Переход: `make run_docker` → код 2 «OpenBao is sealed: run make bao_unseal» →
|
||||
`make bao_unseal` → `make run_docker` (код 0; пересозданы `loki` и `s3-bootstrap`), старт стенда — 03:06 UTC.
|
||||
|
||||
Через 13 мин работы (compactor запущен в 03:16, проходы меток 03:16, 03:17, … — `marker.go:206 "no marks file
|
||||
found"`: на volume `loki_data`, пересозданном при verify, меток ещё нет, обработку метки увидят только после срока
|
||||
168 ч), счёт строк в журнале каждого контейнера с его `StartedAt`:
|
||||
|
||||
```
|
||||
контейнер (23, в том числе завершённые migrate, postgres-bootstrap, s3-bootstrap) ro eperm eacces threads
|
||||
api-3, api-4, cleaner, relay, worker, migrate, postgres-bootstrap 0 0 0 0
|
||||
postgres, valkey, rabbitmq, s3, s3-bootstrap, openbao, haproxy 0 0 0 0
|
||||
otel-gateway, loki-gateway, tempo-gateway, prometheus-gateway 0 0 0 0
|
||||
otel-collector, prometheus, loki (250 строк), tempo (150), grafana (2003) 0 0 0 0
|
||||
(ro — «read-only file system», eperm — «operation not permitted», threads — «can't start new thread» /
|
||||
«failed to create new OS thread»; «permission denied» — 0 у всех)
|
||||
```
|
||||
|
||||
Проба в пространстве PID Loki (образ API, `--read-only --cap-drop ALL --user 10001`, через `/proc/<pid>/root`
|
||||
процесса `loki`): `/tmp` — `written (removed)`, `/var/tmp` — `EROFS`; каталог `/loki/compactor/retention/…/markers` —
|
||||
пуст.
|
||||
|
||||
**S7, журнал в `make hardening_check`** — строка «log since start: write errors» у каждого контейнера (631 → 654
|
||||
проверки: +23 контейнера). На стенде через 14 мин работы:
|
||||
|
||||
```
|
||||
mtusi-lab7-loki-1 tmpfs - /tmp(size=32m,mode=1777)
|
||||
mtusi-lab7-loki-1 matches compose model yes yes
|
||||
mtusi-lab7-loki-1 log since start: write errors none none
|
||||
mtusi-lab7-s3-bootstrap-1 tmpfs - /data(size=1m,uid=1000,gid=1000,mode=0700) /tmp(size=16m,mode=1777)
|
||||
mtusi-lab7-s3-bootstrap-1 log since start: write errors none none
|
||||
one-off worker threads until refusal < pids limit 64, refused 63 (RuntimeError: can't start new thread)
|
||||
one-off worker /health/ready via LB meanwhile 200 200
|
||||
PASS: 654 checks (make: код 0)
|
||||
```
|
||||
|
||||
Контроль — разовый контейнер `docker compose run -d --no-deps --name mtusi-probe-harden-logwrite --entrypoint sh
|
||||
relay -c 'touch /probe-root-write; sleep 300'`:
|
||||
|
||||
```
|
||||
mtusi-probe-harden-logwrite log since start: write errors none read-only file system ×1: touch: cannot touch '/probe-root-write': Read-only file system FAIL
|
||||
FAIL: 1 check(s) failed make hardening_check — код 2 (make), driver.py hardening-check — код 1
|
||||
```
|
||||
|
||||
После `docker rm -f` пробы — `PASS: 654 checks`, код 0; контейнеров `mtusi-probe-harden-*` — 0. Коды (S6): у
|
||||
драйвера 0 / 1 / 2, у make — 0 или ненулевой (2), как у `bao_check` и прочих целей проверок.
|
||||
|
||||
**S3, `s3-bootstrap`** — `/data:size=1m,uid=1000,gid=1000,mode=0700` (`id seaweed` образа — `uid=1000 gid=1000`):
|
||||
|
||||
```
|
||||
make start_s3 код 0; s3-bootstrap: checks passed (api key put/get; cleaner key get/delete and list …; worker key put/get; … anonymous get and list denied); exited with code 0
|
||||
make s3_check код 0; gRPC of gateway without TLS: no HTTP/2 answer (closed); TLS without client certificate: refused
|
||||
(TLSV13_ALERT_CERTIFICATE_REQUIRED); other CA: refused (SSLV3_ALERT_BAD_CERTIFICATE); stand CA client
|
||||
certificate: HTTP/2 answer (TLSv1.3); PASS: 94 checks, bucket messenger is private
|
||||
make test PASS: lab7 public API scenario (до и после 14 мин работы)
|
||||
```
|
||||
|
||||
Выборка `make failure_checks FAULT_ARGS='-k "object_storage or upload_after_idle_s3 or reconcile_finds_and_fixes"'`
|
||||
(свой стенд: `s3-bootstrap` с новым tmpfs — `exited with code 0`; остановка, пауза и простой S3, сверка; рабочий стенд
|
||||
остановлен):
|
||||
|
||||
```
|
||||
================ 8 passed, 391 deselected in 160.43s (0:02:40) =================
|
||||
[failure_checks] postgres log: 59 lines, crash markers 0; "too many clients" 0, "administrator command" 0, "no encryption" 0, "permission denied" 0
|
||||
[failure_checks] secrets log: 8 containers, …; refused access, renewal failures, missing fields 0
|
||||
«read-only file system» / «operation not permitted» в выводе прогона — 0; временная PKI удалена
|
||||
```
|
||||
|
||||
**S4, быстрый тест** — `test_compose_hardening.py` 9 → 14: override `bench/queue.compose.yml`,
|
||||
`bench/telemetry.compose.yml` и `TS_OVERRIDE` драйвера; монтирования и tmpfs override; контроли — сокет Docker
|
||||
длинной и короткой записью в override, bind на запись в `TS_OVERRIDE`. На коде `8fc5bbf` прежняя `override_problems`
|
||||
сокет в override стенда отказов не находит: `old override_problems with docker.sock: [] -> control FAIL (not
|
||||
detected)`.
|
||||
|
||||
**S8, Tempo** — `make stop`: `mtusi-lab7-tempo-1 exit=137 oom=false` (`FinishedAt` на 3 с позже Loki), `loki`, `prometheus` — 0;
|
||||
запись `KNOWN_ISSUES.md`.
|
||||
|
||||
**Проверки проекта и сверка покрытия:**
|
||||
|
||||
```
|
||||
make lint All checks passed!
|
||||
make check PASS: offline skeleton structure, local refs and Python syntax
|
||||
make service_test 737 passed
|
||||
openspec validate container-hardening --strict Change 'container-hardening' is valid
|
||||
driver.py: ast.parse(feature_version=(3, 9)) ok
|
||||
сверка покрытия (копия openspec/ и student-tests/, openspec archive container-hardening --yes): 423 → 423, added [], removed []
|
||||
поиск утечек в изменённых файлах (PEM закрытых ключей, токены s.… / hvs.…) совпадений нет
|
||||
```
|
||||
|
||||
В конце рабочий стенд остановлен (`make stop`); контейнеров проб, временных проектов, сетей и копий не осталось.
|
||||
|
||||
Reference in New Issue
Block a user