Защитить связи TLS и mTLS, добавить OpenBao и сервисные политики
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments/staging/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments/staging/*",
|
||||
"arn:aws:s3:::attachments/originals/*",
|
||||
"arn:aws:s3:::attachments/variants/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /root/.mc/certs/CAs
|
||||
cp /tls/ca.crt /root/.mc/certs/CAs/lab7.crt
|
||||
attempt=0
|
||||
until mc alias set local https://s3:9000 "$(cat /run/private/s3_root_user)" "$(cat /run/private/s3_root_password)" >/dev/null 2>&1; do
|
||||
attempt=$((attempt+1)); [ "$attempt" -lt 60 ] || exit 1; sleep 1
|
||||
done
|
||||
mc mb --ignore-existing local/attachments >/dev/null
|
||||
mc anonymous set none local/attachments >/dev/null
|
||||
for role in api worker cleaner; do
|
||||
mc admin user add local "$(cat /run/private/s3_${role}_user)" "$(cat /run/private/s3_${role})" >/dev/null
|
||||
mc admin policy create local "lab7-${role}" "/bootstrap/${role}.json" >/dev/null
|
||||
mc admin policy attach local "lab7-${role}" --user "$(cat /run/private/s3_${role}_user)" >/dev/null
|
||||
done
|
||||
echo 'Private bucket and separate scoped identities ready'
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:DeleteObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments/staging/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments"
|
||||
],
|
||||
"Condition": {
|
||||
"StringLike": {
|
||||
"s3:prefix": [
|
||||
"staging/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /tmp/db-tls
|
||||
cp /tls/cert.crt /tmp/db-tls/server.crt
|
||||
cp /tls/key.key /tmp/db-tls/server.key
|
||||
chown -R postgres:postgres /tmp/db-tls
|
||||
chmod 600 /tmp/db-tls/server.key
|
||||
exec /usr/local/bin/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/pg_hba.conf
|
||||
@@ -0,0 +1,146 @@
|
||||
{
|
||||
"uid": "messenger",
|
||||
"title": "Messenger Lab7",
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "HTTP requests",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(rate(messenger_http_requests_total[1m]))",
|
||||
"query": "sum(rate(messenger_http_requests_total[1m]))",
|
||||
"queryType": "range"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "HTTP p95 seconds",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 0,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95,sum by(le)(rate(messenger_http_duration_seconds_bucket[1m])))",
|
||||
"query": "histogram_quantile(0.95,sum by(le)(rate(messenger_http_duration_seconds_bucket[1m])))",
|
||||
"queryType": "range"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Jobs by outcome",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by(outcome)(messenger_jobs_total)",
|
||||
"query": "sum by(outcome)(messenger_jobs_total)",
|
||||
"queryType": "range"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Job p95 seconds",
|
||||
"type": "timeseries",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 8,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95,sum by(le)(rate(messenger_job_duration_seconds_bucket[1m])))",
|
||||
"query": "histogram_quantile(0.95,sum by(le)(rate(messenger_job_duration_seconds_bucket[1m])))",
|
||||
"queryType": "range"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "API and worker events",
|
||||
"type": "logs",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "{service_name=~\"messenger-api|messenger-worker\"}",
|
||||
"query": "{service_name=~\"messenger-api|messenger-worker\"}",
|
||||
"queryType": "range"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Traces",
|
||||
"type": "traces",
|
||||
"datasource": {
|
||||
"type": "tempo",
|
||||
"uid": "tempo"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 12,
|
||||
"y": 16,
|
||||
"w": 12,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "{}",
|
||||
"query": "{}",
|
||||
"queryType": "traceql"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
type: file
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,9 @@
|
||||
GRANT USAGE ON SCHEMA public TO api,worker,dispatcher,cleaner;
|
||||
GRANT SELECT ON schema_migrations TO api,worker,dispatcher,cleaner;
|
||||
GRANT SELECT,INSERT,UPDATE,DELETE ON users,sessions,chats,chat_members,messages,message_requests,message_attachments,login_limits TO api;
|
||||
GRANT SELECT,INSERT ON attachments,attachment_jobs TO api;
|
||||
GRANT SELECT ON attachment_variants TO api;
|
||||
GRANT SELECT,UPDATE ON attachments,attachment_jobs TO worker;
|
||||
GRANT SELECT,INSERT,UPDATE ON attachment_variants,attachment_replays TO worker;
|
||||
GRANT SELECT,UPDATE ON attachments,attachment_jobs TO dispatcher;
|
||||
GRANT SELECT ON attachment_jobs TO cleaner;
|
||||
@@ -0,0 +1,25 @@
|
||||
global
|
||||
maxconn 128
|
||||
ssl-default-bind-options ssl-min-ver TLSv1.2
|
||||
ssl-default-server-options ssl-min-ver TLSv1.2
|
||||
defaults
|
||||
mode http
|
||||
timeout connect 3s
|
||||
timeout client 30s
|
||||
timeout server 30s
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
resolve_retries 3
|
||||
timeout resolve 1s
|
||||
timeout retry 1s
|
||||
hold valid 2s
|
||||
frontend ingress
|
||||
bind :8443 ssl crt /tls/combined.pem
|
||||
default_backend application
|
||||
backend application
|
||||
balance roundrobin
|
||||
option httpchk GET /health/ready
|
||||
http-check expect status 200
|
||||
default-server inter 1s fall 2 rise 1
|
||||
server api1 api1:8443 ssl verify required ca-file /tls/ca.crt crt /tls/combined.pem verifyhost api1 sni str(api1) check resolvers docker init-addr libc,none
|
||||
server api2 api2:8443 ssl verify required ca-file /tls/ca.crt crt /tls/combined.pem verifyhost api2 sni str(api2) check resolvers docker init-addr libc,none
|
||||
@@ -0,0 +1 @@
|
||||
path "secret/data/api" { capabilities = ["read"] }
|
||||
@@ -0,0 +1 @@
|
||||
path "secret/data/cleaner" { capabilities = ["read"] }
|
||||
@@ -0,0 +1,12 @@
|
||||
ui = false
|
||||
disable_mlock = true
|
||||
storage "file" {
|
||||
path = "/bao/data"
|
||||
}
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/tls/cert.crt"
|
||||
tls_key_file = "/tls/key.key"
|
||||
tls_min_version = "tls12"
|
||||
}
|
||||
api_addr = "https://openbao:8200"
|
||||
@@ -0,0 +1 @@
|
||||
path "secret/data/dispatcher" { capabilities = ["read"] }
|
||||
@@ -0,0 +1 @@
|
||||
path "secret/data/worker" { capabilities = ["read"] }
|
||||
@@ -0,0 +1,75 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /tls/cert.crt
|
||||
key_file: /tls/key.key
|
||||
client_ca_file: /tls/ca.crt
|
||||
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:
|
||||
otlphttp/tempo:
|
||||
endpoint: https://tempo:9444
|
||||
tls: &id001
|
||||
ca_file: /tls/ca.crt
|
||||
cert_file: /tls/cert.crt
|
||||
key_file: /tls/key.key
|
||||
timeout: 5s
|
||||
retry_on_failure:
|
||||
max_elapsed_time: 15s
|
||||
sending_queue:
|
||||
queue_size: 128
|
||||
num_consumers: 2
|
||||
otlphttp/loki:
|
||||
endpoint: https://loki:9443/otlp
|
||||
tls: *id001
|
||||
timeout: 5s
|
||||
retry_on_failure:
|
||||
max_elapsed_time: 15s
|
||||
sending_queue:
|
||||
queue_size: 128
|
||||
num_consumers: 2
|
||||
prometheusremotewrite/prometheus:
|
||||
endpoint: https://prometheus:9443/api/v1/write
|
||||
tls: *id001
|
||||
timeout: 5s
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
service:
|
||||
telemetry:
|
||||
metrics:
|
||||
level: none
|
||||
pipelines:
|
||||
traces:
|
||||
receivers:
|
||||
- otlp
|
||||
processors:
|
||||
- memory_limiter
|
||||
- batch
|
||||
exporters:
|
||||
- otlphttp/tempo
|
||||
logs:
|
||||
receivers:
|
||||
- otlp
|
||||
processors:
|
||||
- memory_limiter
|
||||
- batch
|
||||
exporters:
|
||||
- otlphttp/loki
|
||||
metrics:
|
||||
receivers:
|
||||
- otlp
|
||||
processors:
|
||||
- memory_limiter
|
||||
- batch
|
||||
exporters:
|
||||
- prometheusremotewrite/prometheus
|
||||
@@ -0,0 +1,31 @@
|
||||
auth_enabled: false
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
http_listen_address: 127.0.0.1
|
||||
grpc_listen_address: 127.0.0.1
|
||||
common:
|
||||
path_prefix: /loki
|
||||
replication_factor: 1
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
storage:
|
||||
filesystem:
|
||||
chunks_directory: /loki/chunks
|
||||
rules_directory: /loki/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
|
||||
compactor:
|
||||
working_directory: /loki/compactor
|
||||
retention_enabled: true
|
||||
delete_request_store: filesystem
|
||||
@@ -0,0 +1,3 @@
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
scrape_configs: []
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
local all all trust
|
||||
hostnossl all all all reject
|
||||
hostssl messenger all all scram-sha-256
|
||||
@@ -0,0 +1,11 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /tls/ca.crt
|
||||
ssl_options.certfile = /tls/cert.crt
|
||||
ssl_options.keyfile = /tls/key.key
|
||||
ssl_options.versions.1 = tlsv1.3
|
||||
ssl_options.versions.2 = tlsv1.2
|
||||
definitions.import_backend = local_filesystem
|
||||
definitions.local.path = /run/private/broker.json
|
||||
default_user = disabled-bootstrap
|
||||
default_pass = disabled-bootstrap-not-a-service
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
export MINIO_ROOT_USER="$(cat "$MINIO_ROOT_USER_FILE")"
|
||||
export MINIO_ROOT_PASSWORD="$(cat "$MINIO_ROOT_PASSWORD_FILE")"
|
||||
exec minio "$@"
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments/staging/*",
|
||||
"arn:aws:s3:::attachments/originals/*",
|
||||
"arn:aws:s3:::attachments/variants/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::attachments/originals/*",
|
||||
"arn:aws:s3:::attachments/variants/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user