forked from mtusi2026/mtusi2026lab7
ЛР 7: безопасность, mTLS и OpenBao на оценку 3
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
{
|
||||
"uid": "messenger-observability",
|
||||
"title": "Messenger — Observability",
|
||||
"tags": ["messenger", "lab6"],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"refresh": "5s",
|
||||
"editable": false,
|
||||
"time": {
|
||||
"from": "now-15m",
|
||||
"to": "now"
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "HTTP Requests / sec",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(http_requests_total{service_name=\"messenger-api\"}[1m]))",
|
||||
"legendFormat": "Requests/sec"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "HTTP Error Ratio",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 8,
|
||||
"y": 0
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "100 * (sum(rate(http_requests_total{service_name=\"messenger-api\",status_class=\"5xx\"}[1m])) or 0 * sum(rate(http_requests_total{service_name=\"messenger-api\"}[1m]))) / sum(rate(http_requests_total{service_name=\"messenger-api\"}[1m]))",
|
||||
"legendFormat": "5xx errors"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percent",
|
||||
"min": 0,
|
||||
"max": 100
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "HTTP Duration p95",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 16,
|
||||
"y": 0
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket{service_name=\"messenger-api\"}[1m]) and ignoring(le) http_request_duration_seconds_bucket{service_name=\"messenger-api\",le=\"0.005\"}))",
|
||||
"legendFormat": "HTTP p95"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Job Attempts / sec",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 0,
|
||||
"y": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(jobs_processed_total{service_name=\"messenger-worker\"}[1m]))",
|
||||
"legendFormat": "Attempts/sec"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "ops",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Job Outcomes",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 8,
|
||||
"y": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (outcome) (jobs_processed_total{service_name=\"messenger-worker\"})",
|
||||
"legendFormat": "{{outcome}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Job Duration p95",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 8,
|
||||
"x": 16,
|
||||
"y": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(job_processing_duration_seconds_bucket{service_name=\"messenger-worker\"}[1m]) and ignoring(le) job_processing_duration_seconds_bucket{service_name=\"messenger-worker\",le=\"0.05\"}))",
|
||||
"legendFormat": "Worker p95"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: Messenger
|
||||
orgId: 1
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: true
|
||||
editable: false
|
||||
updateIntervalSeconds: 10
|
||||
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"apiVersion": 1,
|
||||
"datasources": [
|
||||
{
|
||||
"name": "Prometheus",
|
||||
"uid": "prometheus",
|
||||
"type": "prometheus",
|
||||
"access": "proxy",
|
||||
"url": "https://telemetry:8444/prometheus",
|
||||
"isDefault": true,
|
||||
"editable": false,
|
||||
"basicAuth": true,
|
||||
"basicAuthUser": "grafana",
|
||||
"jsonData": {
|
||||
"tlsAuthWithCACert": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Loki",
|
||||
"uid": "loki",
|
||||
"type": "loki",
|
||||
"access": "proxy",
|
||||
"url": "https://telemetry:8444/loki",
|
||||
"isDefault": false,
|
||||
"editable": false,
|
||||
"basicAuth": true,
|
||||
"basicAuthUser": "grafana",
|
||||
"jsonData": {
|
||||
"tlsAuthWithCACert": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Tempo",
|
||||
"uid": "tempo",
|
||||
"type": "tempo",
|
||||
"access": "proxy",
|
||||
"url": "https://telemetry:8444/tempo",
|
||||
"isDefault": false,
|
||||
"editable": false,
|
||||
"basicAuth": true,
|
||||
"basicAuthUser": "grafana",
|
||||
"jsonData": {
|
||||
"tlsAuthWithCACert": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# База lab6
|
||||
|
||||
Из lab6 перенесены FastAPI, Alembic, PostgreSQL, Redis, S3, RabbitMQ, обработчик вложений, transactional outbox и наблюдаемость. Текущий `docker-compose.yml` запускает защищённый стенд lab7. Параметры, порядок запуска и команды проверок приведены в [отчёте lab7](../REPORT.md).
|
||||
@@ -0,0 +1,38 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
grpc_listen_address: 127.0.0.1
|
||||
grpc_listen_port: 9096
|
||||
http_listen_port: 3100
|
||||
|
||||
common:
|
||||
instance_addr: 127.0.0.1
|
||||
path_prefix: /loki
|
||||
|
||||
storage:
|
||||
filesystem:
|
||||
chunks_directory: /loki/chunks
|
||||
rules_directory: /loki/rules
|
||||
|
||||
replication_factor: 1
|
||||
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
|
||||
schema_config:
|
||||
configs:
|
||||
- from: 2024-01-01
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
|
||||
analytics:
|
||||
reporting_enabled: false
|
||||
@@ -1,7 +1,5 @@
|
||||
# OpenBao — реализовать конфигурацию и политики
|
||||
# OpenBao в стенде lab7
|
||||
|
||||
Добавьте non-dev конфигурацию listener/storage/TLS, API/worker policies, bootstrap и rotation scripts. Credentials и unseal material создаются локально; здесь нет готового root token или private key.
|
||||
Сервер использует TLS и зашифрованное файловое хранилище в именованном томе. Оператор с хоста запускает `python3 scripts/lab7.py up`. Bootstrap создаёт три доли разблокировки с порогом два и хранит их в защищённом операторском каталоге. Процессы приложения получают собственные файлы AppRole через bind mount и обращаются к OpenBao через TLS.
|
||||
|
||||
Решение должно показать реальную сервисную аутентификацию и получение нужного secret по ограниченной policy; просто работающий контейнер OpenBao не засчитывается. На 3 статический KV secret допустим. На 4 покажите expiry/renewal/rotation и allow/deny. Путь KV v2 data/metadata и ACL должен соответствовать фактическому mount; не копируйте широкое `path "*"` для приложения.
|
||||
|
||||
Документируйте шаги оператора init/unseal и восстановление после restart. Скрипт не должен печатать tokens/shares или хранить их в Git. См. contracts/trust-matrix.md и REPORT.md.
|
||||
Политика каждой роли разрешает один путь `messenger/data/<роль>`. Токен действует до пяти минут и отзывается после чтения. После остановки OpenBao оператор выполняет `python3 scripts/lab7.py unseal`. Команды запуска и проверки политик есть в [отчёте](../../REPORT.md).
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
ui = false
|
||||
disable_mlock = true
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/file"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/run/identity/server.crt"
|
||||
tls_key_file = "/run/identity/server.key"
|
||||
tls_min_version = "tls12"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
path "messenger/data/ROLE_NAME" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:14318
|
||||
|
||||
extensions:
|
||||
basicauth/collector:
|
||||
client_auth:
|
||||
username: collector
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 192
|
||||
spike_limit_mib: 48
|
||||
batch:
|
||||
timeout: 1s
|
||||
send_batch_size: 512
|
||||
|
||||
exporters:
|
||||
prometheus:
|
||||
endpoint: 127.0.0.1:8889
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
otlphttp/loki:
|
||||
logs_endpoint: https://telemetry:8444/loki-write
|
||||
tls:
|
||||
ca_file: /run/ca/ca.crt
|
||||
auth:
|
||||
authenticator: basicauth/collector
|
||||
otlphttp/tempo:
|
||||
traces_endpoint: https://telemetry:8444/tempo-write
|
||||
tls:
|
||||
ca_file: /run/ca/ca.crt
|
||||
auth:
|
||||
authenticator: basicauth/collector
|
||||
|
||||
service:
|
||||
extensions: [basicauth/collector]
|
||||
telemetry:
|
||||
metrics:
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 127.0.0.1
|
||||
port: 8888
|
||||
pipelines:
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/loki]
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [memory_limiter, batch]
|
||||
exporters: [otlphttp/tempo]
|
||||
@@ -0,0 +1,25 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
evaluation_interval: 5s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
scheme: https
|
||||
static_configs:
|
||||
- targets: ["telemetry:8444"]
|
||||
tls_config:
|
||||
ca_file: /run/ca/ca.crt
|
||||
basic_auth:
|
||||
username: prometheus
|
||||
password_file: /run/identity/scrape_password
|
||||
|
||||
- job_name: collector-internal
|
||||
scheme: https
|
||||
metrics_path: /collector-metrics
|
||||
static_configs:
|
||||
- targets: ["telemetry:8444"]
|
||||
tls_config:
|
||||
ca_file: /run/ca/ca.crt
|
||||
basic_auth:
|
||||
username: prometheus
|
||||
password_file: /run/identity/scrape_password
|
||||
@@ -0,0 +1,16 @@
|
||||
-- API owns business operations. The two background processes have separate roles.
|
||||
GRANT SELECT, INSERT ON users, chats, chat_members, messages TO messenger_api;
|
||||
GRANT SELECT, INSERT ON attachments TO messenger_api;
|
||||
GRANT INSERT ON outbox_events TO messenger_api;
|
||||
GRANT SELECT (created_at) ON outbox_events TO messenger_api;
|
||||
|
||||
GRANT SELECT ON attachments TO messenger_worker;
|
||||
GRANT UPDATE (status, error_code, updated_at, lease_expires_at, thumbnail_key,
|
||||
thumbnail_sha256, thumbnail_size_bytes, thumbnail_width,
|
||||
thumbnail_height, crop_key, webp_key)
|
||||
ON attachments TO messenger_worker;
|
||||
|
||||
GRANT SELECT ON attachments, outbox_events TO messenger_outbox;
|
||||
GRANT UPDATE (status, lease_expires_at, updated_at) ON attachments TO messenger_outbox;
|
||||
GRANT INSERT ON outbox_events TO messenger_outbox;
|
||||
GRANT UPDATE (published_at) ON outbox_events TO messenger_outbox;
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /tmp/mc/certs/CAs
|
||||
cp /run/ca/ca.crt /tmp/mc/certs/CAs/lab7.crt
|
||||
export MC_CONFIG_DIR=/tmp/mc
|
||||
attempt=0
|
||||
until mc alias set storage https://minio:9000 messenger-admin "$(cat /run/identity/admin_password)" >/dev/null 2>&1; do
|
||||
attempt=$((attempt + 1))
|
||||
[ "$attempt" -lt 30 ] || exit 1
|
||||
sleep 1
|
||||
done
|
||||
mc mb --ignore-existing storage/messenger-attachments
|
||||
mc anonymous set none storage/messenger-attachments
|
||||
for role in api worker; do
|
||||
mc admin user add storage "messenger-$role" "$(cat "/run/identity/${role}_password")" >/dev/null
|
||||
mc admin policy create storage "messenger-$role" "/run/identity/${role}_policy.json"
|
||||
mc admin policy attach storage "messenger-$role" --user "messenger-$role"
|
||||
done
|
||||
@@ -0,0 +1,3 @@
|
||||
local all all trust
|
||||
hostssl all all 0.0.0.0/0 scram-sha-256
|
||||
hostssl all all ::/0 scram-sha-256
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
install -d -m 0700 -o postgres -g postgres /tmp/db-tls
|
||||
install -m 0600 -o postgres -g postgres /run/identity/server.key /tmp/db-tls/server.key
|
||||
install -m 0644 -o postgres -g postgres /run/identity/server.crt /tmp/db-tls/server.crt
|
||||
export POSTGRES_PASSWORD_FILE=/run/identity/admin_password
|
||||
exec docker-entrypoint.sh postgres \
|
||||
-c ssl=on -c ssl_cert_file=/tmp/db-tls/server.crt -c ssl_key_file=/tmp/db-tls/server.key \
|
||||
-c hba_file=/etc/lab7/pg_hba.conf -c password_encryption=scram-sha-256
|
||||
@@ -0,0 +1 @@
|
||||
[].
|
||||
@@ -0,0 +1,10 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /run/ca/ca.crt
|
||||
ssl_options.certfile = /run/identity/server.crt
|
||||
ssl_options.keyfile = /run/identity/server.key
|
||||
ssl_options.verify = verify_none
|
||||
ssl_options.fail_if_no_peer_cert = false
|
||||
distribution.listener.interface = 127.0.0.1
|
||||
definitions.import_backend = local_filesystem
|
||||
definitions.local.path = /run/identity/definitions.json
|
||||
@@ -0,0 +1,9 @@
|
||||
port 0
|
||||
tls-port 6380
|
||||
tls-cert-file /run/identity/server.crt
|
||||
tls-key-file /run/identity/server.key
|
||||
tls-ca-cert-file /run/ca/ca.crt
|
||||
tls-auth-clients no
|
||||
aclfile /run/identity/users.acl
|
||||
appendonly yes
|
||||
dir /data
|
||||
@@ -0,0 +1,84 @@
|
||||
pid /tmp/nginx.pid;
|
||||
events { worker_connections 512; }
|
||||
|
||||
http {
|
||||
access_log off;
|
||||
server_tokens off;
|
||||
client_body_temp_path /tmp/nginx-body;
|
||||
proxy_temp_path /tmp/nginx-proxy;
|
||||
fastcgi_temp_path /tmp/nginx-fastcgi;
|
||||
uwsgi_temp_path /tmp/nginx-uwsgi;
|
||||
scgi_temp_path /tmp/nginx-scgi;
|
||||
client_max_body_size 16m;
|
||||
|
||||
server {
|
||||
listen 8444 ssl;
|
||||
ssl_certificate /run/identity/server.crt;
|
||||
ssl_certificate_key /run/identity/server.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
proxy_set_header Authorization "";
|
||||
|
||||
location ~ ^/ingest/v1/(logs|metrics|traces)$ {
|
||||
auth_basic "otlp-ingest";
|
||||
auth_basic_user_file /run/identity/ingest.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
rewrite ^/ingest(.*)$ $1 break;
|
||||
proxy_pass http://127.0.0.1:14318;
|
||||
}
|
||||
location = /loki-write {
|
||||
auth_basic "loki-write";
|
||||
auth_basic_user_file /run/identity/collector.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:3100/otlp/v1/logs;
|
||||
}
|
||||
location = /tempo-write {
|
||||
auth_basic "tempo-write";
|
||||
auth_basic_user_file /run/identity/collector.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:14319/v1/traces;
|
||||
}
|
||||
location = /metrics {
|
||||
auth_basic "prometheus-scrape";
|
||||
auth_basic_user_file /run/identity/scrape.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:8889/metrics;
|
||||
}
|
||||
location = /collector-metrics {
|
||||
auth_basic "prometheus-scrape";
|
||||
auth_basic_user_file /run/identity/scrape.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:8888/metrics;
|
||||
}
|
||||
location /prometheus/api/v1/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:9090/api/v1/;
|
||||
}
|
||||
location /loki/loki/api/v1/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:3100/loki/api/v1/;
|
||||
}
|
||||
location /tempo/api/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:3200/api/;
|
||||
}
|
||||
location / { return 404; }
|
||||
}
|
||||
|
||||
server {
|
||||
listen 3443 ssl;
|
||||
ssl_certificate /run/identity/server.crt;
|
||||
ssl_certificate_key /run/identity/server.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
location / {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
server:
|
||||
http_listen_address: 127.0.0.1
|
||||
grpc_listen_address: 127.0.0.1
|
||||
http_listen_port: 3200
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 127.0.0.1:14319
|
||||
|
||||
ingester:
|
||||
max_block_duration: 5m
|
||||
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 168h
|
||||
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
|
||||
local:
|
||||
path: /var/tempo/blocks
|
||||
Reference in New Issue
Block a user