Закрыть внешний вход TLS и выдавать секреты через OpenBao.
LB ходит в API только с клиентским сертификатом нужной identity, остальные связи проверяют серверный сертификат, root token в приложение не попадает. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
if [ -f /certs/ca.crt ]; then
|
||||
cat /certs/ca.crt >> /etc/ssl/certs/ca-certificates.crt
|
||||
fi
|
||||
if [ -f /run/secrets/grafana_password ]; then
|
||||
GF_SECURITY_ADMIN_PASSWORD=$(cat /run/secrets/grafana_password)
|
||||
export GF_SECURITY_ADMIN_PASSWORD
|
||||
fi
|
||||
exec /run.sh "$@"
|
||||
@@ -5,7 +5,7 @@ datasources:
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
url: https://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
jsonData:
|
||||
@@ -14,7 +14,7 @@ datasources:
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
url: https://loki:3100
|
||||
editable: false
|
||||
jsonData:
|
||||
derivedFields:
|
||||
@@ -26,7 +26,7 @@ datasources:
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
url: https://tempo:3200
|
||||
editable: false
|
||||
jsonData:
|
||||
tracesToLogsV2:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
global
|
||||
log stdout format raw local0 info
|
||||
maxconn 200
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
timeout connect 3s
|
||||
timeout client 60s
|
||||
timeout server 60s
|
||||
|
||||
frontend ft_otlp
|
||||
bind *:4318 ssl crt /certs/otel.pem ca-file /certs/ca.crt verify required
|
||||
acl api_id ssl_c_san -m sub spiffe://messenger/api
|
||||
acl worker_id ssl_c_san -m sub spiffe://messenger/worker
|
||||
http-request deny unless api_id or worker_id
|
||||
default_backend be_local
|
||||
|
||||
backend be_local
|
||||
server collector 127.0.0.1:14318
|
||||
@@ -0,0 +1,22 @@
|
||||
global
|
||||
log stdout format raw local0 info
|
||||
maxconn 200
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode tcp
|
||||
timeout connect 3s
|
||||
timeout client 120s
|
||||
timeout server 120s
|
||||
|
||||
frontend ft_amqp
|
||||
bind *:5671 ssl crt /certs/rabbitmq.pem ca-file /certs/ca.crt verify required
|
||||
tcp-request inspect-delay 5s
|
||||
tcp-request content accept if { req_ssl_hello_type 1 }
|
||||
acl api_id ssl_c_san -m sub spiffe://messenger/api
|
||||
acl worker_id ssl_c_san -m sub spiffe://messenger/worker
|
||||
tcp-request content reject unless api_id or worker_id
|
||||
default_backend be_local
|
||||
|
||||
backend be_local
|
||||
server rabbit 127.0.0.1:5672 check
|
||||
@@ -0,0 +1,18 @@
|
||||
global
|
||||
log stdout format raw local0 info
|
||||
maxconn 200
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
timeout connect 3s
|
||||
timeout client 120s
|
||||
timeout server 120s
|
||||
timeout http-request 30s
|
||||
|
||||
frontend ft_s3
|
||||
bind *:9000 ssl crt /certs/s3.pem
|
||||
default_backend be_local
|
||||
|
||||
backend be_local
|
||||
server weed 127.0.0.1:19000
|
||||
+7
-4
@@ -22,8 +22,11 @@ resolvers docker
|
||||
hold valid 1s
|
||||
accepted_payload_size 8192
|
||||
|
||||
frontend fe_http
|
||||
bind *:8080
|
||||
frontend fe_https
|
||||
bind *:8443 ssl crt /certs/lb.pem
|
||||
http-request set-header X-Real-IP %[src]
|
||||
http-request del-header X-Forwarded-For
|
||||
option forwardfor
|
||||
default_backend be_api
|
||||
|
||||
backend be_api
|
||||
@@ -31,5 +34,5 @@ backend be_api
|
||||
option httpchk
|
||||
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr host api
|
||||
http-check expect status 200
|
||||
default-server inter 1s fall 2 rise 1
|
||||
server-template srv 8 api:8080 check resolvers docker init-addr none resolve-prefer ipv4
|
||||
default-server inter 1s fall 2 rise 1 resolvers docker init-addr none resolve-prefer ipv4
|
||||
server-template srv 8 api:8443 check ssl verify required ca-file /certs/ca.crt crt /certs/lb-client.pem
|
||||
|
||||
@@ -3,6 +3,12 @@ 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:
|
||||
instance_addr: 127.0.0.1
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
ui = false
|
||||
disable_mlock = true
|
||||
api_addr = "https://openbao:8200"
|
||||
|
||||
storage "file" {
|
||||
path = "/openbao/file"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_cert_file = "/certs/openbao.crt"
|
||||
tls_key_file = "/certs/openbao.key"
|
||||
}
|
||||
|
||||
# Dev mode is not used. The process starts sealed; the operator unseals it.
|
||||
@@ -0,0 +1,16 @@
|
||||
# API may read only its own KV document and renew its own token.
|
||||
path "secret/data/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
path "secret/data/messenger/migrate" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/migrate" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
path "secret/data/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
@@ -5,10 +5,8 @@
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
endpoint: 127.0.0.1:14318
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
@@ -22,9 +20,10 @@ processors:
|
||||
|
||||
exporters:
|
||||
otlphttp/tempo:
|
||||
traces_endpoint: http://tempo:4318/v1/traces
|
||||
traces_endpoint: https://tempo:4318/v1/traces
|
||||
tls:
|
||||
insecure: true
|
||||
insecure: false
|
||||
ca_file: /certs/ca.crt
|
||||
timeout: 5s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
@@ -36,9 +35,10 @@ exporters:
|
||||
max_interval: 15s
|
||||
max_elapsed_time: 30s
|
||||
prometheusremotewrite:
|
||||
endpoint: http://prometheus:9090/api/v1/write
|
||||
endpoint: https://prometheus:9090/api/v1/write
|
||||
tls:
|
||||
insecure: true
|
||||
insecure: false
|
||||
ca_file: /certs/ca.crt
|
||||
resource_to_telemetry_conversion:
|
||||
enabled: true
|
||||
remote_write_queue:
|
||||
@@ -51,9 +51,10 @@ exporters:
|
||||
max_interval: 15s
|
||||
max_elapsed_time: 30s
|
||||
otlphttp/loki:
|
||||
logs_endpoint: http://loki:3100/otlp/v1/logs
|
||||
logs_endpoint: https://loki:3100/otlp/v1/logs
|
||||
tls:
|
||||
insecure: true
|
||||
insecure: false
|
||||
ca_file: /certs/ca.crt
|
||||
timeout: 5s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cp /certs/postgres.crt /var/lib/postgresql/server.crt
|
||||
cp /certs/postgres.key /var/lib/postgresql/server.key
|
||||
cp /certs/ca.crt /var/lib/postgresql/ca.crt
|
||||
chown postgres:postgres /var/lib/postgresql/server.crt /var/lib/postgresql/server.key /var/lib/postgresql/ca.crt
|
||||
chmod 644 /var/lib/postgresql/server.crt /var/lib/postgresql/ca.crt
|
||||
chmod 600 /var/lib/postgresql/server.key
|
||||
exec docker-entrypoint.sh postgres \
|
||||
-c ssl=on \
|
||||
-c ssl_cert_file=/var/lib/postgresql/server.crt \
|
||||
-c ssl_key_file=/var/lib/postgresql/server.key \
|
||||
-c ssl_ca_file=/var/lib/postgresql/ca.crt \
|
||||
-c hba_file=/etc/postgres/pg_hba.conf
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
# Create limited roles after migrations. Passwords come from mounted files, not from Git.
|
||||
set -eu
|
||||
api_pass=$(cat /run/secrets/db_api_password)
|
||||
worker_pass=$(cat /run/secrets/db_worker_password)
|
||||
psql -v ON_ERROR_STOP=1 --username messenger --dbname messenger <<SQL
|
||||
DO \$\$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'messenger_api') THEN
|
||||
CREATE ROLE messenger_api LOGIN PASSWORD '${api_pass}';
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'messenger_worker') THEN
|
||||
CREATE ROLE messenger_worker LOGIN PASSWORD '${worker_pass}';
|
||||
END IF;
|
||||
END
|
||||
\$\$;
|
||||
ALTER ROLE messenger_api PASSWORD '${api_pass}';
|
||||
ALTER ROLE messenger_worker PASSWORD '${worker_pass}';
|
||||
GRANT CONNECT ON DATABASE messenger TO messenger_api, messenger_worker;
|
||||
GRANT USAGE ON SCHEMA public TO messenger_api, messenger_worker;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON
|
||||
users, chats, chat_members, messages, idempotency_keys,
|
||||
attachments, message_attachments, blob_writes, direct_uploads,
|
||||
attachment_variants, attachment_jobs, attachment_job_events,
|
||||
pipeline_faults, schema_migrations
|
||||
TO messenger_api;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON
|
||||
attachments, message_attachments, blob_writes,
|
||||
attachment_variants, attachment_jobs, attachment_job_events,
|
||||
pipeline_faults
|
||||
TO messenger_worker;
|
||||
SQL
|
||||
echo "database roles granted"
|
||||
@@ -0,0 +1,5 @@
|
||||
local all all trust
|
||||
hostssl all all 0.0.0.0/0 scram-sha-256
|
||||
hostssl all all ::/0 scram-sha-256
|
||||
host all all 0.0.0.0/0 reject
|
||||
host all all ::/0 reject
|
||||
@@ -0,0 +1,3 @@
|
||||
tls_server_config:
|
||||
cert_file: /certs/prometheus.crt
|
||||
key_file: /certs/prometheus.key
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /etc/rabbitmq/certs
|
||||
cp /certs/rabbitmq.crt /etc/rabbitmq/certs/server.crt
|
||||
cp /certs/rabbitmq.key /etc/rabbitmq/certs/server.key
|
||||
cp /certs/ca.crt /etc/rabbitmq/certs/ca.crt
|
||||
chown -R rabbitmq:rabbitmq /etc/rabbitmq/certs
|
||||
chmod 600 /etc/rabbitmq/certs/server.key
|
||||
api_pass=$(cat /run/secrets/rabbit_api_password)
|
||||
worker_pass=$(cat /run/secrets/rabbit_worker_password)
|
||||
cat > /etc/rabbitmq/definitions.json <<EOF
|
||||
{
|
||||
"vhosts": [{"name": "/"}],
|
||||
"users": [
|
||||
{"name": "messenger_api", "password": "${api_pass}", "tags": ""},
|
||||
{"name": "messenger_worker", "password": "${worker_pass}", "tags": ""}
|
||||
],
|
||||
"permissions": [
|
||||
{
|
||||
"user": "messenger_api",
|
||||
"vhost": "/",
|
||||
"configure": ".*",
|
||||
"write": ".*",
|
||||
"read": ".*"
|
||||
},
|
||||
{
|
||||
"user": "messenger_worker",
|
||||
"vhost": "/",
|
||||
"configure": "^(attachment\\\\.jobs.*)$",
|
||||
"write": "^(attachment\\\\.jobs.*)$",
|
||||
"read": "^(attachment\\\\.jobs.*)$"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
chown rabbitmq:rabbitmq /etc/rabbitmq/definitions.json
|
||||
chmod 640 /etc/rabbitmq/definitions.json
|
||||
cat > /etc/rabbitmq/rabbitmq.conf <<EOF
|
||||
listeners.tcp.1 = 127.0.0.1:5672
|
||||
management.listener.ip = 127.0.0.1
|
||||
management.listener.port = 15672
|
||||
loopback_users.guest = true
|
||||
load_definitions = /etc/rabbitmq/definitions.json
|
||||
EOF
|
||||
exec docker-entrypoint.sh rabbitmq-server
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cp /certs/redis.crt /tmp/redis.crt
|
||||
cp /certs/redis.key /tmp/redis.key
|
||||
cp /certs/ca.crt /tmp/ca.crt
|
||||
chown redis:redis /tmp/redis.crt /tmp/redis.key /tmp/ca.crt
|
||||
chmod 600 /tmp/redis.key
|
||||
pass=$(cat /run/secrets/redis_password)
|
||||
umask 077
|
||||
cat > /tmp/users.acl <<EOF
|
||||
user default off
|
||||
user api on >${pass} ~* &* +@all
|
||||
EOF
|
||||
chown redis:redis /tmp/users.acl
|
||||
exec docker-entrypoint.sh redis-server \
|
||||
--port 0 \
|
||||
--tls-port 6379 \
|
||||
--tls-cert-file /tmp/redis.crt \
|
||||
--tls-key-file /tmp/redis.key \
|
||||
--tls-ca-cert-file /tmp/ca.crt \
|
||||
--tls-auth-clients no \
|
||||
--aclfile /tmp/users.acl \
|
||||
--appendonly yes \
|
||||
--appendfsync everysec \
|
||||
--save 60 1
|
||||
@@ -1,34 +1,48 @@
|
||||
#!/bin/sh
|
||||
# One SeaweedFS process: master, volume, filer, S3. The filer UI is off.
|
||||
# Anonymous identity has no actions. The API user is limited to one bucket.
|
||||
# One SeaweedFS process bound to localhost. HAProxy in this network namespace
|
||||
# is the TLS endpoint other containers use.
|
||||
set -eu
|
||||
: "${S3_BUCKET:?}"
|
||||
: "${S3_ACCESS_KEY_ID:?}"
|
||||
: "${S3_SECRET_ACCESS_KEY:?}"
|
||||
admin_key=$(cat /run/secrets/s3_admin_access)
|
||||
admin_secret=$(cat /run/secrets/s3_admin_secret)
|
||||
api_key=$(cat /run/secrets/s3_api_access)
|
||||
api_secret=$(cat /run/secrets/s3_api_secret)
|
||||
worker_key=$(cat /run/secrets/s3_worker_access)
|
||||
worker_secret=$(cat /run/secrets/s3_worker_secret)
|
||||
|
||||
cat > /tmp/s3.json <<EOF
|
||||
{
|
||||
"identities": [
|
||||
{"name": "anonymous", "actions": []},
|
||||
{
|
||||
"name": "anonymous",
|
||||
"actions": []
|
||||
"name": "s3-admin",
|
||||
"credentials": [{"accessKey": "${admin_key}", "secretKey": "${admin_secret}"}],
|
||||
"actions": ["Admin:${S3_BUCKET}"]
|
||||
},
|
||||
{
|
||||
"name": "messenger-app",
|
||||
"credentials": [
|
||||
{
|
||||
"accessKey": "${S3_ACCESS_KEY_ID}",
|
||||
"secretKey": "${S3_SECRET_ACCESS_KEY}"
|
||||
}
|
||||
],
|
||||
"name": "messenger-api",
|
||||
"credentials": [{"accessKey": "${api_key}", "secretKey": "${api_secret}"}],
|
||||
"actions": [
|
||||
"Read:${S3_BUCKET}",
|
||||
"Read:${S3_BUCKET}/*",
|
||||
"Write:${S3_BUCKET}",
|
||||
"Write:${S3_BUCKET}/*",
|
||||
"List:${S3_BUCKET}",
|
||||
"Tagging:${S3_BUCKET}/*",
|
||||
"Admin:${S3_BUCKET}"
|
||||
"Write:${S3_BUCKET}/staging/*",
|
||||
"Write:${S3_BUCKET}/originals/*",
|
||||
"Tagging:${S3_BUCKET}/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "messenger-worker",
|
||||
"credentials": [{"accessKey": "${worker_key}", "secretKey": "${worker_secret}"}],
|
||||
"actions": [
|
||||
"Read:${S3_BUCKET}/staging/*",
|
||||
"Read:${S3_BUCKET}/originals/*",
|
||||
"Read:${S3_BUCKET}/variants/*",
|
||||
"List:${S3_BUCKET}",
|
||||
"Write:${S3_BUCKET}/originals/*",
|
||||
"Write:${S3_BUCKET}/variants/*",
|
||||
"Write:${S3_BUCKET}/staging/*",
|
||||
"Tagging:${S3_BUCKET}/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -37,12 +51,12 @@ EOF
|
||||
|
||||
exec weed server \
|
||||
-dir=/data \
|
||||
-ip.bind=0.0.0.0 \
|
||||
-ip.bind=127.0.0.1 \
|
||||
-master.port=9333 \
|
||||
-volume.port=8080 \
|
||||
-filer \
|
||||
-filer.port=8888 \
|
||||
-filer.exposeDirectoryData=false \
|
||||
-s3 \
|
||||
-s3.port=9000 \
|
||||
-s3.port=19000 \
|
||||
-s3.config=/tmp/s3.json
|
||||
|
||||
@@ -2,6 +2,9 @@ stream_over_http_enabled: true
|
||||
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
http_tls_config:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
@@ -9,8 +12,11 @@ distributor:
|
||||
protocols:
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
tls:
|
||||
cert_file: /certs/tempo.crt
|
||||
key_file: /certs/tempo.key
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
endpoint: 127.0.0.1:4317
|
||||
|
||||
ingester:
|
||||
max_block_duration: 5m
|
||||
|
||||
Reference in New Issue
Block a user