forked from mtusi2026/mtusi2026lab7
feat: drop capabilities, run read-only and non-root in every container, mTLS for the S3 gRPC gateway
Every service of the stand gets the x-hardening anchor (cap_drop ALL, no-new-privileges, read-only root) with an empty exception table, tmpfs with size limits, pids limits by measurement and non-root users for PostgreSQL, Valkey, RabbitMQ and SeaweedFS. The S3 gateway gRPC accepts only mTLS with the stand CA. make hardening_check checks inspect data, processes and listeners against the compose model; a fast test keeps the override files from removing restrictions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+93
-1
@@ -39,8 +39,68 @@
|
||||
# seaweed 1000; ключ 0400), CA — ещё s3-bootstrap (seaweed 1000) и клиентам на
|
||||
# образе API (10001); pg_hba.conf — configs (bind mount в основном файле).
|
||||
|
||||
# С change container-hardening (design, решение 7) — единственное отличие
|
||||
# ограничений контейнеров от рабочего стенда: read_only: false у каждого
|
||||
# сервиса, которому CI доставляет configs / secrets из окружения (сейчас — у
|
||||
# всех). Compose без Swarm копирует их в файловую систему контейнера после
|
||||
# создания и для сервиса с корнем только на чтение отказывает сам («cannot
|
||||
# create secret … in read-only service»; tmpfs на каталогах назначения не
|
||||
# помогает — проба propose). Capabilities, no-new-privileges, пользователь,
|
||||
# tmpfs и пределы — из основного файла; согласованность сверяет
|
||||
# service-tests/unit/test_compose_hardening.py. Строки исключений — ниже, в
|
||||
# формате основного файла.
|
||||
x-hardening-exceptions:
|
||||
postgres:
|
||||
read_only: &ci-delivery >-
|
||||
доставка configs / secrets из окружения копией в контейнер: Compose
|
||||
отказывает сервису с корнем только на чтение, bind mount файла job на
|
||||
хосте раннера нет (design change container-hardening, решение 7)
|
||||
valkey:
|
||||
read_only: *ci-delivery
|
||||
s3:
|
||||
read_only: *ci-delivery
|
||||
s3-bootstrap:
|
||||
read_only: *ci-delivery
|
||||
rabbitmq:
|
||||
read_only: *ci-delivery
|
||||
migrate:
|
||||
read_only: *ci-delivery
|
||||
postgres-bootstrap:
|
||||
read_only: *ci-delivery
|
||||
api:
|
||||
read_only: *ci-delivery
|
||||
cleaner:
|
||||
read_only: *ci-delivery
|
||||
openbao:
|
||||
read_only: *ci-delivery
|
||||
relay:
|
||||
read_only: *ci-delivery
|
||||
worker:
|
||||
read_only: *ci-delivery
|
||||
haproxy:
|
||||
read_only: *ci-delivery
|
||||
otel-gateway:
|
||||
read_only: *ci-delivery
|
||||
loki-gateway:
|
||||
read_only: *ci-delivery
|
||||
tempo-gateway:
|
||||
read_only: *ci-delivery
|
||||
prometheus-gateway:
|
||||
read_only: *ci-delivery
|
||||
otel-collector:
|
||||
read_only: *ci-delivery
|
||||
prometheus:
|
||||
read_only: *ci-delivery
|
||||
loki:
|
||||
read_only: *ci-delivery
|
||||
tempo:
|
||||
read_only: *ci-delivery
|
||||
grafana:
|
||||
read_only: *ci-delivery
|
||||
|
||||
services:
|
||||
postgres:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
# !override: bind mount pg_hba.conf заменяет configs, volume данных остаётся
|
||||
volumes: !override
|
||||
@@ -63,6 +123,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
valkey:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
volumes: !reset []
|
||||
configs:
|
||||
@@ -87,7 +148,15 @@ services:
|
||||
mode: 0400
|
||||
|
||||
s3:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
# !override: bind mount security.toml (mTLS gRPC шлюза, change
|
||||
# container-hardening) заменяет configs, volume данных остаётся
|
||||
volumes: !override
|
||||
- s3_data:/data
|
||||
configs:
|
||||
- source: s3_security
|
||||
target: /etc/seaweedfs/security.toml
|
||||
secrets: !override
|
||||
- source: ca.crt
|
||||
uid: "1000"
|
||||
@@ -103,6 +172,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
s3-bootstrap:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: s3_bootstrap
|
||||
@@ -116,8 +186,10 @@ services:
|
||||
# брокер (change messaging-telemetry-mtls, design, решение 9): четыре файла
|
||||
# конфигурации — configs (entrypoint sh читает start.sh, исполняемый бит не
|
||||
# нужен), tmpfs /run/rabbitmq — из основного файла; пара rabbitmq — владелец
|
||||
# rabbitmq (999), ключ 0400 (start.sh от root копирует её в tmpfs)
|
||||
# rabbitmq (999), ключ 0400 (start.sh копирует её в tmpfs от того же
|
||||
# пользователя rabbitmq — с change container-hardening не от root)
|
||||
rabbitmq:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
# !override: bind mount конфигов заменяют configs, volume данных остаётся
|
||||
volumes: !override
|
||||
@@ -150,6 +222,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
migrate:
|
||||
read_only: false
|
||||
image: &ci-image mtusi-messenger:${CI_IMAGE_TAG:?CI_IMAGE_TAG is not set}
|
||||
volumes: !reset []
|
||||
configs: &config-toml
|
||||
@@ -179,6 +252,7 @@ services:
|
||||
|
||||
# bootstrap ролей PostgreSQL (change storage-roles): образ прогона
|
||||
postgres-bootstrap:
|
||||
read_only: false
|
||||
image: *ci-image
|
||||
volumes: !reset []
|
||||
configs: *config-toml
|
||||
@@ -189,6 +263,7 @@ services:
|
||||
mode: 0444
|
||||
|
||||
api:
|
||||
read_only: false
|
||||
image: *ci-image
|
||||
volumes: !reset []
|
||||
configs: *config-toml
|
||||
@@ -221,6 +296,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
cleaner:
|
||||
read_only: false
|
||||
image: *ci-image
|
||||
volumes: !reset []
|
||||
configs: *config-toml
|
||||
@@ -248,6 +324,7 @@ services:
|
||||
# порта на хосте нет; config.hcl — configs, данные — volume проекта;
|
||||
# файлы — CA и пара openbao, владелец — пользователь образа openbao (100:1000)
|
||||
openbao:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
volumes: !override
|
||||
- openbao_data:/openbao/file
|
||||
@@ -271,6 +348,7 @@ services:
|
||||
# relay и worker (change messaging-telemetry-mtls): CA, CRL и своя пара
|
||||
# identity у брокера, владелец app (10001), ключ 0400
|
||||
relay:
|
||||
read_only: false
|
||||
image: *ci-image
|
||||
volumes: !reset []
|
||||
configs: *config-toml
|
||||
@@ -293,6 +371,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
worker:
|
||||
read_only: false
|
||||
image: *ci-image
|
||||
volumes: !reset []
|
||||
configs: *config-toml
|
||||
@@ -315,6 +394,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
haproxy:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
volumes: !reset []
|
||||
configs:
|
||||
@@ -351,6 +431,7 @@ services:
|
||||
# 0444. Collector — в сетевом пространстве шлюза (network_mode основного
|
||||
# файла): сетей override ему не добавляет
|
||||
otel-gateway:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: otel_gateway_cfg
|
||||
@@ -376,6 +457,7 @@ services:
|
||||
# 0400, CA и CRL 0444. Хранилища — в пространствах шлюзов (network_mode
|
||||
# основного файла): сетей override им не добавляет
|
||||
loki-gateway:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: loki_gateway_cfg
|
||||
@@ -397,6 +479,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
tempo-gateway:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: tempo_gateway_cfg
|
||||
@@ -418,6 +501,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
prometheus-gateway:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: prometheus_gateway_cfg
|
||||
@@ -441,6 +525,7 @@ services:
|
||||
# Collector (пользователь образа 10001): CA и клиентская пара
|
||||
# otel-collector-client (change telemetry-backends-tls), ключ 0400
|
||||
otel-collector:
|
||||
read_only: false
|
||||
volumes: !reset []
|
||||
configs:
|
||||
- source: otel_collector
|
||||
@@ -461,6 +546,7 @@ services:
|
||||
|
||||
# Prometheus (nobody, 65534): CA и пара prometheus-client
|
||||
prometheus:
|
||||
read_only: false
|
||||
volumes: !override
|
||||
- prometheus_data:/prometheus
|
||||
configs:
|
||||
@@ -484,6 +570,7 @@ services:
|
||||
mode: 0400
|
||||
|
||||
loki:
|
||||
read_only: false
|
||||
volumes: !override
|
||||
- loki_data:/loki
|
||||
configs:
|
||||
@@ -491,6 +578,7 @@ services:
|
||||
target: /etc/loki/loki.yaml
|
||||
|
||||
tempo:
|
||||
read_only: false
|
||||
volumes: !override
|
||||
- tempo_data:/var/tempo
|
||||
configs:
|
||||
@@ -498,6 +586,7 @@ services:
|
||||
target: /etc/tempo/tempo.yaml
|
||||
|
||||
grafana:
|
||||
read_only: false
|
||||
ports: !reset []
|
||||
volumes: !reset []
|
||||
configs:
|
||||
@@ -542,6 +631,9 @@ configs:
|
||||
environment: CI_VALKEY_START
|
||||
s3_bootstrap:
|
||||
environment: CI_S3_BOOTSTRAP
|
||||
# mTLS служебного gRPC шлюза S3 (change container-hardening)
|
||||
s3_security:
|
||||
environment: CI_S3_SECURITY
|
||||
rabbitmq_conf:
|
||||
environment: CI_RABBITMQ_CONF
|
||||
rabbitmq_advanced:
|
||||
|
||||
@@ -48,6 +48,9 @@ export CI_OTEL_COLLECTOR CI_PROMETHEUS_YML CI_LOKI_YAML CI_TEMPO_YAML \
|
||||
# конфигурация сервера OpenBao (change openbao-tooling)
|
||||
CI_OPENBAO_CONFIG="$(cat infra/openbao/config.hcl)$nl"
|
||||
export CI_OPENBAO_CONFIG
|
||||
# mTLS служебного gRPC шлюза S3 (change container-hardening)
|
||||
CI_S3_SECURITY="$(cat infra/s3/security.toml)$nl"
|
||||
export CI_S3_SECURITY
|
||||
|
||||
# файлы PKI прогона (change https-tooling, design, решение 3) — secrets
|
||||
# override из окружения: каталог стенда, который заполнил make pki_stand
|
||||
|
||||
Reference in New Issue
Block a user