ЛР 7: Безопасность, mTLS и OpenBao
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"annotations": {"list": []},
|
||||
"editable": true,
|
||||
"fiscalYearStartMonth": 0,
|
||||
"graphTooltip": 1,
|
||||
"id": null,
|
||||
"links": [],
|
||||
"liveNow": false,
|
||||
"panels": [
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP RPS",
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"targets": [{"expr": "sum(rate(messenger_http_requests_total[$__rate_interval]))","legendFormat":"requests/s","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP 5xx ratio",
|
||||
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"targets": [{"expr":"sum(rate(messenger_http_requests_total{status_class=\"5xx\"}[$__rate_interval])) / clamp_min(sum(rate(messenger_http_requests_total[$__rate_interval])), 1e-9)","legendFormat":"5xx ratio","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "HTTP duration p95",
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"targets": [{"expr":"histogram_quantile(0.95, sum(rate(messenger_http_duration_seconds_bucket[$__rate_interval])) by (le))","legendFormat":"p95","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Image jobs",
|
||||
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 8},
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"targets": [{"expr":"sum by (outcome) (rate(messenger_jobs_processed_total[$__rate_interval]))","legendFormat":"{{outcome}}","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "timeseries",
|
||||
"title": "Worker duration p95",
|
||||
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 16},
|
||||
"datasource": {"type": "prometheus", "uid": "prometheus"},
|
||||
"targets": [{"expr":"histogram_quantile(0.95, sum(rate(messenger_job_duration_seconds_bucket[$__rate_interval])) by (le))","legendFormat":"p95","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "logs",
|
||||
"title": "API and worker logs",
|
||||
"gridPos": {"h": 10, "w": 12, "x": 12, "y": 16},
|
||||
"datasource": {"type": "loki", "uid": "loki"},
|
||||
"targets": [{"expr":"{service_name=~\"messenger-api|messenger-worker\"}","refId":"A"}]
|
||||
},
|
||||
{
|
||||
"type": "traces",
|
||||
"title": "Recent traces",
|
||||
"gridPos": {"h": 10, "w": 24, "x": 0, "y": 26},
|
||||
"datasource": {"type": "tempo", "uid": "tempo"},
|
||||
"targets": [{"queryType":"traceql","query":"{}","refId":"A","limit":20}]
|
||||
}
|
||||
],
|
||||
"refresh": "10s",
|
||||
"schemaVersion": 39,
|
||||
"style": "dark",
|
||||
"tags": ["lab6", "messenger", "otel"],
|
||||
"templating": {"list": []},
|
||||
"time": {"from": "now-15m", "to": "now"},
|
||||
"timepicker": {},
|
||||
"timezone": "browser",
|
||||
"title": "Messenger Observability",
|
||||
"uid": "messenger-lab6",
|
||||
"version": 1,
|
||||
"weekStart": ""
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: Lab6
|
||||
orgId: 1
|
||||
folder: Lab6
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 10
|
||||
allowUiUpdates: true
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,35 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: https://prometheus:9090
|
||||
jsonData:
|
||||
tlsSkipVerify: false
|
||||
isDefault: true
|
||||
editable: false
|
||||
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: https://loki:3100
|
||||
jsonData:
|
||||
tlsSkipVerify: false
|
||||
editable: false
|
||||
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: https://tempo:3200
|
||||
jsonData:
|
||||
tlsSkipVerify: false
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
filterByTraceID: true
|
||||
filterBySpanID: false
|
||||
tracesToMetrics:
|
||||
datasourceUid: prometheus
|
||||
@@ -0,0 +1,39 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
grpc_listen_port: 9096
|
||||
http_tls_config:
|
||||
cert_file: /certs/loki.crt
|
||||
key_file: /certs/loki.key
|
||||
grpc_tls_config:
|
||||
cert_file: /certs/loki.crt
|
||||
key_file: /certs/loki.key
|
||||
|
||||
common:
|
||||
path_prefix: /loki
|
||||
replication_factor: 1
|
||||
ring:
|
||||
instance_addr: 127.0.0.1
|
||||
kvstore:
|
||||
store: inmemory
|
||||
|
||||
schema_config:
|
||||
configs:
|
||||
- from: "2024-01-01"
|
||||
store: tsdb
|
||||
object_store: filesystem
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
storage_config:
|
||||
tsdb_shipper:
|
||||
active_index_directory: /loki/tsdb-index
|
||||
cache_location: /loki/tsdb-cache
|
||||
filesystem:
|
||||
directory: /loki/chunks
|
||||
|
||||
limits_config:
|
||||
allow_structured_metadata: true
|
||||
@@ -0,0 +1,16 @@
|
||||
FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c
|
||||
|
||||
ARG MINIO_RELEASE=RELEASE.2025-02-07T23-21-09Z
|
||||
ARG MINIO_SHA256=5a1b5bc661f0b8fd55eee530ea472205e77624718e31f7b4402bc269299501d5
|
||||
|
||||
RUN apk add --no-cache ca-certificates curl \
|
||||
&& curl --fail --location --silent --show-error \
|
||||
"https://github.com/minio/minio/releases/download/${MINIO_RELEASE}/minio.linux-amd64.${MINIO_RELEASE}" \
|
||||
--output /usr/local/bin/minio \
|
||||
&& echo "${MINIO_SHA256} /usr/local/bin/minio" | sha256sum -c - \
|
||||
&& chmod 0755 /usr/local/bin/minio \
|
||||
&& apk del curl
|
||||
|
||||
EXPOSE 9000 9001
|
||||
ENTRYPOINT ["/usr/local/bin/minio"]
|
||||
CMD ["server", "/data", "--console-address", ":9001"]
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket", "s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::__BUCKET__"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::__BUCKET__/attachments/*",
|
||||
"arn:aws:s3:::__BUCKET__/staging/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::__BUCKET__/staging/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:PutObject"],
|
||||
"Resource": ["arn:aws:s3:::__BUCKET__/attachments/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
ui = false
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/file"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_disable = 0
|
||||
tls_cert_file = "/openbao/certs/openbao.crt"
|
||||
tls_key_file = "/openbao/certs/openbao.key"
|
||||
tls_client_ca_file = "/openbao/certs/internal-ca.crt"
|
||||
tls_require_and_verify_client_cert = false
|
||||
}
|
||||
|
||||
disable_mlock = true
|
||||
@@ -0,0 +1,3 @@
|
||||
path "secret/data/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
path "secret/data/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
Добавьте `collector.yaml` с OTLP receivers, processors и exporters выбранной версии Collector. Укажите явные bind endpoints, внутренние сети, memory limits/batch и поведение при backpressure по уровню. Сопоставьте все три pipeline с реально развёрнутыми backend.
|
||||
|
||||
В Lab7 каждая связь должна проверять TLS серверный сертификат: сервисы проверяют CA и hostname/SAN, Collector -> backends и Grafana -> datasources также идут по HTTPS/gRPC TLS. Отключённый `insecure`/`tlsSkipVerify` не считается проверкой.
|
||||
|
||||
Добавьте конфигурации storage, Grafana provisioning/datasources, provisioning/dashboards и импортируемые dashboard JSON. На 4 — alert rules и runbooks. Пустой dashboard или debug exporter, который только печатает данные в stdout, не заменяют хранилища/доказательства из `contracts/observability.md`.
|
||||
|
||||
Не публикуйте OTLP/metrics/административные ports в общую сеть без необходимости. В lab7 реализуйте TLS/mTLS по trust matrix; экспорт Authorization и message bodies запрещён.
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /certs/otel-collector.crt
|
||||
key_file: /certs/otel-collector.key
|
||||
ca_file: /certs/internal-ca.crt
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
check_interval: 1s
|
||||
limit_mib: 256
|
||||
spike_limit_mib: 64
|
||||
batch:
|
||||
timeout: 2s
|
||||
send_batch_size: 512
|
||||
|
||||
exporters:
|
||||
prometheus:
|
||||
endpoint: 0.0.0.0:9464
|
||||
tls:
|
||||
cert_file: /certs/otel-collector.crt
|
||||
key_file: /certs/otel-collector.key
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:3100/otlp
|
||||
tls:
|
||||
ca_file: /certs/internal-ca.crt
|
||||
server_name_override: loki
|
||||
otlp/tempo:
|
||||
endpoint: tempo:4317
|
||||
tls:
|
||||
ca_file: /certs/internal-ca.crt
|
||||
server_name_override: tempo
|
||||
debug:
|
||||
verbosity: basic
|
||||
|
||||
service:
|
||||
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: [otlp/tempo]
|
||||
@@ -0,0 +1,12 @@
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
evaluation_interval: 15s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: otel-collector
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /certs/internal-ca.crt
|
||||
server_name: otel-collector
|
||||
static_configs:
|
||||
- targets: ["otel-collector:9464"]
|
||||
@@ -0,0 +1,4 @@
|
||||
tls_server_config:
|
||||
cert_file: /certs/prometheus.crt
|
||||
key_file: /certs/prometheus.key
|
||||
min_version: TLS12
|
||||
@@ -0,0 +1,13 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /etc/rabbitmq/certs/internal-ca.crt
|
||||
ssl_options.certfile = /etc/rabbitmq/certs/broker.crt
|
||||
ssl_options.keyfile = /etc/rabbitmq/certs/broker.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = false
|
||||
management.ssl.port = 15671
|
||||
management.ssl.cacertfile = /etc/rabbitmq/certs/internal-ca.crt
|
||||
management.ssl.certfile = /etc/rabbitmq/certs/broker.crt
|
||||
management.ssl.keyfile = /etc/rabbitmq/certs/broker.key
|
||||
management.ssl.verify = verify_none
|
||||
management.ssl.fail_if_no_peer_cert = false
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Idempotently create the private MinIO bucket before starting the API."""
|
||||
import os
|
||||
import time
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
|
||||
|
||||
def main():
|
||||
endpoint = os.environ.get("S3_ENDPOINT", "").strip()
|
||||
region = os.environ.get("S3_REGION", "us-east-1").strip()
|
||||
bucket = os.environ.get("S3_BUCKET", "").strip()
|
||||
access_key = os.environ.get("MINIO_ROOT_USER", "").strip()
|
||||
secret_key = os.environ.get("MINIO_ROOT_PASSWORD", "")
|
||||
if not all((endpoint, region, bucket, access_key, secret_key)):
|
||||
raise SystemExit("S3 bootstrap configuration is incomplete")
|
||||
|
||||
client = boto3.client(
|
||||
"s3",
|
||||
endpoint_url=endpoint,
|
||||
region_name=region,
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
verify=os.environ.get("INTERNAL_CA_CERT", True),
|
||||
config=Config(
|
||||
signature_version="s3v4",
|
||||
s3={"addressing_style": "path"},
|
||||
connect_timeout=3,
|
||||
read_timeout=5,
|
||||
retries={"max_attempts": 1, "mode": "standard"},
|
||||
),
|
||||
)
|
||||
for attempt in range(30):
|
||||
try:
|
||||
client.head_bucket(Bucket=bucket)
|
||||
print("S3 bucket is ready")
|
||||
return
|
||||
except ClientError as error:
|
||||
code = error.response.get("Error", {}).get("Code", "")
|
||||
if code not in ("404", "NoSuchBucket", "NotFound"):
|
||||
raise SystemExit("S3 bucket bootstrap failed") from None
|
||||
try:
|
||||
client.create_bucket(Bucket=bucket)
|
||||
print("S3 bucket created and ready")
|
||||
return
|
||||
except ClientError as create_error:
|
||||
create_code = create_error.response.get("Error", {}).get("Code", "")
|
||||
if create_code not in ("BucketAlreadyExists", "BucketAlreadyOwnedByYou"):
|
||||
raise SystemExit("S3 bucket bootstrap failed") from None
|
||||
except BotoCoreError:
|
||||
if attempt == 29:
|
||||
raise SystemExit("S3 endpoint did not become available") from None
|
||||
time.sleep(2)
|
||||
raise SystemExit("S3 bucket bootstrap timed out")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,17 @@
|
||||
FROM python:3.12.8-slim-bookworm
|
||||
|
||||
ARG MC_VERSION=RELEASE.2024-11-21T17-21-54Z
|
||||
ARG MC_SHA256=0312010A9D0AA7A52B4DFB14330F289EE4E295DEF80B3A3F530D4F38C1B71DA0
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl \
|
||||
&& curl --fail --location --silent --show-error \
|
||||
"https://github.com/minio/mc/releases/download/${MC_VERSION}/mc.linux-amd64.${MC_VERSION}" \
|
||||
--output /usr/local/bin/mc \
|
||||
&& echo "${MC_SHA256} /usr/local/bin/mc" | sha256sum -c - \
|
||||
&& chmod 0755 /usr/local/bin/mc \
|
||||
&& apt-get purge -y --auto-remove curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY scripts/provision-s3.py /scripts/provision-s3.py
|
||||
ENTRYPOINT ["python", "/scripts/provision-s3.py"]
|
||||
@@ -0,0 +1,40 @@
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
http_tls_config:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
grpc_tls_config:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
tls:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
|
||||
ingester:
|
||||
trace_idle_period: 10s
|
||||
max_block_bytes: 1000000
|
||||
max_block_duration: 5m
|
||||
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 168h
|
||||
|
||||
storage:
|
||||
trace:
|
||||
backend: local
|
||||
local:
|
||||
path: /var/tempo/traces
|
||||
wal:
|
||||
path: /var/tempo/wal
|
||||
Reference in New Issue
Block a user