feat: complete lab 7 grade 3 security controls

This commit is contained in:
Dmitrii Grishko
2026-11-14 20:08:27 +03:00
parent 8986ba6bef
commit c5e3ac3aff
49 changed files with 1670 additions and 149 deletions
+9
View File
@@ -0,0 +1,9 @@
api_addr = "https://openbao:8200"
storage "file" {
path = "/openbao/file"
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/run/tls/bao.crt"
tls_key_file = "/run/tls/bao.key"
}
+18 -2
View File
@@ -3,6 +3,10 @@ receivers:
protocols:
http:
endpoint: 0.0.0.0:4318
tls:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_ca_file: /run/otel/ingest-ca.crt
processors:
memory_limiter:
check_interval: 1s
@@ -15,16 +19,28 @@ processors:
exporters:
prometheus:
endpoint: 0.0.0.0:8889
tls:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_ca_file: /run/otel/export-ca.crt
resource_to_telemetry_conversion:
enabled: true
otlphttp/loki:
endpoint: http://loki:3100/otlp
endpoint: https://loki:3100/otlp
tls:
ca_file: /run/tls/ca.crt
cert_file: /run/otel/client.crt
key_file: /run/otel/client.key
sending_queue:
queue_size: 64
retry_on_failure:
max_elapsed_time: 30s
otlphttp/tempo:
endpoint: http://tempo:4318
endpoint: https://tempo:4318
tls:
ca_file: /run/tls/ca.crt
cert_file: /run/otel/client.crt
key_file: /run/otel/client.key
sending_queue:
queue_size: 64
retry_on_failure:
@@ -4,14 +4,23 @@ datasources:
uid: lab6-prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
url: https://prometheus:9090
isDefault: true
secureJsonData:
tlsClientCert: ${GRAFANA_READER_CERT}
tlsClientKey: ${GRAFANA_READER_KEY}
jsonData:
tlsAuth: true
- name: Loki
uid: lab6-loki
type: loki
access: proxy
url: http://loki:3100
url: https://loki:3100
secureJsonData:
tlsClientCert: ${GRAFANA_READER_CERT}
tlsClientKey: ${GRAFANA_READER_KEY}
jsonData:
tlsAuth: true
derivedFields:
- name: Trace
matcherType: label
@@ -22,8 +31,12 @@ datasources:
uid: lab6-tempo
type: tempo
access: proxy
url: http://tempo:3200
url: https://tempo:3200
secureJsonData:
tlsClientCert: ${GRAFANA_READER_CERT}
tlsClientKey: ${GRAFANA_READER_KEY}
jsonData:
tlsAuth: true
tracesToLogsV2:
datasourceUid: lab6-loki
spanStartTimeShift: '-5s'
+5
View File
@@ -1,6 +1,11 @@
auth_enabled: false
server:
http_listen_port: 3100
http_tls_config:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_auth_type: RequireAndVerifyClientCert
client_ca_file: /run/otel/loki-client-ca.crt
common:
path_prefix: /loki
replication_factor: 1
+5
View File
@@ -0,0 +1,5 @@
tls_server_config:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_auth_type: RequireAndVerifyClientCert
client_ca_file: /run/otel/read-ca.crt
+5
View File
@@ -4,5 +4,10 @@ rule_files:
- /etc/prometheus/alerts.yaml
scrape_configs:
- job_name: otel-collector
scheme: https
tls_config:
ca_file: /run/tls/ca.crt
cert_file: /run/otel/client.crt
key_file: /run/otel/client.key
static_configs:
- targets: [otel-collector:8889]
+9
View File
@@ -1,11 +1,20 @@
server:
http_listen_port: 3200
http_tls_config:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_auth_type: RequireAndVerifyClientCert
client_ca_file: /run/otel/read-ca.crt
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
tls:
cert_file: /run/otel/server.crt
key_file: /run/otel/server.key
client_ca_file: /run/otel/export-ca.crt
storage:
trace:
backend: local
+2
View File
@@ -0,0 +1,2 @@
local all all trust
hostssl all all all scram-sha-256
+33
View File
@@ -0,0 +1,33 @@
\getenv api_password api_password
\getenv worker_password worker_password
\getenv dispatcher_password dispatcher_password
\getenv cleanup_password cleanup_password
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
SELECT format('CREATE ROLE %I LOGIN', 'messenger_' || role)
FROM unnest(ARRAY['api', 'worker', 'dispatcher', 'cleanup']) AS role
WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'messenger_' || role)
\gexec
ALTER ROLE messenger_api PASSWORD :'api_password';
ALTER ROLE messenger_worker PASSWORD :'worker_password';
ALTER ROLE messenger_dispatcher PASSWORD :'dispatcher_password';
ALTER ROLE messenger_cleanup PASSWORD :'cleanup_password';
GRANT SELECT, INSERT ON users, chats, chat_members, messages, message_attachments TO messenger_api;
GRANT SELECT, INSERT, UPDATE ON attachments, direct_uploads TO messenger_api;
GRANT SELECT, INSERT, DELETE ON upload_attempts, message_idempotency TO messenger_api;
GRANT UPDATE ON message_idempotency TO messenger_api;
GRANT UPDATE ON upload_attempts TO messenger_api;
GRANT DELETE ON direct_uploads TO messenger_cleanup;
GRANT INSERT ON attachment_jobs TO messenger_api;
GRANT SELECT, UPDATE ON attachments, attachment_jobs TO messenger_worker;
GRANT SELECT, INSERT, UPDATE ON attachment_job_attempts, attachment_job_failures TO messenger_worker;
GRANT INSERT ON attachment_publications TO messenger_worker;
GRANT SELECT ON attachments, attachment_jobs, attachment_job_failures TO messenger_dispatcher;
GRANT UPDATE (published_at) ON attachment_jobs TO messenger_dispatcher;
GRANT SELECT, UPDATE ON upload_attempts, direct_uploads TO messenger_cleanup;
GRANT DELETE ON upload_attempts TO messenger_cleanup;
GRANT SELECT ON attachments TO messenger_cleanup;
GRANT USAGE ON SEQUENCE attachment_publications_id_seq TO messenger_worker;
GRANT SELECT ON attachment_jobs, attachment_job_failures TO messenger_cleanup;
GRANT UPDATE (staging_deleted_at) ON attachment_jobs TO messenger_cleanup;
GRANT UPDATE (updated_at) ON attachments TO messenger_cleanup;
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
set -eu
until rabbitmq-diagnostics -q check_running >/dev/null 2>&1; do sleep 1; done
for role in dispatcher worker; do
username="messenger_$role"
password=$(cat "/run/secrets/broker_${role}_password")
if rabbitmqctl -q list_users | cut -f1 | grep -qx "$username"; then
rabbitmqctl -q change_password "$username" "$password"
else
rabbitmqctl -q add_user "$username" "$password"
fi
if [ "$role" = dispatcher ]; then write='^amq\.default$'; read='^$'
else write='^$'; read='^attachments\.v1$'; fi
rabbitmqctl -q set_permissions "$username" '^attachments\.v1$' "$write" "$read"
done
+10
View File
@@ -0,0 +1,10 @@
listeners.tcp = none
listeners.ssl.default = 5671
ssl_options.cacertfile = /run/tls/ca.crt
ssl_options.certfile = /run/tls/broker.crt
ssl_options.keyfile = /run/tls/broker.key
ssl_options.verify = verify_none
ssl_options.fail_if_no_peer_cert = false
management.tcp.port = 15672
management.tcp.ip = 127.0.0.1
prometheus.tcp.ip = 127.0.0.1