ЛР 7: TLS, mTLS, OpenBao и безопасность — на 3
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-11-22 06:03:17 +03:00
parent 20afc2c790
commit 9fb7dde29b
112 changed files with 6226 additions and 80 deletions
+5
View File
@@ -0,0 +1,5 @@
FROM python:3.12.10-slim-bookworm
ADD --checksum=sha256:4a8128911ccad4e7b481f26635a4cfd1ec064412210526e57ad2c748d356f3b7 https://github.com/rustfs/cli/releases/download/v0.1.36/rustfs-cli-linux-amd64-v0.1.36.tar.gz /tmp/rc.tar.gz
RUN tar -xzf /tmp/rc.tar.gz -C /usr/local/bin rc && rm /tmp/rc.tar.gz
COPY --chmod=0755 scripts/bootstrap-s3.sh /usr/local/bin/bootstrap-s3
ENTRYPOINT ["/usr/local/bin/bootstrap-s3"]
+14
View File
@@ -0,0 +1,14 @@
FROM docker:27.5.1-cli
RUN apk add --no-cache python3 py3-pip make && python3 -m venv /opt/venv
ENV PATH=/opt/venv/bin:$PATH PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /workspace
COPY infra/requirements-tools.lock /tmp/requirements-tools.lock
RUN pip install --no-cache-dir -r /tmp/requirements-tools.lock
COPY Makefile lab.json README.md COURSE.md CONTRIBUTING.md REPORT.md ./
COPY contracts/ ./contracts/
COPY tests/ ./tests/
COPY scripts/check_contract.py scripts/validate_openapi.py ./scripts/
COPY --chmod=0755 scripts/restart.sh scripts/stop-one.sh scripts/compose-hook.sh ./scripts/
COPY student-tests/ ./student-tests/
ENTRYPOINT []
CMD ["make", "check"]
+176
View File
@@ -0,0 +1,176 @@
{
"title": "ЛР6 · Messenger",
"uid": "lab6-messenger",
"schemaVersion": 39,
"version": 1,
"editable": false,
"time": {
"from": "now-15m",
"to": "now"
},
"refresh": "10s",
"timezone": "browser",
"panels": [
{
"id": 1,
"title": "API · запросы/с",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (method, route) (rate(messenger_http_requests_total{route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 2,
"title": "API · 4xx и 5xx/с",
"type": "timeseries",
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (status_class) (rate(messenger_http_requests_total{status_class=~\"4xx|5xx\",route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 3,
"title": "API · средняя длительность",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum(rate(messenger_http_duration_seconds_sum{route!~\"/health/.*\"}[1m])) / sum(rate(messenger_http_duration_seconds_count{route!~\"/health/.*\"}[1m]))"
}
]
},
{
"id": 4,
"title": "Worker · успешные и неуспешные задания",
"type": "timeseries",
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (messenger_job_outcomes_total)"
}
]
},
{
"id": 5,
"title": "Worker · средняя длительность",
"type": "timeseries",
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"datasource": {
"type": "prometheus",
"uid": "lab6-prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
},
"overrides": []
},
"targets": [
{
"refId": "A",
"expr": "sum by (outcome) (messenger_job_duration_seconds_sum) / sum by (outcome) (messenger_job_duration_seconds_count)"
}
]
},
{
"id": 6,
"title": "События API и worker",
"type": "logs",
"gridPos": {
"x": 0,
"y": 24,
"w": 24,
"h": 10
},
"datasource": {
"type": "loki",
"uid": "lab6-loki"
},
"targets": [
{
"refId": "A",
"expr": "{service_name=~\"messenger-api|messenger-worker\"} | event != \"\"",
"queryType": "range"
}
],
"options": {
"showTime": true,
"enableLogDetails": true
}
}
]
}
@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: lab6
type: file
disableDeletion: true
updateIntervalSeconds: 30
options:
path: /var/lib/grafana/dashboards
+34
View File
@@ -0,0 +1,34 @@
global
ssl-default-bind-options ssl-min-ver TLSv1.2
ssl-default-server-options ssl-min-ver TLSv1.2
maxconn 128
defaults
mode http
timeout connect 2s
timeout client 15s
timeout server 15s
timeout http-request 8s
resolvers docker
nameserver dns 127.0.0.11:53
hold valid 2s
frontend public
bind :8443 ssl crt /run/tls/server.pem
stick-table type ip size 1024 expire 30s store http_req_rate(30s)
acl login path -i /api/v1/auth/sessions
acl post method POST
http-request track-sc0 src if login post
acl excessive sc_http_req_rate(0) gt 30
http-request set-var(txn.rate_id) uuid() if login post excessive
http-request return status 429 content-type application/json lf-string '{"error":{"code":"rate_limited","message":"Retry later","request_id":"%[var(txn.rate_id)]"}}' hdr Retry-After 30 hdr X-Request-Id '%[var(txn.rate_id)]' hdr X-Instance-Id lb if login post excessive
default_backend api
backend api
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server ssl verify required ca-file /run/ca/server.crt crt /run/identity/client.pem check inter 1s fall 2 rise 1 resolvers docker init-addr libc,none
server api1 api1:8444 verifyhost api1 sni str(api1) check-sni api1
server api2 api2:8444 verifyhost api2 sni str(api2) check-sni api2
+3
View File
@@ -0,0 +1,3 @@
path "lab7/data/api" {
capabilities = ["read"]
}
+11
View File
@@ -0,0 +1,11 @@
ui = false
storage "file" {
path = "/openbao/file"
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/run/tls/server.crt"
tls_key_file = "/run/tls/server.key"
tls_min_version = "tls12"
}
api_addr = "https://openbao:8200"
+3
View File
@@ -0,0 +1,3 @@
path "lab7/data/worker" {
capabilities = ["read"]
}
+42
View File
@@ -0,0 +1,42 @@
auth_enabled: false
analytics:
reporting_enabled: false
server:
http_listen_address: 127.0.0.1
http_listen_port: 13100
grpc_listen_address: 127.0.0.1
log_level: warn
common:
instance_addr: 127.0.0.1
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}
ingester:
wal:
dir: /loki/wal
flush_on_shutdown: true
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
limits_config:
allow_structured_metadata: true
retention_period: 48h
otlp_config:
resource_attributes:
ignore_defaults: true
attributes_config:
- action: index_label
attributes: [service.name]
+3
View File
@@ -0,0 +1,3 @@
global:
scrape_interval: 5s
scrape_configs: []
+28
View File
@@ -0,0 +1,28 @@
server:
http_listen_address: 127.0.0.1
http_listen_port: 13200
grpc_listen_address: 127.0.0.1
log_level: warn
usage_report:
reporting_enabled: false
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:14318
ingester:
lifecycler:
address: 127.0.0.1
max_block_duration: 30s
flush_all_on_shutdown: true
compactor:
compaction:
block_retention: 48h
storage:
trace:
backend: local
wal:
path: /var/tempo/wal
local:
path: /var/tempo/blocks
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
set -eu
psql --set ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<'SQL'
\getenv database POSTGRES_DB
\set api_password `cat /run/private/pg_api`
\set worker_password `cat /run/private/pg_worker`
\set migrate_password `cat /run/private/pg_migrate`
CREATE ROLE lab_api LOGIN PASSWORD :'api_password';
CREATE ROLE lab_worker LOGIN PASSWORD :'worker_password';
CREATE ROLE lab_migrate LOGIN PASSWORD :'migrate_password';
REVOKE CONNECT, TEMP ON DATABASE :"database" FROM PUBLIC;
GRANT CONNECT ON DATABASE :"database" TO lab_api, lab_worker, lab_migrate;
REVOKE ALL ON SCHEMA public FROM PUBLIC;
GRANT USAGE ON SCHEMA public TO lab_api, lab_worker;
GRANT USAGE, CREATE ON SCHEMA public TO lab_migrate;
SQL
+4
View File
@@ -0,0 +1,4 @@
local all all trust
hostnossl all all all reject
hostssl messenger lab_api,lab_worker,lab_migrate all scram-sha-256
hostssl all all all reject
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
install -d -o postgres -g postgres -m 0700 /run/pg-tls
install -o postgres -g postgres -m 0600 /run/tls/server.key /run/pg-tls/server.key
install -o postgres -g postgres -m 0644 /run/tls/server.crt /run/pg-tls/server.crt
exec docker-entrypoint.sh postgres -c ssl=on -c ssl_cert_file=/run/pg-tls/server.crt \
-c ssl_key_file=/run/pg-tls/server.key -c hba_file=/run/config/pg_hba.conf
+11
View File
@@ -0,0 +1,11 @@
listeners.tcp = none
listeners.ssl.default = 5671
ssl_options.certfile = /run/tls/server.crt
ssl_options.keyfile = /run/tls/server.key
ssl_options.cacertfile = /run/ca/server.crt
ssl_options.verify = verify_none
ssl_options.fail_if_no_peer_cert = false
ssl_options.versions.1 = tlsv1.3
ssl_options.versions.2 = tlsv1.2
definitions.import_backend = local_filesystem
definitions.local.path = /run/config/definitions.json
+20
View File
@@ -0,0 +1,20 @@
attrs==26.1.0
certifi==2026.10.23
charset-normalizer==3.5.2
idna==3.20
jsonschema==4.26.0
jsonschema-path==0.3.4
jsonschema-specifications==2025.9.1
lazy-object-proxy==1.13.0
openapi-schema-validator==0.6.3
openapi-spec-validator==0.7.2
pathable==0.4.4
PyYAML==6.0.3
referencing==0.36.2
requests==2.34.2
rfc3339-validator==0.1.4
rpds-py==2026.9.1
six==1.17.0
typing_extensions==4.16.0
urllib3==2.8.0
Pillow==12.2.0