Prepare verified laboratory 7 implementation and evidence

This commit is contained in:
rey
2026-11-17 17:32:06 +03:00
parent 20afc2c790
commit eb1b5c7b84
677 changed files with 208256 additions and 64 deletions
+603
View File
@@ -0,0 +1,603 @@
{
"uid": "messenger-security",
"title": "Messenger lab7 security and pipeline",
"schemaVersion": 39,
"version": 1,
"editable": false,
"time": {
"from": "now-15m",
"to": "now"
},
"refresh": "5s",
"panels": [
{
"id": 1,
"title": "Requests / second",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(http_requests[1m]))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 2,
"title": "HTTP p50 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.50,sum by (le)(rate(http_duration_bucket[1m])))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 3,
"title": "HTTP p99 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.99,sum by (le)(rate(http_duration_bucket[1m])))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 4,
"title": "HTTP server error ratio",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "(sum(rate(http_requests{status_class=\"5xx\"}[1m])) or vector(0)) / clamp_min(sum(rate(http_requests[1m])),0.001)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 5,
"title": "HTTP p95 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95,sum by (le)(rate(http_duration_bucket[1m])))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 6,
"title": "Jobs by outcome",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome)(rate(jobs_processed[1m]))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 7,
"title": "Job duration p95 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95,sum by(le)(rate(job_duration_bucket[1m])))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 8,
"title": "Time to ready p95 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "histogram_quantile(0.95,sum by(le)(rate(time_to_ready_bucket[1m])))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 9,
"title": "Oldest unfinished job seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "max(queue_oldest_age_seconds)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 10,
"title": "Unfinished jobs",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "max(queue_depth)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 11,
"title": "Worker busy",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum(worker_busy)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 12,
"title": "Worker capacity",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum((worker_capacity and (timestamp(worker_capacity) > time()-10)))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 13,
"title": "Database observer up",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "min((database_observer_up and (timestamp(database_observer_up) > time()-10)))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 14,
"title": "Database pool used",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum(db_pool_used)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 15,
"title": "Database pending acquires",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum(db_pool_pending_acquires)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 16,
"title": "Database pool capacity",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "sum((db_pool_capacity and (timestamp(db_pool_capacity)>time()-10)))"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 17,
"title": "Ready within 10 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 64,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "max(ready_slo_timely_10s) / clamp_min(max(ready_slo_matured_10s),1)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 18,
"title": "Ready within 30 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 12,
"y": 64,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "max(ready_slo_timely_30s) / clamp_min(max(ready_slo_matured_30s),1)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
},
{
"id": 19,
"title": "Ready within 300 seconds",
"type": "timeseries",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"gridPos": {
"x": 0,
"y": 72,
"w": 12,
"h": 8
},
"targets": [
{
"refId": "A",
"expr": "max(ready_slo_timely_300s) / clamp_min(max(ready_slo_matured_300s),1)"
}
],
"fieldConfig": {
"defaults": {},
"overrides": []
},
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
}
}
]
}
@@ -0,0 +1,95 @@
apiVersion: 1
groups:
- orgId: 1
name: messenger-security
folder: Messenger lab7
interval: 10s
rules:
- uid: vp7-server-errors
title: Messenger server error ratio
condition: C
for: 30s
noDataState: NoData
execErrState: Error
isPaused: false
labels: { severity: warning, service: messenger-api }
annotations:
summary: API server error ratio exceeds five percent
runbook: RUN.md, telemetry incidents
data:
- refId: A
datasourceUid: prometheus
relativeTimeRange: { from: 60, to: 0 }
model:
datasource: { type: prometheus, uid: prometheus }
expr: (sum(rate(http_requests{status_class="5xx"}[1m])) or vector(0)) / clamp_min(sum(rate(http_requests[1m])),0.001)
instant: true
range: false
refId: A
- refId: B
datasourceUid: __expr__
relativeTimeRange: { from: 0, to: 0 }
model:
datasource: { type: __expr__, uid: __expr__ }
expression: A
type: reduce
reducer: last
refId: B
- refId: C
datasourceUid: __expr__
relativeTimeRange: { from: 0, to: 0 }
model:
datasource: { type: __expr__, uid: __expr__ }
expression: B
type: threshold
refId: C
conditions:
- evaluator: { type: gt, params: [0.05] }
operator: { type: and }
query: { params: [C] }
reducer: { type: last, params: [] }
type: query
- uid: vp7-old-jobs
title: Messenger oldest unfinished job
condition: C
for: 15s
noDataState: NoData
execErrState: Error
isPaused: false
labels: { severity: warning, service: messenger-worker }
annotations:
summary: An unfinished attachment job is older than thirty seconds
runbook: RUN.md, worker backlog recovery
data:
- refId: A
datasourceUid: prometheus
relativeTimeRange: { from: 60, to: 0 }
model:
datasource: { type: prometheus, uid: prometheus }
expr: max(queue_oldest_age_seconds)
instant: true
range: false
refId: A
- refId: B
datasourceUid: __expr__
relativeTimeRange: { from: 0, to: 0 }
model:
datasource: { type: __expr__, uid: __expr__ }
expression: A
type: reduce
reducer: last
refId: B
- refId: C
datasourceUid: __expr__
relativeTimeRange: { from: 0, to: 0 }
model:
datasource: { type: __expr__, uid: __expr__ }
expression: B
type: threshold
refId: C
conditions:
- evaluator: { type: gt, params: [30] }
operator: { type: and }
query: { params: [C] }
reducer: { type: last, params: [] }
type: query
@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: Messenger
type: file
disableDeletion: true
editable: false
options:
path: /var/lib/grafana/dashboards
@@ -0,0 +1,36 @@
apiVersion: 1
datasources:
- name: OpenObserve metrics
uid: prometheus
type: prometheus
access: proxy
url: http://127.0.0.1:15080/api/default/prometheus
isDefault: true
editable: false
basicAuth: true
basicAuthUser: $OO_QUERY_USER
secureJsonData:
basicAuthPassword: $OO_QUERY_PASSWORD
jsonData:
httpMethod: GET
- name: OpenObserve logs and traces
uid: openobserve
type: openobserve
access: proxy
url: http://127.0.0.1:15080
editable: false
basicAuth: true
basicAuthUser: $OO_QUERY_USER
secureJsonData:
basicAuthPassword: $OO_QUERY_PASSWORD
jsonData:
default_organization: default
default_log_stream: messenger
default_trace_stream: messenger
timestamp_column: _timestamp
log_message_field: body
trace_id_field: trace_id
span_id_field: span_id
service_name_field: service_name
span_name_field: operation_name
status_field: span_status
+58
View File
@@ -0,0 +1,58 @@
pid_file = "/tmp/bao-agent.pid"
log_level = "error"
vault {
address = "https://openbao:8200"
ca_cert = "/pki/ca.crt"
}
auto_auth {
method "cert" {
mount_path = "auth/cert"
config = {
name = "api"
ca_cert = "/pki/ca.crt"
client_cert = "/pki/cert.pem"
client_key = "/pki/key.pem"
reload = true
}
}
}
template_config {
static_secret_render_interval = "5s"
exit_on_retry_failure = false
}
template {
destination = "/run/app/database_url"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/api" }}{{ .Data.data.database_url }}{{ end }}
EOT
}
template {
destination = "/run/app/cache_url"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/api" }}{{ .Data.data.cache_url }}{{ end }}
EOT
}
template {
destination = "/run/app/s3.json"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/api" }}{{ .Data.data.s3_json }}{{ end }}
EOT
}
template {
destination = "/run/app/freshness"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/api" }}{{ timestamp }}{{ end }}
EOT
}
+4
View File
@@ -0,0 +1,4 @@
path "kv/data/api" { capabilities = ["read"] }
path "auth/token/lookup-self" { capabilities = ["read"] }
path "auth/token/renew-self" { capabilities = ["update"] }
path "auth/token/revoke-self" { capabilities = ["update"] }
+27
View File
@@ -0,0 +1,27 @@
ui = false
api_addr = "https://openbao:8200"
default_lease_ttl = "60s"
max_lease_ttl = "5m"
log_level = "warn"
storage "pebbledb" { path = "/bao/data/pebbledb" }
audit "file" "file" {
description = "Private HMAC-protected operator audit"
options {
file_path = "/bao/data/audit.log"
log_raw = "false"
mode = "0600"
}
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/pki/cert.pem"
tls_key_file = "/pki/key.pem"
tls_client_ca_file = "/pki/ca.crt"
tls_min_version = "tls12"
tls_disable_client_certs = false
tls_require_and_verify_client_cert = false
max_request_size = 1048576
http_read_header_timeout = "5s"
http_read_timeout = "10s"
http_write_timeout = "10s"
}
+67
View File
@@ -0,0 +1,67 @@
pid_file = "/tmp/bao-agent.pid"
log_level = "error"
vault {
address = "https://openbao:8200"
ca_cert = "/pki/ca.crt"
}
auto_auth {
method "cert" {
mount_path = "auth/cert"
config = {
name = "worker"
ca_cert = "/pki/ca.crt"
client_cert = "/pki/cert.pem"
client_key = "/pki/key.pem"
reload = true
}
}
}
template_config {
static_secret_render_interval = "5s"
exit_on_retry_failure = false
}
template {
destination = "/run/app/database_url"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/worker" }}{{ .Data.data.database_url }}{{ end }}
EOT
}
template {
destination = "/run/app/cache_url"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/worker" }}{{ .Data.data.cache_url }}{{ end }}
EOT
}
template {
destination = "/run/app/s3.json"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/worker" }}{{ .Data.data.s3_json }}{{ end }}
EOT
}
template {
destination = "/run/app/publisher_url"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/worker" }}{{ .Data.data.publisher_url }}{{ end }}
EOT
}
template {
destination = "/run/app/freshness"
perms = "0600"
backup = false
error_on_missing_key = true
contents = <<EOT
{{ with secret "kv/data/worker" }}{{ timestamp }}{{ end }}
EOT
}
+4
View File
@@ -0,0 +1,4 @@
path "kv/data/worker" { capabilities = ["read"] }
path "auth/token/lookup-self" { capabilities = ["read"] }
path "auth/token/renew-self" { capabilities = ["update"] }
path "auth/token/revoke-self" { capabilities = ["update"] }
+17
View File
@@ -0,0 +1,17 @@
groups:
- name: messenger
rules:
- alert: MessengerServerErrors
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: 30s
labels: { severity: warning }
annotations:
summary: API server error ratio exceeds 5 percent
runbook: See RUN.md, telemetry and dependency incidents
- alert: MessengerOldJobs
expr: max(messenger_queue_oldest_age_seconds) > 30
for: 15s
labels: { severity: warning }
annotations:
summary: An unfinished attachment job is older than 30 seconds
runbook: See RUN.md, worker backlog recovery
+63
View File
@@ -0,0 +1,63 @@
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 128
spike_limit_mib: 32
batch:
timeout: 1s
send_batch_size: 64
send_batch_max_size: 128
exporters:
otlp_http/openobserve:
endpoint: http://127.0.0.1:15080/api/default
headers:
Authorization: ${file:/run/secrets/openobserve_ingest_auth}
stream-name: messenger
compression: gzip
timeout: 2s
sending_queue:
sizer: bytes
queue_size: 8388608
num_consumers: 2
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 5s
otlp_http/openobserve_metrics:
endpoint: http://127.0.0.1:15080/api/default
headers:
Authorization: ${file:/run/secrets/openobserve_ingest_auth}
compression: gzip
timeout: 2s
sending_queue:
sizer: bytes
queue_size: 8388608
num_consumers: 2
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 5s
service:
telemetry:
logs:
level: error
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/openobserve_metrics]
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/openobserve]
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/openobserve]
+27
View File
@@ -0,0 +1,27 @@
auth_enabled: false
server:
http_listen_address: 127.0.0.1
http_listen_port: 13100
grpc_listen_address: 127.0.0.1
grpc_listen_port: 19095
common:
path_prefix: /data
replication_factor: 1
ring:
kvstore: { store: inmemory }
storage:
filesystem:
chunks_directory: /data/chunks
rules_directory: /data/rules
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
analytics:
reporting_enabled: false
+6
View File
@@ -0,0 +1,6 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs: []
rule_files:
- /etc/prometheus/alerts.yaml
+21
View File
@@ -0,0 +1,21 @@
server:
http_listen_address: 127.0.0.1
http_listen_port: 13200
grpc_listen_address: 127.0.0.1
grpc_listen_port: 19096
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:14317
storage:
trace:
backend: local
wal: { path: /data/wal }
local: { path: /data/blocks }
compactor:
compaction:
block_retention: 24h
usage_report:
reporting_enabled: false