forked from mtusi2026/mtusi2026lab7
ЛР 7: безопасность, mTLS и OpenBao на оценку 3
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
-- API owns business operations. The two background processes have separate roles.
|
||||
GRANT SELECT, INSERT ON users, chats, chat_members, messages TO messenger_api;
|
||||
GRANT SELECT, INSERT ON attachments TO messenger_api;
|
||||
GRANT INSERT ON outbox_events TO messenger_api;
|
||||
GRANT SELECT (created_at) ON outbox_events TO messenger_api;
|
||||
|
||||
GRANT SELECT ON attachments TO messenger_worker;
|
||||
GRANT UPDATE (status, error_code, updated_at, lease_expires_at, thumbnail_key,
|
||||
thumbnail_sha256, thumbnail_size_bytes, thumbnail_width,
|
||||
thumbnail_height, crop_key, webp_key)
|
||||
ON attachments TO messenger_worker;
|
||||
|
||||
GRANT SELECT ON attachments, outbox_events TO messenger_outbox;
|
||||
GRANT UPDATE (status, lease_expires_at, updated_at) ON attachments TO messenger_outbox;
|
||||
GRANT INSERT ON outbox_events TO messenger_outbox;
|
||||
GRANT UPDATE (published_at) ON outbox_events TO messenger_outbox;
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /tmp/mc/certs/CAs
|
||||
cp /run/ca/ca.crt /tmp/mc/certs/CAs/lab7.crt
|
||||
export MC_CONFIG_DIR=/tmp/mc
|
||||
attempt=0
|
||||
until mc alias set storage https://minio:9000 messenger-admin "$(cat /run/identity/admin_password)" >/dev/null 2>&1; do
|
||||
attempt=$((attempt + 1))
|
||||
[ "$attempt" -lt 30 ] || exit 1
|
||||
sleep 1
|
||||
done
|
||||
mc mb --ignore-existing storage/messenger-attachments
|
||||
mc anonymous set none storage/messenger-attachments
|
||||
for role in api worker; do
|
||||
mc admin user add storage "messenger-$role" "$(cat "/run/identity/${role}_password")" >/dev/null
|
||||
mc admin policy create storage "messenger-$role" "/run/identity/${role}_policy.json"
|
||||
mc admin policy attach storage "messenger-$role" --user "messenger-$role"
|
||||
done
|
||||
@@ -0,0 +1,3 @@
|
||||
local all all trust
|
||||
hostssl all all 0.0.0.0/0 scram-sha-256
|
||||
hostssl all all ::/0 scram-sha-256
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
install -d -m 0700 -o postgres -g postgres /tmp/db-tls
|
||||
install -m 0600 -o postgres -g postgres /run/identity/server.key /tmp/db-tls/server.key
|
||||
install -m 0644 -o postgres -g postgres /run/identity/server.crt /tmp/db-tls/server.crt
|
||||
export POSTGRES_PASSWORD_FILE=/run/identity/admin_password
|
||||
exec 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/lab7/pg_hba.conf -c password_encryption=scram-sha-256
|
||||
@@ -0,0 +1 @@
|
||||
[].
|
||||
@@ -0,0 +1,10 @@
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
ssl_options.cacertfile = /run/ca/ca.crt
|
||||
ssl_options.certfile = /run/identity/server.crt
|
||||
ssl_options.keyfile = /run/identity/server.key
|
||||
ssl_options.verify = verify_none
|
||||
ssl_options.fail_if_no_peer_cert = false
|
||||
distribution.listener.interface = 127.0.0.1
|
||||
definitions.import_backend = local_filesystem
|
||||
definitions.local.path = /run/identity/definitions.json
|
||||
@@ -0,0 +1,9 @@
|
||||
port 0
|
||||
tls-port 6380
|
||||
tls-cert-file /run/identity/server.crt
|
||||
tls-key-file /run/identity/server.key
|
||||
tls-ca-cert-file /run/ca/ca.crt
|
||||
tls-auth-clients no
|
||||
aclfile /run/identity/users.acl
|
||||
appendonly yes
|
||||
dir /data
|
||||
@@ -0,0 +1,84 @@
|
||||
pid /tmp/nginx.pid;
|
||||
events { worker_connections 512; }
|
||||
|
||||
http {
|
||||
access_log off;
|
||||
server_tokens off;
|
||||
client_body_temp_path /tmp/nginx-body;
|
||||
proxy_temp_path /tmp/nginx-proxy;
|
||||
fastcgi_temp_path /tmp/nginx-fastcgi;
|
||||
uwsgi_temp_path /tmp/nginx-uwsgi;
|
||||
scgi_temp_path /tmp/nginx-scgi;
|
||||
client_max_body_size 16m;
|
||||
|
||||
server {
|
||||
listen 8444 ssl;
|
||||
ssl_certificate /run/identity/server.crt;
|
||||
ssl_certificate_key /run/identity/server.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
proxy_set_header Authorization "";
|
||||
|
||||
location ~ ^/ingest/v1/(logs|metrics|traces)$ {
|
||||
auth_basic "otlp-ingest";
|
||||
auth_basic_user_file /run/identity/ingest.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
rewrite ^/ingest(.*)$ $1 break;
|
||||
proxy_pass http://127.0.0.1:14318;
|
||||
}
|
||||
location = /loki-write {
|
||||
auth_basic "loki-write";
|
||||
auth_basic_user_file /run/identity/collector.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:3100/otlp/v1/logs;
|
||||
}
|
||||
location = /tempo-write {
|
||||
auth_basic "tempo-write";
|
||||
auth_basic_user_file /run/identity/collector.htpasswd;
|
||||
limit_except POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:14319/v1/traces;
|
||||
}
|
||||
location = /metrics {
|
||||
auth_basic "prometheus-scrape";
|
||||
auth_basic_user_file /run/identity/scrape.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:8889/metrics;
|
||||
}
|
||||
location = /collector-metrics {
|
||||
auth_basic "prometheus-scrape";
|
||||
auth_basic_user_file /run/identity/scrape.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:8888/metrics;
|
||||
}
|
||||
location /prometheus/api/v1/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET POST { deny all; }
|
||||
proxy_pass http://127.0.0.1:9090/api/v1/;
|
||||
}
|
||||
location /loki/loki/api/v1/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:3100/loki/api/v1/;
|
||||
}
|
||||
location /tempo/api/ {
|
||||
auth_basic "grafana";
|
||||
auth_basic_user_file /run/identity/grafana.htpasswd;
|
||||
limit_except GET { deny all; }
|
||||
proxy_pass http://127.0.0.1:3200/api/;
|
||||
}
|
||||
location / { return 404; }
|
||||
}
|
||||
|
||||
server {
|
||||
listen 3443 ssl;
|
||||
ssl_certificate /run/identity/server.crt;
|
||||
ssl_certificate_key /run/identity/server.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
location / {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user