Implement TLS identities, scoped OpenBao access and worker security study

This commit is contained in:
2026-11-16 11:57:32 +03:00
parent 20afc2c790
commit 32795a92ac
78 changed files with 8798 additions and 19 deletions
+3
View File
@@ -0,0 +1,3 @@
[leveldb2]
enabled = true
dir = "/data/filerldb2"
+450
View File
@@ -0,0 +1,450 @@
{
"uid": "messenger-overview",
"title": "Messenger: API and image pipeline",
"schemaVersion": 39,
"version": 1,
"refresh": "5s",
"time": {
"from": "now-15m",
"to": "now"
},
"panels": [
{
"id": 1,
"title": "Business RPS",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_requests_total[1m]))"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
}
},
{
"id": 2,
"title": "Business 5xx ratio",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_requests_total{status_class=\"5xx\"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total[1m])),0.001)"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 3,
"title": "HTTP latency quantiles",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.5, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p50"
},
{
"refId": "B",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p95"
},
{
"refId": "C",
"expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_http_duration_seconds_bucket[1m])))",
"legendFormat": "p99"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 4,
"title": "Job outcomes",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (rate(messenger_jobs_total[1m]))"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 5,
"title": "Job p95 processing",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 16
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 6,
"title": "End-to-end p95 to ready",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_attachment_ready_duration_seconds_bucket[1m])))"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 16
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 7,
"title": "Outstanding jobs",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_depth)"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 24
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 8,
"title": "Oldest outstanding age",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "max(messenger_queue_oldest_age_seconds)"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 24
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
}
},
{
"id": 9,
"title": "DB pool used",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "messenger_db_pool_used"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 32
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 10,
"title": "DB pool waiting",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "messenger_db_pool_waiting"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 32
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
}
},
{
"id": 11,
"title": "Worker busy/capacity",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "messenger_worker_busy / messenger_worker_capacity"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 40
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
},
"overrides": []
}
},
{
"id": 12,
"title": "Process resident memory",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "messenger_process_memory_bytes"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 40
},
"fieldConfig": {
"defaults": {
"unit": "bytes"
},
"overrides": []
}
},
{
"id": 13,
"title": "Process CPU (100%=1 core)",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "messenger_process_cpu_percent"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 48
},
"fieldConfig": {
"defaults": {
"unit": "percent"
},
"overrides": []
}
},
{
"id": 14,
"title": "Sampling decisions",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "sum by (decision) (rate(messenger_http_trace_decisions_total[1m]))"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 48
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 15,
"title": "Collector failed span sends",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"targets": [
{
"refId": "A",
"expr": "rate(otelcol_exporter_send_failed_spans_total[1m])"
}
],
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 56
},
"fieldConfig": {
"defaults": {
"unit": "ops"
},
"overrides": []
}
},
{
"id": 99,
"title": "Structured application logs (trace_id and request_id)",
"type": "logs",
"datasource": {
"type": "loki",
"uid": "loki"
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"}"
}
],
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 64
}
}
]
}
@@ -0,0 +1,7 @@
apiVersion: 1
providers:
- name: messenger
folder: Messenger
type: file
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,27 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: false
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
editable: false
jsonData:
derivedFields:
- datasourceUid: tempo
matcherRegex: '"trace_id": "([a-f0-9]{32})"'
name: TraceID
url: '$${__value.raw}'
- name: Tempo
uid: tempo
type: tempo
access: proxy
url: http://tempo:3200
editable: false
+38
View File
@@ -0,0 +1,38 @@
global
log stdout format raw local0
maxconn 256
stats socket /tmp/haproxy.sock mode 600 level user
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
ssl-default-server-options ssl-min-ver TLSv1.2 no-tls-tickets
defaults
mode http
log global
timeout connect 1s
timeout client 20s
timeout server 15s
timeout check 2s
timeout queue 2s
retries 0
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 1s
hold obsolete 1s
hold nx 1s
frontend public
bind :8443 ssl crt /run/tls/identity/combined.pem
http-request set-var(txn.lb_request_id) uuid()
http-request return status 503 content-type application/json lf-string '{"error":{"code":"unavailable","message":"No ready API","request_id":"%[var(txn.lb_request_id)]"}}' hdr X-Request-Id '%[var(txn.lb_request_id)]' if { nbsrv(apis) eq 0 }
default_backend apis
backend apis
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server inter 1s fastinter 500ms downinter 1s fall 2 rise 2
server-template api 1-8 api:9443 ssl verify required ca-file /run/tls/ca.pem crt /run/tls/identity/combined.pem verifyhost api sni str(api) check check-sni api resolvers docker resolve-prefer ipv4 init-addr libc,none
+24
View File
@@ -0,0 +1,24 @@
groups:
- name: messenger-slo
rules:
- alert: MessengerHighErrorRate
expr: sum(rate(messenger_http_requests_total{status_class="5xx"}[1m])) / clamp_min(sum(rate(messenger_http_requests_total[1m])), 0.001) > 0.05
for: 10s
labels: {severity: warning}
annotations:
summary: Business HTTP 5xx ratio above 5% over 1 minute
runbook_url: file:RUNBOOK.md#api-errors
- alert: MessengerQueueLag
expr: max(messenger_queue_oldest_age_seconds) > 15 and max(messenger_queue_depth) > 0
for: 10s
labels: {severity: warning}
annotations:
summary: Outstanding attachment job age above 15 seconds
runbook_url: file:RUNBOOK.md#queue-lag
- alert: MessengerTelemetryUnavailable
expr: up{job="messenger"} == 0
for: 10s
labels: {severity: warning}
annotations:
summary: Collector metrics unavailable
runbook_url: file:RUNBOOK.md#telemetry-unavailable
+87
View File
@@ -0,0 +1,87 @@
extensions:
health_check:
endpoint: 127.0.0.1:13133
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 160
spike_limit_mib: 32
batch:
timeout: 1s
send_batch_size: 128
send_batch_max_size: 256
exporters:
prometheus:
endpoint: 127.0.0.1:19464
metric_expiration: 15m
resource_to_telemetry_conversion:
enabled: true
otlphttp/tempo:
endpoint: https://tempo:44318
tls:
ca_file: /run/tls/ca.pem
cert_file: /run/tls/identity/cert.pem
key_file: /run/tls/identity/key.pem
timeout: 2s
sending_queue:
queue_size: 128
num_consumers: 1
retry_on_failure:
initial_interval: 1s
max_interval: 2s
max_elapsed_time: 5s
otlphttp/loki:
endpoint: https://loki:9443/otlp
timeout: 2s
sending_queue:
queue_size: 128
num_consumers: 1
retry_on_failure:
initial_interval: 1s
max_interval: 2s
max_elapsed_time: 5s
tls:
ca_file: /run/tls/ca.pem
cert_file: /run/tls/identity/cert.pem
key_file: /run/tls/identity/key.pem
service:
extensions:
- health_check
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: 127.0.0.1
port: 18888
pipelines:
traces:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlphttp/tempo
metrics:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- prometheus
logs:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlphttp/loki
+34
View File
@@ -0,0 +1,34 @@
auth_enabled: false
server:
http_listen_port: 3100
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
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
retention_period: 24h
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
analytics:
reporting_enabled: false
+26
View File
@@ -0,0 +1,26 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
rule_files:
- /etc/prometheus/alerts.yaml
scrape_configs:
- job_name: messenger
static_configs:
- targets:
- collector:9464
scheme: https
tls_config:
ca_file: /run/tls/ca.pem
cert_file: /run/tls/identity/cert.pem
key_file: /run/tls/identity/key.pem
server_name: collector
- job_name: collector
static_configs:
- targets:
- collector:8888
scheme: https
tls_config:
ca_file: /run/tls/ca.pem
cert_file: /run/tls/identity/cert.pem
key_file: /run/tls/identity/key.pem
server_name: collector
+24
View File
@@ -0,0 +1,24 @@
server:
http_listen_port: 3200
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:4318
ingester:
max_block_duration: 1m
compactor:
compaction:
block_retention: 24h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
usage_report:
reporting_enabled: false
+12
View File
@@ -0,0 +1,12 @@
ui = true
disable_mlock = true
storage "file" { path = "/bao/data" }
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/run/tls/identity/cert.pem"
tls_key_file = "/run/tls/identity/key.pem"
tls_client_ca_file = "/run/tls/ca.pem"
tls_require_and_verify_client_cert = true
tls_min_version = "tls12"
}
api_addr = "https://openbao:8200"
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu
cp /run/tls/identity/key.pem /tmp/postgres-key.pem
chown postgres:postgres /tmp/postgres-key.pem
chmod 600 /tmp/postgres-key.pem
exec docker-entrypoint.sh "$@"
+3
View File
@@ -0,0 +1,3 @@
local all all trust
hostnossl all all 0.0.0.0/0 reject
hostssl messenger api,worker,dispatcher,messenger 0.0.0.0/0 scram-sha-256