forked from mtusi2026/mtusi2026lab7
Compare commits
3
Commits
main
..
ba7aabede2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba7aabede2 | ||
|
|
58c9bb027b | ||
|
|
951e554e06 |
+10
-56
@@ -14,7 +14,7 @@ concurrency:
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
timeout-minutes: 45
|
||||
env:
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab7-${{ github.run_id }}
|
||||
API_BIND_ADDRESS: 127.0.0.1:0
|
||||
@@ -23,10 +23,6 @@ jobs:
|
||||
GRAFANA_BIND_ADDRESS: 127.0.0.1:0
|
||||
LOKI_BIND_ADDRESS: 127.0.0.1:0
|
||||
TEMPO_BIND_ADDRESS: 127.0.0.1:0
|
||||
OPENBAO_BIND_ADDRESS: 127.0.0.1:0
|
||||
BAO_ADDR: https://openbao:8200
|
||||
DOCKER_WORKSPACE_MIRROR: "1"
|
||||
CI_WORKSPACE: /tmp/mtusi2026lab7-${{ github.run_id }}
|
||||
steps:
|
||||
- name: Checkout exact commit
|
||||
run: |
|
||||
@@ -37,7 +33,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.10"
|
||||
go-version-file: go.mod
|
||||
cache: false
|
||||
|
||||
- name: Check contract
|
||||
@@ -52,8 +48,8 @@ jobs:
|
||||
- name: Check formatting and shell scripts
|
||||
run: |
|
||||
test -z "$(gofmt -l cmd internal migrations)"
|
||||
for file in infra/minio/*.sh infra/pki/*.sh infra/postgres/*.sh infra/redis/*.sh infra/security/*.sh infra/openbao/*.sh scripts/*.sh; do sh -n "$file"; done
|
||||
python3 -m py_compile scripts/lab6-traffic.py scripts/lab6-observe.py scripts/lab6-alert.py scripts/lab6-correlation.py scripts/validate-lab6-evidence.py scripts/test-login-rate-limit.py
|
||||
sh -n infra/minio/bootstrap.sh infra/pki/bootstrap.sh infra/pki/install.sh scripts/restart.sh scripts/rolling-update.sh scripts/stop-one.sh scripts/test-lab5.sh scripts/test-lab5-acceptance.sh scripts/test-lab6.sh scripts/test-tls-matrix.sh scripts/incident-worker.sh scripts/incident-database.sh scripts/incident-telemetry.sh
|
||||
python3 -m py_compile scripts/lab6-traffic.py scripts/lab6-observe.py scripts/lab6-alert.py scripts/lab6-correlation.py scripts/validate-lab6-evidence.py
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
@@ -69,79 +65,37 @@ jobs:
|
||||
|
||||
- name: Prepare local stack
|
||||
run: |
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
./infra/pki/bootstrap.sh
|
||||
./scripts/openbao-seed.sh .env
|
||||
./scripts/sync-docker-workspace.sh
|
||||
docker compose up -d security-bootstrap openbao-permissions openbao
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME"
|
||||
./scripts/bootstrap-local.sh .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 150
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME"
|
||||
|
||||
- name: Integration checks
|
||||
run: |
|
||||
cd "$CI_WORKSPACE"
|
||||
test "$(curl --noproxy '*' --cacert .runtime/security/internal-ca/ca.crt -s -o /dev/null -w '%{http_code}' "https://s3:9000/messenger-attachments")" = "403"
|
||||
test "$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' "http://s3:9000/messenger-attachments")" = "403"
|
||||
make test BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-security BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-tls-matrix ENV_FILE=.env
|
||||
ENV_FILE=.env BASE_URL=https://nginx:8443 ./scripts/test-leaf-rotation.sh
|
||||
docker compose --profile security run --rm dependency-tests
|
||||
ENV_FILE=.env BAO_ADDR=https://openbao:8200 BAO_CACERT="$PWD/.runtime/security/openbao/ca.crt" ./scripts/openbao-test-policy.sh
|
||||
ENV_FILE=.env BAO_ADDR=https://openbao:8200 BAO_CACERT="$PWD/.runtime/security/openbao/ca.crt" ./scripts/test-openbao-lifecycle.sh
|
||||
make test-login-rate-limit BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-tls-matrix
|
||||
docker compose --profile tests run --rm --build tests
|
||||
go run ./cmd/dependencycheck -base-url=https://nginx:8443 -ca-file=.runtime/security/public-ca/ca.crt
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
docker compose up -d --scale api=2 --wait --wait-timeout 90
|
||||
make test-lab5-acceptance
|
||||
make test-worker-compromise ENV_FILE=.env
|
||||
make scan-security
|
||||
make test-lab5
|
||||
ENV_FILE=.env CA_FILE=.runtime/security/public-ca/ca.crt PROMETHEUS_URL=http://prometheus:9090 TEMPO_URL=http://tempo:3200 LOKI_URL=http://loki:3100 make test-lab6-smoke BASE_URL=https://nginx:8443
|
||||
mkdir -p evidence/runtime
|
||||
api_restart_counts=$(docker inspect --format '{{.RestartCount}}' $(docker compose ps -q api))
|
||||
go run ./cmd/loginburst -base-url=https://nginx:8443 -ca-file=.runtime/security/public-ca/ca.crt > evidence/runtime/login-burst.json
|
||||
test "$(docker inspect --format '{{.RestartCount}}' $(docker compose ps -q api))" = "$api_restart_counts"
|
||||
|
||||
- name: Container logs
|
||||
if: failure()
|
||||
run: if [ -f "$CI_WORKSPACE/.env" ]; then cd "$CI_WORKSPACE"; docker compose logs --no-color --tail=200; fi
|
||||
|
||||
- name: Upload security evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
env:
|
||||
ACTIONS_RUNTIME_URL: https://gitea.privcloud.tech/api/actions_pipeline/
|
||||
with:
|
||||
name: lab7-security-${{ github.sha }}
|
||||
path: |
|
||||
${{ env.CI_WORKSPACE }}/evidence/lab7-*.json
|
||||
${{ env.CI_WORKSPACE }}/evidence/runtime/security-scan
|
||||
${{ env.CI_WORKSPACE }}/evidence/runtime/login-burst.json
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
run: if [ -f .env ]; then docker compose logs --no-color --tail=200; fi
|
||||
|
||||
- name: Stop local stack
|
||||
if: always()
|
||||
run: |
|
||||
test -d "$CI_WORKSPACE" || exit 0
|
||||
cd "$CI_WORKSPACE"
|
||||
trap './scripts/sync-docker-workspace.sh --clean' EXIT
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME" 2>/dev/null || true
|
||||
if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
||||
|
||||
+10
-41
@@ -12,7 +12,7 @@ jobs:
|
||||
name: Verify selected commit
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
timeout-minutes: 45
|
||||
outputs:
|
||||
api_image: ${{ steps.publish.outputs.api_image }}
|
||||
nginx_image: ${{ steps.publish.outputs.nginx_image }}
|
||||
@@ -30,10 +30,6 @@ jobs:
|
||||
GRAFANA_BIND_ADDRESS: 127.0.0.1:0
|
||||
LOKI_BIND_ADDRESS: 127.0.0.1:0
|
||||
TEMPO_BIND_ADDRESS: 127.0.0.1:0
|
||||
OPENBAO_BIND_ADDRESS: 127.0.0.1:0
|
||||
BAO_ADDR: https://openbao:8200
|
||||
DOCKER_WORKSPACE_MIRROR: "1"
|
||||
CI_WORKSPACE: /tmp/mtusi2026lab7-${{ github.run_id }}
|
||||
API_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-api:${{ github.sha }}
|
||||
NGINX_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-nginx:${{ github.sha }}
|
||||
SWAGGER_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-swagger:${{ github.sha }}
|
||||
@@ -51,7 +47,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.10"
|
||||
go-version-file: go.mod
|
||||
cache: false
|
||||
|
||||
- name: Check contract
|
||||
@@ -66,8 +62,8 @@ jobs:
|
||||
- name: Check formatting and shell scripts
|
||||
run: |
|
||||
test -z "$(gofmt -l cmd internal migrations)"
|
||||
for file in infra/minio/*.sh infra/pki/*.sh infra/postgres/*.sh infra/redis/*.sh infra/security/*.sh infra/openbao/*.sh scripts/*.sh; do sh -n "$file"; done
|
||||
python3 -m py_compile scripts/lab6-traffic.py scripts/lab6-observe.py scripts/lab6-alert.py scripts/lab6-correlation.py scripts/validate-lab6-evidence.py scripts/test-login-rate-limit.py
|
||||
sh -n infra/minio/bootstrap.sh infra/pki/bootstrap.sh infra/pki/install.sh scripts/restart.sh scripts/rolling-update.sh scripts/stop-one.sh scripts/test-lab5.sh scripts/test-lab5-acceptance.sh scripts/test-lab6.sh scripts/test-tls-matrix.sh scripts/incident-worker.sh scripts/incident-database.sh scripts/incident-telemetry.sh
|
||||
python3 -m py_compile scripts/lab6-traffic.py scripts/lab6-observe.py scripts/lab6-alert.py scripts/lab6-correlation.py scripts/validate-lab6-evidence.py
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
@@ -83,47 +79,27 @@ jobs:
|
||||
|
||||
- name: Prepare local stack
|
||||
run: |
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
./infra/pki/bootstrap.sh
|
||||
./scripts/openbao-seed.sh .env
|
||||
./scripts/sync-docker-workspace.sh
|
||||
docker compose up -d security-bootstrap openbao-permissions openbao
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME"
|
||||
./scripts/bootstrap-local.sh .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 150
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME"
|
||||
|
||||
- name: Integration checks
|
||||
run: |
|
||||
cd "$CI_WORKSPACE"
|
||||
test "$(curl --noproxy '*' --cacert .runtime/security/internal-ca/ca.crt -s -o /dev/null -w '%{http_code}' "https://s3:9000/messenger-attachments")" = "403"
|
||||
test "$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' "http://s3:9000/messenger-attachments")" = "403"
|
||||
make test BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-security BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-tls-matrix ENV_FILE=.env
|
||||
ENV_FILE=.env BASE_URL=https://nginx:8443 ./scripts/test-leaf-rotation.sh
|
||||
docker compose --profile security run --rm dependency-tests
|
||||
ENV_FILE=.env BAO_ADDR=https://openbao:8200 BAO_CACERT="$PWD/.runtime/security/openbao/ca.crt" ./scripts/openbao-test-policy.sh
|
||||
ENV_FILE=.env BAO_ADDR=https://openbao:8200 BAO_CACERT="$PWD/.runtime/security/openbao/ca.crt" ./scripts/test-openbao-lifecycle.sh
|
||||
make test-login-rate-limit BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-tls-matrix
|
||||
docker compose --profile tests run --rm --build tests
|
||||
go run ./cmd/dependencycheck -base-url=https://nginx:8443 -ca-file=.runtime/security/public-ca/ca.crt
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=https://nginx:8443 CA_FILE=.runtime/security/public-ca/ca.crt
|
||||
make test-lab5-acceptance
|
||||
make test-worker-compromise ENV_FILE=.env
|
||||
make test-lab5
|
||||
ENV_FILE=.env CA_FILE=.runtime/security/public-ca/ca.crt PROMETHEUS_URL=http://prometheus:9090 TEMPO_URL=http://tempo:3200 LOKI_URL=http://loki:3100 make test-lab6-smoke BASE_URL=https://nginx:8443
|
||||
mkdir -p evidence/runtime
|
||||
api_restart_counts=$(docker inspect --format '{{.RestartCount}}' $(docker compose ps -q api))
|
||||
go run ./cmd/loginburst -base-url=https://nginx:8443 -ca-file=.runtime/security/public-ca/ca.crt > evidence/runtime/login-burst.json
|
||||
test "$(docker inspect --format '{{.RestartCount}}' $(docker compose ps -q api))" = "$api_restart_counts"
|
||||
|
||||
- name: Publish verified images
|
||||
id: publish
|
||||
@@ -154,21 +130,14 @@ jobs:
|
||||
|
||||
- name: Container logs
|
||||
if: failure()
|
||||
run: if [ -f "$CI_WORKSPACE/.env" ]; then cd "$CI_WORKSPACE"; docker compose logs --no-color --tail=200; fi
|
||||
run: if [ -f .env ]; then docker compose logs --no-color --tail=200; fi
|
||||
|
||||
- name: Stop local stack
|
||||
if: always()
|
||||
run: |
|
||||
test -d "$CI_WORKSPACE" || exit 0
|
||||
cd "$CI_WORKSPACE"
|
||||
trap './scripts/sync-docker-workspace.sh --clean' EXIT
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME" 2>/dev/null || true
|
||||
if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi
|
||||
|
||||
deploy:
|
||||
|
||||
@@ -19,10 +19,6 @@ jobs:
|
||||
GRAFANA_BIND_ADDRESS: 127.0.0.1:0
|
||||
LOKI_BIND_ADDRESS: 127.0.0.1:0
|
||||
TEMPO_BIND_ADDRESS: 127.0.0.1:0
|
||||
OPENBAO_BIND_ADDRESS: 127.0.0.1:0
|
||||
BAO_ADDR: https://openbao:8200
|
||||
DOCKER_WORKSPACE_MIRROR: "1"
|
||||
CI_WORKSPACE: /tmp/mtusi2026lab7-${{ github.run_id }}
|
||||
steps:
|
||||
- name: Checkout exact commit
|
||||
run: |
|
||||
@@ -33,32 +29,21 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.10"
|
||||
go-version-file: go.mod
|
||||
cache: false
|
||||
|
||||
- name: Prepare stack
|
||||
run: |
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
./infra/pki/bootstrap.sh
|
||||
./scripts/openbao-seed.sh .env
|
||||
./scripts/sync-docker-workspace.sh
|
||||
docker compose up -d security-bootstrap openbao-permissions openbao
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME"
|
||||
./scripts/bootstrap-local.sh .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 180
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME"
|
||||
docker network connect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME"
|
||||
|
||||
- name: Reproduce SLO incidents
|
||||
run: |
|
||||
cd "$CI_WORKSPACE"
|
||||
ENV_FILE=.env \
|
||||
BASE_URL=https://nginx:8443 \
|
||||
CA_FILE=.runtime/security/public-ca/ca.crt \
|
||||
@@ -70,30 +55,21 @@ jobs:
|
||||
|
||||
- name: Upload sanitized evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
env:
|
||||
ACTIONS_RUNTIME_URL: https://gitea.privcloud.tech/api/actions_pipeline/
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lab6-incidents-${{ github.sha }}
|
||||
path: ${{ env.CI_WORKSPACE }}/evidence/runtime/ci
|
||||
path: evidence/runtime/ci
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
|
||||
- name: Container logs
|
||||
if: failure()
|
||||
run: if [ -f "$CI_WORKSPACE/.env" ]; then cd "$CI_WORKSPACE"; docker compose logs --no-color --tail=200; fi
|
||||
run: docker compose logs --no-color --tail=200
|
||||
|
||||
- name: Stop local stack
|
||||
if: always()
|
||||
run: |
|
||||
test -d "$CI_WORKSPACE" || exit 0
|
||||
cd "$CI_WORKSPACE"
|
||||
trap './scripts/sync-docker-workspace.sh --clean' EXIT
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secrets" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_data_backend" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_monitoring" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_secure_clients" "$HOSTNAME" 2>/dev/null || true
|
||||
docker network disconnect "${COMPOSE_PROJECT_NAME}_telemetry_storage" "$HOSTNAME" 2>/dev/null || true
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
@@ -33,3 +33,4 @@ coverage/
|
||||
# Inspect git diff --cached: ignore rules are not a secret scanner.
|
||||
|
||||
evidence/runtime/
|
||||
.runtime/
|
||||
|
||||
+3
-7
@@ -5,7 +5,7 @@ WORKDIR /src
|
||||
COPY scripts/test-tls-matrix.sh /src/scripts/test-tls-matrix.sh
|
||||
CMD ["/bin/sh", "/src/scripts/test-tls-matrix.sh"]
|
||||
|
||||
FROM golang:1.26.10-alpine3.24 AS build
|
||||
FROM golang:1.26.5-alpine3.24 AS build
|
||||
|
||||
ARG GOPROXY=https://proxy.golang.org
|
||||
|
||||
@@ -17,7 +17,6 @@ RUN GOPROXY="$GOPROXY" go mod download
|
||||
COPY . .
|
||||
RUN go build -p=1 -o /out/messenger ./cmd/messenger
|
||||
RUN go build -p=1 -o /out/lab5experiment ./cmd/lab5experiment
|
||||
RUN go build -p=1 -o /out/mtlsproxy ./cmd/mtlsproxy
|
||||
|
||||
FROM build AS test
|
||||
|
||||
@@ -38,19 +37,16 @@ FROM grafana/grafana:13.2.4 AS grafana
|
||||
COPY monitoring/grafana/provisioning /etc/grafana/provisioning
|
||||
COPY monitoring/grafana/dashboards /etc/grafana/dashboards
|
||||
|
||||
FROM nginx:1.30.6-alpine AS loadbalancer
|
||||
|
||||
RUN apk upgrade --no-cache
|
||||
FROM nginx:1.30.5-alpine AS loadbalancer
|
||||
|
||||
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY nginx/upstream.conf /etc/nginx/conf.d/upstream.conf
|
||||
|
||||
FROM alpine:3.24.2
|
||||
|
||||
RUN apk upgrade --no-cache && addgroup -S app && adduser -S -G app -u 10001 app
|
||||
RUN addgroup -S app && adduser -S -G app -u 10001 app
|
||||
COPY --from=build --chown=app:app /out/messenger /app/messenger
|
||||
COPY --from=build --chown=app:app /out/lab5experiment /app/lab5experiment
|
||||
COPY --from=build --chown=app:app /out/mtlsproxy /app/mtlsproxy
|
||||
|
||||
USER app
|
||||
WORKDIR /app
|
||||
|
||||
@@ -5,7 +5,7 @@ ACTION_SCRIPT ?=
|
||||
ENV_FILE ?= $(if $(wildcard .env),.env,lab7.env.example)
|
||||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||||
|
||||
.PHONY: help check validate test load test-persistence test-failover test-security test-tls-matrix test-leaf-rotation test-openbao-lifecycle test-login-rate-limit test-worker-compromise scan-security test-lab5 test-lab5-acceptance lab6-load test-lab6-smoke test-lab6
|
||||
.PHONY: help check validate test load test-persistence test-failover test-security test-tls-matrix test-lab5 test-lab5-acceptance lab6-load test-lab6-smoke test-lab6
|
||||
|
||||
help:
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||||
@@ -36,22 +36,6 @@ test-security:
|
||||
test-tls-matrix:
|
||||
docker compose --env-file "$(ENV_FILE)" --profile security run --rm security-tests
|
||||
|
||||
test-leaf-rotation:
|
||||
ENV_FILE="$(ENV_FILE)" BASE_URL="$(BASE_URL)" ./scripts/test-leaf-rotation.sh
|
||||
|
||||
test-openbao-lifecycle:
|
||||
ENV_FILE="$(ENV_FILE)" ./scripts/test-openbao-lifecycle.sh
|
||||
|
||||
test-login-rate-limit:
|
||||
@test -n "$(CA_FILE)" || (echo "Set CA_FILE"; exit 2)
|
||||
$(PYTHON) scripts/test-login-rate-limit.py --base-url "$(BASE_URL)" --ca-file "$(CA_FILE)"
|
||||
|
||||
test-worker-compromise:
|
||||
ENV_FILE="$(ENV_FILE)" ./scripts/lab7-worker-compromise.sh
|
||||
|
||||
scan-security:
|
||||
./scripts/scan-security.sh
|
||||
|
||||
test-lab5:
|
||||
./scripts/test-lab5.sh
|
||||
|
||||
|
||||
@@ -1,186 +1,37 @@
|
||||
# Отчёт — лабораторная работа № 7
|
||||
# Отчёт — лабораторная 7
|
||||
|
||||
**Автор:** Пластинин Денис, БВТ2303
|
||||
|
||||
**Целевая оценка:** 5
|
||||
|
||||
**Выбранный трек:** 1 — компрометация worker
|
||||
|
||||
## Цель работы
|
||||
|
||||
Цель работы — провести границы доверия в ранее реализованном мессенджере, включить проверяемое TLS/mTLS взаимодействие, разделить права сервисов и вынести runtime secrets в OpenBao. За основу взята лабораторная работа № 6: сохранены API, обработка вложений через Redis Streams, PostgreSQL, MinIO и стек наблюдаемости.
|
||||
|
||||
Внешний клиент подключается только к Nginx по HTTPS. Nginx обращается к двум API-репликам по mTLS, причём API принимает только сертификат с разрешённым URI SAN балансировщика. Внутренние зависимости используют TLS, отдельные service identities и минимальные ACL. Наличие сертификата, подписанного доверенным CA, само по себе не даёт доступ: identity дополнительно сопоставляется с разрешённой ролью.
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
|
||||
## Запуск из чистого clone
|
||||
|
||||
Требуются Docker с Compose v2, `make`, Python 3 и `curl`. Все используемые образы закреплены по версиям в `compose.yaml`. Локальные ключи и operator material создаются в игнорируемой директории `.runtime`.
|
||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
||||
|
||||
```sh
|
||||
cp lab7.env.example .env
|
||||
./scripts/bootstrap-local.sh .env
|
||||
```
|
||||
## Архитектура и решения
|
||||
|
||||
Скрипт создаёт локальную PKI, запускает OpenBao с Raft storage, при первом запуске выполняет `init`/`unseal`, создаёт policies и AppRole, затем поднимает стенд с двумя API-репликами. Повторный запуск использует сохранённое состояние OpenBao и выполняет только необходимый bootstrap.
|
||||
|
||||
Основные интерфейсы:
|
||||
|
||||
- API и Swagger через HTTPS: `https://localhost:8443` и `http://localhost:8081`;
|
||||
- Grafana: `https://localhost:3000`;
|
||||
- Prometheus: `http://localhost:9090`;
|
||||
- OpenBao operator endpoint: `https://localhost:8200`.
|
||||
|
||||
Публичный CA создаётся в `.runtime/security/public-ca/ca.crt`. Проверка API:
|
||||
|
||||
```sh
|
||||
make test BASE_URL=https://localhost:8443 CA_FILE="$PWD/.runtime/security/public-ca/ca.crt"
|
||||
make test-security BASE_URL=https://localhost:8443 CA_FILE="$PWD/.runtime/security/public-ca/ca.crt"
|
||||
```
|
||||
|
||||
Безопасная остановка сохраняет volumes:
|
||||
|
||||
```sh
|
||||
docker compose --env-file .env stop
|
||||
```
|
||||
|
||||
Намеренное удаление учебного стенда и его данных:
|
||||
|
||||
```sh
|
||||
docker compose --env-file .env down --volumes --remove-orphans
|
||||
rm -rf .runtime
|
||||
```
|
||||
|
||||
Root token и unseal key находятся только в `.runtime/openbao/operator/init.json` с правами `0600`. Их хранит оператор; приложения и CI runtime их не получают. В production этот файл должен находиться во внешнем защищённом хранилище, а unseal shares должны быть разделены между операторами.
|
||||
|
||||
## Архитектура
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
C[Client] -->|HTTPS + Bearer| N[Nginx]
|
||||
N -->|mTLS| A1[API 1]
|
||||
N -->|mTLS| A2[API 2]
|
||||
A1 & A2 -->|TLS + api role| P[(PostgreSQL)]
|
||||
A1 & A2 -->|mTLS + ACL| V[(Valkey)]
|
||||
A1 & A2 -->|HTTPS + staging policy| S[(MinIO)]
|
||||
D[Dispatcher] -->|mTLS producer| R[(Redis Streams)]
|
||||
R -->|mTLS consumer| W[Worker]
|
||||
W -->|HTTPS + attachment policy| S
|
||||
A1 & A2 & D & W -->|mTLS| O[OTel gateway]
|
||||
BA[OpenBao Agents] -->|TLS + AppRole| B[(OpenBao Raft)]
|
||||
BA -->|secret file 0600| A1 & A2 & W
|
||||
```
|
||||
|
||||
PostgreSQL остаётся источником истины для пользователей, чатов, сообщений, metadata вложений, outbox и состояния заданий. MinIO хранит содержимое вложений. Redis Streams переносит задания с гарантией at-least-once, а Valkey хранит session token hashes и общие счётчики login rate limit. Дедупликация и переходы состояний выполняются транзакционно в PostgreSQL.
|
||||
|
||||
OpenBao работает в non-dev режиме на persistent Raft storage. API и worker имеют разные AppRole и KV policies. Agent аутентифицируется короткоживущим SecretID, обновляет renewable token и рендерит JSON secret в защищённый Docker volume; приложение получает путь через `MESSENGER_SECRETS_FILE`. Token Agent хранится в tmpfs, root token не используется приложением. SecretID действует один час и позволяет повторную аутентификацию после рестарта; затем оператор выдаёт новый.
|
||||
|
||||
PostgreSQL использует `verify-full` и отдельные роли API, dispatcher, worker, reconciler, exporter и migrator. Valkey и Redis Streams защищены native TLS, ACL и Envoy gateway, который проверяет точный URI SAN клиента. MinIO использует HTTPS и отдельные scoped users. OTel ingest и metrics endpoints требуют mTLS с allowlist identities. Полная схема связей приведена в `contracts/trust-matrix.md`.
|
||||
|
||||
Контейнеры приложения запускаются non-root, с `read_only`, `no-new-privileges`, `cap_drop: ALL`, отдельным `tmpfs` и лимитами CPU/RAM. Stateful компоненты сохраняют данные в named volumes; их исключения из `read_only` ограничены каталогами данных.
|
||||
|
||||
## Пароли, сессии и защита login
|
||||
|
||||
Пароли хешируются Argon2id с индивидуальной солью и сохранёнными параметрами. При успешном входе `NeedsRehash` сравнивает параметры хеша с текущей политикой; устаревший хеш обновляется compare-and-swap запросом, поэтому параллельный login не перезаписывает более новый пароль.
|
||||
|
||||
Параметры `m=65536 KiB`, `t=3`, `p=2` измерены в Linux-контейнере с лимитом 2 CPU и 512 MiB. Пять операций дали около 60,0 мс на hash и 64,8 мс на verify при примерно 64 MiB памяти на операцию. Частотный лимит ограничивает login, а общий semaphore внутри Hasher допускает не более двух `Hash`/`Verify` на API-реплику, включая регистрацию и rehash. Поэтому одновременно занятая Argon2 память ограничена примерно 128 MiB на реплику; лишние операции сразу получают `429 Retry-After: 1`. Лимит задаётся `server.password.max_concurrent_operations`. Raw summary сохранён в `evidence/lab7-argon2-budget.json`.
|
||||
|
||||
`cmd/loginburst` создаёт одновременные волны по 20 регистраций и login-запросов через Nginx, проверяет ответы `429` с положительным `Retry-After`, отсутствие `5xx` и readiness после нагрузки. CI дополнительно проверяет, что API containers не перезапускались. `X-Instance-Id` — случайный alias на время жизни процесса; hostname и IP в него не входят.
|
||||
|
||||
Session token является случайным opaque bearer token. В Valkey сохраняется только его SHA-256 hash с TTL; logout удаляет запись. Login limiter общий для API-реплик: Lua script атомарно увеличивает счётчики по нормализованному login и адресу источника, выставляет TTL и возвращает время до повторной попытки. При превышении лимита API отвечает `429` и положительным `Retry-After`.
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab6, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
|
||||
## Доказательства критериев
|
||||
|
||||
| Критерий | Команда/сценарий | Наблюдаемый результат | Доказательство |
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| --- | --- | --- | --- |
|
||||
| Контракт и OpenAPI | `make check`, `make validate` | структура и OpenAPI 3.1 проходят проверку | CI `verify` |
|
||||
| Unit и integration | `go test ./...`, PostgreSQL/Valkey integration tests | тесты проходят по TLS connections | CI и test output |
|
||||
| Публичный API через HTTPS | `make test ... CA_FILE=...` | полный smoke проходит через Nginx | public smoke output |
|
||||
| Недоверенный внешний TLS | `make test-security` | правильный CA проходит, пустой/чужой CA отклонён | security test output |
|
||||
| LB→API mTLS | `make test-tls-matrix` | 13 положительных и отрицательных cases проходят | TLS matrix output |
|
||||
| DB/S3/broker/OTel least privilege | `infra/security/test-dependency-matrix.sh` | разрешённые операции проходят, cross-role операции отклонены | dependency matrix output |
|
||||
| OpenBao scoped policy | `scripts/openbao-test-policy.sh` | own read `200`, cross/write/policy `403`, token renew `200` | policy test output |
|
||||
| OpenBao expiry/revoke/seal | `make test-openbao-lifecycle` | revoked/expired token `403`, sealed login `503`, Agent восстановил аутентификацию после unseal | lifecycle test output |
|
||||
| Ротация leaf и отзыв identity | `make test-leaf-rotation` | новая LB identity проходит, прежняя same-CA identity и expired leaf отклонены на новых connections | rotation test output |
|
||||
| Общий login limiter | `make test-login-rate-limit ...` | запросы через обе replicas завершаются `429` с `Retry-After` | rate-limit test output |
|
||||
| Rehash Argon2id | `go test ./internal/password ./internal/postgres ./internal/messenger/httpapi` | проверены `NeedsRehash` и конкурентное CAS update | unit/integration tests |
|
||||
| Argon2/login DoS budget | `go test ./internal/password -run '^$' -bench 'BenchmarkArgon2id(Hash\|Verify)$' -benchtime=5x -benchmem` | hash 60,0 мс, verify 64,8 мс, около 64 MiB/op при 2 CPU | `evidence/lab7-argon2-budget.json` |
|
||||
| Dependency/image/security scan | `make scan-security` | secrets не найдены; исправляемые high/critical Go CVE обновлены | `evidence/lab7-security-scan.json` |
|
||||
| Компрометация worker | `make test-worker-compromise` | старый broker credential отклонён, после rotation queued attachment обработан без потери | `evidence/lab7-worker-compromise.json` |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
|
||||
## Эксперимент: компрометация worker
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
|
||||
### Гипотеза
|
||||
## Эксперименты и отказы
|
||||
|
||||
Если worker credential будет скомпрометирован, злоумышленник получит только consumer operations своего stream, ограниченные таблицы PostgreSQL и два MinIO prefix. После смены broker password и worker secret старая identity перестанет работать, а уже поставленное задание сохранится и завершится после восстановления worker.
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
|
||||
### Методика
|
||||
|
||||
Стенд запускался в контейнерах с лимитом worker `2 CPU / 1 GiB`. Скрипт `scripts/lab7-worker-compromise.sh` останавливает worker, создаёт реальное задание загрузки через API, меняет Redis ACL password, не обновляя secret работающего worker, и проверяет отказ старой identity. Затем он записывает новый secret в OpenBao, пересоздаёт OpenBao Agent и worker и проверяет созданное вложение через API. В `trap` всегда восстанавливается исходный учебный secret.
|
||||
|
||||
Отдельная dependency matrix моделирует возможности скомпрометированного worker: ему разрешены чтение/изменение attachment job state, consumer/ack операции stream и работа с `staging/`/`attachments/`; запрещены таблица `users`, unrelated Redis streams и произвольный S3 prefix.
|
||||
|
||||
### Изменение blast radius относительно lab6
|
||||
|
||||
| Ресурс | До разделения прав в lab6 | После least privilege в lab7 |
|
||||
| --- | --- | --- |
|
||||
| PostgreSQL | API, dispatcher, worker и reconciler получали общий `DATABASE_URL`; worker мог использовать права основной роли на пользователей, чаты и сообщения | `messenger_worker` читает/обновляет только attachments/jobs/variants, создаёт audit/outbox; чтение `users` запрещено |
|
||||
| MinIO | один `S3_ACCESS_KEY` имел `Get/Put/Delete` на весь bucket | worker видит только `staging/*` и `attachments/*`; `private/*` и управление users/policies запрещены |
|
||||
| Redis Streams | dispatcher и worker использовали общий `BROKER_URL` | dispatcher может только `XADD` в `attachment-jobs`; worker может consumer/ack/recovery команды только для job/DLQ streams |
|
||||
| TLS identity | внутренние зависимости принимали сетевое соединение без service URI проверки | gateway сопоставляет worker certificate с `spiffe://mtusi/lab7/worker`; same-CA чужая identity отклоняется |
|
||||
| Secrets | все static credentials находились в общем `.env` процесса | worker получает отдельный JSON через scoped OpenBao AppRole; API policy не читает worker path |
|
||||
|
||||
Таким образом, до разделения кража worker environment давала общий доступ к данным приложения и всему bucket. После разделения она ограничена обработкой вложений. Ротация в эксперименте меняет broker, PostgreSQL и MinIO credentials внутри worker secret; старые credentials не открывают новое соединение даже при наличии прежнего leaf certificate.
|
||||
|
||||
### Результат
|
||||
|
||||
| Воздействие | Ожидание | Наблюдение | Потеря данных |
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| Старый broker password после ротации | authentication error | worker получил `WRONGPASS/invalid username-password` | нет |
|
||||
| Cross-role DB/S3/stream operations | ACL denial | все отрицательные cases dependency matrix отклонены | нет |
|
||||
| Обновление worker secret в OpenBao | Agent рендерит новый secret, worker становится healthy | от начала сценария до проверки вложения — 21 секунда; возврат исходных паролей измеряется отдельно | нет |
|
||||
| Проверка задания, созданного до отзыва | вложение обработано после восстановления | API verification прошла | queued attachment сохранён |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
|
||||
Эксперимент доказывает ограничение blast radius и восстановление задания, но не моделирует кражу root-доступа к Docker host. Сценарий разрывает broker connections перезапуском gateway и завершает PostgreSQL sessions роли worker через `pg_terminate_backend`; затем проверяет новые подключения со старыми паролями и отказ старому S3 key. Для production потребуются внешний KMS/HSM для CA, response-wrapped SecretID, автоматизированный revoke и несколько независимых повторов с измерением времени восстановления.
|
||||
## Ограничения и следующие шаги
|
||||
|
||||
## Scan triage
|
||||
|
||||
`scripts/scan-security.sh` запускает Trivy filesystem scan и image scan всех образов работающего Compose-стенда. Raw JSON сохраняется в игнорируемом `evidence/runtime/security-scan` и CI artifact, компактная сводка — в `evidence/lab7-security-scan.json`. Найденные у приложения CVE устранены обновлением OpenTelemetry, gRPC, `x/net`, `klauspost/compress`, Go toolchain и Nginx. Весь стенд не объявляется свободным от CVE: сканирование сторонних образов находит отдельные уязвимые компоненты. Secrets в repository/images не найдены.
|
||||
|
||||
| Finding / класс | Применимость и решение |
|
||||
| --- | --- |
|
||||
| `CVE-2026-81871`, `CVE-2026-81872`, `CVE-2026-81870` в OTLP | Затрагивают используемые приложением exporters/log SDK. Обновлены до OTLP `1.45.0` / log `0.21.0`; отключение TLS verification не используется |
|
||||
| `CVE-2026-33322`, `CVE-2026-33419` в MinIO | Требуют OIDC/LDAP auth, которые в стенде не настроены; используется локальная scoped access-key auth. Образ не опубликован наружу. Обновление MinIO остаётся задачей перед production |
|
||||
| `CVE-2026-77405`, `CVE-2026-77408`, `CVE-2026-77411` в AMQP library сторонних images | AMQP receivers/exporters и MinIO AMQP notifications не настроены; брокер стенда — Redis Streams. Пакет присутствует в бинарнике, но этот путь не используется конфигурацией |
|
||||
| `CVE-2026-31789` в OpenSSL | Advisory относится к 32-bit обработке X.509; измеренный стенд `linux/arm64`. Не экстраполируем это исключение на остальные CVE OpenSSL |
|
||||
| `CVE-2026-111497` (Brotli), `CVE-2026-48930` (Node.js) в UI images | Grafana/Swagger доступны только на loopback; приложение Go не использует эти пакеты. Достижимость уязвимых UI-путей не доказана; фиксированные upstream images нужны перед внешней публикацией |
|
||||
| `CVE-2025-68121` и остальные stdlib/OS findings сторонних images | Собственный API пересобран patched Go. Для сторонних бинарников пересборка не выполнялась; это остаточный риск, который не снимается одной сетевой изоляцией. Ограничиваем доступ и ресурсы, сохраняем raw findings для обновления images |
|
||||
| `UNKNOWN`, например `CVE-2026-39824` в Windows API | Severity не определена источником. Windows-only путь не выполняется в Linux; остальные UNKNOWN требуют отдельной проверки, а не считаются автоматически безопасными |
|
||||
|
||||
Данный scan triage подтверждает применимость конкретных ограничений учебного стенда. Он не заменяет обновление сторонних образов и не является разрешением на production deployment.
|
||||
|
||||
Замечания к отсутствию `HEALTHCHECK` внутри отдельных toolbox/bootstrap images не дают обхода runtime health: Compose задаёт healthchecks долговечным сервисам, а bootstrap containers одноразовые и должны завершиться с кодом 0. Это остаётся осознанным ограничением, а не исключением проверки приложения.
|
||||
|
||||
## Ограничения
|
||||
|
||||
- PKI локальная и не содержит CRL/OCSP. Отзыв leaf выполняется удалением доверия/сменой allowlist и пересозданием соединений.
|
||||
- PostgreSQL, Valkey, Redis, MinIO и OpenBao запущены по одному экземпляру; работа проверяет безопасность границ, а не HA этих хранилищ.
|
||||
- Operator init/unseal ручной. Это допустимо для учебного стенда, но production требует auto-unseal через KMS/HSM и раздельного хранения shares.
|
||||
- Static S3/DB/broker credentials выдаются через OpenBao KV и ротируются оператором. Dynamic database credentials были бы следующим улучшением.
|
||||
- Rate limiter хранится в Valkey и при его отказе блокирует login; уже выданные сессии также зависят от Valkey.
|
||||
|
||||
## Источники
|
||||
|
||||
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)
|
||||
- [OWASP File Upload Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html)
|
||||
- [OpenBao AppRole](https://openbao.org/docs/auth/approle/)
|
||||
- [OpenBao policies](https://openbao.org/docs/concepts/policies/)
|
||||
- [OpenBao production hardening](https://openbao.org/docs/internals/security/)
|
||||
- [PostgreSQL SSL support](https://www.postgresql.org/docs/current/libpq-ssl.html)
|
||||
- [Redis TLS](https://redis.io/docs/latest/operate/oss_and_stack/management/security/encryption/)
|
||||
- [Redis ACL](https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/)
|
||||
- [MinIO policy based access control](https://min.io/docs/minio/linux/administration/identity-access-management/policy-based-access-control.html)
|
||||
- [OpenTelemetry Collector security](https://opentelemetry.io/docs/security/config-best-practices/)
|
||||
- [Docker Engine security](https://docs.docker.com/engine/security/)
|
||||
- [Trivy filesystem scanning](https://trivy.dev/latest/docs/target/filesystem/)
|
||||
|
||||
OpenAI Codex использовался для подготовки и ревью реализации; результаты проверены тестами, CI-сценариями и воспроизводимыми отрицательными экспериментами.
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/outbox"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -133,7 +132,7 @@ func newExperiment(ctx context.Context) (*experiment, func(), error) {
|
||||
objects, err := objectstore.New(objectstore.Config{
|
||||
Endpoint: settings.S3Endpoint, Region: settings.S3Region, Bucket: settings.S3Bucket,
|
||||
AccessKey: settings.S3AccessKey, SecretKey: settings.S3SecretKey,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
@@ -144,15 +143,6 @@ func newExperiment(ctx context.Context) (*experiment, func(), error) {
|
||||
pool.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
brokerTLS, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: settings.BrokerTLS.CAPath, CertificatePath: settings.BrokerTLS.CertificatePath,
|
||||
PrivateKeyPath: settings.BrokerTLS.PrivateKeyPath, ServerName: settings.BrokerTLS.ServerName,
|
||||
})
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
redisOptions.TLSConfig = brokerTLS
|
||||
client := redis.NewClient(redisOptions)
|
||||
if err := client.Ping(ctx).Err(); err != nil {
|
||||
pool.Close()
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type result struct {
|
||||
status int
|
||||
retryAfter string
|
||||
instance string
|
||||
duration time.Duration
|
||||
err error
|
||||
}
|
||||
|
||||
type phase struct {
|
||||
Name string `json:"name"`
|
||||
Requests int `json:"requests"`
|
||||
Statuses map[int]int `json:"statuses"`
|
||||
DurationMS int64 `json:"duration_ms"`
|
||||
P95MS int64 `json:"p95_ms"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
var (
|
||||
baseURL = flag.String("base-url", "https://localhost:8443", "API endpoint")
|
||||
caFile = flag.String("ca-file", ".runtime/security/public-ca/ca.crt", "trusted public CA")
|
||||
count = flag.Int("requests", 20, "concurrent requests per phase")
|
||||
)
|
||||
flag.Parse()
|
||||
if *count < 8 || *count > 100 {
|
||||
return errors.New("requests must be between 8 and 100")
|
||||
}
|
||||
ca, err := os.ReadFile(*caFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roots := x509.NewCertPool()
|
||||
if !roots.AppendCertsFromPEM(ca) {
|
||||
return errors.New("invalid public CA")
|
||||
}
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS13, RootCAs: roots},
|
||||
DisableKeepAlives: true, MaxConnsPerHost: *count,
|
||||
}
|
||||
defer transport.CloseIdleConnections()
|
||||
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
|
||||
username := fmt.Sprintf("burst_%d", time.Now().UnixNano())
|
||||
body, err := json.Marshal(map[string]string{
|
||||
"username": username, "display_name": "Login burst", "password": "T3st-burst-password-123",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
register, err := burst(client, *count, "registration", func(index int) (*http.Request, error) {
|
||||
request, err := http.NewRequest(http.MethodPost, *baseURL+"/api/v1/users", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
login, err := burst(client, *count, "login", func(index int) (*http.Request, error) {
|
||||
request, err := http.NewRequest(http.MethodPost, *baseURL+"/api/v1/auth/sessions", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.SetBasicAuth(fmt.Sprintf("%s_%d", username, index), "wrong-password")
|
||||
return request, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err := client.Get(*baseURL + "/health/ready")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("readiness after burst: HTTP %d", response.StatusCode)
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(struct {
|
||||
Phases []phase `json:"phases"`
|
||||
Ready bool `json:"ready_after_burst"`
|
||||
}{[]phase{register, login}, true})
|
||||
}
|
||||
|
||||
func burst(client *http.Client, count int, name string, request func(int) (*http.Request, error)) (phase, error) {
|
||||
var (
|
||||
start = make(chan struct{})
|
||||
results = make(chan result, count)
|
||||
group sync.WaitGroup
|
||||
instances = make(map[string]struct{})
|
||||
statuses = make(map[int]int)
|
||||
durations = make([]time.Duration, 0, count)
|
||||
started = time.Now()
|
||||
)
|
||||
for index := range count {
|
||||
group.Add(1)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
<-start
|
||||
began := time.Now()
|
||||
value, err := request(index)
|
||||
if err != nil {
|
||||
results <- result{err: err}
|
||||
return
|
||||
}
|
||||
response, err := client.Do(value)
|
||||
if err != nil {
|
||||
results <- result{err: err}
|
||||
return
|
||||
}
|
||||
_, copyErr := io.Copy(io.Discard, response.Body)
|
||||
_ = response.Body.Close()
|
||||
results <- result{response.StatusCode, response.Header.Get("Retry-After"), response.Header.Get("X-Instance-Id"), time.Since(began), copyErr}
|
||||
}()
|
||||
}
|
||||
close(start)
|
||||
group.Wait()
|
||||
close(results)
|
||||
for value := range results {
|
||||
if value.err != nil {
|
||||
return phase{}, fmt.Errorf("%s burst: %w", name, value.err)
|
||||
}
|
||||
if value.status == http.StatusTooManyRequests {
|
||||
retryAfter, err := strconv.Atoi(value.retryAfter)
|
||||
if err != nil || retryAfter < 1 {
|
||||
return phase{}, errors.New("overload response has no positive Retry-After")
|
||||
}
|
||||
}
|
||||
allowed := value.status == http.StatusTooManyRequests
|
||||
if name == "registration" {
|
||||
allowed = allowed || value.status == http.StatusCreated || value.status == http.StatusConflict
|
||||
} else {
|
||||
allowed = allowed || value.status == http.StatusUnauthorized
|
||||
}
|
||||
if !allowed {
|
||||
return phase{}, fmt.Errorf("%s burst: unexpected HTTP %d", name, value.status)
|
||||
}
|
||||
statuses[value.status]++
|
||||
durations = append(durations, value.duration)
|
||||
if strings.TrimSpace(value.instance) != "" {
|
||||
instances[value.instance] = struct{}{}
|
||||
}
|
||||
}
|
||||
if statuses[http.StatusTooManyRequests] == 0 || len(instances) < 2 {
|
||||
return phase{}, fmt.Errorf("%s burst: expected overload across two replicas, statuses=%v instances=%d", name, statuses, len(instances))
|
||||
}
|
||||
sort.Slice(durations, func(i, j int) bool { return durations[i] < durations[j] })
|
||||
return phase{name, count, statuses, time.Since(started).Milliseconds(), durations[(count*95+99)/100-1].Milliseconds()}, nil
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/bootstrap"
|
||||
@@ -10,24 +11,24 @@ import (
|
||||
|
||||
func main() {
|
||||
appLogger := logger.New()
|
||||
if err := run(os.Args[1:]); err != nil {
|
||||
if err := run(appLogger, os.Args[1:]); err != nil {
|
||||
appLogger.Error("application stopped", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(arguments []string) error {
|
||||
func run(logger *slog.Logger, arguments []string) error {
|
||||
if len(arguments) == 0 {
|
||||
return bootstrap.RunServer()
|
||||
return bootstrap.RunServer(logger)
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "migrate" {
|
||||
return bootstrap.RunMigrations()
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "dispatch" {
|
||||
return bootstrap.RunDispatcher()
|
||||
return bootstrap.RunDispatcher(logger)
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "worker" {
|
||||
return bootstrap.RunWorker()
|
||||
return bootstrap.RunWorker(logger)
|
||||
}
|
||||
if arguments[0] == "reconcile-attachments" {
|
||||
return bootstrap.RunReconciliation(arguments[1:], os.Stdout)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/mtlsproxy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
config := mtlsproxy.Config{
|
||||
ListenAddress: required("PROXY_LISTEN_ADDRESS"), TargetAddress: required("PROXY_TARGET_ADDRESS"),
|
||||
CAPath: required("PROXY_TLS_CA_PATH"), CertificatePath: required("PROXY_TLS_CERTIFICATE_PATH"),
|
||||
PrivateKeyPath: required("PROXY_TLS_PRIVATE_KEY_PATH"), AllowedClientURI: required("PROXY_ALLOWED_CLIENT_URI"),
|
||||
ALPNProtocols: strings.Split(required("PROXY_ALPN_PROTOCOLS"), ","),
|
||||
DialTimeout: 5 * time.Second,
|
||||
}
|
||||
if config.ListenAddress == "" || config.TargetAddress == "" || config.CAPath == "" ||
|
||||
config.CertificatePath == "" || config.PrivateKeyPath == "" || config.AllowedClientURI == "" ||
|
||||
len(config.ALPNProtocols) == 0 || config.ALPNProtocols[0] == "" {
|
||||
return errors.New("mTLS proxy environment is incomplete")
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
return mtlsproxy.Run(ctx, config)
|
||||
}
|
||||
|
||||
func required(name string) string {
|
||||
return os.Getenv(name)
|
||||
}
|
||||
+80
-612
@@ -7,22 +7,8 @@ x-messenger-config-volume: &messenger-config-volume
|
||||
x-telemetry-environment: &telemetry-environment
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT}
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL: ${OTEL_EXPORTER_OTLP_PROTOCOL}
|
||||
OTEL_EXPORTER_OTLP_INSECURE: "false"
|
||||
OTEL_EXPORTER_OTLP_CERTIFICATE: /run/security/internal-ca/ca.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE: /run/security/client/tls.crt
|
||||
OTEL_EXPORTER_OTLP_CLIENT_KEY: /run/security/client/tls.key
|
||||
OTEL_EXPORTER_OTLP_SERVER_NAME: otel-gateway
|
||||
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=${DEPLOYMENT_ENVIRONMENT},service.version=${SERVICE_VERSION}
|
||||
|
||||
x-app-hardening: &app-hardening
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=64m
|
||||
|
||||
services:
|
||||
security-bootstrap:
|
||||
image: alpine:3.24.2
|
||||
@@ -34,58 +20,9 @@ services:
|
||||
- nginx_security:/target/nginx
|
||||
- prometheus_security:/target/prometheus
|
||||
- client_security:/target/client
|
||||
- postgres_security:/target/postgres
|
||||
- valkey_security:/target/valkey
|
||||
- redis_broker_security:/target/redis-broker
|
||||
- redis_gateway_security:/target/redis-gateway
|
||||
- minio_security:/target/minio
|
||||
- otel_gateway_security:/target/otel-gateway
|
||||
- dispatcher_security:/target/dispatcher
|
||||
- worker_security:/target/worker
|
||||
- migrate_security:/target/migrate
|
||||
- reconciler_security:/target/reconciler
|
||||
- postgres_bootstrap_security:/target/postgres-bootstrap
|
||||
- postgres_exporter_security:/target/postgres-exporter
|
||||
- valkey_exporter_security:/target/valkey-exporter
|
||||
- redis_exporter_security:/target/redis-exporter
|
||||
- s3_bootstrap_security:/target/s3-bootstrap
|
||||
- openbao_security:/target/openbao
|
||||
- openbao_agent_security:/target/openbao-agent
|
||||
- telemetry_gateway_security:/target/telemetry-gateway
|
||||
- collector_security:/target/collector
|
||||
- grafana_security:/target/grafana
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: "no"
|
||||
network_mode: none
|
||||
|
||||
acl-bootstrap:
|
||||
image: alpine:3.24.2
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
command:
|
||||
- |
|
||||
/bootstrap-acl.sh valkey /target/valkey/valkey/users.acl
|
||||
/bootstrap-acl.sh broker /target/redis/redis-broker/users.acl
|
||||
chown 999:999 /target/valkey/valkey/users.acl /target/redis/redis-broker/users.acl
|
||||
environment:
|
||||
VALKEY_API_PASSWORD: ${VALKEY_API_PASSWORD}
|
||||
VALKEY_EXPORTER_PASSWORD: ${VALKEY_EXPORTER_PASSWORD}
|
||||
VALKEY_HEALTH_PASSWORD: ${VALKEY_HEALTH_PASSWORD}
|
||||
REDIS_DISPATCHER_PASSWORD: ${REDIS_DISPATCHER_PASSWORD}
|
||||
REDIS_WORKER_PASSWORD: ${REDIS_WORKER_PASSWORD}
|
||||
REDIS_EXPORTER_PASSWORD: ${REDIS_EXPORTER_PASSWORD}
|
||||
REDIS_HEALTH_PASSWORD: ${REDIS_HEALTH_PASSWORD}
|
||||
volumes:
|
||||
- ./infra/redis/bootstrap-acl.sh:/bootstrap-acl.sh:ro
|
||||
- valkey_security:/target/valkey
|
||||
- redis_broker_security:/target/redis
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: "no"
|
||||
network_mode: none
|
||||
|
||||
postgres:
|
||||
image: postgres:17.6-alpine3.22
|
||||
@@ -93,12 +30,8 @@ services:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
command: ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- postgres_security:/run/security:ro
|
||||
- ./infra/postgres/postgresql.conf:/etc/postgresql/postgresql.conf:ro
|
||||
- ./infra/postgres/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
@@ -107,73 +40,50 @@ services:
|
||||
cpus: ${POSTGRES_CPUS}
|
||||
mem_limit: ${POSTGRES_MEMORY}
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
networks: [data]
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.4-alpine
|
||||
command: ["valkey-server", "/etc/valkey/valkey.conf"]
|
||||
command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec", "--requirepass", "${VALKEY_PASSWORD}"]
|
||||
environment:
|
||||
VALKEY_HEALTH_PASSWORD: ${VALKEY_HEALTH_PASSWORD}
|
||||
VALKEY_PASSWORD: ${VALKEY_PASSWORD}
|
||||
volumes:
|
||||
- valkey_data:/data
|
||||
- valkey_security:/run/security:ro
|
||||
- ./infra/redis/valkey.conf:/etc/valkey/valkey.conf:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "valkey-cli --no-auth-warning -s /tmp/valkey.sock --user valkey_health -a \"$$VALKEY_HEALTH_PASSWORD\" ping | grep -q PONG"]
|
||||
test: ["CMD-SHELL", "valkey-cli --no-auth-warning -a \"$$VALKEY_PASSWORD\" ping | grep -q PONG"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${VALKEY_CPUS}
|
||||
mem_limit: ${VALKEY_MEMORY}
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
acl-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
networks: [data_backend]
|
||||
networks: [data]
|
||||
|
||||
redis-broker:
|
||||
image: redis:8.2.2-alpine
|
||||
command: ["redis-server", "/etc/redis/redis.conf"]
|
||||
command:
|
||||
- redis-server
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --appendfsync
|
||||
- always
|
||||
- --maxmemory-policy
|
||||
- noeviction
|
||||
- --requirepass
|
||||
- ${REDIS_BROKER_PASSWORD}
|
||||
environment:
|
||||
REDIS_HEALTH_PASSWORD: ${REDIS_HEALTH_PASSWORD}
|
||||
REDIS_BROKER_PASSWORD: ${REDIS_BROKER_PASSWORD}
|
||||
volumes:
|
||||
- redis_broker_data:/data
|
||||
- redis_broker_security:/run/security:ro
|
||||
- ./infra/redis/redis-broker.conf:/etc/redis/redis.conf:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "redis-cli --no-auth-warning -s /tmp/redis.sock --user redis_health -a \"$$REDIS_HEALTH_PASSWORD\" ping | grep -q PONG"]
|
||||
test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$REDIS_BROKER_PASSWORD\" ping | grep -q PONG"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${REDIS_BROKER_CPUS}
|
||||
mem_limit: ${REDIS_BROKER_MEMORY}
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
acl-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
networks: [data_backend]
|
||||
|
||||
redis-gateway:
|
||||
image: envoyproxy/envoy:v1.35.2
|
||||
command: ["-c", "/etc/envoy/gateway.yaml", "--log-level", "warning"]
|
||||
volumes:
|
||||
- ./infra/redis/gateway.yaml:/etc/envoy/gateway.yaml:ro
|
||||
- redis_gateway_security:/run/security:ro
|
||||
expose: ["16379", "26379", "36379"]
|
||||
depends_on:
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
redis-broker:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
cpus: ${REDIS_GATEWAY_CPUS}
|
||||
mem_limit: ${REDIS_GATEWAY_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [data, data_backend, secure_clients]
|
||||
networks: [data]
|
||||
|
||||
s3:
|
||||
build:
|
||||
@@ -182,29 +92,24 @@ services:
|
||||
args:
|
||||
MINIO_VERSION: RELEASE.2025-10-15T17-29-55Z
|
||||
image: mtusi-minio:RELEASE.2025-10-15T17-29-55Z
|
||||
command: ["server", "/data", "--address", ":9000", "--certs-dir", "/run/security/minio"]
|
||||
command: ["server", "/data", "--address", ":9000"]
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
MINIO_BROWSER: "off"
|
||||
MINIO_PROMETHEUS_AUTH_TYPE: public
|
||||
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- minio_security:/run/security:ro
|
||||
expose:
|
||||
- "9000"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "https://s3:9000/minio/health/ready"]
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9000/minio/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${S3_CPUS}
|
||||
mem_limit: ${S3_MEMORY}
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
networks: [data]
|
||||
|
||||
s3-bootstrap:
|
||||
@@ -219,17 +124,8 @@ services:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_API_ACCESS_KEY: ${S3_API_ACCESS_KEY}
|
||||
S3_API_SECRET_KEY: ${S3_API_SECRET_KEY}
|
||||
S3_WORKER_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
|
||||
S3_WORKER_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
|
||||
S3_RECONCILER_ACCESS_KEY: ${S3_RECONCILER_ACCESS_KEY}
|
||||
S3_RECONCILER_SECRET_KEY: ${S3_RECONCILER_SECRET_KEY}
|
||||
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
|
||||
MC_CONFIG_DIR: /tmp/mc-bootstrap
|
||||
volumes:
|
||||
- s3_bootstrap_security:/run/security:ro
|
||||
- ./infra/minio/bootstrap.sh:/usr/local/bin/bootstrap.sh:ro
|
||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_SECRET_KEY}
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
@@ -240,42 +136,17 @@ services:
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
|
||||
postgres-roles:
|
||||
image: postgres:17.6-alpine3.22
|
||||
command: ["/bootstrap/bootstrap-roles.sh", "create"]
|
||||
environment: &postgres-role-environment
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_API_PASSWORD: ${POSTGRES_API_PASSWORD}
|
||||
POSTGRES_DISPATCHER_PASSWORD: ${POSTGRES_DISPATCHER_PASSWORD}
|
||||
POSTGRES_WORKER_PASSWORD: ${POSTGRES_WORKER_PASSWORD}
|
||||
POSTGRES_RECONCILER_PASSWORD: ${POSTGRES_RECONCILER_PASSWORD}
|
||||
POSTGRES_EXPORTER_PASSWORD: ${POSTGRES_EXPORTER_PASSWORD}
|
||||
POSTGRES_MIGRATE_PASSWORD: ${POSTGRES_MIGRATE_PASSWORD}
|
||||
volumes:
|
||||
- ./infra/postgres:/bootstrap:ro
|
||||
- postgres_bootstrap_security:/run/security:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
|
||||
migrate:
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/messenger", "migrate"]
|
||||
environment:
|
||||
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
|
||||
DATABASE_URL: ${DATABASE_MIGRATE_URL}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- migrate_security:/run/security:ro
|
||||
depends_on:
|
||||
postgres-roles:
|
||||
condition: service_completed_successfully
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
cpus: ${MIGRATE_CPUS}
|
||||
@@ -283,152 +154,7 @@ services:
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
|
||||
postgres-grants:
|
||||
image: postgres:17.6-alpine3.22
|
||||
command: ["/bootstrap/bootstrap-roles.sh", "grant"]
|
||||
environment: *postgres-role-environment
|
||||
volumes:
|
||||
- ./infra/postgres:/bootstrap:ro
|
||||
- postgres_bootstrap_security:/run/security:ro
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: "no"
|
||||
networks: [data]
|
||||
|
||||
openbao-permissions:
|
||||
image: alpine:3.24.2
|
||||
command: ["/bin/sh", "-c", "chown -R 100:100 /openbao/data && chown -R 10001:10001 /secrets/api /secrets/worker"]
|
||||
volumes:
|
||||
- openbao_data:/openbao/data
|
||||
- openbao_api_secrets:/secrets/api
|
||||
- openbao_worker_secrets:/secrets/worker
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: "no"
|
||||
network_mode: none
|
||||
|
||||
openbao:
|
||||
image: openbao/openbao:2.7.1
|
||||
command: ["server", "-config=/etc/openbao/config.hcl"]
|
||||
environment:
|
||||
BAO_ENABLE_FILE_PERMISSIONS_CHECK: "false"
|
||||
volumes:
|
||||
- ./infra/openbao/config.hcl:/etc/openbao/config.hcl:ro
|
||||
- openbao_data:/openbao/data
|
||||
- openbao_security:/run/security:ro
|
||||
ports:
|
||||
- "${OPENBAO_BIND_ADDRESS}:8200"
|
||||
depends_on:
|
||||
openbao-permissions:
|
||||
condition: service_completed_successfully
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop:
|
||||
- ALL
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=16m
|
||||
- /run/openbao:rw,noexec,nosuid,size=8m
|
||||
cpus: ${OPENBAO_CPUS}
|
||||
mem_limit: ${OPENBAO_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [secrets, edge]
|
||||
|
||||
openbao-cli:
|
||||
profiles: ["tools"]
|
||||
image: openbao/openbao:2.7.1
|
||||
user: "0:0"
|
||||
entrypoint: ["bao"]
|
||||
environment:
|
||||
BAO_ADDR: https://openbao:8200
|
||||
BAO_CACERT: /run/security/openbao/ca.crt
|
||||
BAO_TOKEN: ${BAO_TOKEN:-}
|
||||
volumes:
|
||||
- openbao_agent_security:/run/security:ro
|
||||
depends_on:
|
||||
- openbao
|
||||
networks: [secrets]
|
||||
|
||||
openbao-identity-install:
|
||||
profiles: ["tools"]
|
||||
image: alpine:3.24.2
|
||||
entrypoint: ["/bin/sh", "/install-identity.sh"]
|
||||
volumes:
|
||||
- ./infra/openbao/install-identity.sh:/install-identity.sh:ro
|
||||
- ./.runtime/openbao/approle:/source:ro
|
||||
- openbao_api_identity:/identities/api
|
||||
- openbao_worker_identity:/identities/worker
|
||||
network_mode: none
|
||||
restart: "no"
|
||||
|
||||
openbao-agent-api:
|
||||
image: openbao/openbao:2.7.1
|
||||
user: "10001:10001"
|
||||
command: ["agent", "-config=/etc/openbao-agent/agent.hcl"]
|
||||
volumes:
|
||||
- ./infra/openbao/agent/api.hcl:/etc/openbao-agent/agent.hcl:ro
|
||||
- ./infra/openbao/agent/api-secrets.ctmpl:/etc/openbao-agent/api-secrets.ctmpl:ro
|
||||
- openbao_api_identity:/run/openbao-identity:ro
|
||||
- openbao_api_secrets:/run/openbao-secrets
|
||||
- openbao_agent_security:/run/security:ro
|
||||
depends_on:
|
||||
openbao-permissions:
|
||||
condition: service_completed_successfully
|
||||
openbao:
|
||||
condition: service_started
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "test -s /run/openbao-secrets/secrets.json && BAO_ADDR=https://openbao:8200 BAO_CACERT=/run/security/openbao/ca.crt BAO_TOKEN=$$(cat /run/openbao-agent/token) bao token lookup >/dev/null 2>&1"]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 60
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop: ["ALL"]
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=8m
|
||||
- /run/openbao-agent:rw,noexec,nosuid,size=8m,uid=10001,gid=10001,mode=0700
|
||||
restart: unless-stopped
|
||||
networks: [secrets]
|
||||
|
||||
openbao-agent-worker:
|
||||
image: openbao/openbao:2.7.1
|
||||
user: "10001:10001"
|
||||
command: ["agent", "-config=/etc/openbao-agent/agent.hcl"]
|
||||
volumes:
|
||||
- ./infra/openbao/agent/worker.hcl:/etc/openbao-agent/agent.hcl:ro
|
||||
- ./infra/openbao/agent/worker-secrets.ctmpl:/etc/openbao-agent/worker-secrets.ctmpl:ro
|
||||
- openbao_worker_identity:/run/openbao-identity:ro
|
||||
- openbao_worker_secrets:/run/openbao-secrets
|
||||
- openbao_agent_security:/run/security:ro
|
||||
depends_on:
|
||||
openbao-permissions:
|
||||
condition: service_completed_successfully
|
||||
openbao:
|
||||
condition: service_started
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "test -s /run/openbao-secrets/secrets.json && BAO_ADDR=https://openbao:8200 BAO_CACERT=/run/security/openbao/ca.crt BAO_TOKEN=$$(cat /run/openbao-agent/token) bao token lookup >/dev/null 2>&1"]
|
||||
interval: 2s
|
||||
timeout: 1s
|
||||
retries: 60
|
||||
read_only: true
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cap_drop: ["ALL"]
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=8m
|
||||
- /run/openbao-agent:rw,noexec,nosuid,size=8m,uid=10001,gid=10001,mode=0700
|
||||
restart: unless-stopped
|
||||
networks: [secrets]
|
||||
|
||||
api:
|
||||
<<: *app-hardening
|
||||
build: .
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
environment:
|
||||
@@ -438,15 +164,17 @@ services:
|
||||
APP_HOST: ${APP_HOST}
|
||||
APP_PORT: ${APP_PORT}
|
||||
APP_HEALTH_ADDRESS: ${APP_HEALTH_ADDRESS}
|
||||
MESSENGER_SECRETS_FILE: /run/openbao-secrets/secrets.json
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
CACHE_URL: ${CACHE_URL}
|
||||
SWAGGER_PORT: ${SWAGGER_PORT}
|
||||
S3_ENDPOINT: https://${S3_ENDPOINT}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT}
|
||||
S3_REGION: ${S3_REGION}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_SECRET_KEY}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- api_security:/run/security:ro
|
||||
- openbao_api_secrets:/run/openbao-secrets:ro
|
||||
expose:
|
||||
- "8443"
|
||||
- "9091"
|
||||
@@ -455,14 +183,10 @@ services:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
postgres-grants:
|
||||
condition: service_completed_successfully
|
||||
redis-gateway:
|
||||
condition: service_started
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
s3-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
openbao-agent-api:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8082/health/ready || exit 1"]
|
||||
interval: 2s
|
||||
@@ -478,29 +202,25 @@ services:
|
||||
networks: [application, data, monitoring]
|
||||
|
||||
dispatcher:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/messenger", "dispatch"]
|
||||
environment:
|
||||
<<: *telemetry-environment
|
||||
OTEL_SERVICE_NAME: messenger-dispatcher
|
||||
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
|
||||
DATABASE_URL: ${DATABASE_DISPATCHER_URL}
|
||||
BROKER_URL: ${BROKER_DISPATCHER_URL}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
BROKER_URL: ${BROKER_URL}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- dispatcher_security:/run/security:ro
|
||||
expose:
|
||||
- "9091"
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
postgres-grants:
|
||||
condition: service_completed_successfully
|
||||
redis-gateway:
|
||||
condition: service_started
|
||||
redis-broker:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9092/health/live || exit 1"]
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9091/health/live || exit 1"]
|
||||
interval: 5s
|
||||
timeout: 2s
|
||||
retries: 20
|
||||
@@ -510,36 +230,32 @@ services:
|
||||
networks: [data, monitoring]
|
||||
|
||||
worker:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/messenger", "worker"]
|
||||
environment:
|
||||
<<: *telemetry-environment
|
||||
OTEL_SERVICE_NAME: messenger-worker
|
||||
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
|
||||
MESSENGER_SECRETS_FILE: /run/openbao-secrets/secrets.json
|
||||
S3_ENDPOINT: https://${S3_ENDPOINT}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT}
|
||||
S3_REGION: ${S3_REGION}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_SECRET_KEY}
|
||||
BROKER_URL: ${BROKER_URL}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- worker_security:/run/security:ro
|
||||
- openbao_worker_secrets:/run/openbao-secrets:ro
|
||||
expose:
|
||||
- "9091"
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
postgres-grants:
|
||||
condition: service_completed_successfully
|
||||
redis-gateway:
|
||||
condition: service_started
|
||||
redis-broker:
|
||||
condition: service_healthy
|
||||
s3-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
openbao-agent-worker:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9092/health/live || exit 1"]
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9091/health/live || exit 1"]
|
||||
interval: 5s
|
||||
timeout: 2s
|
||||
retries: 20
|
||||
@@ -549,31 +265,6 @@ services:
|
||||
restart: unless-stopped
|
||||
networks: [data, monitoring]
|
||||
|
||||
reconciler:
|
||||
profiles: ["maintenance"]
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/messenger", "reconcile-attachments", "--grace-period=1h", "--page-size=100"]
|
||||
environment:
|
||||
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
|
||||
DATABASE_URL: ${DATABASE_RECONCILER_URL}
|
||||
S3_ENDPOINT: https://${S3_ENDPOINT}
|
||||
S3_REGION: ${S3_REGION}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_ACCESS_KEY: ${S3_RECONCILER_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_RECONCILER_SECRET_KEY}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- reconciler_security:/run/security:ro
|
||||
depends_on:
|
||||
postgres-grants:
|
||||
condition: service_completed_successfully
|
||||
s3-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
healthcheck:
|
||||
disable: true
|
||||
networks: [data]
|
||||
|
||||
nginx:
|
||||
build:
|
||||
context: .
|
||||
@@ -616,39 +307,6 @@ services:
|
||||
condition: service_healthy
|
||||
networks: [edge, application]
|
||||
|
||||
dependency-tests:
|
||||
profiles: ["security"]
|
||||
image: mtusi-mc:RELEASE.2025-08-13T08-35-41Z
|
||||
user: "0:0"
|
||||
entrypoint: ["/bin/sh", "/test-dependency-matrix.sh"]
|
||||
environment:
|
||||
SECURITY_DIR: /run/security-source
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_API_PASSWORD: ${POSTGRES_API_PASSWORD}
|
||||
POSTGRES_WORKER_PASSWORD: ${POSTGRES_WORKER_PASSWORD}
|
||||
POSTGRES_DISPATCHER_PASSWORD: ${POSTGRES_DISPATCHER_PASSWORD}
|
||||
VALKEY_API_PASSWORD: ${VALKEY_API_PASSWORD}
|
||||
REDIS_DISPATCHER_PASSWORD: ${REDIS_DISPATCHER_PASSWORD}
|
||||
REDIS_WORKER_PASSWORD: ${REDIS_WORKER_PASSWORD}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_API_ACCESS_KEY: ${S3_API_ACCESS_KEY}
|
||||
S3_API_SECRET_KEY: ${S3_API_SECRET_KEY}
|
||||
S3_WORKER_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
|
||||
S3_WORKER_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
|
||||
volumes:
|
||||
- ./infra/security/test-dependency-matrix.sh:/test-dependency-matrix.sh:ro
|
||||
- ./.runtime/security:/run/security-source:ro
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
dispatcher:
|
||||
condition: service_healthy
|
||||
worker:
|
||||
condition: service_healthy
|
||||
otel-gateway:
|
||||
condition: service_started
|
||||
networks: [data, data_backend, secure_clients]
|
||||
|
||||
swagger:
|
||||
build:
|
||||
context: .
|
||||
@@ -670,20 +328,13 @@ services:
|
||||
context: .
|
||||
target: test
|
||||
environment:
|
||||
TEST_DATABASE_URL: postgres://messenger_migrate:${POSTGRES_MIGRATE_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=verify-full&sslrootcert=/run/database-security/internal-ca/ca.crt&sslcert=/run/database-security/client/tls.crt&sslkey=/run/database-security/client/tls.key
|
||||
TEST_DATABASE_URL: ${DATABASE_URL}
|
||||
TEST_CACHE_URL: ${CACHE_URL}
|
||||
TEST_CACHE_TLS_CA_PATH: /run/cache-security/internal-ca/ca.crt
|
||||
TEST_CACHE_TLS_CERTIFICATE_PATH: /run/cache-security/client/tls.crt
|
||||
TEST_CACHE_TLS_PRIVATE_KEY_PATH: /run/cache-security/client/tls.key
|
||||
TEST_CACHE_TLS_SERVER_NAME: redis-gateway
|
||||
volumes:
|
||||
- migrate_security:/run/database-security:ro
|
||||
- api_security:/run/cache-security:ro
|
||||
depends_on:
|
||||
postgres-grants:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
redis-gateway:
|
||||
condition: service_started
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
cpus: ${TEST_CPUS}
|
||||
mem_limit: ${TEST_MEMORY}
|
||||
networks: [data]
|
||||
@@ -694,16 +345,16 @@ services:
|
||||
command: ["/app/lab5experiment"]
|
||||
environment:
|
||||
MESSENGER_CONFIG_PATH: /etc/messenger/messenger.yaml
|
||||
DATABASE_URL: ${DATABASE_WORKER_URL}
|
||||
S3_ENDPOINT: https://${S3_ENDPOINT}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
S3_ENDPOINT: ${S3_ENDPOINT}
|
||||
S3_REGION: ${S3_REGION}
|
||||
S3_BUCKET: ${S3_BUCKET}
|
||||
S3_ACCESS_KEY: ${S3_WORKER_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_WORKER_SECRET_KEY}
|
||||
BROKER_URL: ${BROKER_WORKER_URL}
|
||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
|
||||
S3_SECRET_KEY: ${S3_SECRET_KEY}
|
||||
BROKER_URL: ${BROKER_URL}
|
||||
volumes:
|
||||
- *messenger-config-volume
|
||||
- worker_security:/run/security:ro
|
||||
- client_security:/run/security:ro
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
@@ -718,15 +369,16 @@ services:
|
||||
postgres-exporter:
|
||||
image: quay.io/prometheuscommunity/postgres-exporter:v0.20.1
|
||||
environment:
|
||||
DATA_SOURCE_NAME: postgres://messenger_exporter:${POSTGRES_EXPORTER_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATA_SOURCE_URI: postgres:5432/${POSTGRES_DB}?sslmode=disable
|
||||
DATA_SOURCE_USER: ${POSTGRES_USER}
|
||||
DATA_SOURCE_PASS: ${POSTGRES_PASSWORD}
|
||||
PG_EXPORTER_COLLECTION_TIMEOUT: 5s
|
||||
PG_EXPORTER_EXTEND_QUERY_PATH: /etc/postgres_exporter/queries.yml
|
||||
volumes:
|
||||
- ./monitoring/postgres-queries.yml:/etc/postgres_exporter/queries.yml:ro
|
||||
- postgres_exporter_security:/run/security:ro
|
||||
depends_on:
|
||||
postgres-grants:
|
||||
condition: service_completed_successfully
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
@@ -735,43 +387,31 @@ services:
|
||||
valkey-exporter:
|
||||
image: oliver006/redis_exporter:v1.89.0-alpine
|
||||
environment:
|
||||
REDIS_ADDR: rediss://valkey:6379
|
||||
REDIS_USER: valkey_exporter
|
||||
REDIS_PASSWORD: ${VALKEY_EXPORTER_PASSWORD}
|
||||
REDIS_EXPORTER_TLS_CLIENT_KEY_FILE: /run/security/client/tls.key
|
||||
REDIS_EXPORTER_TLS_CLIENT_CERT_FILE: /run/security/client/tls.crt
|
||||
REDIS_EXPORTER_TLS_CA_CERT_FILE: /run/security/internal-ca/ca.crt
|
||||
REDIS_EXPORTER_TLS_SERVER_NAME: valkey
|
||||
volumes:
|
||||
- valkey_exporter_security:/run/security:ro
|
||||
REDIS_ADDR: redis://valkey:6379
|
||||
REDIS_USER: default
|
||||
REDIS_PASSWORD: ${VALKEY_PASSWORD}
|
||||
depends_on:
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [data_backend, monitoring]
|
||||
networks: [data, monitoring]
|
||||
|
||||
redis-broker-exporter:
|
||||
image: oliver006/redis_exporter:v1.89.0-alpine
|
||||
environment:
|
||||
REDIS_ADDR: rediss://redis-broker:6379
|
||||
REDIS_USER: redis_exporter
|
||||
REDIS_PASSWORD: ${REDIS_EXPORTER_PASSWORD}
|
||||
REDIS_EXPORTER_TLS_CLIENT_KEY_FILE: /run/security/client/tls.key
|
||||
REDIS_EXPORTER_TLS_CLIENT_CERT_FILE: /run/security/client/tls.crt
|
||||
REDIS_EXPORTER_TLS_CA_CERT_FILE: /run/security/internal-ca/ca.crt
|
||||
REDIS_EXPORTER_TLS_SERVER_NAME: redis-broker
|
||||
REDIS_ADDR: redis://redis-broker:6379
|
||||
REDIS_USER: default
|
||||
REDIS_PASSWORD: ${REDIS_BROKER_PASSWORD}
|
||||
REDIS_EXPORTER_CHECK_SINGLE_STREAMS: attachment-jobs,attachment-jobs-failed
|
||||
volumes:
|
||||
- redis_exporter_security:/run/security:ro
|
||||
depends_on:
|
||||
redis-broker:
|
||||
condition: service_healthy
|
||||
cpus: ${EXPORTER_CPUS}
|
||||
mem_limit: ${EXPORTER_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [data_backend, monitoring]
|
||||
networks: [data, monitoring]
|
||||
|
||||
nginx-exporter:
|
||||
image: nginx/nginx-prometheus-exporter:1.5.1
|
||||
@@ -832,7 +472,7 @@ services:
|
||||
cpus: ${PROMETHEUS_CPUS}
|
||||
mem_limit: ${PROMETHEUS_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [application, data, monitoring, telemetry_storage]
|
||||
networks: [edge, application, data, monitoring]
|
||||
|
||||
grafana:
|
||||
build:
|
||||
@@ -844,32 +484,23 @@ services:
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD}
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_EXPLORE_ENABLED: "true"
|
||||
GF_SERVER_PROTOCOL: https
|
||||
GF_SERVER_CERT_FILE: /run/security/grafana-server.crt
|
||||
GF_SERVER_CERT_KEY: /run/security/grafana-server.key
|
||||
GF_SERVER_DOMAIN: localhost
|
||||
SSL_CERT_FILE: /run/security/internal-ca/ca.crt
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
- grafana_security:/run/security:ro
|
||||
ports:
|
||||
- "${GRAFANA_BIND_ADDRESS}:3000"
|
||||
depends_on:
|
||||
prometheus-grafana-gateway:
|
||||
condition: service_started
|
||||
loki-grafana-gateway:
|
||||
condition: service_started
|
||||
tempo-grafana-gateway:
|
||||
condition: service_started
|
||||
- prometheus
|
||||
- loki
|
||||
- tempo
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null https://localhost:3000/api/health || exit 1"]
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:3000/api/health || exit 1"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
cpus: ${GRAFANA_CPUS}
|
||||
mem_limit: ${GRAFANA_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [edge, secure_clients]
|
||||
networks: [edge, monitoring]
|
||||
|
||||
loki:
|
||||
image: grafana/loki:3.7.9
|
||||
@@ -877,6 +508,8 @@ services:
|
||||
volumes:
|
||||
- ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- loki_data:/loki
|
||||
ports:
|
||||
- "${LOKI_BIND_ADDRESS}:3100"
|
||||
healthcheck:
|
||||
test: ["CMD", "/usr/bin/loki", "-version"]
|
||||
interval: 10s
|
||||
@@ -885,7 +518,7 @@ services:
|
||||
cpus: ${LOKI_CPUS}
|
||||
mem_limit: ${LOKI_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [telemetry_storage]
|
||||
networks: [edge, monitoring]
|
||||
|
||||
tempo:
|
||||
image: grafana/tempo:2.10.10
|
||||
@@ -893,6 +526,8 @@ services:
|
||||
volumes:
|
||||
- ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||
- tempo_data:/var/tempo
|
||||
ports:
|
||||
- "${TEMPO_BIND_ADDRESS}:3200"
|
||||
healthcheck:
|
||||
test: ["CMD", "/tempo", "-version"]
|
||||
interval: 10s
|
||||
@@ -901,145 +536,13 @@ services:
|
||||
cpus: ${TEMPO_CPUS}
|
||||
mem_limit: ${TEMPO_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [telemetry_storage]
|
||||
|
||||
otel-gateway:
|
||||
image: envoyproxy/envoy:v1.35.2
|
||||
command: ["-c", "/etc/envoy/gateway.yaml", "--log-level", "warning"]
|
||||
volumes:
|
||||
- ./infra/otel/gateway.yaml:/etc/envoy/gateway.yaml:ro
|
||||
- otel_gateway_security:/run/security:ro
|
||||
expose: ["4317", "4318"]
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
otel-collector:
|
||||
condition: service_healthy
|
||||
cpus: ${OTEL_GATEWAY_CPUS}
|
||||
mem_limit: ${OTEL_GATEWAY_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [data, telemetry_backend]
|
||||
|
||||
tempo-collector-gateway:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/mtlsproxy"]
|
||||
environment:
|
||||
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
|
||||
PROXY_TARGET_ADDRESS: tempo:4317
|
||||
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
|
||||
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
|
||||
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
|
||||
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/collector
|
||||
PROXY_ALPN_PROTOCOLS: h2
|
||||
volumes:
|
||||
- telemetry_gateway_security:/run/security:ro
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
tempo:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
networks: [secure_clients, telemetry_storage]
|
||||
|
||||
loki-collector-gateway:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/mtlsproxy"]
|
||||
environment:
|
||||
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
|
||||
PROXY_TARGET_ADDRESS: loki:3100
|
||||
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
|
||||
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
|
||||
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
|
||||
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/collector
|
||||
PROXY_ALPN_PROTOCOLS: http/1.1
|
||||
volumes:
|
||||
- telemetry_gateway_security:/run/security:ro
|
||||
depends_on:
|
||||
security-bootstrap:
|
||||
condition: service_completed_successfully
|
||||
loki:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
networks: [secure_clients, telemetry_storage]
|
||||
|
||||
prometheus-grafana-gateway:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/mtlsproxy"]
|
||||
environment:
|
||||
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
|
||||
PROXY_TARGET_ADDRESS: prometheus:9090
|
||||
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
|
||||
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
|
||||
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
|
||||
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
|
||||
PROXY_ALPN_PROTOCOLS: http/1.1
|
||||
volumes:
|
||||
- telemetry_gateway_security:/run/security:ro
|
||||
depends_on:
|
||||
prometheus:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
networks: [secure_clients, telemetry_storage]
|
||||
|
||||
loki-grafana-gateway:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/mtlsproxy"]
|
||||
environment:
|
||||
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
|
||||
PROXY_TARGET_ADDRESS: loki:3100
|
||||
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
|
||||
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
|
||||
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
|
||||
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
|
||||
PROXY_ALPN_PROTOCOLS: http/1.1
|
||||
volumes:
|
||||
- telemetry_gateway_security:/run/security:ro
|
||||
depends_on:
|
||||
loki:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
networks: [secure_clients, telemetry_storage]
|
||||
|
||||
tempo-grafana-gateway:
|
||||
<<: *app-hardening
|
||||
image: ${API_IMAGE:-mtusi-messenger:lab7}
|
||||
command: ["/app/mtlsproxy"]
|
||||
environment:
|
||||
PROXY_LISTEN_ADDRESS: 0.0.0.0:8443
|
||||
PROXY_TARGET_ADDRESS: tempo:3200
|
||||
PROXY_TLS_CA_PATH: /run/security/internal-ca/ca.crt
|
||||
PROXY_TLS_CERTIFICATE_PATH: /run/security/telemetry-gateway/tls.crt
|
||||
PROXY_TLS_PRIVATE_KEY_PATH: /run/security/telemetry-gateway/tls.key
|
||||
PROXY_ALLOWED_CLIENT_URI: spiffe://mtusi/lab7/grafana
|
||||
PROXY_ALPN_PROTOCOLS: http/1.1
|
||||
volumes:
|
||||
- telemetry_gateway_security:/run/security:ro
|
||||
depends_on:
|
||||
tempo:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
disable: true
|
||||
restart: unless-stopped
|
||||
networks: [secure_clients, telemetry_storage]
|
||||
networks: [edge, monitoring]
|
||||
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:0.160.0
|
||||
command: ["--config=/etc/otelcol-contrib/collector.yaml"]
|
||||
volumes:
|
||||
- ./infra/otel/collector.yaml:/etc/otelcol-contrib/collector.yaml:ro
|
||||
- collector_security:/run/security:ro
|
||||
expose:
|
||||
- "4317"
|
||||
- "4318"
|
||||
@@ -1057,38 +560,13 @@ services:
|
||||
cpus: ${OTEL_COLLECTOR_CPUS}
|
||||
mem_limit: ${OTEL_COLLECTOR_MEMORY}
|
||||
restart: unless-stopped
|
||||
networks: [telemetry_backend, secure_clients, monitoring]
|
||||
networks: [application, data, monitoring]
|
||||
|
||||
volumes:
|
||||
api_security:
|
||||
nginx_security:
|
||||
prometheus_security:
|
||||
client_security:
|
||||
postgres_security:
|
||||
valkey_security:
|
||||
redis_broker_security:
|
||||
redis_gateway_security:
|
||||
minio_security:
|
||||
otel_gateway_security:
|
||||
dispatcher_security:
|
||||
worker_security:
|
||||
migrate_security:
|
||||
reconciler_security:
|
||||
postgres_bootstrap_security:
|
||||
postgres_exporter_security:
|
||||
valkey_exporter_security:
|
||||
redis_exporter_security:
|
||||
s3_bootstrap_security:
|
||||
openbao_security:
|
||||
openbao_agent_security:
|
||||
telemetry_gateway_security:
|
||||
collector_security:
|
||||
grafana_security:
|
||||
openbao_api_secrets:
|
||||
openbao_worker_secrets:
|
||||
openbao_api_identity:
|
||||
openbao_worker_identity:
|
||||
openbao_data:
|
||||
postgres_data:
|
||||
valkey_data:
|
||||
redis_broker_data:
|
||||
@@ -1104,15 +582,5 @@ networks:
|
||||
internal: true
|
||||
data:
|
||||
internal: true
|
||||
data_backend:
|
||||
internal: true
|
||||
monitoring:
|
||||
internal: true
|
||||
telemetry_backend:
|
||||
internal: true
|
||||
telemetry_storage:
|
||||
internal: true
|
||||
secure_clients:
|
||||
internal: true
|
||||
secrets:
|
||||
internal: true
|
||||
|
||||
+1
-25
@@ -12,10 +12,6 @@ server:
|
||||
session_store: valkey
|
||||
session_ttl: 1h
|
||||
idempotency_ttl: 24h
|
||||
login_rate_limit:
|
||||
account_attempts: 5
|
||||
source_attempts: 20
|
||||
window: 1m
|
||||
request_timeout: 5s
|
||||
http:
|
||||
read_header_timeout: 5s
|
||||
@@ -29,7 +25,6 @@ server:
|
||||
parallelism: 2
|
||||
salt_length: 16
|
||||
key_length: 32
|
||||
max_concurrent_operations: 2
|
||||
|
||||
database:
|
||||
min_connections: 1
|
||||
@@ -39,19 +34,11 @@ database:
|
||||
health_check_period: 30s
|
||||
dependency_timeout: 5s
|
||||
|
||||
cache:
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/client/tls.crt
|
||||
private_key_path: /run/security/client/tls.key
|
||||
server_name: redis-gateway
|
||||
|
||||
migration:
|
||||
timeout: 30s
|
||||
|
||||
object_storage:
|
||||
use_tls: true
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
use_tls: false
|
||||
timeout: 5s
|
||||
|
||||
attachments:
|
||||
@@ -64,11 +51,6 @@ pipeline:
|
||||
version: 1
|
||||
|
||||
broker:
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/client/tls.crt
|
||||
private_key_path: /run/security/client/tls.key
|
||||
server_name: redis-gateway
|
||||
stream: attachment-jobs
|
||||
consumer_group: attachment-workers
|
||||
failed_stream: attachment-jobs-failed
|
||||
@@ -100,9 +82,3 @@ worker:
|
||||
|
||||
monitoring:
|
||||
metrics_address: 0.0.0.0:9091
|
||||
health_address: 127.0.0.1:9092
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/metrics/tls.crt
|
||||
private_key_path: /run/security/metrics/tls.key
|
||||
allowed_client_uri: spiffe://mtusi/lab7/prometheus
|
||||
|
||||
+34
-24
@@ -1,27 +1,37 @@
|
||||
# Матрица доверия
|
||||
# Матрица доверия — заполнить в решении lab7
|
||||
|
||||
| Связь | Порт и протокол | Server trust и client identity | Минимальные права / lifecycle | Доказательство |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Клиент → Nginx | `8443`, TLS 1.3 | Public CA, SAN `localhost`; Bearer session | Сессия хранится как hash с TTL; общий login limiter | `make test-security`; `make test`; `make test-login-rate-limit` |
|
||||
| Nginx → API replicas | `8443`, mTLS | Internal CA; server SAN `api`; client URI `spiffe://mtusi/lab7/load-balancer` | Leaf выпускается bootstrap и меняется без rebuild | `make test-tls-matrix`: allow LB, deny no-cert/foreign/forbidden |
|
||||
| Prometheus → API metrics | `9091`, mTLS | Internal CA; URI `spiffe://mtusi/lab7/prometheus` | Только `/metrics`; business route отсутствует | `make test-tls-matrix` |
|
||||
| API/worker/dispatcher/reconciler → PostgreSQL | `5432`, TLS 1.3 `verify-full` + client cert | SAN `postgres`; отдельные API, worker, dispatcher, reconciler certs | Разные DB roles/grants; migrator отдельный one-shot | `infra/security/test-dependency-matrix.sh` |
|
||||
| API → Valkey | gateway `16379`, mTLS; backend TLS | SAN `redis-gateway`; API URI SAN; Valkey ACL user `messenger_api` | Только session/rate-limit prefixes; password приходит из OpenBao | dependency matrix: разрешён session key, запрещён arbitrary key |
|
||||
| Dispatcher → Redis Streams | gateway `26379`, mTLS; backend TLS | Dispatcher URI SAN | Producer ACL без consume | dependency matrix: `XADD` разрешён, `XREAD` запрещён |
|
||||
| Worker → Redis Streams | gateway `36379`, mTLS; backend TLS | Worker URI SAN | Consumer/ack ACL, unrelated stream запрещён; credential ротируется | dependency matrix и `make test-worker-compromise` |
|
||||
| API/worker/reconciler → MinIO | `9000`, HTTPS | Internal CA, SAN `s3` | API: staging; worker: staging+attachments; reconciler: cleanup; разные keys | dependency matrix проверяет разрешённые и запрещённые prefixes |
|
||||
| API/worker/dispatcher/reconciler → OTel gateway | `4317/4318`, mTLS | Internal CA; exact allowlist service URI SAN | Только telemetry ingest | dependency matrix отклоняет same-CA Prometheus identity |
|
||||
| OTel Collector → Loki/Tempo/Prometheus | локальный TLS gateway → backend network | Collector identity и Internal CA | Backend ports не опубликованы; plaintext hop только внутри выделенной `telemetry_storage` network | `infra/otel/collector.yaml`, Prometheus targets, TLS matrix |
|
||||
| Grafana → Prometheus/Loki/Tempo | отдельные HTTPS gateways | Grafana client certificate, Internal CA, exact URI SAN | Read-only datasource access; UI опубликован только на `127.0.0.1:3000` по HTTPS | provisioned datasource health API и gateway config |
|
||||
| OpenBao Agent API/worker → OpenBao | `8200`, TLS 1.3 | OpenBao SAN; AppRole RoleID+SecretID с TTL 1 час | Раздельные KV policies; renewable token; rendered file `0600` в защищённом volume, Agent token в tmpfs | `scripts/openbao-test-policy.sh`, `scripts/openbao-rotate.sh` |
|
||||
| Оператор → OpenBao | `127.0.0.1:8200`, TLS 1.3 | CA; root token только в operator runtime file | Init/unseal/bootstrap/rotation; Raft volume persistent | `scripts/bootstrap-local.sh`, `infra/openbao/README.md` |
|
||||
| Оператор → Grafana | `127.0.0.1:3000`, HTTPS | Internal CA, login/password | Административный UI не слушает внешний интерфейс | `docker compose port grafana 3000` и HTTPS health |
|
||||
| Replication/cluster channels | N/A | PostgreSQL, Valkey, Redis, MinIO и OpenBao запущены по одному экземпляру | Репликация не заявлена; отказ зависимости обнаруживается readiness | Документированное ограничение стенда |
|
||||
Это обязательная матрица покрытия. Для каждой строки укажите реальный порт, endpoint, CA, service identity, проверку SAN/ACL, срок жизни credentials и команду положительного/отрицательного теста. TLS шифрует и подтверждает сервер; mTLS также проверяет клиента. При доверенном CA всё равно нужно ограничивать разрешённую identity. Plaintext hop допустим только внутри закрытого локального transport/proxy boundary, без опубликованного обхода; границу и rationale нужно доказать.
|
||||
|
||||
## Каналы bootstrap, health и scrape
|
||||
| Связь | Минимум на 3 | Дополнительно на 4 | Доказательство / конфиг |
|
||||
| --- | --- | --- | --- |
|
||||
| Клиент → ingress/LB | TLS, CA + hostname, Bearer | Проверка expiry/revocation сессии и общего login rate limit | TODO |
|
||||
| LB → API (все реплики) | mTLS + allowlist LB identity | Ротация leaf без обхода проверки | TODO |
|
||||
| API/worker → PostgreSQL | TLS verify-full + раздельные ограниченные DB roles | Ротация credentials; mTLS — допустимое усиление | TODO |
|
||||
| API/worker → S3 | TLS + разные scoped credentials/prefix rights | Проверка denied prefix и ротация | TODO |
|
||||
| API/worker → broker | TLS + разные producer/consumer identities и ACL | mTLS + ограничение допустимых SAN/ролей | TODO |
|
||||
| API/worker → Collector | TLS; сеть/аутентификация запрещает произвольный ingest | mTLS с раздельными identities | TODO |
|
||||
| Collector → telemetry backends | TLS + scoped backend credentials или mTLS | Ротация и проверка least privilege | TODO |
|
||||
| Grafana → data sources | TLS с проверкой сервера, ограниченная identity | Отрицательные проверки доступа | TODO |
|
||||
| API/worker/agent → OpenBao | TLS + сервисный auth + scoped policy | Renewal/expiry/revocation | TODO |
|
||||
| Оператор → OpenBao/Grafana/S3 admin | TLS + authentication, доступ локальный/через защищённый канал | Разделение operator/application roles | TODO |
|
||||
| API → Redis/Valkey, если используется | TLS + ACL/пароль с минимальными правами | Ротация; mTLS по возможности | TODO |
|
||||
| Replication/кластерные каналы, если добавлены | TLS/mTLS либо подтверждённый шифрованный transport | Проверка заявленной модели отказа | TODO |
|
||||
|
||||
- `127.0.0.1:8082` существует только внутри каждого app container и используется Docker healthcheck; business router на нём отсутствует.
|
||||
- Публичный `/health/ready` проходит через ingress TLS, но не раскрывает credentials или содержимое зависимостей.
|
||||
- Metrics listener требует Prometheus URI SAN; сертификат LB и сертификаты приложений отклоняются.
|
||||
- Bootstrap jobs подключены только к нужным внутренним сетям, не публикуют порты и завершаются после установки ACL/roles/secrets.
|
||||
- Private keys, root token, unseal shares, RoleID/SecretID и rendered secrets хранятся в `.runtime`/Docker volumes и отсутствуют в Git.
|
||||
Нет выбранного компонента — отметьте N/A с причиной, а не оставляйте пустую строку. Внутренний публичный health listener, если нужен, минимален и изолирован; через него нельзя обращаться к бизнес-API без mTLS. Отдельно задокументируйте scrape/health/bootstrap каналы: они тоже не должны создавать обход.
|
||||
|
||||
## Обязательные отрицательные проверки
|
||||
|
||||
1. HTTPS с правильным CA/hostname проходит; с пустым/чужим CA и неправильным hostname — ошибка верификации, не «сервер недоступен».
|
||||
2. LB→API: без client cert, с cert чужого CA, с запрещённой identity от доверенного CA — отказ; с разрешённой LB identity — успех.
|
||||
3. На 4 повторите набор для broker и Collector; ограничение на network policy не заменяет проверку identity.
|
||||
4. Пользователь вне чата не читает metadata/content и не прикрепляет чужой файл; поддельный X-User-Id не меняет Bearer identity.
|
||||
5. OpenBao app policy читает только свой secret/path; запись policy и чтение чужого path запрещены. Worker не получает admin credentials API/БД/S3.
|
||||
6. На 4 отзовите secret/cert и дождитесь контролируемого эффекта с учётом действующих соединений, TLS resumption и cache/TTL. Покажите новое подключение, иначе тест отзыва может ничего не проверить.
|
||||
|
||||
## Bootstrap и эксплуатация
|
||||
|
||||
В репозитории только открытые конфиги, policy templates и scripts. CA private key, leaf keys, root token, unseal shares и SecretID не коммитятся, не запекаются в образ и не печатаются в отчёте. Для локального стенда оператор создаёт их вне Git и передаёт через files/secrets с ограниченными правами. Опишите, кто имеет доступ к CA/unseal, что нужно после рестарта OpenBao и как восстановить работу.
|
||||
|
||||
OpenBao не использует dev-mode. Выберите persistent storage и auth метод (например AppRole с короткоживущим SecretID/response wrapping, cert auth или иная обоснованная identity). Не подменяйте root token постоянной переменной BAO_TOKEN в приложении. Рабочие tokens имеют policy, TTL и renewal/re-auth сценарий. Статические KV secrets на 3 допустимы при реальном чтении через сервисную identity; динамические DB credentials — хорошее расширение, но не обязательное название технологии.
|
||||
|
||||
Разрешённый компромисс учебного стенда: ручной operator init/unseal, если он безопасно документирован и не нужен при каждом обычном рестарте API. Автоматическое хранение всех unseal shares рядом с OpenBao без защиты не считается решённым bootstrap.
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"environment": {
|
||||
"os": "linux",
|
||||
"architecture": "arm64",
|
||||
"cpu_limit": 2,
|
||||
"memory_limit_mib": 512,
|
||||
"go_version": "1.26.5"
|
||||
},
|
||||
"parameters": {
|
||||
"memory_kib": 65536,
|
||||
"iterations": 3,
|
||||
"parallelism": 2,
|
||||
"salt_length": 16,
|
||||
"key_length": 32
|
||||
},
|
||||
"method": "go test benchmark, 5 iterations per operation",
|
||||
"hash": {
|
||||
"nanoseconds_per_operation": 60029195,
|
||||
"bytes_per_operation": 67114704,
|
||||
"allocations_per_operation": 59
|
||||
},
|
||||
"verify": {
|
||||
"nanoseconds_per_operation": 64816424,
|
||||
"bytes_per_operation": 67113590,
|
||||
"allocations_per_operation": 53
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"generated_at": "2026-11-06T18:18:28.005396+00:00",
|
||||
"scope": "local runtime checks on the lab7 Compose stack; remote CI is separate",
|
||||
"public_https_smoke": "PASS",
|
||||
"public_and_api_mtls_matrix_cases": 13,
|
||||
"dependency_mtls_and_acl_matrix": "PASS",
|
||||
"openbao_policy_allow_deny_and_renewal": "PASS",
|
||||
"openbao_expiry_revoke_seal_and_reauth": "PASS",
|
||||
"leaf_rotation_old_identity_and_expired_leaf_denied": "PASS",
|
||||
"shared_login_rate_limit_across_two_replicas": "PASS",
|
||||
"postgres_and_valkey_integration": "PASS",
|
||||
"go_tests_and_vet": "PASS",
|
||||
"grafana_datasource_health": {
|
||||
"prometheus": "OK",
|
||||
"loki": "OK",
|
||||
"tempo": "OK"
|
||||
}
|
||||
}
|
||||
@@ -1,331 +0,0 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"scanner": "Trivy 0.76.2",
|
||||
"generated_at": "2026-11-06T18:17:33+00:00",
|
||||
"scope": "repository filesystem: vulnerabilities, misconfigurations, secrets",
|
||||
"vulnerabilities": {
|
||||
"UNKNOWN": 3
|
||||
},
|
||||
"misconfigurations": {
|
||||
"LOW": 2
|
||||
},
|
||||
"secret_findings": 0,
|
||||
"scanned_images": [
|
||||
"envoyproxy/envoy:v1.35.2",
|
||||
"grafana/loki:3.7.9",
|
||||
"grafana/tempo:2.10.10",
|
||||
"mtusi-grafana:lab7",
|
||||
"mtusi-messenger:lab7",
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z",
|
||||
"mtusi-nginx:lab7",
|
||||
"mtusi-prometheus:lab7",
|
||||
"mtusi-swagger:lab7",
|
||||
"nginx/nginx-prometheus-exporter:1.5.1",
|
||||
"oliver006/redis_exporter:v1.89.0-alpine",
|
||||
"openbao/openbao:2.7.1",
|
||||
"otel/opentelemetry-collector-contrib:0.160.0",
|
||||
"postgres:17.6-alpine3.22",
|
||||
"quay.io/prometheuscommunity/postgres-exporter:v0.20.1",
|
||||
"redis:8.2.2-alpine",
|
||||
"valkey/valkey:8.1.4-alpine"
|
||||
],
|
||||
"image_vulnerabilities": {
|
||||
"CRITICAL": 26,
|
||||
"HIGH": 479,
|
||||
"LOW": 508,
|
||||
"MEDIUM": 795,
|
||||
"UNKNOWN": 92
|
||||
},
|
||||
"image_secret_findings": 0,
|
||||
"findings": [
|
||||
{
|
||||
"id": "CVE-2026-111497",
|
||||
"package": "brotli-libs",
|
||||
"installed_version": "1.2.0-r1",
|
||||
"fixed_version": "1.2.1-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "brotli: Out-of-Bounds Write in Google Brotli Decoder",
|
||||
"scopes": [
|
||||
"mtusi-grafana:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-111497",
|
||||
"package": "brotli-libs",
|
||||
"installed_version": "1.2.0-r0",
|
||||
"fixed_version": "1.2.1-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "brotli: Out-of-Bounds Write in Google Brotli Decoder",
|
||||
"scopes": [
|
||||
"mtusi-swagger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-33322",
|
||||
"package": "github.com/minio/minio",
|
||||
"installed_version": "v0.0.0-20251015172955-9e49d5e7a648",
|
||||
"fixed_version": "",
|
||||
"severity": "CRITICAL",
|
||||
"title": "MinIO has JWT Algorithm Confusion in OIDC Authentication",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-33419",
|
||||
"package": "github.com/minio/minio",
|
||||
"installed_version": "v0.0.0-20251015172955-9e49d5e7a648",
|
||||
"fixed_version": "",
|
||||
"severity": "CRITICAL",
|
||||
"title": "MinIO LDAP login brute-force via user enumeration and missing rate limit",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77405",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.10.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Missing Explicit TLS Minimum Version Configuration In URI Parser",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77405",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.12.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Missing Explicit TLS Minimum Version Configuration In URI Parser",
|
||||
"scopes": [
|
||||
"otel/opentelemetry-collector-contrib:0.160.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77408",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.10.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Silent Data Truncation and State Corruption via Shortstr Integer Overflow",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77408",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.12.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Silent Data Truncation and State Corruption via Shortstr Integer Overflow",
|
||||
"scopes": [
|
||||
"otel/opentelemetry-collector-contrib:0.160.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77411",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.10.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Protocol Desynchronization and Frame Injection via Integer Overflow in readLongstr",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-77411",
|
||||
"package": "github.com/rabbitmq/amqp091-go",
|
||||
"installed_version": "v1.12.0",
|
||||
"fixed_version": "1.13.0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "github.com/rabbitmq/amqp091-go: RabbitMQ amqp091-go: Protocol Desynchronization and Frame Injection via Integer Overflow in readLongstr",
|
||||
"scopes": [
|
||||
"otel/opentelemetry-collector-contrib:0.160.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "GO-2026-5932",
|
||||
"package": "golang.org/x/crypto",
|
||||
"installed_version": "v0.57.0",
|
||||
"fixed_version": "0.58.1-0.20261009181718-2f1f834330b2",
|
||||
"severity": "UNKNOWN",
|
||||
"title": "The golang.org/x/crypto/openpgp package is unmaintained, unsafe by design, and has known security issues",
|
||||
"scopes": [
|
||||
"repository",
|
||||
"grafana/tempo:2.10.10",
|
||||
"mtusi-grafana:lab7",
|
||||
"mtusi-messenger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-78661",
|
||||
"package": "golang.org/x/net",
|
||||
"installed_version": "v0.60.0",
|
||||
"fixed_version": "0.62.0",
|
||||
"severity": "UNKNOWN",
|
||||
"title": "When coalescing adjacent text nodes in addText and fosterParent, appen ...",
|
||||
"scopes": [
|
||||
"repository",
|
||||
"grafana/tempo:2.10.10",
|
||||
"mtusi-grafana:lab7",
|
||||
"mtusi-messenger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-97045",
|
||||
"package": "golang.org/x/net",
|
||||
"installed_version": "v0.60.0",
|
||||
"fixed_version": "0.62.0",
|
||||
"severity": "UNKNOWN",
|
||||
"title": "In childTextNodesAreLiteral, walking up the tree previously stopped at ...",
|
||||
"scopes": [
|
||||
"repository",
|
||||
"grafana/tempo:2.10.10",
|
||||
"mtusi-grafana:lab7",
|
||||
"mtusi-messenger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-33186",
|
||||
"package": "google.golang.org/grpc",
|
||||
"installed_version": "v1.72.0",
|
||||
"fixed_version": "1.79.3",
|
||||
"severity": "CRITICAL",
|
||||
"title": "google.golang.org/grpc/grpc-go: google.golang.org/grpc/authz: gRPC-Go: Authorization bypass due to improper HTTP/2 path validation",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-31789",
|
||||
"package": "libcrypto3",
|
||||
"installed_version": "3.5.4-r0",
|
||||
"fixed_version": "3.5.6-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "openssl: OpenSSL: Heap buffer overflow on 32-bit systems from large X.509 certificate processing",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z",
|
||||
"postgres:17.6-alpine3.22",
|
||||
"redis:8.2.2-alpine",
|
||||
"valkey/valkey:8.1.4-alpine"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-31789",
|
||||
"package": "libcrypto3",
|
||||
"installed_version": "3.5.5-r0",
|
||||
"fixed_version": "3.5.6-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "openssl: OpenSSL: Heap buffer overflow on 32-bit systems from large X.509 certificate processing",
|
||||
"scopes": [
|
||||
"mtusi-swagger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-31789",
|
||||
"package": "libssl3",
|
||||
"installed_version": "3.5.4-r0",
|
||||
"fixed_version": "3.5.6-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "openssl: OpenSSL: Heap buffer overflow on 32-bit systems from large X.509 certificate processing",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z",
|
||||
"postgres:17.6-alpine3.22",
|
||||
"redis:8.2.2-alpine",
|
||||
"valkey/valkey:8.1.4-alpine"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-31789",
|
||||
"package": "libssl3",
|
||||
"installed_version": "3.5.5-r0",
|
||||
"fixed_version": "3.5.6-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "openssl: OpenSSL: Heap buffer overflow on 32-bit systems from large X.509 certificate processing",
|
||||
"scopes": [
|
||||
"mtusi-swagger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-48930",
|
||||
"package": "nodejs",
|
||||
"installed_version": "24.13.0-r1",
|
||||
"fixed_version": "24.17.0-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "nodejs: Node.js: Silent authority rebinding due to embedded-nul hostnames in TLS handling",
|
||||
"scopes": [
|
||||
"mtusi-swagger:lab7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2026-31789",
|
||||
"package": "openssl",
|
||||
"installed_version": "3.5.4-r0",
|
||||
"fixed_version": "3.5.6-r0",
|
||||
"severity": "CRITICAL",
|
||||
"title": "openssl: OpenSSL: Heap buffer overflow on 32-bit systems from large X.509 certificate processing",
|
||||
"scopes": [
|
||||
"valkey/valkey:8.1.4-alpine"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2025-68121",
|
||||
"package": "stdlib",
|
||||
"installed_version": "v1.24.8",
|
||||
"fixed_version": "1.24.13, 1.25.7, 1.26.0-rc.3",
|
||||
"severity": "CRITICAL",
|
||||
"title": "crypto/tls: crypto/tls: Incorrect certificate validation during TLS session resumption",
|
||||
"scopes": [
|
||||
"mtusi-minio:RELEASE.2025-10-15T17-29-55Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2025-68121",
|
||||
"package": "stdlib",
|
||||
"installed_version": "v1.25.3",
|
||||
"fixed_version": "1.24.13, 1.25.7, 1.26.0-rc.3",
|
||||
"severity": "CRITICAL",
|
||||
"title": "crypto/tls: crypto/tls: Incorrect certificate validation during TLS session resumption",
|
||||
"scopes": [
|
||||
"nginx/nginx-prometheus-exporter:1.5.1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "CVE-2025-68121",
|
||||
"package": "stdlib",
|
||||
"installed_version": "v1.24.6",
|
||||
"fixed_version": "1.24.13, 1.25.7, 1.26.0-rc.3",
|
||||
"severity": "CRITICAL",
|
||||
"title": "crypto/tls: crypto/tls: Incorrect certificate validation during TLS session resumption",
|
||||
"scopes": [
|
||||
"postgres:17.6-alpine3.22"
|
||||
]
|
||||
}
|
||||
],
|
||||
"findings_scope": "all repository findings and critical image findings; full findings in raw reports",
|
||||
"raw_report": "evidence/runtime/security-scan/trivy-fs.json",
|
||||
"image_raw_reports": [
|
||||
"evidence/runtime/security-scan/trivy-image-1.json",
|
||||
"evidence/runtime/security-scan/trivy-image-2.json",
|
||||
"evidence/runtime/security-scan/trivy-image-3.json",
|
||||
"evidence/runtime/security-scan/trivy-image-4.json",
|
||||
"evidence/runtime/security-scan/trivy-image-5.json",
|
||||
"evidence/runtime/security-scan/trivy-image-6.json",
|
||||
"evidence/runtime/security-scan/trivy-image-7.json",
|
||||
"evidence/runtime/security-scan/trivy-image-8.json",
|
||||
"evidence/runtime/security-scan/trivy-image-9.json",
|
||||
"evidence/runtime/security-scan/trivy-image-10.json",
|
||||
"evidence/runtime/security-scan/trivy-image-11.json",
|
||||
"evidence/runtime/security-scan/trivy-image-12.json",
|
||||
"evidence/runtime/security-scan/trivy-image-13.json",
|
||||
"evidence/runtime/security-scan/trivy-image-14.json",
|
||||
"evidence/runtime/security-scan/trivy-image-15.json",
|
||||
"evidence/runtime/security-scan/trivy-image-16.json",
|
||||
"evidence/runtime/security-scan/trivy-image-17.json"
|
||||
]
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"scenario": "worker credential compromise and rotation",
|
||||
"generated_at": "2026-11-06T18:08:45+00:00",
|
||||
"recovery_seconds": 21,
|
||||
"old_credential_rejected": true,
|
||||
"old_database_credential_rejected": true,
|
||||
"old_s3_credential_rejected": true,
|
||||
"openbao_secret_rotated": true,
|
||||
"queued_attachment_preserved": true,
|
||||
"result": "PASS"
|
||||
}
|
||||
@@ -2,8 +2,6 @@ module gitea.privcloud.tech/dizi/mtusi2026lab7
|
||||
|
||||
go 1.26.0
|
||||
|
||||
toolchain go1.26.10
|
||||
|
||||
require (
|
||||
github.com/deepteams/webp v1.2.8
|
||||
github.com/google/uuid v1.6.0
|
||||
@@ -14,21 +12,20 @@ require (
|
||||
github.com/spf13/viper v1.21.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/valkey-io/valkey-go v1.0.78
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.20.0
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0
|
||||
go.opentelemetry.io/otel v1.45.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.45.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0
|
||||
go.opentelemetry.io/otel v1.38.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.60.0
|
||||
go.opentelemetry.io/otel/metric v1.45.0
|
||||
go.opentelemetry.io/otel/sdk v1.45.0
|
||||
go.opentelemetry.io/otel/sdk/log v0.21.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.45.0
|
||||
go.opentelemetry.io/otel/trace v1.45.0
|
||||
go.opentelemetry.io/otel/metric v1.38.0
|
||||
go.opentelemetry.io/otel/sdk v1.38.0
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0
|
||||
go.opentelemetry.io/otel/trace v1.38.0
|
||||
golang.org/x/crypto v0.57.0
|
||||
golang.org/x/sync v0.23.0
|
||||
google.golang.org/grpc v1.83.2
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -40,15 +37,15 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-logr/logr v1.4.4 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/klauspost/compress v1.18.7 // indirect
|
||||
github.com/klauspost/compress v1.18.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
|
||||
github.com/klauspost/crc32 v1.3.0 // indirect
|
||||
github.com/minio/crc64nvme v1.1.1 // indirect
|
||||
@@ -69,17 +66,18 @@ require (
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/tinylib/msgp v1.6.1 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.21.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.14.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||
golang.org/x/net v0.60.0 // indirect
|
||||
golang.org/x/net v0.58.0 // indirect
|
||||
golang.org/x/sys v0.48.0 // indirect
|
||||
golang.org/x/text v0.42.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
|
||||
google.golang.org/grpc v1.75.0 // indirect
|
||||
google.golang.org/protobuf v1.36.8 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -24,8 +24,8 @@ github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
|
||||
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
@@ -38,8 +38,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
|
||||
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
@@ -48,8 +48,8 @@ github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg=
|
||||
github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/klauspost/compress v1.18.7 h1:aUyZsS4kH3QTKurYhAOwAHxllVPnOthb3vPfnF1Ehjw=
|
||||
github.com/klauspost/compress v1.18.7/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
|
||||
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU=
|
||||
github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
@@ -89,8 +89,8 @@ github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7D
|
||||
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
|
||||
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=
|
||||
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
@@ -116,42 +116,40 @@ github.com/tinylib/msgp v1.6.1 h1:ESRv8eL3u+DNHUoSAAQRE50Hm162zqAnBoGv9PzScPY=
|
||||
github.com/tinylib/msgp v1.6.1/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
|
||||
github.com/valkey-io/valkey-go v1.0.78 h1:1Ce8hRaaNXpKfqmqZQRhnbVh1eW8MGR873pdXVvE4y8=
|
||||
github.com/valkey-io/valkey-go v1.0.78/go.mod h1:gvC/r2m3eW4Hbj0YnjogTzNtFdPSM/D+NCqen+5OABM=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.20.0 h1:oEl2Pw/i4OQwhAuda2pAHFAcOMivA+Xa+iTccBfab/g=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.20.0/go.mod h1:yMSQaiiq5dpfrSJCYLBcqFeJkFFI67seT4ngvx6jfVo=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0 h1:bwnLpizECbPr1RrQ27waeY2SPIPeccCx/xLuoYADZ9s=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0/go.mod h1:3nWlOiiqA9UtUnrcNk82mYasNxD8ehOspL0gOfEo6Y4=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0 h1:0NgN/3SYkqYJ9NBlDfl/2lzVlwos/YQLvi8sUrzJRBE=
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.60.0/go.mod h1:oxpUfhTkhgQaYIjtBt3T3w135dLoxq//qo3WPlPIKkE=
|
||||
go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU=
|
||||
go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0 h1:WseeVYf5dJZTsyPiyW5L14k5qsSibqXAMTSiFEDiWr0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0/go.mod h1:SiLZnQS6Qk2eCpvr2CH/XMAOa64TWGXxEZJZCpD2Lmc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.45.0 h1:klTViGcsvLCd1xN3rZzfZ12NslC/OimbmR+k+A006RI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.45.0/go.mod h1:jRsK04CWmXuY8A0O+wMpSf+t90RHZ53o5Qmxn2PQPfk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 h1:QRefszxJmfPdjXUUm3j6iDzY03mTPXMjqErFqQ67vUg=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0/go.mod h1:Tiz03lTBVBrm7eWZBOidzEaYaJa8tjwGUGv6d8mlTyk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0 h1:fG5MCxGz8+2VtrN/WgqSpJFctVz24gpxj8CxkKmc8Ww=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0/go.mod h1:BmAYTn+3ysbRe+IU2msxmf5Rx3g6DHvex+tWI3LdhYI=
|
||||
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0 h1:OMqPldHt79PqWKOMYIAQs3CxAi7RLgPxwfFSwr4ZxtM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0/go.mod h1:1biG4qiqTxKiUCtoWDPpL3fB3KxVwCiGw81j3nKMuHE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0 h1:vl9obrcoWVKp/lwl8tRE33853I8Xru9HFbw/skNeLs8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0/go.mod h1:GAXRxmLJcVM3u22IjTg74zWBrRCKq8BnOqUVLodpcpw=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0 h1:lwI4Dc5leUqENgGuQImwLo4WnuXFPetmPpkLi2IrX54=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0/go.mod h1:Kz/oCE7z5wuyhPxsXDuaPteSWqjSBD5YaSdbxZYGbGk=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.60.0 h1:cGtQxGvZbnrWdC2GyjZi0PDKVSLWP/Jocix3QWfXtbo=
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.60.0/go.mod h1:hkd1EekxNo69PTV4OWFGZcKQiIqg0RfuWExcPKFvepk=
|
||||
go.opentelemetry.io/otel/log v0.21.0 h1:SLsVDGmtyBrdw8/a2Z0bOIxou/+bN4z56GebH7T0LvA=
|
||||
go.opentelemetry.io/otel/log v0.21.0/go.mod h1:iReetQrZL9Wyg84cCkOoCmqDHS5RCFfyxC7J+r8fn8g=
|
||||
go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M=
|
||||
go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s=
|
||||
go.opentelemetry.io/otel/metric/x v0.67.0 h1:PcicCNZFkZ4bXfSooXdo3WN7RBOVOtjVdo1wD358Uns=
|
||||
go.opentelemetry.io/otel/metric/x v0.67.0/go.mod h1:FBjCWZe6wgcqxcMtjdGiClDKXb2YxxXii0CXftE4QtI=
|
||||
go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw=
|
||||
go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA=
|
||||
go.opentelemetry.io/otel/sdk/log v0.21.0 h1:QsE7XSR0ktQdKmRKGnR+f1ObGF32WG+7MER/P9KgmYc=
|
||||
go.opentelemetry.io/otel/sdk/log v0.21.0/go.mod h1:m9mApjCoD2/1QuKCAptjv+BrG9WKOvQLVdNx+iBldTo=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.21.0 h1:X+JBBgKlswCGYsmgL0CnoUUtlE//VB345c84jYAYkdQ=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.21.0/go.mod h1:HD1575K8e6sIFBBDd5tZB3t9DlMytWXq9FuR+Y4rfjE=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA=
|
||||
go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag=
|
||||
go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk=
|
||||
go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E=
|
||||
go.opentelemetry.io/otel/log v0.14.0 h1:2rzJ+pOAZ8qmZ3DDHg73NEKzSZkhkGIua9gXtxNGgrM=
|
||||
go.opentelemetry.io/otel/log v0.14.0/go.mod h1:5jRG92fEAgx0SU/vFPxmJvhIuDU9E1SUnEQrMlJpOno=
|
||||
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0 h1:JU/U3O7N6fsAXj0+CXz21Czg532dW2V4gG1HE/e8Zrg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.14.0/go.mod h1:imQvII+0ZylXfKU7/wtOND8Hn4OpT3YUoIgqJVksUkM=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0 h1:Ijbtz+JKXl8T2MngiwqBlPaHqc4YCaP/i13Qrow6gAM=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.14.0/go.mod h1:dCU8aEL6q+L9cYTqcVOk8rM9Tp8WdnHOPLiBgp0SGOA=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||
go.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4=
|
||||
go.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
||||
@@ -160,24 +158,24 @@ go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||
golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
|
||||
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
|
||||
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
||||
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
|
||||
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
|
||||
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
|
||||
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
|
||||
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
|
||||
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
|
||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d h1:FarXi840EJWSHYTN3ERkADbPWjl307+FGrA22KAVjjc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d/go.mod h1:K/+WGbmBY7aNW1HDw1fJnKYo10i0DkAX6pows00dLig=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d h1:IL4hdHzcUv2l/gcg98/Rj3FbtE6axwqslOW8SW0C+S0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU=
|
||||
google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 h1:BIRfGDEjiHRrk0QKZe3Xv2ieMhtgRGeLcZQ0mIVn4EY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5/go.mod h1:j3QtIyytwqGr1JUDtYXwtMXWPKsEa5LtzIFN1Wn5WvE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 h1:eaY8u2EuxbRv7c3NiGK0/NedzVsCcV6hDuU5qPX5EGE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5/go.mod h1:M4/wBTSeyLxupu3W3tJtOgB14jILAS/XWPSSa3TAlJc=
|
||||
google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=
|
||||
google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
||||
Executable → Regular
+11
-100
@@ -2,124 +2,35 @@
|
||||
|
||||
set -eu
|
||||
|
||||
: "${MINIO_ROOT_USER:?MINIO_ROOT_USER is required}"
|
||||
: "${MINIO_ROOT_PASSWORD:?MINIO_ROOT_PASSWORD is required}"
|
||||
: "${S3_BUCKET:?S3_BUCKET is required}"
|
||||
: "${S3_API_ACCESS_KEY:?S3_API_ACCESS_KEY is required}"
|
||||
: "${S3_API_SECRET_KEY:?S3_API_SECRET_KEY is required}"
|
||||
: "${S3_WORKER_ACCESS_KEY:?S3_WORKER_ACCESS_KEY is required}"
|
||||
: "${S3_WORKER_SECRET_KEY:?S3_WORKER_SECRET_KEY is required}"
|
||||
: "${S3_RECONCILER_ACCESS_KEY:?S3_RECONCILER_ACCESS_KEY is required}"
|
||||
: "${S3_RECONCILER_SECRET_KEY:?S3_RECONCILER_SECRET_KEY is required}"
|
||||
|
||||
export SSL_CERT_FILE=${SSL_CERT_FILE:-/run/security/internal-ca/ca.crt}
|
||||
|
||||
alias_name=bootstrap
|
||||
policy_dir=/tmp/minio-policies
|
||||
mkdir -p "$policy_dir"
|
||||
policy_name=messenger-attachments
|
||||
policy_file=/tmp/messenger-attachments-policy.json
|
||||
|
||||
mc alias set "$alias_name" https://s3:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
|
||||
mc alias set "$alias_name" http://s3:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
|
||||
mc mb --ignore-existing "$alias_name/$S3_BUCKET"
|
||||
mc anonymous set none "$alias_name/$S3_BUCKET"
|
||||
|
||||
cat >"$policy_dir/messenger-api.json" <<EOF
|
||||
cat >"$policy_file" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/attachments/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/staging/*"]
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >"$policy_dir/messenger-worker.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/staging/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/attachments/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
mc admin policy create "$alias_name" "$policy_name" "$policy_file"
|
||||
mc admin user add "$alias_name" "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
|
||||
mc admin policy attach "$alias_name" "$policy_name" --user "$S3_ACCESS_KEY"
|
||||
|
||||
cat >"$policy_dir/messenger-reconciler.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::$S3_BUCKET/staging/*",
|
||||
"arn:aws:s3:::$S3_BUCKET/attachments/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
create_user() {
|
||||
access_key=$1
|
||||
secret_key=$2
|
||||
policy=$3
|
||||
|
||||
mc admin policy create "$alias_name" "$policy" "$policy_dir/$policy.json"
|
||||
mc admin user add "$alias_name" "$access_key" "$secret_key"
|
||||
mc admin policy attach "$alias_name" "$policy" --user "$access_key"
|
||||
}
|
||||
|
||||
create_user "$S3_API_ACCESS_KEY" "$S3_API_SECRET_KEY" messenger-api
|
||||
create_user "$S3_WORKER_ACCESS_KEY" "$S3_WORKER_SECRET_KEY" messenger-worker
|
||||
create_user "$S3_RECONCILER_ACCESS_KEY" "$S3_RECONCILER_SECRET_KEY" messenger-reconciler
|
||||
|
||||
mc alias set application https://s3:9000 "$S3_API_ACCESS_KEY" "$S3_API_SECRET_KEY"
|
||||
mc ls "application/$S3_BUCKET/staging/" >/dev/null
|
||||
mc alias set application http://s3:9000 "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
|
||||
mc ls "application/$S3_BUCKET" >/dev/null
|
||||
|
||||
@@ -10,11 +10,7 @@ RUN LDFLAGS="$(MC_RELEASE=RELEASE go run buildscripts/gen-ldflags.go)" && \
|
||||
|
||||
FROM alpine:3.22.2
|
||||
|
||||
RUN apk add --no-cache curl openssl postgresql17-client redis && \
|
||||
addgroup -g 10001 messenger && \
|
||||
adduser -D -H -u 10001 -G messenger messenger
|
||||
COPY --from=build /out/mc /usr/local/bin/mc
|
||||
COPY infra/minio/bootstrap.sh /usr/local/bin/bootstrap.sh
|
||||
|
||||
USER 10001:10001
|
||||
ENTRYPOINT ["mc"]
|
||||
|
||||
+4
-42
@@ -1,45 +1,7 @@
|
||||
# OpenBao
|
||||
# OpenBao — реализовать конфигурацию и политики
|
||||
|
||||
OpenBao работает вне dev-mode с single-node integrated Raft. Данные сохраняются в `/openbao/data`, API принимает только TLS 1.3 на `8200`, cluster transport использует `8201`. Сертификат и ключ передаются в `/run/security/openbao`, а не входят в образ.
|
||||
Добавьте non-dev конфигурацию listener/storage/TLS, API/worker policies, bootstrap и rotation scripts. Credentials и unseal material создаются локально; здесь нет готового root token или private key.
|
||||
|
||||
## Идентичности
|
||||
Решение должно показать реальную сервисную аутентификацию и получение нужного secret по ограниченной policy; просто работающий контейнер OpenBao не засчитывается. На 3 статический KV secret допустим. На 4 покажите expiry/renewal/rotation и allow/deny. Путь KV v2 data/metadata и ACL должен соответствовать фактическому mount; не копируйте широкое `path "*"` для приложения.
|
||||
|
||||
`messenger-api` и `messenger-worker` — разные AppRole. Каждая роль:
|
||||
|
||||
- читает только свой `secret/data/messenger/<service>` в KV v2;
|
||||
- получает renewable token на 15 минут с максимальным TTL 1 час;
|
||||
- использует короткоживущий `SecretID` с TTL один час;
|
||||
- не получает policy `default`, доступ к чужому secret или управление policies.
|
||||
|
||||
OpenBao Agent читает `RoleID` и короткоживущий `SecretID`, renew-ит token и повторно аутентифицируется после его истечения или рестарта. SecretID действует один час и хранится в operator-controlled каталоге с правами `0600`; после истечения оператор выдаёт новый через `openbao-issue-approle.sh`. KV v2 secret рендерится в защищённый Docker volume `/run/openbao-secrets/secrets.json` с правами `0600`; токен Agent хранится отдельно в tmpfs `/run/openbao-agent`. Старый rendered secret не считается признаком здоровья: healthcheck также проверяет token и процесс Agent.
|
||||
|
||||
## Bootstrap оператора
|
||||
|
||||
Все команды выполняются с проверкой CA и hostname. `BAO_ADDR` по умолчанию равен `https://localhost:8200`, `BAO_CACERT` — `.runtime/security/openbao/ca.crt`.
|
||||
|
||||
```sh
|
||||
scripts/openbao-init.sh
|
||||
scripts/openbao-unseal.sh
|
||||
chmod 0600 .runtime/openbao/seed/api.json .runtime/openbao/seed/worker.json
|
||||
scripts/openbao-bootstrap.sh \
|
||||
"$PWD/.runtime/openbao/seed/api.json" \
|
||||
"$PWD/.runtime/openbao/seed/worker.json"
|
||||
scripts/openbao-test-policy.sh
|
||||
```
|
||||
|
||||
Seed-файлы — непустые JSON-объекты с фактическими credentials сервиса. Скрипт не выводит значения в консоль. `operator init` создаёт три unseal share с threshold 2 и сохраняет единственную локальную копию в `.runtime/openbao/operator/init.json` с правами `0600`. Этот каталог игнорируется Git.
|
||||
|
||||
Для учебного локального стенда оператор хранит init-файл вне контейнера. В реальном окружении shares нужно разделить между операторами либо защитить KMS/HSM, а root token отозвать после настройки recovery-доступа. API, worker и Agent не получают root token или unseal shares.
|
||||
|
||||
После обычного перезапуска данные остаются в Raft volume, но процесс остаётся sealed до ручного `scripts/openbao-unseal.sh`. Перезапуск API и worker не требует unseal.
|
||||
|
||||
## Ротация
|
||||
|
||||
```sh
|
||||
chmod 0600 .runtime/openbao/seed/api-next.json
|
||||
scripts/openbao-rotate.sh api "$PWD/.runtime/openbao/seed/api-next.json"
|
||||
```
|
||||
|
||||
Ротация создаёт новую версию KV v2 и новый короткоживущий `SecretID`; предыдущий accessor отзывается. Agent перечитывает статический secret не позднее пяти минут. Уже выданный token может жить до своего TTL, поэтому при компрометации дополнительно отзывают его accessor или отключают роль и перезапускают Agent с новой идентичностью.
|
||||
|
||||
`scripts/openbao-test-policy.sh` выдаёт временные AppRole credentials, проверяет разрешённое чтение собственного пути, запрет чужого пути, записи и управления policies, а также renewal. Временные tokens отзываются при завершении.
|
||||
Документируйте шаги оператора init/unseal и восстановление после restart. Скрипт не должен печатать tokens/shares или хранить их в Git. См. contracts/trust-matrix.md и REPORT.md.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{{- with secret "secret/data/messenger/api" -}}
|
||||
{{ .Data.data | toJSON }}
|
||||
{{- end -}}
|
||||
@@ -1,43 +0,0 @@
|
||||
pid_file = "/run/openbao-agent/agent.pid"
|
||||
|
||||
vault {
|
||||
address = "https://openbao:8200"
|
||||
ca_cert = "/run/security/openbao/ca.crt"
|
||||
tls_server_name = "openbao"
|
||||
}
|
||||
|
||||
auto_auth {
|
||||
method {
|
||||
type = "approle"
|
||||
mount_path = "auth/approle"
|
||||
|
||||
config = {
|
||||
role_id_file_path = "/run/openbao-identity/role-id"
|
||||
secret_id_file_path = "/run/openbao-identity/secret-id"
|
||||
remove_secret_id_file_after_reading = false
|
||||
}
|
||||
}
|
||||
|
||||
sink {
|
||||
type = "file"
|
||||
|
||||
config = {
|
||||
path = "/run/openbao-agent/token"
|
||||
mode = 384
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template_config {
|
||||
exit_on_retry_failure = true
|
||||
static_secret_render_interval = "5m"
|
||||
}
|
||||
|
||||
template {
|
||||
source = "/etc/openbao-agent/api-secrets.ctmpl"
|
||||
destination = "/run/openbao-secrets/secrets.json"
|
||||
create_dest_dirs = true
|
||||
error_on_missing_key = true
|
||||
perms = "0600"
|
||||
backup = false
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{{- with secret "secret/data/messenger/worker" -}}
|
||||
{{ .Data.data | toJSON }}
|
||||
{{- end -}}
|
||||
@@ -1,43 +0,0 @@
|
||||
pid_file = "/run/openbao-agent/agent.pid"
|
||||
|
||||
vault {
|
||||
address = "https://openbao:8200"
|
||||
ca_cert = "/run/security/openbao/ca.crt"
|
||||
tls_server_name = "openbao"
|
||||
}
|
||||
|
||||
auto_auth {
|
||||
method {
|
||||
type = "approle"
|
||||
mount_path = "auth/approle"
|
||||
|
||||
config = {
|
||||
role_id_file_path = "/run/openbao-identity/role-id"
|
||||
secret_id_file_path = "/run/openbao-identity/secret-id"
|
||||
remove_secret_id_file_after_reading = false
|
||||
}
|
||||
}
|
||||
|
||||
sink {
|
||||
type = "file"
|
||||
|
||||
config = {
|
||||
path = "/run/openbao-agent/token"
|
||||
mode = 384
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template_config {
|
||||
exit_on_retry_failure = true
|
||||
static_secret_render_interval = "5m"
|
||||
}
|
||||
|
||||
template {
|
||||
source = "/etc/openbao-agent/worker-secrets.ctmpl"
|
||||
destination = "/run/openbao-secrets/secrets.json"
|
||||
create_dest_dirs = true
|
||||
error_on_missing_key = true
|
||||
perms = "0600"
|
||||
backup = false
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
ui = false
|
||||
|
||||
api_addr = "https://openbao:8200"
|
||||
cluster_addr = "https://openbao:8201"
|
||||
|
||||
storage "raft" {
|
||||
path = "/openbao/data"
|
||||
node_id = "messenger-openbao-1"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
cluster_address = "0.0.0.0:8201"
|
||||
tls_cert_file = "/run/security/openbao/tls.crt"
|
||||
tls_key_file = "/run/security/openbao/tls.key"
|
||||
tls_min_version = "tls13"
|
||||
}
|
||||
|
||||
log_level = "info"
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
umask 077
|
||||
|
||||
case "${SERVICE:-}" in
|
||||
api|worker) ;;
|
||||
*) echo "SERVICE must be api or worker" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
source_dir="/source/$SERVICE"
|
||||
target_dir="/identities/$SERVICE"
|
||||
mkdir -p "$target_dir"
|
||||
for file in role-id secret-id secret-id-accessor; do
|
||||
cp "$source_dir/$file" "$target_dir/$file.next"
|
||||
chown 10001:10001 "$target_dir/$file.next"
|
||||
chmod 0600 "$target_dir/$file.next"
|
||||
mv "$target_dir/$file.next" "$target_dir/$file"
|
||||
done
|
||||
chown 10001:10001 "$target_dir"
|
||||
chmod 0700 "$target_dir"
|
||||
@@ -1,31 +0,0 @@
|
||||
path "secret/data/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/api" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/data/messenger/worker" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/worker" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/revoke-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "sys/policies/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
path "secret/data/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/worker" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "secret/data/messenger/api" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "secret/metadata/messenger/api" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
|
||||
path "auth/token/lookup-self" {
|
||||
capabilities = ["read"]
|
||||
}
|
||||
|
||||
path "auth/token/renew-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "auth/token/revoke-self" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
|
||||
path "sys/policies/*" {
|
||||
capabilities = ["deny"]
|
||||
}
|
||||
@@ -6,9 +6,9 @@ receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:14317
|
||||
endpoint: 0.0.0.0:4317
|
||||
http:
|
||||
endpoint: 0.0.0.0:14318
|
||||
endpoint: 0.0.0.0:4318
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
@@ -29,12 +29,9 @@ exporters:
|
||||
- service.version
|
||||
- deployment.environment.name
|
||||
otlp_grpc/tempo:
|
||||
endpoint: tempo-collector-gateway:8443
|
||||
endpoint: tempo:4317
|
||||
tls:
|
||||
ca_file: /run/security/internal-ca/ca.crt
|
||||
cert_file: /run/security/client/tls.crt
|
||||
key_file: /run/security/client/tls.key
|
||||
server_name_override: telemetry-gateway
|
||||
insecure: true
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
@@ -45,12 +42,7 @@ exporters:
|
||||
max_interval: 5s
|
||||
max_elapsed_time: 30s
|
||||
otlp_http/loki:
|
||||
endpoint: https://loki-collector-gateway:8443/otlp
|
||||
tls:
|
||||
ca_file: /run/security/internal-ca/ca.crt
|
||||
cert_file: /run/security/client/tls.crt
|
||||
key_file: /run/security/client/tls.key
|
||||
server_name_override: telemetry-gateway
|
||||
endpoint: http://loki:3100/otlp
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
static_resources:
|
||||
listeners:
|
||||
- name: otlp_grpc_mtls
|
||||
address:
|
||||
socket_address:
|
||||
address: 0.0.0.0
|
||||
port_value: 4317
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.http_connection_manager
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
|
||||
stat_prefix: otlp_grpc
|
||||
codec_type: HTTP2
|
||||
route_config:
|
||||
name: otlp_grpc
|
||||
virtual_hosts:
|
||||
- name: collector
|
||||
domains: ["*"]
|
||||
routes:
|
||||
- match: {prefix: "/"}
|
||||
route:
|
||||
cluster: collector_grpc
|
||||
timeout: 0s
|
||||
http_filters:
|
||||
- name: envoy.filters.http.router
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
|
||||
require_client_certificate: true
|
||||
common_tls_context:
|
||||
tls_params:
|
||||
tls_minimum_protocol_version: TLSv1_3
|
||||
tls_maximum_protocol_version: TLSv1_3
|
||||
alpn_protocols: [h2]
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/otel-gateway/tls.crt}
|
||||
private_key: {filename: /run/security/otel-gateway/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: URI
|
||||
matcher:
|
||||
safe_regex:
|
||||
regex: "^spiffe://mtusi/lab7/(api|dispatcher|worker)$"
|
||||
|
||||
- name: otlp_http_mtls
|
||||
address:
|
||||
socket_address:
|
||||
address: 0.0.0.0
|
||||
port_value: 4318
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.http_connection_manager
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
|
||||
stat_prefix: otlp_http
|
||||
codec_type: AUTO
|
||||
route_config:
|
||||
name: otlp_http
|
||||
virtual_hosts:
|
||||
- name: collector
|
||||
domains: ["*"]
|
||||
routes:
|
||||
- match: {prefix: "/"}
|
||||
route:
|
||||
cluster: collector_http
|
||||
timeout: 30s
|
||||
http_filters:
|
||||
- name: envoy.filters.http.router
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
|
||||
require_client_certificate: true
|
||||
common_tls_context:
|
||||
tls_params:
|
||||
tls_minimum_protocol_version: TLSv1_3
|
||||
tls_maximum_protocol_version: TLSv1_3
|
||||
alpn_protocols: [h2, http/1.1]
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/otel-gateway/tls.crt}
|
||||
private_key: {filename: /run/security/otel-gateway/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: URI
|
||||
matcher:
|
||||
safe_regex:
|
||||
regex: "^spiffe://mtusi/lab7/(api|dispatcher|worker)$"
|
||||
|
||||
clusters:
|
||||
- name: collector_grpc
|
||||
connect_timeout: 2s
|
||||
type: STRICT_DNS
|
||||
load_assignment:
|
||||
cluster_name: collector_grpc
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address:
|
||||
socket_address:
|
||||
address: otel-collector
|
||||
port_value: 14317
|
||||
typed_extension_protocol_options:
|
||||
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
|
||||
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
|
||||
explicit_http_config:
|
||||
http2_protocol_options: {}
|
||||
|
||||
- name: collector_http
|
||||
connect_timeout: 2s
|
||||
type: STRICT_DNS
|
||||
load_assignment:
|
||||
cluster_name: collector_http
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address:
|
||||
socket_address:
|
||||
address: otel-collector
|
||||
port_value: 14318
|
||||
|
||||
admin:
|
||||
address:
|
||||
socket_address:
|
||||
address: 127.0.0.1
|
||||
port_value: 9901
|
||||
+1
-52
@@ -81,29 +81,6 @@ create_leaf ingress localhost public-ca ingress.cnf
|
||||
create_leaf api api internal-ca api.cnf
|
||||
create_leaf load-balancer load-balancer internal-ca load-balancer.cnf
|
||||
create_leaf prometheus prometheus internal-ca prometheus.cnf
|
||||
create_leaf postgres postgres internal-ca postgres.cnf
|
||||
create_leaf valkey valkey internal-ca valkey.cnf
|
||||
create_leaf redis-broker redis-broker internal-ca redis-broker.cnf
|
||||
create_leaf redis-gateway redis-gateway internal-ca redis-gateway.cnf
|
||||
create_leaf redis-gateway-client redis-gateway internal-ca redis-gateway-client.cnf
|
||||
create_leaf minio s3 internal-ca minio.cnf
|
||||
create_leaf otel-gateway otel-gateway internal-ca otel-gateway.cnf
|
||||
create_leaf openbao openbao internal-ca openbao.cnf
|
||||
cp "$staging_dir/internal-ca/ca.crt" "$staging_dir/openbao/ca.crt"
|
||||
create_leaf telemetry-gateway telemetry-gateway internal-ca telemetry-gateway.cnf
|
||||
create_leaf collector-client collector internal-ca collector-client.cnf
|
||||
create_leaf grafana-client grafana internal-ca grafana-client.cnf
|
||||
create_leaf grafana-server grafana internal-ca grafana-server.cnf
|
||||
create_leaf pipeline-metrics pipeline-metrics internal-ca pipeline-metrics.cnf
|
||||
create_leaf api-client messenger_api internal-ca api-client.cnf
|
||||
create_leaf dispatcher-client messenger_dispatcher internal-ca dispatcher-client.cnf
|
||||
create_leaf worker-client messenger_worker internal-ca worker-client.cnf
|
||||
create_leaf migrate-client messenger_migrate internal-ca migrate-client.cnf
|
||||
create_leaf reconciler-client messenger_reconciler internal-ca reconciler-client.cnf
|
||||
create_leaf postgres-exporter messenger_exporter internal-ca postgres-exporter.cnf
|
||||
create_leaf postgres-admin-client messenger internal-ca postgres-admin-client.cnf
|
||||
create_leaf valkey-exporter valkey_exporter internal-ca valkey-exporter.cnf
|
||||
create_leaf redis-exporter redis_exporter internal-ca redis-exporter.cnf
|
||||
create_leaf forbidden-client worker internal-ca forbidden-client.cnf
|
||||
create_leaf foreign-client load-balancer foreign-ca load-balancer.cnf
|
||||
|
||||
@@ -111,31 +88,10 @@ openssl verify -purpose sslserver -verify_hostname localhost \
|
||||
-CAfile "$staging_dir/public-ca/ca.crt" "$staging_dir/ingress/tls.crt" >/dev/null
|
||||
openssl verify -purpose sslserver -verify_hostname api \
|
||||
-CAfile "$staging_dir/internal-ca/ca.crt" "$staging_dir/api/tls.crt" >/dev/null
|
||||
for server in postgres valkey redis-broker redis-gateway minio otel-gateway openbao telemetry-gateway grafana-server pipeline-metrics; do
|
||||
case "$server" in
|
||||
minio) hostname=s3 ;;
|
||||
grafana-server) hostname=grafana ;;
|
||||
*) hostname=$server ;;
|
||||
esac
|
||||
openssl verify -purpose sslserver -verify_hostname "$hostname" \
|
||||
-CAfile "$staging_dir/internal-ca/ca.crt" "$staging_dir/$server/tls.crt" >/dev/null
|
||||
done
|
||||
openssl verify -purpose sslclient \
|
||||
-CAfile "$staging_dir/internal-ca/ca.crt" \
|
||||
"$staging_dir/load-balancer/tls.crt" \
|
||||
"$staging_dir/prometheus/tls.crt" \
|
||||
"$staging_dir/api-client/tls.crt" \
|
||||
"$staging_dir/dispatcher-client/tls.crt" \
|
||||
"$staging_dir/worker-client/tls.crt" \
|
||||
"$staging_dir/migrate-client/tls.crt" \
|
||||
"$staging_dir/reconciler-client/tls.crt" \
|
||||
"$staging_dir/postgres-exporter/tls.crt" \
|
||||
"$staging_dir/postgres-admin-client/tls.crt" \
|
||||
"$staging_dir/valkey-exporter/tls.crt" \
|
||||
"$staging_dir/redis-exporter/tls.crt" \
|
||||
"$staging_dir/redis-gateway-client/tls.crt" \
|
||||
"$staging_dir/collector-client/tls.crt" \
|
||||
"$staging_dir/grafana-client/tls.crt" \
|
||||
"$staging_dir/forbidden-client/tls.crt" >/dev/null
|
||||
openssl verify -purpose sslclient \
|
||||
-CAfile "$staging_dir/foreign-ca/ca.crt" "$staging_dir/foreign-client/tls.crt" >/dev/null
|
||||
@@ -143,14 +99,7 @@ openssl verify -purpose sslclient \
|
||||
find "$staging_dir" -type d -exec chmod 0700 {} \;
|
||||
find "$staging_dir" -type f -exec chmod 0600 {} \;
|
||||
|
||||
for directory in \
|
||||
public-ca internal-ca foreign-ca ingress api load-balancer prometheus \
|
||||
postgres valkey redis-broker redis-gateway redis-gateway-client minio otel-gateway openbao \
|
||||
telemetry-gateway collector-client grafana-client grafana-server \
|
||||
pipeline-metrics \
|
||||
api-client dispatcher-client worker-client migrate-client reconciler-client \
|
||||
postgres-exporter postgres-admin-client valkey-exporter redis-exporter \
|
||||
forbidden-client foreign-client; do
|
||||
for directory in public-ca internal-ca foreign-ca ingress api load-balancer prometheus forbidden-client foreign-client; do
|
||||
rm -rf "$security_dir/$directory"
|
||||
mv "$staging_dir/$directory" "$security_dir/$directory"
|
||||
done
|
||||
|
||||
+2
-101
@@ -4,13 +4,11 @@ set -eu
|
||||
|
||||
umask 077
|
||||
|
||||
rm -rf /target/api/internal-ca /target/api/api /target/api/client
|
||||
mkdir -p /target/api/internal-ca /target/api/api /target/api/client
|
||||
rm -rf /target/api/internal-ca /target/api/api
|
||||
mkdir -p /target/api/internal-ca /target/api/api
|
||||
cp /source/internal-ca/ca.crt /target/api/internal-ca/ca.crt
|
||||
cp /source/api/tls.crt /target/api/api/tls.crt
|
||||
cp /source/api/tls.key /target/api/api/tls.key
|
||||
cp /source/api-client/tls.crt /target/api/client/tls.crt
|
||||
cp /source/api-client/tls.key /target/api/client/tls.key
|
||||
chown -R 10001:10001 /target/api
|
||||
find /target/api -type d -exec chmod 0700 {} \;
|
||||
find /target/api -type f -exec chmod 0600 {} \;
|
||||
@@ -42,100 +40,3 @@ cp /source/public-ca/ca.crt /target/client/public-ca/ca.crt
|
||||
chown -R 10001:10001 /target/client
|
||||
find /target/client -type d -exec chmod 0700 {} \;
|
||||
find /target/client -type f -exec chmod 0600 {} \;
|
||||
|
||||
install_server() {
|
||||
target=$1
|
||||
identity=$2
|
||||
owner=$3
|
||||
|
||||
rm -rf "/target/$target/internal-ca" "/target/$target/$identity"
|
||||
mkdir -p "/target/$target/internal-ca" "/target/$target/$identity"
|
||||
cp /source/internal-ca/ca.crt "/target/$target/internal-ca/ca.crt"
|
||||
cp "/source/$identity/tls.crt" "/target/$target/$identity/tls.crt"
|
||||
cp "/source/$identity/tls.key" "/target/$target/$identity/tls.key"
|
||||
chown -R "$owner" "/target/$target"
|
||||
find "/target/$target" -type d -exec chmod 0700 {} \;
|
||||
find "/target/$target" -type f -exec chmod 0600 {} \;
|
||||
}
|
||||
|
||||
install_client() {
|
||||
target=$1
|
||||
identity=$2
|
||||
owner=$3
|
||||
|
||||
rm -rf "/target/$target/internal-ca" "/target/$target/public-ca" "/target/$target/client"
|
||||
mkdir -p "/target/$target/internal-ca" "/target/$target/public-ca" "/target/$target/client"
|
||||
cp /source/internal-ca/ca.crt "/target/$target/internal-ca/ca.crt"
|
||||
cp /source/public-ca/ca.crt "/target/$target/public-ca/ca.crt"
|
||||
cp "/source/$identity/tls.crt" "/target/$target/client/tls.crt"
|
||||
cp "/source/$identity/tls.key" "/target/$target/client/tls.key"
|
||||
chown -R "$owner" "/target/$target"
|
||||
find "/target/$target" -type d -exec chmod 0700 {} \;
|
||||
find "/target/$target" -type f -exec chmod 0600 {} \;
|
||||
}
|
||||
|
||||
install_server postgres postgres 70:70
|
||||
install_server valkey valkey 999:999
|
||||
install_server redis-broker redis-broker 999:999
|
||||
install_server minio minio 100:101
|
||||
cp /source/minio/tls.crt /target/minio/minio/public.crt
|
||||
cp /source/minio/tls.key /target/minio/minio/private.key
|
||||
chown 100:101 /target/minio/minio/public.crt /target/minio/minio/private.key
|
||||
chmod 0600 /target/minio/minio/public.crt /target/minio/minio/private.key
|
||||
install_server otel-gateway otel-gateway 101:101
|
||||
install_server openbao openbao 100:100
|
||||
cp /source/internal-ca/ca.crt /target/openbao/openbao/ca.crt
|
||||
chown 100:100 /target/openbao/openbao/ca.crt
|
||||
chmod 0600 /target/openbao/openbao/ca.crt
|
||||
|
||||
rm -rf /target/openbao-agent/openbao
|
||||
mkdir -p /target/openbao-agent/openbao
|
||||
cp /source/internal-ca/ca.crt /target/openbao-agent/openbao/ca.crt
|
||||
chown -R 10001:10001 /target/openbao-agent
|
||||
find /target/openbao-agent -type d -exec chmod 0700 {} \;
|
||||
find /target/openbao-agent -type f -exec chmod 0600 {} \;
|
||||
chmod 0644 /target/openbao-agent/openbao/ca.crt
|
||||
chmod 0755 /target/openbao-agent /target/openbao-agent/openbao
|
||||
|
||||
install_server telemetry-gateway telemetry-gateway 10001:10001
|
||||
install_client collector collector-client 10001:10001
|
||||
install_client grafana grafana-client 472:472
|
||||
cp /source/grafana-server/tls.crt /target/grafana/grafana-server.crt
|
||||
cp /source/grafana-server/tls.key /target/grafana/grafana-server.key
|
||||
chown 472:472 /target/grafana/grafana-server.crt /target/grafana/grafana-server.key
|
||||
chmod 0600 /target/grafana/grafana-server.crt /target/grafana/grafana-server.key
|
||||
|
||||
rm -rf /target/redis-gateway/internal-ca /target/redis-gateway/redis-gateway /target/redis-gateway/client
|
||||
mkdir -p /target/redis-gateway/internal-ca /target/redis-gateway/redis-gateway /target/redis-gateway/client
|
||||
cp /source/internal-ca/ca.crt /target/redis-gateway/internal-ca/ca.crt
|
||||
cp /source/redis-gateway/tls.crt /target/redis-gateway/redis-gateway/tls.crt
|
||||
cp /source/redis-gateway/tls.key /target/redis-gateway/redis-gateway/tls.key
|
||||
cp /source/redis-gateway-client/tls.crt /target/redis-gateway/client/tls.crt
|
||||
cp /source/redis-gateway-client/tls.key /target/redis-gateway/client/tls.key
|
||||
chown -R 101:101 /target/redis-gateway
|
||||
find /target/redis-gateway -type d -exec chmod 0700 {} \;
|
||||
find /target/redis-gateway -type f -exec chmod 0600 {} \;
|
||||
|
||||
install_client dispatcher dispatcher-client 10001:10001
|
||||
install_client worker worker-client 10001:10001
|
||||
for target in dispatcher worker; do
|
||||
mkdir -p "/target/$target/metrics"
|
||||
cp /source/pipeline-metrics/tls.crt "/target/$target/metrics/tls.crt"
|
||||
cp /source/pipeline-metrics/tls.key "/target/$target/metrics/tls.key"
|
||||
chown -R 10001:10001 "/target/$target/metrics"
|
||||
find "/target/$target/metrics" -type d -exec chmod 0700 {} \;
|
||||
find "/target/$target/metrics" -type f -exec chmod 0600 {} \;
|
||||
done
|
||||
install_client migrate migrate-client 10001:10001
|
||||
install_client reconciler reconciler-client 10001:10001
|
||||
install_client postgres-exporter postgres-exporter 65534:65534
|
||||
install_client postgres-bootstrap postgres-admin-client 0:0
|
||||
install_client valkey-exporter valkey-exporter 59000:59000
|
||||
install_client redis-exporter redis-exporter 59000:59000
|
||||
|
||||
rm -rf /target/s3-bootstrap/internal-ca
|
||||
mkdir -p /target/s3-bootstrap/internal-ca
|
||||
cp /source/internal-ca/ca.crt /target/s3-bootstrap/internal-ca/ca.crt
|
||||
chown -R 10001:10001 /target/s3-bootstrap
|
||||
find /target/s3-bootstrap -type d -exec chmod 0700 {} \;
|
||||
find /target/s3-bootstrap -type f -exec chmod 0600 {} \;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/api
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/collector
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/dispatcher
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/grafana
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,11 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
DNS.1 = grafana
|
||||
DNS.2 = localhost
|
||||
IP.1 = 127.0.0.1
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/migrate
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:s3
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,11 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
DNS.1 = openbao
|
||||
DNS.2 = localhost
|
||||
IP.1 = 127.0.0.1
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:otel-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:pipeline-metrics
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/postgres-bootstrap
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/postgres-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:postgres
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/reconciler
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:redis-broker
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/redis-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/redis-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:redis-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:telemetry-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/valkey-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:valkey
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,6 +0,0 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/worker
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
case "${1:-}" in
|
||||
create) sql_file=/bootstrap/roles.sql ;;
|
||||
grant) sql_file=/bootstrap/grants.sql ;;
|
||||
*) echo "usage: $0 create|grant" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
: "${POSTGRES_DB:?POSTGRES_DB is required}"
|
||||
: "${POSTGRES_USER:?POSTGRES_USER is required}"
|
||||
: "${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}"
|
||||
: "${POSTGRES_API_PASSWORD:?POSTGRES_API_PASSWORD is required}"
|
||||
: "${POSTGRES_DISPATCHER_PASSWORD:?POSTGRES_DISPATCHER_PASSWORD is required}"
|
||||
: "${POSTGRES_WORKER_PASSWORD:?POSTGRES_WORKER_PASSWORD is required}"
|
||||
: "${POSTGRES_RECONCILER_PASSWORD:?POSTGRES_RECONCILER_PASSWORD is required}"
|
||||
: "${POSTGRES_EXPORTER_PASSWORD:?POSTGRES_EXPORTER_PASSWORD is required}"
|
||||
: "${POSTGRES_MIGRATE_PASSWORD:?POSTGRES_MIGRATE_PASSWORD is required}"
|
||||
|
||||
export PGPASSWORD=$POSTGRES_PASSWORD
|
||||
export PGSSLROOTCERT=${PGSSLROOTCERT:-/run/security/internal-ca/ca.crt}
|
||||
export PGSSLCERT=${PGSSLCERT:-/run/security/client/tls.crt}
|
||||
export PGSSLKEY=${PGSSLKEY:-/run/security/client/tls.key}
|
||||
export PGSSLMODE=verify-full
|
||||
|
||||
psql \
|
||||
--host=postgres \
|
||||
--username="$POSTGRES_USER" \
|
||||
--dbname="$POSTGRES_DB" \
|
||||
--set=ON_ERROR_STOP=1 \
|
||||
--set=api_password="$POSTGRES_API_PASSWORD" \
|
||||
--set=dispatcher_password="$POSTGRES_DISPATCHER_PASSWORD" \
|
||||
--set=worker_password="$POSTGRES_WORKER_PASSWORD" \
|
||||
--set=reconciler_password="$POSTGRES_RECONCILER_PASSWORD" \
|
||||
--set=exporter_password="$POSTGRES_EXPORTER_PASSWORD" \
|
||||
--set=migrate_password="$POSTGRES_MIGRATE_PASSWORD" \
|
||||
--file="$sql_file"
|
||||
@@ -1,25 +0,0 @@
|
||||
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON
|
||||
users,
|
||||
chats,
|
||||
chat_members,
|
||||
messages,
|
||||
message_idempotency,
|
||||
attachments,
|
||||
message_attachments,
|
||||
attachment_jobs,
|
||||
outbox_events
|
||||
TO messenger_api;
|
||||
GRANT SELECT ON attachment_variants TO messenger_api;
|
||||
|
||||
GRANT SELECT, UPDATE, DELETE ON outbox_events TO messenger_dispatcher;
|
||||
|
||||
GRANT SELECT, UPDATE ON attachments, attachment_jobs TO messenger_worker;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON attachment_variants TO messenger_worker;
|
||||
GRANT INSERT ON attachment_replay_audit TO messenger_worker;
|
||||
GRANT INSERT ON outbox_events TO messenger_worker;
|
||||
|
||||
GRANT SELECT, UPDATE, DELETE ON attachments TO messenger_reconciler;
|
||||
GRANT SELECT ON attachment_variants, message_attachments TO messenger_reconciler;
|
||||
GRANT pg_monitor TO messenger_exporter;
|
||||
@@ -1,15 +0,0 @@
|
||||
# Local bootstrap and health checks stay inside the PostgreSQL container.
|
||||
local all all trust
|
||||
|
||||
# TLS verifies the server. clientcert=verify-full additionally binds the
|
||||
# certificate CN to the database role; SCRAM remains a second factor.
|
||||
hostssl messenger messenger_api all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger_dispatcher all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger_worker all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger_reconciler all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger_exporter all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger_migrate all scram-sha-256 clientcert=verify-full
|
||||
hostssl messenger messenger all scram-sha-256 clientcert=verify-full
|
||||
|
||||
hostnossl all all all reject
|
||||
hostssl all all all reject
|
||||
@@ -1,11 +0,0 @@
|
||||
listen_addresses = '*'
|
||||
port = 5432
|
||||
|
||||
ssl = on
|
||||
ssl_cert_file = '/run/security/postgres/tls.crt'
|
||||
ssl_key_file = '/run/security/postgres/tls.key'
|
||||
ssl_ca_file = '/run/security/internal-ca/ca.crt'
|
||||
ssl_min_protocol_version = 'TLSv1.3'
|
||||
|
||||
hba_file = '/etc/postgresql/pg_hba.conf'
|
||||
password_encryption = 'scram-sha-256'
|
||||
@@ -1,38 +0,0 @@
|
||||
SELECT format('CREATE ROLE %I LOGIN', role_name)
|
||||
FROM unnest(ARRAY[
|
||||
'messenger_api',
|
||||
'messenger_dispatcher',
|
||||
'messenger_worker',
|
||||
'messenger_reconciler',
|
||||
'messenger_exporter',
|
||||
'messenger_migrate'
|
||||
]) AS roles(role_name)
|
||||
WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = role_name)
|
||||
\gexec
|
||||
|
||||
ALTER ROLE messenger_api PASSWORD :'api_password';
|
||||
ALTER ROLE messenger_dispatcher PASSWORD :'dispatcher_password';
|
||||
ALTER ROLE messenger_worker PASSWORD :'worker_password';
|
||||
ALTER ROLE messenger_reconciler PASSWORD :'reconciler_password';
|
||||
ALTER ROLE messenger_exporter PASSWORD :'exporter_password';
|
||||
ALTER ROLE messenger_migrate PASSWORD :'migrate_password';
|
||||
|
||||
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
|
||||
|
||||
GRANT CONNECT ON DATABASE messenger TO
|
||||
messenger_api,
|
||||
messenger_dispatcher,
|
||||
messenger_worker,
|
||||
messenger_reconciler,
|
||||
messenger_exporter,
|
||||
messenger_migrate;
|
||||
GRANT USAGE ON SCHEMA public TO
|
||||
messenger_api,
|
||||
messenger_dispatcher,
|
||||
messenger_worker,
|
||||
messenger_reconciler,
|
||||
messenger_exporter;
|
||||
GRANT USAGE, CREATE ON SCHEMA public TO messenger_migrate;
|
||||
|
||||
ALTER DEFAULT PRIVILEGES FOR ROLE messenger_migrate IN SCHEMA public
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO messenger_api;
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 valkey|broker OUTPUT" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
valid_secret() {
|
||||
value=$1
|
||||
case "$value" in
|
||||
""|*[!A-Za-z0-9_@%+=:,./-]*) return 1 ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
write_valkey_acl() {
|
||||
: "${VALKEY_API_PASSWORD:?VALKEY_API_PASSWORD is required}"
|
||||
: "${VALKEY_EXPORTER_PASSWORD:?VALKEY_EXPORTER_PASSWORD is required}"
|
||||
: "${VALKEY_HEALTH_PASSWORD:?VALKEY_HEALTH_PASSWORD is required}"
|
||||
valid_secret "$VALKEY_API_PASSWORD" || exit 1
|
||||
valid_secret "$VALKEY_EXPORTER_PASSWORD" || exit 1
|
||||
valid_secret "$VALKEY_HEALTH_PASSWORD" || exit 1
|
||||
|
||||
cat >"$output" <<EOF
|
||||
user default reset off
|
||||
user messenger_api reset on >$VALKEY_API_PASSWORD ~session:* ~login-rate:* +ping +get +set +del +unlink +expire +pexpire +ttl +pttl +incr +eval +evalsha +script|load
|
||||
user valkey_exporter reset on >$VALKEY_EXPORTER_PASSWORD ~* +ping +info +client +config|get +scan +dbsize +slowlog
|
||||
user valkey_health reset on >$VALKEY_HEALTH_PASSWORD +ping
|
||||
EOF
|
||||
}
|
||||
|
||||
write_broker_acl() {
|
||||
: "${REDIS_DISPATCHER_PASSWORD:?REDIS_DISPATCHER_PASSWORD is required}"
|
||||
: "${REDIS_WORKER_PASSWORD:?REDIS_WORKER_PASSWORD is required}"
|
||||
: "${REDIS_EXPORTER_PASSWORD:?REDIS_EXPORTER_PASSWORD is required}"
|
||||
: "${REDIS_HEALTH_PASSWORD:?REDIS_HEALTH_PASSWORD is required}"
|
||||
valid_secret "$REDIS_DISPATCHER_PASSWORD" || exit 1
|
||||
valid_secret "$REDIS_WORKER_PASSWORD" || exit 1
|
||||
valid_secret "$REDIS_EXPORTER_PASSWORD" || exit 1
|
||||
valid_secret "$REDIS_HEALTH_PASSWORD" || exit 1
|
||||
|
||||
cat >"$output" <<EOF
|
||||
user default reset off
|
||||
user messenger_dispatcher reset on >$REDIS_DISPATCHER_PASSWORD ~attachment-jobs +ping +xadd
|
||||
user messenger_worker reset on >$REDIS_WORKER_PASSWORD ~attachment-jobs ~attachment-jobs-failed +ping +xgroup +xreadgroup +xautoclaim +xpending +xack +xdel +xadd +eval +evalsha +script|load
|
||||
user redis_exporter reset on >$REDIS_EXPORTER_PASSWORD ~* +ping +info +client +config|get +scan +dbsize +slowlog +xinfo
|
||||
user redis_health reset on >$REDIS_HEALTH_PASSWORD +ping
|
||||
EOF
|
||||
}
|
||||
|
||||
[ "$#" -eq 2 ] || usage
|
||||
mode=$1
|
||||
output=$2
|
||||
|
||||
umask 077
|
||||
mkdir -p "$(dirname -- "$output")"
|
||||
|
||||
case "$mode" in
|
||||
valkey) write_valkey_acl ;;
|
||||
broker) write_broker_acl ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
||||
chmod 0600 "$output"
|
||||
@@ -1,136 +0,0 @@
|
||||
static_resources:
|
||||
listeners:
|
||||
- name: valkey_api
|
||||
address:
|
||||
socket_address: {address: 0.0.0.0, port_value: 16379}
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.tcp_proxy
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
|
||||
stat_prefix: valkey_api
|
||||
cluster: valkey
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
|
||||
require_client_certificate: true
|
||||
common_tls_context:
|
||||
tls_params: {tls_minimum_protocol_version: TLSv1_3, tls_maximum_protocol_version: TLSv1_3}
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/redis-gateway/tls.crt}
|
||||
private_key: {filename: /run/security/redis-gateway/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: URI
|
||||
matcher: {exact: "spiffe://mtusi/lab7/api"}
|
||||
|
||||
- name: broker_dispatcher
|
||||
address:
|
||||
socket_address: {address: 0.0.0.0, port_value: 26379}
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.tcp_proxy
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
|
||||
stat_prefix: broker_dispatcher
|
||||
cluster: redis_broker
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
|
||||
require_client_certificate: true
|
||||
common_tls_context:
|
||||
tls_params: {tls_minimum_protocol_version: TLSv1_3, tls_maximum_protocol_version: TLSv1_3}
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/redis-gateway/tls.crt}
|
||||
private_key: {filename: /run/security/redis-gateway/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: URI
|
||||
matcher: {exact: "spiffe://mtusi/lab7/dispatcher"}
|
||||
|
||||
- name: broker_worker
|
||||
address:
|
||||
socket_address: {address: 0.0.0.0, port_value: 36379}
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.tcp_proxy
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
|
||||
stat_prefix: broker_worker
|
||||
cluster: redis_broker
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
|
||||
require_client_certificate: true
|
||||
common_tls_context:
|
||||
tls_params: {tls_minimum_protocol_version: TLSv1_3, tls_maximum_protocol_version: TLSv1_3}
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/redis-gateway/tls.crt}
|
||||
private_key: {filename: /run/security/redis-gateway/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: URI
|
||||
matcher: {exact: "spiffe://mtusi/lab7/worker"}
|
||||
|
||||
clusters:
|
||||
- name: valkey
|
||||
connect_timeout: 2s
|
||||
type: STRICT_DNS
|
||||
load_assignment:
|
||||
cluster_name: valkey
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address:
|
||||
socket_address: {address: valkey, port_value: 6379}
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
|
||||
sni: valkey
|
||||
common_tls_context:
|
||||
tls_params: {tls_minimum_protocol_version: TLSv1_3, tls_maximum_protocol_version: TLSv1_3}
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/client/tls.crt}
|
||||
private_key: {filename: /run/security/client/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: DNS
|
||||
matcher: {exact: valkey}
|
||||
|
||||
- name: redis_broker
|
||||
connect_timeout: 2s
|
||||
type: STRICT_DNS
|
||||
load_assignment:
|
||||
cluster_name: redis_broker
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address:
|
||||
socket_address: {address: redis-broker, port_value: 6379}
|
||||
transport_socket:
|
||||
name: envoy.transport_sockets.tls
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
|
||||
sni: redis-broker
|
||||
common_tls_context:
|
||||
tls_params: {tls_minimum_protocol_version: TLSv1_3, tls_maximum_protocol_version: TLSv1_3}
|
||||
tls_certificates:
|
||||
- certificate_chain: {filename: /run/security/client/tls.crt}
|
||||
private_key: {filename: /run/security/client/tls.key}
|
||||
validation_context:
|
||||
trusted_ca: {filename: /run/security/internal-ca/ca.crt}
|
||||
match_typed_subject_alt_names:
|
||||
- san_type: DNS
|
||||
matcher: {exact: redis-broker}
|
||||
|
||||
admin:
|
||||
address:
|
||||
socket_address: {address: 127.0.0.1, port_value: 9901}
|
||||
@@ -1,17 +0,0 @@
|
||||
bind 0.0.0.0
|
||||
protected-mode yes
|
||||
port 0
|
||||
tls-port 6379
|
||||
tls-cert-file /run/security/redis-broker/tls.crt
|
||||
tls-key-file /run/security/redis-broker/tls.key
|
||||
tls-ca-cert-file /run/security/internal-ca/ca.crt
|
||||
tls-auth-clients yes
|
||||
tls-protocols "TLSv1.3"
|
||||
unixsocket /tmp/redis.sock
|
||||
unixsocketperm 700
|
||||
|
||||
aclfile /run/security/redis-broker/users.acl
|
||||
appendonly yes
|
||||
appendfsync always
|
||||
maxmemory-policy noeviction
|
||||
dir /data
|
||||
@@ -1,16 +0,0 @@
|
||||
bind 0.0.0.0
|
||||
protected-mode yes
|
||||
port 0
|
||||
tls-port 6379
|
||||
tls-cert-file /run/security/valkey/tls.crt
|
||||
tls-key-file /run/security/valkey/tls.key
|
||||
tls-ca-cert-file /run/security/internal-ca/ca.crt
|
||||
tls-auth-clients yes
|
||||
tls-protocols "TLSv1.3"
|
||||
unixsocket /tmp/valkey.sock
|
||||
unixsocketperm 700
|
||||
|
||||
aclfile /run/security/valkey/users.acl
|
||||
appendonly yes
|
||||
appendfsync everysec
|
||||
dir /data
|
||||
@@ -1,199 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
: "${SECURITY_DIR:=/run/security-source}"
|
||||
: "${POSTGRES_HOST:=postgres}"
|
||||
: "${VALKEY_HOST:=redis-gateway}"
|
||||
: "${VALKEY_PORT:=16379}"
|
||||
: "${REDIS_HOST:=redis-gateway}"
|
||||
: "${REDIS_DISPATCHER_PORT:=26379}"
|
||||
: "${REDIS_WORKER_PORT:=36379}"
|
||||
: "${S3_HOST:=s3}"
|
||||
: "${OTEL_HOST:=otel-gateway}"
|
||||
: "${POSTGRES_DB:=messenger}"
|
||||
: "${S3_BUCKET:=messenger-attachments}"
|
||||
|
||||
required_commands="curl mc openssl psql redis-cli"
|
||||
for command in $required_commands; do
|
||||
command -v "$command" >/dev/null 2>&1 || {
|
||||
echo "$command is required" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
ca=$SECURITY_DIR/internal-ca/ca.crt
|
||||
|
||||
expect_failure() {
|
||||
description=$1
|
||||
shift
|
||||
if "$@" >/dev/null 2>&1; then
|
||||
echo "expected failure: $description" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
expect_redis_denied() {
|
||||
description=$1
|
||||
shift
|
||||
output=$("$@" 2>&1 || true)
|
||||
case "$output" in
|
||||
*NOPERM*|*DENIED*) ;;
|
||||
*) echo "expected Redis ACL denial: $description" >&2; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
expect_redis_allowed() {
|
||||
description=$1
|
||||
shift
|
||||
output=$("$@" 2>&1) || {
|
||||
echo "expected Redis ACL allow: $description: $output" >&2
|
||||
exit 1
|
||||
}
|
||||
case "$output" in
|
||||
*NOPERM*|*DENIED*) echo "expected Redis ACL allow: $description: $output" >&2; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_server() {
|
||||
host=$1
|
||||
port=$2
|
||||
identity=${3:-}
|
||||
client_options=
|
||||
if [ -n "$identity" ]; then
|
||||
client_options="-cert $SECURITY_DIR/$identity/tls.crt -key $SECURITY_DIR/$identity/tls.key"
|
||||
fi
|
||||
# client_options contains only paths assembled by this script.
|
||||
# shellcheck disable=SC2086
|
||||
printf '' | openssl s_client $client_options \
|
||||
-connect "$host:$port" \
|
||||
-servername "$host" \
|
||||
-verify_hostname "$host" \
|
||||
-verify_return_error \
|
||||
-CAfile "$ca" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
check_server "$POSTGRES_HOST" 5432 api-client
|
||||
check_server "$VALKEY_HOST" "$VALKEY_PORT" api-client
|
||||
check_server "$REDIS_HOST" "$REDIS_WORKER_PORT" worker-client
|
||||
check_server "$S3_HOST" 9000
|
||||
|
||||
: "${POSTGRES_API_PASSWORD:?POSTGRES_API_PASSWORD is required}"
|
||||
: "${POSTGRES_WORKER_PASSWORD:?POSTGRES_WORKER_PASSWORD is required}"
|
||||
: "${POSTGRES_DISPATCHER_PASSWORD:?POSTGRES_DISPATCHER_PASSWORD is required}"
|
||||
|
||||
pg_url() {
|
||||
role=$1
|
||||
cert=$2
|
||||
password=$3
|
||||
printf 'postgresql://%s:%s@%s:5432/%s?sslmode=verify-full&sslrootcert=%s&sslcert=%s&sslkey=%s' \
|
||||
"$role" "$password" "$POSTGRES_HOST" "$POSTGRES_DB" "$ca" \
|
||||
"$SECURITY_DIR/$cert/tls.crt" "$SECURITY_DIR/$cert/tls.key"
|
||||
}
|
||||
|
||||
api_db=$(pg_url messenger_api api-client "$POSTGRES_API_PASSWORD")
|
||||
worker_db=$(pg_url messenger_worker worker-client "$POSTGRES_WORKER_PASSWORD")
|
||||
dispatcher_db=$(pg_url messenger_dispatcher dispatcher-client "$POSTGRES_DISPATCHER_PASSWORD")
|
||||
api_with_worker_cert=$(pg_url messenger_api worker-client "$POSTGRES_API_PASSWORD")
|
||||
|
||||
psql "$api_db" --set=ON_ERROR_STOP=1 --command='SELECT count(*) FROM users' >/dev/null
|
||||
psql "$worker_db" --set=ON_ERROR_STOP=1 --command='SELECT count(*) FROM attachment_jobs' >/dev/null
|
||||
psql "$worker_db" --set=ON_ERROR_STOP=1 --command='UPDATE attachment_jobs SET updated_at = updated_at WHERE false' >/dev/null
|
||||
psql "$dispatcher_db" --set=ON_ERROR_STOP=1 --command='SELECT count(*) FROM outbox_events' >/dev/null
|
||||
expect_failure "worker reads users" psql "$worker_db" --set=ON_ERROR_STOP=1 --command='SELECT count(*) FROM users'
|
||||
expect_failure "dispatcher reads attachments" psql "$dispatcher_db" --set=ON_ERROR_STOP=1 --command='SELECT count(*) FROM attachments'
|
||||
expect_failure "API role uses worker certificate" psql "$api_with_worker_cert" --set=ON_ERROR_STOP=1 --command='SELECT 1'
|
||||
|
||||
: "${VALKEY_API_PASSWORD:?VALKEY_API_PASSWORD is required}"
|
||||
: "${REDIS_DISPATCHER_PASSWORD:?REDIS_DISPATCHER_PASSWORD is required}"
|
||||
: "${REDIS_WORKER_PASSWORD:?REDIS_WORKER_PASSWORD is required}"
|
||||
|
||||
expect_failure "broker without client certificate" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" PING
|
||||
for identity in foreign-client api-client; do
|
||||
expect_failure "broker rejects $identity" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/$identity/tls.crt" \
|
||||
--key "$SECURITY_DIR/$identity/tls.key" --user messenger_worker \
|
||||
-h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" PING
|
||||
done
|
||||
|
||||
redis_tls() {
|
||||
identity=$1
|
||||
shift
|
||||
redis-cli --tls --cacert "$ca" \
|
||||
--cert "$SECURITY_DIR/$identity/tls.crt" \
|
||||
--key "$SECURITY_DIR/$identity/tls.key" "$@"
|
||||
}
|
||||
|
||||
REDISCLI_AUTH=$VALKEY_API_PASSWORD redis_tls api-client \
|
||||
--user messenger_api -h "$VALKEY_HOST" -p "$VALKEY_PORT" SET session:acl-test value EX 30 >/dev/null
|
||||
expect_redis_denied "session identity writes an arbitrary key" env REDISCLI_AUTH="$VALKEY_API_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/api-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/api-client/tls.key" --user messenger_api -h "$VALKEY_HOST" -p "$VALKEY_PORT" SET forbidden value
|
||||
|
||||
REDISCLI_AUTH=$REDIS_DISPATCHER_PASSWORD redis_tls dispatcher-client \
|
||||
--user messenger_dispatcher -h "$REDIS_HOST" -p "$REDIS_DISPATCHER_PORT" XADD attachment-jobs '*' payload acl-test >/dev/null
|
||||
expect_redis_denied "dispatcher consumes jobs" env REDISCLI_AUTH="$REDIS_DISPATCHER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/dispatcher-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/dispatcher-client/tls.key" --user messenger_dispatcher -h "$REDIS_HOST" -p "$REDIS_DISPATCHER_PORT" \
|
||||
XREAD COUNT 1 STREAMS attachment-jobs 0
|
||||
REDISCLI_AUTH=$REDIS_WORKER_PASSWORD redis_tls worker-client \
|
||||
--user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" XGROUP DESTROY attachment-jobs acl-worker-check >/dev/null 2>&1 || true
|
||||
expect_redis_allowed "worker creates its consumer group" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/worker-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/worker-client/tls.key" --user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" \
|
||||
XGROUP CREATE attachment-jobs acl-worker-check '$' MKSTREAM
|
||||
expect_redis_allowed "worker consumes its stream" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/worker-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/worker-client/tls.key" --user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" \
|
||||
XREADGROUP GROUP acl-worker-check acl-worker-consumer COUNT 1 STREAMS attachment-jobs '>'
|
||||
expect_redis_allowed "worker acknowledges its stream" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/worker-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/worker-client/tls.key" --user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" \
|
||||
XACK attachment-jobs acl-worker-check 0-1
|
||||
REDISCLI_AUTH=$REDIS_WORKER_PASSWORD redis_tls worker-client \
|
||||
--user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" XGROUP DESTROY attachment-jobs acl-worker-check >/dev/null
|
||||
expect_redis_denied "worker accesses an unrelated stream" env REDISCLI_AUTH="$REDIS_WORKER_PASSWORD" \
|
||||
redis-cli --tls --cacert "$ca" --cert "$SECURITY_DIR/worker-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/worker-client/tls.key" --user messenger_worker -h "$REDIS_HOST" -p "$REDIS_WORKER_PORT" XADD unrelated '*' payload denied
|
||||
|
||||
: "${S3_API_ACCESS_KEY:?S3_API_ACCESS_KEY is required}"
|
||||
: "${S3_API_SECRET_KEY:?S3_API_SECRET_KEY is required}"
|
||||
: "${S3_WORKER_ACCESS_KEY:?S3_WORKER_ACCESS_KEY is required}"
|
||||
: "${S3_WORKER_SECRET_KEY:?S3_WORKER_SECRET_KEY is required}"
|
||||
|
||||
export SSL_CERT_FILE=$ca
|
||||
export MC_CONFIG_DIR=/tmp/mc-acl-test
|
||||
test_file=/tmp/acl-test-object
|
||||
printf 'acl-test' >"$test_file"
|
||||
mc alias set api "https://$S3_HOST:9000" "$S3_API_ACCESS_KEY" "$S3_API_SECRET_KEY" >/dev/null
|
||||
mc alias set worker "https://$S3_HOST:9000" "$S3_WORKER_ACCESS_KEY" "$S3_WORKER_SECRET_KEY" >/dev/null
|
||||
mc cp "$test_file" "api/$S3_BUCKET/staging/acl-test" >/dev/null
|
||||
expect_failure "API writes processed objects" mc cp "$test_file" "api/$S3_BUCKET/attachments/acl-test"
|
||||
mc cp "$test_file" "worker/$S3_BUCKET/attachments/acl-test" >/dev/null
|
||||
expect_failure "worker writes outside attachment prefixes" mc cp "$test_file" "worker/$S3_BUCKET/private/acl-test"
|
||||
mc rm "api/$S3_BUCKET/staging/acl-test" >/dev/null
|
||||
mc rm "worker/$S3_BUCKET/attachments/acl-test" >/dev/null
|
||||
|
||||
expect_failure "OTel without client certificate" curl --silent --show-error \
|
||||
--cacert "$ca" "https://$OTEL_HOST:4318/"
|
||||
expect_failure "OTel with foreign CA client certificate" curl --silent --show-error \
|
||||
--cacert "$ca" --cert "$SECURITY_DIR/foreign-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/foreign-client/tls.key" "https://$OTEL_HOST:4318/"
|
||||
|
||||
curl --silent --show-error --fail-with-body \
|
||||
--cacert "$ca" \
|
||||
--cert "$SECURITY_DIR/api-client/tls.crt" \
|
||||
--key "$SECURITY_DIR/api-client/tls.key" \
|
||||
"https://$OTEL_HOST:4318/" >/dev/null 2>&1 || status=$?
|
||||
case "${status:-0}" in
|
||||
0|22) ;;
|
||||
*) echo "allowed OTel identity failed TLS" >&2; exit 1 ;;
|
||||
esac
|
||||
expect_failure "Prometheus same-CA identity reaches OTel" curl --silent --show-error \
|
||||
--cacert "$ca" \
|
||||
--cert "$SECURITY_DIR/prometheus/tls.crt" \
|
||||
--key "$SECURITY_DIR/prometheus/tls.key" \
|
||||
"https://$OTEL_HOST:4318/"
|
||||
|
||||
echo "dependency TLS and least-privilege matrix passed"
|
||||
@@ -2,7 +2,6 @@ package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
@@ -24,11 +23,10 @@ import (
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/outbox"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
func RunDispatcher() error {
|
||||
func RunDispatcher(logger *slog.Logger) error {
|
||||
settings, err := config.LoadDispatcher()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -50,11 +48,7 @@ func RunDispatcher() error {
|
||||
if err := telemetry.ObserveDatabasePool(observability.MeterProvider().Meter("messenger-dispatcher/database"), pool); err != nil {
|
||||
return err
|
||||
}
|
||||
brokerTLSConfiguration, err := loadClientTLS(settings.BrokerTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL, brokerTLSConfiguration)
|
||||
client, err := newRedisClient(settings.BrokerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,6 +61,9 @@ func RunDispatcher() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := broker.Ensure(context.Background()); err != nil {
|
||||
return err
|
||||
}
|
||||
metrics := pipeline.NewMetrics(observability.MeterProvider().Meter("messenger-dispatcher"), observability.MetricsHandler(), 0)
|
||||
dispatcher, err := outbox.New(postgres.New(pool), broker, metrics, outbox.Config{
|
||||
BatchSize: settings.BatchSize, LeaseDuration: settings.LeaseDuration,
|
||||
@@ -77,17 +74,11 @@ func RunDispatcher() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metricsTLSConfiguration, err := loadServerTLS(settings.MetricsTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("outbox dispatcher started", "stream", settings.Stream)
|
||||
return runPipelineProcess(
|
||||
logger, settings.MetricsAddress, settings.HealthAddress, metricsTLSConfiguration, metrics.Handler(), dispatcher.Run,
|
||||
)
|
||||
return runPipelineProcess(logger, settings.MetricsAddress, metrics.Handler(), dispatcher.Run)
|
||||
}
|
||||
|
||||
func RunWorker() error {
|
||||
func RunWorker(logger *slog.Logger) error {
|
||||
settings, err := config.LoadWorker()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -112,16 +103,12 @@ func RunWorker() error {
|
||||
objects, err := objectstore.New(objectstore.Config{
|
||||
Endpoint: settings.S3Endpoint, Region: settings.S3Region, Bucket: settings.S3Bucket,
|
||||
AccessKey: settings.S3AccessKey, SecretKey: settings.S3SecretKey,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
brokerTLSConfiguration, err := loadClientTLS(settings.BrokerTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL, brokerTLSConfiguration)
|
||||
client, err := newRedisClient(settings.BrokerURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -157,36 +144,15 @@ func RunWorker() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metricsTLSConfiguration, err := loadServerTLS(settings.MetricsTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("attachment worker started", "consumer", consumer, "concurrency", settings.Concurrency)
|
||||
return runPipelineProcess(
|
||||
logger, settings.MetricsAddress, settings.HealthAddress, metricsTLSConfiguration, metrics.Handler(), processorWorker.Run,
|
||||
)
|
||||
return runPipelineProcess(logger, settings.MetricsAddress, metrics.Handler(), processorWorker.Run)
|
||||
}
|
||||
|
||||
func loadClientTLS(config config.ClientTLSConfig) (*tls.Config, error) {
|
||||
return tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: config.CAPath, CertificatePath: config.CertificatePath,
|
||||
PrivateKeyPath: config.PrivateKeyPath, ServerName: config.ServerName,
|
||||
})
|
||||
}
|
||||
|
||||
func loadServerTLS(config config.ServerTLSConfig) (*tls.Config, error) {
|
||||
return tlsconfig.LoadServer(tlsconfig.ServerConfig{
|
||||
CAPath: config.CAPath, CertificatePath: config.CertificatePath,
|
||||
PrivateKeyPath: config.PrivateKeyPath, AllowedClientURI: config.AllowedClientURI,
|
||||
})
|
||||
}
|
||||
|
||||
func newRedisClient(rawURL string, tlsConfiguration *tls.Config) (*redis.Client, error) {
|
||||
func newRedisClient(rawURL string) (*redis.Client, error) {
|
||||
options, err := redis.ParseURL(rawURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options.TLSConfig = tlsConfiguration.Clone()
|
||||
client := redis.NewClient(options)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
@@ -200,32 +166,19 @@ func newRedisClient(rawURL string, tlsConfiguration *tls.Config) (*redis.Client,
|
||||
func runPipelineProcess(
|
||||
logger *slog.Logger,
|
||||
metricsAddress string,
|
||||
healthAddress string,
|
||||
metricsTLSConfiguration *tls.Config,
|
||||
metricsHandler http.Handler,
|
||||
run func(context.Context) error,
|
||||
) error {
|
||||
metricsMux := http.NewServeMux()
|
||||
metricsMux.Handle("/metrics", metricsHandler)
|
||||
metricsServer := &http.Server{
|
||||
Addr: metricsAddress, Handler: metricsMux, ReadHeaderTimeout: 5 * time.Second,
|
||||
TLSConfig: metricsTLSConfiguration,
|
||||
}
|
||||
healthMux := http.NewServeMux()
|
||||
healthMux.HandleFunc("/health/live", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })
|
||||
healthServer := &http.Server{Addr: healthAddress, Handler: healthMux, ReadHeaderTimeout: 5 * time.Second}
|
||||
metricsListener, err := net.Listen("tcp", metricsAddress)
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/metrics", metricsHandler)
|
||||
mux.HandleFunc("/health/live", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })
|
||||
server := &http.Server{Addr: metricsAddress, Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
listener, err := net.Listen("tcp", metricsAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
healthListener, err := net.Listen("tcp", healthAddress)
|
||||
if err != nil {
|
||||
_ = metricsListener.Close()
|
||||
return err
|
||||
}
|
||||
serveResult := make(chan error, 2)
|
||||
go func() { serveResult <- metricsServer.Serve(tls.NewListener(metricsListener, metricsTLSConfiguration)) }()
|
||||
go func() { serveResult <- healthServer.Serve(healthListener) }()
|
||||
serveResult := make(chan error, 1)
|
||||
go func() { serveResult <- server.Serve(listener) }()
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
@@ -242,10 +195,8 @@ func runPipelineProcess(
|
||||
}
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
for _, server := range []*http.Server{metricsServer, healthServer} {
|
||||
if err := server.Shutdown(shutdownCtx); err != nil && result == nil {
|
||||
result = err
|
||||
}
|
||||
if err := server.Shutdown(shutdownCtx); err != nil && result == nil {
|
||||
result = err
|
||||
}
|
||||
if errors.Is(result, http.ErrServerClosed) || errors.Is(result, context.Canceled) {
|
||||
return nil
|
||||
|
||||
@@ -57,7 +57,7 @@ func RunReconciliation(arguments []string, output io.Writer) error {
|
||||
objects, err := objectstore.New(objectstore.Config{
|
||||
Endpoint: settings.S3Endpoint, Region: settings.S3Region, Bucket: settings.S3Bucket,
|
||||
AccessKey: settings.S3AccessKey, SecretKey: settings.S3SecretKey,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,16 +5,15 @@ import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/loginlimit"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/httpapi"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
@@ -30,7 +29,7 @@ type serverResult struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func RunServer() error {
|
||||
func RunServer(logger *slog.Logger) error {
|
||||
settings, err := config.LoadServer()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -49,11 +48,10 @@ func RunServer() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instanceUUID, err := uuid.NewRandom()
|
||||
instanceID, err := os.Hostname()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instanceID := "api-" + instanceUUID.String()
|
||||
observability, logger, err := startTelemetry("messenger-api", instanceID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -67,32 +65,16 @@ func RunServer() error {
|
||||
if err := telemetry.ObserveDatabasePool(observability.MeterProvider().Meter("messenger-api/database"), pool); err != nil {
|
||||
return err
|
||||
}
|
||||
cacheTLSConfiguration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: settings.CacheTLS.CAPath, CertificatePath: settings.CacheTLS.CertificatePath,
|
||||
PrivateKeyPath: settings.CacheTLS.PrivateKeyPath, ServerName: settings.CacheTLS.ServerName,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sessions, err := session.New(settings.CacheURL, cacheTLSConfiguration)
|
||||
sessions, err := session.New(settings.CacheURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = sessions.Close() }()
|
||||
loginLimiter, err := loginlimit.New(settings.CacheURL, loginlimit.Config{
|
||||
AccountAttempts: int64(settings.LoginRateLimitAccountAttempts),
|
||||
SourceAttempts: int64(settings.LoginRateLimitSourceAttempts),
|
||||
Window: settings.LoginRateLimitWindow,
|
||||
}, cacheTLSConfiguration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = loginLimiter.Close() }()
|
||||
passwords, err := password.New(password.Config{
|
||||
MemoryKiB: settings.PasswordMemoryKiB, Iterations: settings.PasswordIterations,
|
||||
Parallelism: settings.PasswordParallelism, SaltLength: settings.PasswordSaltLength,
|
||||
KeyLength: settings.PasswordKeyLength,
|
||||
}, settings.PasswordMaxConcurrentOperations)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -111,8 +93,7 @@ func RunServer() error {
|
||||
}
|
||||
app := httpapi.NewServer(logger, httpapi.Dependencies{
|
||||
Users: repository, Chats: repository, Messages: repository, Attachments: attachments,
|
||||
Sessions: sessions, Passwords: passwords, LoginLimiter: loginLimiter,
|
||||
Database: repository, Objects: objects,
|
||||
Sessions: sessions, Passwords: passwords, Database: repository, Objects: objects,
|
||||
Meter: observability.MeterProvider().Meter("messenger-api"), Metrics: observability.MetricsHandler(),
|
||||
}, httpapi.Config{
|
||||
SessionTTL: settings.SessionTTL, IdempotencyTTL: settings.IdempotencyTTL,
|
||||
@@ -204,6 +185,6 @@ func objectStoreConfig(settings config.ServerConfig) objectstore.Config {
|
||||
return objectstore.Config{
|
||||
Endpoint: settings.S3Endpoint, Region: settings.S3Region, Bucket: settings.S3Bucket,
|
||||
AccessKey: settings.S3AccessKey, SecretKey: settings.S3SecretKey,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, Timeout: settings.S3Timeout,
|
||||
}
|
||||
}
|
||||
|
||||
+48
-121
@@ -12,54 +12,48 @@ import (
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Address string
|
||||
HealthAddress string
|
||||
MetricsAddress string
|
||||
TLSCAPath string
|
||||
TLSCertificatePath string
|
||||
TLSPrivateKeyPath string
|
||||
TLSAllowedClientURI string
|
||||
TLSAllowedMetricsClientURI string
|
||||
DatabaseURL string
|
||||
CacheURL string
|
||||
CacheTLS ClientTLSConfig
|
||||
SessionTTL time.Duration
|
||||
IdempotencyTTL time.Duration
|
||||
LoginRateLimitAccountAttempts int
|
||||
LoginRateLimitSourceAttempts int
|
||||
LoginRateLimitWindow time.Duration
|
||||
DBMaxConns int32
|
||||
DBMinConns int32
|
||||
DBMaxConnectionAge time.Duration
|
||||
DBMaxConnectionIdle time.Duration
|
||||
DBHealthCheckPeriod time.Duration
|
||||
DependencyTimeout time.Duration
|
||||
RequestTimeout time.Duration
|
||||
HTTPReadHeaderTimeout time.Duration
|
||||
HTTPReadTimeout time.Duration
|
||||
HTTPWriteTimeout time.Duration
|
||||
HTTPIdleTimeout time.Duration
|
||||
HTTPShutdownTimeout time.Duration
|
||||
PasswordMemoryKiB uint32
|
||||
PasswordIterations uint32
|
||||
PasswordParallelism uint8
|
||||
PasswordSaltLength uint32
|
||||
PasswordKeyLength uint32
|
||||
PasswordMaxConcurrentOperations int
|
||||
SwaggerPort string
|
||||
S3Endpoint string
|
||||
S3Region string
|
||||
S3Bucket string
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3CAPath string
|
||||
S3Timeout time.Duration
|
||||
AttachmentMaxBytes int64
|
||||
AttachmentMaxPixels int64
|
||||
AttachmentBodyMemory int64
|
||||
AttachmentDecodeMemory int64
|
||||
PipelineVersion int
|
||||
Address string
|
||||
HealthAddress string
|
||||
MetricsAddress string
|
||||
TLSCAPath string
|
||||
TLSCertificatePath string
|
||||
TLSPrivateKeyPath string
|
||||
TLSAllowedClientURI string
|
||||
TLSAllowedMetricsClientURI string
|
||||
DatabaseURL string
|
||||
CacheURL string
|
||||
SessionTTL time.Duration
|
||||
IdempotencyTTL time.Duration
|
||||
DBMaxConns int32
|
||||
DBMinConns int32
|
||||
DBMaxConnectionAge time.Duration
|
||||
DBMaxConnectionIdle time.Duration
|
||||
DBHealthCheckPeriod time.Duration
|
||||
DependencyTimeout time.Duration
|
||||
RequestTimeout time.Duration
|
||||
HTTPReadHeaderTimeout time.Duration
|
||||
HTTPReadTimeout time.Duration
|
||||
HTTPWriteTimeout time.Duration
|
||||
HTTPIdleTimeout time.Duration
|
||||
HTTPShutdownTimeout time.Duration
|
||||
PasswordMemoryKiB uint32
|
||||
PasswordIterations uint32
|
||||
PasswordParallelism uint8
|
||||
PasswordSaltLength uint32
|
||||
PasswordKeyLength uint32
|
||||
SwaggerPort string
|
||||
S3Endpoint string
|
||||
S3Region string
|
||||
S3Bucket string
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3Timeout time.Duration
|
||||
AttachmentMaxBytes int64
|
||||
AttachmentMaxPixels int64
|
||||
AttachmentBodyMemory int64
|
||||
AttachmentDecodeMemory int64
|
||||
PipelineVersion int
|
||||
}
|
||||
|
||||
type MigrationConfig struct {
|
||||
@@ -87,7 +81,6 @@ type ReconciliationConfig struct {
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3CAPath string
|
||||
S3Timeout time.Duration
|
||||
}
|
||||
|
||||
@@ -108,24 +101,9 @@ type objectStorageConfig struct {
|
||||
accessKey string
|
||||
secretKey string
|
||||
useTLS bool
|
||||
caPath string
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
type ClientTLSConfig struct {
|
||||
CAPath string
|
||||
CertificatePath string
|
||||
PrivateKeyPath string
|
||||
ServerName string
|
||||
}
|
||||
|
||||
type ServerTLSConfig struct {
|
||||
CAPath string
|
||||
CertificatePath string
|
||||
PrivateKeyPath string
|
||||
AllowedClientURI string
|
||||
}
|
||||
|
||||
func LoadServer() (ServerConfig, error) {
|
||||
values, err := loadValues()
|
||||
if err != nil {
|
||||
@@ -176,10 +154,6 @@ func LoadServer() (ServerConfig, error) {
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
cacheTLS, err := loadClientTLSConfig(values, "cache.tls")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
store, err := requiredString(values, "server.session_store")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
@@ -196,18 +170,6 @@ func LoadServer() (ServerConfig, error) {
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
loginRateLimitAccountAttempts, err := integer(values, "server.login_rate_limit.account_attempts", 1, 1_000_000)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
loginRateLimitSourceAttempts, err := integer(values, "server.login_rate_limit.source_attempts", 1, 1_000_000)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
loginRateLimitWindow, err := duration(values, "server.login_rate_limit.window", time.Second, 24*time.Hour)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
requestTimeout, err := duration(values, "server.request_timeout", time.Second, 5*time.Minute)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
@@ -252,10 +214,6 @@ func LoadServer() (ServerConfig, error) {
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
passwordMaxConcurrentOperations, err := integer(values, "server.password.max_concurrent_operations", 1, 64)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
swaggerPort, err := requiredPort(values, "server.swagger_port")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
@@ -297,12 +255,9 @@ func LoadServer() (ServerConfig, error) {
|
||||
TLSCAPath: tlsCAPath, TLSCertificatePath: tlsCertificatePath,
|
||||
TLSPrivateKeyPath: tlsPrivateKeyPath, TLSAllowedClientURI: tlsAllowedClientURI,
|
||||
TLSAllowedMetricsClientURI: tlsAllowedMetricsClientURI,
|
||||
DatabaseURL: database.url, CacheURL: cacheURL, CacheTLS: cacheTLS,
|
||||
DatabaseURL: database.url, CacheURL: cacheURL,
|
||||
SessionTTL: sessionTTL, IdempotencyTTL: idempotencyTTL,
|
||||
LoginRateLimitAccountAttempts: loginRateLimitAccountAttempts,
|
||||
LoginRateLimitSourceAttempts: loginRateLimitSourceAttempts,
|
||||
LoginRateLimitWindow: loginRateLimitWindow,
|
||||
DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
DBMaxConnectionAge: database.maxConnectionAge, DBMaxConnectionIdle: database.maxConnectionIdle,
|
||||
DBHealthCheckPeriod: database.healthCheckPeriod, DependencyTimeout: database.dependencyTimeout,
|
||||
RequestTimeout: requestTimeout,
|
||||
@@ -311,10 +266,9 @@ func LoadServer() (ServerConfig, error) {
|
||||
HTTPShutdownTimeout: shutdownTimeout, PasswordMemoryKiB: uint32(passwordMemory),
|
||||
PasswordIterations: uint32(passwordIterations), PasswordParallelism: uint8(passwordParallelism),
|
||||
PasswordSaltLength: uint32(passwordSaltLength), PasswordKeyLength: uint32(passwordKeyLength),
|
||||
PasswordMaxConcurrentOperations: passwordMaxConcurrentOperations,
|
||||
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
S3AccessKey: storage.accessKey, S3SecretKey: storage.secretKey,
|
||||
S3UseTLS: storage.useTLS, S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
S3UseTLS: storage.useTLS, S3Timeout: storage.timeout,
|
||||
AttachmentMaxBytes: int64(attachmentMaxBytes), AttachmentMaxPixels: int64(attachmentMaxPixels),
|
||||
AttachmentBodyMemory: int64(attachmentBodyMemory),
|
||||
AttachmentDecodeMemory: int64(attachmentDecodeMemory),
|
||||
@@ -362,7 +316,7 @@ func LoadReconciliation() (ReconciliationConfig, error) {
|
||||
DBHealthCheckPeriod: database.healthCheckPeriod, DependencyTimeout: database.dependencyTimeout,
|
||||
S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
S3AccessKey: storage.accessKey, S3SecretKey: storage.secretKey,
|
||||
S3UseTLS: storage.useTLS, S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
S3UseTLS: storage.useTLS, S3Timeout: storage.timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -391,40 +345,13 @@ func loadObjectStorageConfig(values *viper.Viper) (objectStorageConfig, error) {
|
||||
if err != nil {
|
||||
return objectStorageConfig{}, err
|
||||
}
|
||||
caPath, err := requiredString(values, "object_storage.ca_path")
|
||||
if err != nil {
|
||||
return objectStorageConfig{}, err
|
||||
}
|
||||
timeout, err := duration(values, "object_storage.timeout", time.Second, 5*time.Minute)
|
||||
if err != nil {
|
||||
return objectStorageConfig{}, err
|
||||
}
|
||||
return objectStorageConfig{
|
||||
endpoint: endpoint, region: region, bucket: bucket, accessKey: accessKey,
|
||||
secretKey: secretKey, useTLS: useTLS, caPath: caPath, timeout: timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func loadClientTLSConfig(values *viper.Viper, prefix string) (ClientTLSConfig, error) {
|
||||
caPath, err := requiredString(values, prefix+".ca_path")
|
||||
if err != nil {
|
||||
return ClientTLSConfig{}, err
|
||||
}
|
||||
certificatePath, err := requiredString(values, prefix+".certificate_path")
|
||||
if err != nil {
|
||||
return ClientTLSConfig{}, err
|
||||
}
|
||||
privateKeyPath, err := requiredString(values, prefix+".private_key_path")
|
||||
if err != nil {
|
||||
return ClientTLSConfig{}, err
|
||||
}
|
||||
serverName, err := requiredString(values, prefix+".server_name")
|
||||
if err != nil {
|
||||
return ClientTLSConfig{}, err
|
||||
}
|
||||
return ClientTLSConfig{
|
||||
CAPath: caPath, CertificatePath: certificatePath,
|
||||
PrivateKeyPath: privateKeyPath, ServerName: serverName,
|
||||
secretKey: secretKey, useTLS: useTLS, timeout: timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -56,10 +56,6 @@ func TestLoadServerLoadsTLSAndHealthSettings(t *testing.T) {
|
||||
require.Equal(t, "/run/security/internal-ca/ca.crt", settings.TLSCAPath)
|
||||
require.Equal(t, "spiffe://mtusi/lab7/load-balancer", settings.TLSAllowedClientURI)
|
||||
require.Equal(t, "spiffe://mtusi/lab7/prometheus", settings.TLSAllowedMetricsClientURI)
|
||||
require.Equal(t, 5, settings.LoginRateLimitAccountAttempts)
|
||||
require.Equal(t, 20, settings.LoginRateLimitSourceAttempts)
|
||||
require.Equal(t, time.Minute, settings.LoginRateLimitWindow)
|
||||
require.Equal(t, 2, settings.PasswordMaxConcurrentOperations)
|
||||
}
|
||||
|
||||
func TestLoadServerRejectsNonLoopbackHealthAddress(t *testing.T) {
|
||||
@@ -78,35 +74,6 @@ func TestLoadServerRejectsLoopbackMetricsAddress(t *testing.T) {
|
||||
require.ErrorContains(t, err, "server.metrics_address: must use a non-loopback host")
|
||||
}
|
||||
|
||||
func TestLoadServerUsesRenderedOpenBaoSecrets(t *testing.T) {
|
||||
setConfigEnvironment(t, validTestConfig)
|
||||
path := filepath.Join(t.TempDir(), "secrets.json")
|
||||
require.NoError(t, os.WriteFile(path, []byte(`{
|
||||
"database_url":"postgres://openbao/database",
|
||||
"cache_url":"rediss://openbao/cache",
|
||||
"s3_access_key":"openbao-api",
|
||||
"s3_secret_key":"openbao-secret"
|
||||
}`), 0o600))
|
||||
t.Setenv("MESSENGER_SECRETS_FILE", path)
|
||||
|
||||
settings, err := LoadServer()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "postgres://openbao/database", settings.DatabaseURL)
|
||||
require.Equal(t, "rediss://openbao/cache", settings.CacheURL)
|
||||
require.Equal(t, "openbao-api", settings.S3AccessKey)
|
||||
require.Equal(t, "openbao-secret", settings.S3SecretKey)
|
||||
}
|
||||
|
||||
func TestLoadServerRejectsUnknownOpenBaoSecret(t *testing.T) {
|
||||
setConfigEnvironment(t, validTestConfig)
|
||||
path := filepath.Join(t.TempDir(), "secrets.json")
|
||||
require.NoError(t, os.WriteFile(path, []byte(`{"root_token":"forbidden"}`), 0o600))
|
||||
t.Setenv("MESSENGER_SECRETS_FILE", path)
|
||||
|
||||
_, err := LoadServer()
|
||||
require.ErrorContains(t, err, "unsupported field root_token")
|
||||
}
|
||||
|
||||
func setConfigEnvironment(t *testing.T, content string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), "messenger.yaml")
|
||||
@@ -136,10 +103,6 @@ server:
|
||||
session_store: valkey
|
||||
session_ttl: 1h
|
||||
idempotency_ttl: 24h
|
||||
login_rate_limit:
|
||||
account_attempts: 5
|
||||
source_attempts: 20
|
||||
window: 1m
|
||||
request_timeout: 5s
|
||||
http:
|
||||
read_header_timeout: 5s
|
||||
@@ -153,7 +116,6 @@ server:
|
||||
parallelism: 2
|
||||
salt_length: 16
|
||||
key_length: 32
|
||||
max_concurrent_operations: 2
|
||||
database:
|
||||
min_connections: 0
|
||||
max_connections: 4
|
||||
@@ -161,17 +123,10 @@ database:
|
||||
max_connection_idle: 1m
|
||||
health_check_period: 30s
|
||||
dependency_timeout: 5s
|
||||
cache:
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/client/tls.crt
|
||||
private_key_path: /run/security/client/tls.key
|
||||
server_name: redis-gateway
|
||||
migration:
|
||||
timeout: 30s
|
||||
object_storage:
|
||||
use_tls: false
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
timeout: 5s
|
||||
attachments:
|
||||
max_bytes: 10485760
|
||||
@@ -181,11 +136,6 @@ attachments:
|
||||
pipeline:
|
||||
version: 1
|
||||
broker:
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/client/tls.crt
|
||||
private_key_path: /run/security/client/tls.key
|
||||
server_name: redis-gateway
|
||||
stream: attachment-jobs
|
||||
consumer_group: attachment-workers
|
||||
failed_stream: attachment-jobs-failed
|
||||
@@ -214,10 +164,4 @@ worker:
|
||||
memory_bytes: 738197504
|
||||
monitoring:
|
||||
metrics_address: 0.0.0.0:9091
|
||||
health_address: 127.0.0.1:9092
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/metrics/tls.crt
|
||||
private_key_path: /run/security/metrics/tls.key
|
||||
allowed_client_uri: spiffe://mtusi/lab7/prometheus
|
||||
`
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -34,14 +32,6 @@ var environmentKeys = map[string]string{
|
||||
"broker.url": "BROKER_URL",
|
||||
}
|
||||
|
||||
var secretKeys = map[string]string{
|
||||
"database_url": "database.url",
|
||||
"cache_url": "cache.url",
|
||||
"broker_url": "broker.url",
|
||||
"s3_access_key": "object_storage.access_key",
|
||||
"s3_secret_key": "object_storage.secret_key",
|
||||
}
|
||||
|
||||
func loadValues() (*viper.Viper, error) {
|
||||
path := strings.TrimSpace(os.Getenv("MESSENGER_CONFIG_PATH"))
|
||||
if path == "" {
|
||||
@@ -60,40 +50,5 @@ func loadValues() (*viper.Viper, error) {
|
||||
return nil, fmt.Errorf("bind %s: %w", name, err)
|
||||
}
|
||||
}
|
||||
if err := loadSecretFile(values, strings.TrimSpace(os.Getenv("MESSENGER_SECRETS_FILE"))); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func loadSecretFile(values *viper.Viper, path string) error {
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open messenger secrets: %w", err)
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
decoder := json.NewDecoder(io.LimitReader(file, 64<<10))
|
||||
var secrets map[string]string
|
||||
if err := decoder.Decode(&secrets); err != nil {
|
||||
return fmt.Errorf("decode messenger secrets: %w", err)
|
||||
}
|
||||
var trailing any
|
||||
if err := decoder.Decode(&trailing); !errors.Is(err, io.EOF) {
|
||||
return errors.New("decode messenger secrets: trailing JSON value")
|
||||
}
|
||||
for name, value := range secrets {
|
||||
key, ok := secretKeys[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("messenger secrets: unsupported field %s", name)
|
||||
}
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return fmt.Errorf("messenger secrets: %s is empty", name)
|
||||
}
|
||||
values.Set(key, value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ type DispatcherConfig struct {
|
||||
DBHealthCheckPeriod time.Duration
|
||||
DependencyTimeout time.Duration
|
||||
BrokerURL string
|
||||
BrokerTLS ClientTLSConfig
|
||||
Stream string
|
||||
ConsumerGroup string
|
||||
FailedStream string
|
||||
@@ -32,8 +31,6 @@ type DispatcherConfig struct {
|
||||
CleanupInterval time.Duration
|
||||
CleanupBatchSize int
|
||||
MetricsAddress string
|
||||
HealthAddress string
|
||||
MetricsTLS ServerTLSConfig
|
||||
}
|
||||
|
||||
type WorkerConfig struct {
|
||||
@@ -50,10 +47,8 @@ type WorkerConfig struct {
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3CAPath string
|
||||
S3Timeout time.Duration
|
||||
BrokerURL string
|
||||
BrokerTLS ClientTLSConfig
|
||||
Stream string
|
||||
ConsumerGroup string
|
||||
FailedStream string
|
||||
@@ -72,8 +67,6 @@ type WorkerConfig struct {
|
||||
AttachmentMaxPixels int64
|
||||
MemoryBytes int64
|
||||
MetricsAddress string
|
||||
HealthAddress string
|
||||
MetricsTLS ServerTLSConfig
|
||||
}
|
||||
|
||||
type JobAdminConfig struct {
|
||||
@@ -123,10 +116,6 @@ func LoadDispatcher() (DispatcherConfig, error) {
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
}
|
||||
brokerTLS, err := loadClientTLSConfig(values, "broker.tls")
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
}
|
||||
batchSize, err := integer(values, "outbox.batch_size", 1, 1000)
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
@@ -163,24 +152,16 @@ func LoadDispatcher() (DispatcherConfig, error) {
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
}
|
||||
healthAddress, err := loopbackAddress(values, "monitoring.health_address")
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
}
|
||||
metricsTLS, err := loadServerTLSConfig(values, "monitoring.tls")
|
||||
if err != nil {
|
||||
return DispatcherConfig{}, err
|
||||
}
|
||||
return DispatcherConfig{
|
||||
DatabaseURL: database.url, DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
DBMaxConnectionAge: database.maxConnectionAge, DBMaxConnectionIdle: database.maxConnectionIdle,
|
||||
DBHealthCheckPeriod: database.healthCheckPeriod, DependencyTimeout: database.dependencyTimeout,
|
||||
BrokerURL: broker.url, BrokerTLS: brokerTLS, Stream: broker.stream, ConsumerGroup: broker.consumerGroup,
|
||||
BrokerURL: broker.url, Stream: broker.stream, ConsumerGroup: broker.consumerGroup,
|
||||
FailedStream: broker.failedStream, FailedStreamMaxLength: int64(broker.failedStreamMaxLength),
|
||||
BatchSize: batchSize, LeaseDuration: leaseDuration, PollInterval: pollInterval,
|
||||
RecoveryInterval: recoveryInterval, RetryDelay: retryDelay,
|
||||
Retention: retention, CleanupInterval: cleanupInterval, CleanupBatchSize: cleanupBatchSize,
|
||||
MetricsAddress: metricsAddress, HealthAddress: healthAddress, MetricsTLS: metricsTLS,
|
||||
MetricsAddress: metricsAddress,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -201,10 +182,6 @@ func LoadWorker() (WorkerConfig, error) {
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
}
|
||||
brokerTLS, err := loadClientTLSConfig(values, "broker.tls")
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
}
|
||||
concurrency, err := integer(values, "worker.concurrency", 1, 64)
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
@@ -270,22 +247,13 @@ func LoadWorker() (WorkerConfig, error) {
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
}
|
||||
healthAddress, err := loopbackAddress(values, "monitoring.health_address")
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
}
|
||||
metricsTLS, err := loadServerTLSConfig(values, "monitoring.tls")
|
||||
if err != nil {
|
||||
return WorkerConfig{}, err
|
||||
}
|
||||
return WorkerConfig{
|
||||
DatabaseURL: database.url, DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
DBMaxConnectionAge: database.maxConnectionAge, DBMaxConnectionIdle: database.maxConnectionIdle,
|
||||
DBHealthCheckPeriod: database.healthCheckPeriod, DependencyTimeout: database.dependencyTimeout,
|
||||
S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
S3AccessKey: storage.accessKey, S3SecretKey: storage.secretKey, S3UseTLS: storage.useTLS,
|
||||
S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
BrokerURL: broker.url, BrokerTLS: brokerTLS, Stream: broker.stream,
|
||||
S3Timeout: storage.timeout, BrokerURL: broker.url, Stream: broker.stream,
|
||||
ConsumerGroup: broker.consumerGroup, FailedStream: broker.failedStream,
|
||||
FailedStreamMaxLength: int64(broker.failedStreamMaxLength),
|
||||
Concurrency: concurrency, Prefetch: prefetch, LeaseDuration: leaseDuration,
|
||||
@@ -293,7 +261,6 @@ func LoadWorker() (WorkerConfig, error) {
|
||||
ReclaimInterval: reclaimInterval, MaxAttempts: maxAttempts, RetryBase: retryBase, RetryMax: retryMax,
|
||||
AttachmentMaxBytes: int64(attachmentMaxBytes), AttachmentMaxPixels: int64(attachmentMaxPixels),
|
||||
MemoryBytes: int64(memoryBytes), MetricsAddress: metricsAddress,
|
||||
HealthAddress: healthAddress, MetricsTLS: metricsTLS,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -312,29 +279,6 @@ func metricsAddress(values *viper.Viper) (string, error) {
|
||||
return address, nil
|
||||
}
|
||||
|
||||
func loadServerTLSConfig(values *viper.Viper, prefix string) (ServerTLSConfig, error) {
|
||||
caPath, err := requiredString(values, prefix+".ca_path")
|
||||
if err != nil {
|
||||
return ServerTLSConfig{}, err
|
||||
}
|
||||
certificatePath, err := requiredString(values, prefix+".certificate_path")
|
||||
if err != nil {
|
||||
return ServerTLSConfig{}, err
|
||||
}
|
||||
privateKeyPath, err := requiredString(values, prefix+".private_key_path")
|
||||
if err != nil {
|
||||
return ServerTLSConfig{}, err
|
||||
}
|
||||
allowedClientURI, err := requiredString(values, prefix+".allowed_client_uri")
|
||||
if err != nil {
|
||||
return ServerTLSConfig{}, err
|
||||
}
|
||||
return ServerTLSConfig{
|
||||
CAPath: caPath, CertificatePath: certificatePath,
|
||||
PrivateKeyPath: privateKeyPath, AllowedClientURI: allowedClientURI,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func loadBrokerConfig(values *viper.Viper) (brokerConfig, error) {
|
||||
url, err := requiredString(values, "broker.url")
|
||||
if err != nil {
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
package loginlimit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/valkey-io/valkey-go"
|
||||
)
|
||||
|
||||
const keyPrefix = "login-rate:{login}:"
|
||||
|
||||
var (
|
||||
ErrInvalidConfig = errors.New("invalid login rate limit configuration")
|
||||
ErrStore = errors.New("login rate limit store unavailable")
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AccountAttempts int64
|
||||
SourceAttempts int64
|
||||
Window time.Duration
|
||||
}
|
||||
|
||||
type Limiter struct {
|
||||
client valkey.Client
|
||||
script *valkey.Lua
|
||||
config Config
|
||||
}
|
||||
|
||||
func New(rawURL string, config Config, tlsConfiguration ...*tls.Config) (*Limiter, error) {
|
||||
if config.AccountAttempts < 1 || config.SourceAttempts < 1 || config.Window < time.Second {
|
||||
return nil, ErrInvalidConfig
|
||||
}
|
||||
option, err := valkey.ParseURL(rawURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: parse Valkey URL: %w", ErrStore, err)
|
||||
}
|
||||
if len(tlsConfiguration) > 0 && tlsConfiguration[0] != nil {
|
||||
option.TLSConfig = tlsConfiguration[0].Clone()
|
||||
}
|
||||
option.DisableCache = true
|
||||
client, err := valkey.NewClient(option)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: create Valkey client: %w", ErrStore, err)
|
||||
}
|
||||
return &Limiter{client: client, script: valkey.NewLuaScript(limitScript), config: config}, nil
|
||||
}
|
||||
|
||||
func (l *Limiter) Allow(ctx context.Context, username, source string) (bool, time.Duration, error) {
|
||||
result, err := l.script.Exec(ctx, l.client,
|
||||
[]string{key("account", username), key("source", source)},
|
||||
[]string{
|
||||
strconv.FormatInt(l.config.Window.Milliseconds(), 10),
|
||||
strconv.FormatInt(l.config.AccountAttempts, 10),
|
||||
strconv.FormatInt(l.config.SourceAttempts, 10),
|
||||
},
|
||||
).AsIntSlice()
|
||||
if err != nil {
|
||||
return false, 0, fmt.Errorf("%w: account login attempt: %w", ErrStore, err)
|
||||
}
|
||||
if len(result) != 2 {
|
||||
return false, 0, fmt.Errorf("%w: unexpected script result", ErrStore)
|
||||
}
|
||||
return result[0] == 1, time.Duration(result[1]) * time.Millisecond, nil
|
||||
}
|
||||
|
||||
func (l *Limiter) Close() error {
|
||||
l.client.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func key(scope, value string) string {
|
||||
digest := sha256.Sum256([]byte(value))
|
||||
return keyPrefix + scope + ":" + hex.EncodeToString(digest[:])
|
||||
}
|
||||
|
||||
const limitScript = `
|
||||
local function increment(key, window)
|
||||
local count = redis.call('INCR', key)
|
||||
if count == 1 then
|
||||
redis.call('PEXPIRE', key, window)
|
||||
end
|
||||
local ttl = redis.call('PTTL', key)
|
||||
if ttl < 1 then
|
||||
redis.call('PEXPIRE', key, window)
|
||||
ttl = window
|
||||
end
|
||||
return count, ttl
|
||||
end
|
||||
|
||||
local window = tonumber(ARGV[1])
|
||||
local account_count, account_ttl = increment(KEYS[1], window)
|
||||
local source_count, source_ttl = increment(KEYS[2], window)
|
||||
local retry_after = 0
|
||||
|
||||
if account_count > tonumber(ARGV[2]) then
|
||||
retry_after = account_ttl
|
||||
end
|
||||
if source_count > tonumber(ARGV[3]) and source_ttl > retry_after then
|
||||
retry_after = source_ttl
|
||||
end
|
||||
if retry_after > 0 then
|
||||
return {0, retry_after}
|
||||
end
|
||||
return {1, 0}
|
||||
`
|
||||
@@ -1,111 +0,0 @@
|
||||
package loginlimit_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/loginlimit"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
)
|
||||
|
||||
func TestLimitIsSharedByInstances(t *testing.T) {
|
||||
rawURL := testCacheURL(t)
|
||||
tlsConfiguration := testCacheTLS(t)
|
||||
config := loginlimit.Config{AccountAttempts: 5, SourceAttempts: 20, Window: time.Minute}
|
||||
first, err := loginlimit.New(rawURL, config, tlsConfiguration)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, first.Close()) })
|
||||
second, err := loginlimit.New(rawURL, config, tlsConfiguration)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, second.Close()) })
|
||||
|
||||
username := "rate_" + uuid.NewString()
|
||||
limiters := []*loginlimit.Limiter{first, second}
|
||||
results := make(chan bool, 16)
|
||||
errors := make(chan error, 16)
|
||||
var group sync.WaitGroup
|
||||
for i := range 16 {
|
||||
group.Add(1)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
allowed, retryAfter, err := limiters[i%len(limiters)].Allow(context.Background(), username, "192.0.2.10")
|
||||
if err != nil {
|
||||
errors <- err
|
||||
return
|
||||
}
|
||||
if !allowed && retryAfter <= 0 {
|
||||
errors <- loginlimit.ErrStore
|
||||
return
|
||||
}
|
||||
results <- allowed
|
||||
}()
|
||||
}
|
||||
group.Wait()
|
||||
close(results)
|
||||
close(errors)
|
||||
for err := range errors {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
var allowed int
|
||||
for result := range results {
|
||||
if result {
|
||||
allowed++
|
||||
}
|
||||
}
|
||||
require.Equal(t, int(config.AccountAttempts), allowed)
|
||||
}
|
||||
|
||||
func TestSourceLimitCoversDifferentAccounts(t *testing.T) {
|
||||
limiter, err := loginlimit.New(testCacheURL(t), loginlimit.Config{
|
||||
AccountAttempts: 10,
|
||||
SourceAttempts: 2,
|
||||
Window: time.Minute,
|
||||
}, testCacheTLS(t))
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, limiter.Close()) })
|
||||
|
||||
suffix := uuid.NewString()
|
||||
for i, expected := range []bool{true, true, false} {
|
||||
allowed, retryAfter, err := limiter.Allow(context.Background(), suffix+string(rune('a'+i)), "198.51.100.20")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, allowed)
|
||||
if !allowed {
|
||||
require.Positive(t, retryAfter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testCacheTLS(t *testing.T) *tls.Config {
|
||||
t.Helper()
|
||||
configuration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: os.Getenv("TEST_CACHE_TLS_CA_PATH"),
|
||||
CertificatePath: os.Getenv("TEST_CACHE_TLS_CERTIFICATE_PATH"),
|
||||
PrivateKeyPath: os.Getenv("TEST_CACHE_TLS_PRIVATE_KEY_PATH"),
|
||||
ServerName: os.Getenv("TEST_CACHE_TLS_SERVER_NAME"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return configuration
|
||||
}
|
||||
|
||||
func testCacheURL(t *testing.T) string {
|
||||
t.Helper()
|
||||
rawURL := strings.TrimSpace(os.Getenv("TEST_CACHE_URL"))
|
||||
if rawURL != "" {
|
||||
return rawURL
|
||||
}
|
||||
path := strings.TrimSpace(os.Getenv("TEST_CACHE_URL_FILE"))
|
||||
if path == "" {
|
||||
t.Skip("set TEST_CACHE_URL or TEST_CACHE_URL_FILE to run integration tests")
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -152,6 +153,22 @@ func attachmentVariant(query url.Values) (string, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
var traceparentPattern = regexp.MustCompile(`^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`)
|
||||
|
||||
func traceparent(value string) string {
|
||||
if traceparentPattern.MatchString(value) {
|
||||
return value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func tracestate(value string) string {
|
||||
if len(value) <= 512 {
|
||||
return value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func attachmentIDFromRequest(r *http.Request) (string, *apiError) {
|
||||
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||
attachmentID, valid := canonicalID(parts[3])
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
@@ -25,19 +21,10 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
|
||||
if !ok {
|
||||
return unauthorized()
|
||||
}
|
||||
allowed, retryAfter, err := s.loginLimiter.Allow(r.Context(), username, loginSource(r))
|
||||
if err != nil {
|
||||
return unavailable()
|
||||
}
|
||||
if !allowed {
|
||||
retrySeconds := max(int64(1), int64(math.Ceil(retryAfter.Seconds())))
|
||||
w.Header().Set("Retry-After", strconv.FormatInt(retrySeconds, 10))
|
||||
return rateLimited()
|
||||
}
|
||||
credentials, err := s.userRepository.UserByUsername(r.Context(), username)
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
if _, verifyErr := s.passwords.Verify(passwordValue, s.passwords.DummyHash()); verifyErr != nil {
|
||||
return passwordOperationError(verifyErr)
|
||||
return internalError()
|
||||
}
|
||||
return unauthorized()
|
||||
}
|
||||
@@ -46,14 +33,11 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
|
||||
}
|
||||
verified, err := s.passwords.Verify(passwordValue, credentials.PasswordHash)
|
||||
if err != nil {
|
||||
return passwordOperationError(err)
|
||||
return internalError()
|
||||
}
|
||||
if !verified {
|
||||
return unauthorized()
|
||||
}
|
||||
if rehashErr := s.rehashPassword(r.Context(), credentials, passwordValue); rehashErr != nil {
|
||||
return rehashErr
|
||||
}
|
||||
token, expiresAt, err := s.sessions.Create(r.Context(), credentials.ID, s.sessionTTL)
|
||||
if err != nil {
|
||||
return unavailable()
|
||||
@@ -67,57 +51,6 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) rehashPassword(ctx context.Context, credentials model.UserCredentials, passwordValue string) *apiError {
|
||||
needsRehash, err := s.passwords.NeedsRehash(credentials.PasswordHash)
|
||||
if err != nil {
|
||||
return passwordOperationError(err)
|
||||
}
|
||||
if !needsRehash {
|
||||
return nil
|
||||
}
|
||||
passwordHash, err := s.passwords.Hash(passwordValue)
|
||||
if err != nil {
|
||||
return passwordOperationError(err)
|
||||
}
|
||||
updated, err := s.userRepository.UpdatePasswordHash(ctx, credentials.ID, credentials.PasswordHash, passwordHash)
|
||||
if err != nil {
|
||||
return unavailable()
|
||||
}
|
||||
if updated {
|
||||
return nil
|
||||
}
|
||||
current, err := s.userRepository.UserByUsername(ctx, credentials.Username)
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return unauthorized()
|
||||
}
|
||||
if err != nil {
|
||||
return unavailable()
|
||||
}
|
||||
verified, err := s.passwords.Verify(passwordValue, current.PasswordHash)
|
||||
if err != nil {
|
||||
return passwordOperationError(err)
|
||||
}
|
||||
if !verified {
|
||||
return unauthorized()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loginSource(r *http.Request) string {
|
||||
forwarded := strings.Split(r.Header.Get("X-Forwarded-For"), ",")
|
||||
// Nginx appends the address it observed last, so preceding client-supplied entries are not trusted.
|
||||
if address := net.ParseIP(strings.TrimSpace(forwarded[len(forwarded)-1])); address != nil {
|
||||
return address.String()
|
||||
}
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err == nil {
|
||||
if address := net.ParseIP(host); address != nil {
|
||||
return address.String()
|
||||
}
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func singleBasicAuth(r *http.Request) (string, string, bool) {
|
||||
if len(r.Header.Values("Authorization")) != 1 {
|
||||
return "", "", false
|
||||
|
||||
@@ -2,10 +2,7 @@ package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/password"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -39,17 +36,6 @@ func unauthorized() *apiError {
|
||||
return &apiError{http.StatusUnauthorized, errorCodeUnauthorized, "authentication required"}
|
||||
}
|
||||
|
||||
func rateLimited() *apiError {
|
||||
return &apiError{http.StatusTooManyRequests, errorCodeRateLimited, "too many requests"}
|
||||
}
|
||||
|
||||
func passwordOperationError(err error) *apiError {
|
||||
if errors.Is(err, password.ErrBusy) {
|
||||
return rateLimited()
|
||||
}
|
||||
return internalError()
|
||||
}
|
||||
|
||||
func notFound() *apiError {
|
||||
return &apiError{http.StatusNotFound, errorCodeNotFound, "resource not found"}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,12 @@ func (s *Server) readiness(w http.ResponseWriter, r *http.Request) *apiError {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
||||
defer cancel()
|
||||
if err := s.database.Ping(ctx); err != nil {
|
||||
s.logger.ErrorContext(ctx, "readiness dependency failed", "dependency", "postgres", "error", err)
|
||||
return unavailable()
|
||||
}
|
||||
if err := s.sessions.Ping(ctx); err != nil {
|
||||
s.logger.ErrorContext(ctx, "readiness dependency failed", "dependency", "valkey", "error", err)
|
||||
return unavailable()
|
||||
}
|
||||
if err := s.objects.Ping(ctx); err != nil {
|
||||
s.logger.ErrorContext(ctx, "readiness dependency failed", "dependency", "s3", "error", err)
|
||||
return unavailable()
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
|
||||
@@ -64,7 +61,7 @@ func (s *Server) users(w http.ResponseWriter, r *http.Request) *apiError {
|
||||
}
|
||||
passwordHash, err := s.passwords.Hash(input.Password)
|
||||
if err != nil {
|
||||
return passwordOperationError(err)
|
||||
return internalError()
|
||||
}
|
||||
user, err := s.userRepository.CreateUser(r.Context(), input.Username, input.DisplayName, passwordHash)
|
||||
if errors.Is(err, model.ErrConflict) {
|
||||
|
||||
@@ -12,7 +12,6 @@ type UserRepository interface {
|
||||
CreateUser(context.Context, string, string, string) (model.User, error)
|
||||
UserByID(context.Context, string) (model.User, error)
|
||||
UserByUsername(context.Context, string) (model.UserCredentials, error)
|
||||
UpdatePasswordHash(context.Context, string, string, string) (bool, error)
|
||||
}
|
||||
|
||||
type ChatRepository interface {
|
||||
@@ -46,10 +45,5 @@ type SessionStore interface {
|
||||
type PasswordService interface {
|
||||
Hash(string) (string, error)
|
||||
Verify(string, string) (bool, error)
|
||||
NeedsRehash(string) (bool, error)
|
||||
DummyHash() string
|
||||
}
|
||||
|
||||
type LoginLimiter interface {
|
||||
Allow(context.Context, string, string) (bool, time.Duration, error)
|
||||
}
|
||||
|
||||
@@ -19,17 +19,16 @@ import (
|
||||
)
|
||||
|
||||
type Dependencies struct {
|
||||
Users UserRepository
|
||||
Chats ChatRepository
|
||||
Messages MessageRepository
|
||||
Attachments AttachmentService
|
||||
Sessions SessionStore
|
||||
Passwords PasswordService
|
||||
LoginLimiter LoginLimiter
|
||||
Database HealthChecker
|
||||
Objects HealthChecker
|
||||
Meter metric.Meter
|
||||
Metrics http.Handler
|
||||
Users UserRepository
|
||||
Chats ChatRepository
|
||||
Messages MessageRepository
|
||||
Attachments AttachmentService
|
||||
Sessions SessionStore
|
||||
Passwords PasswordService
|
||||
Database HealthChecker
|
||||
Objects HealthChecker
|
||||
Meter metric.Meter
|
||||
Metrics http.Handler
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -47,7 +46,6 @@ type Server struct {
|
||||
attachments AttachmentService
|
||||
sessions SessionStore
|
||||
passwords PasswordService
|
||||
loginLimiter LoginLimiter
|
||||
database HealthChecker
|
||||
objects HealthChecker
|
||||
sessionTTL time.Duration
|
||||
@@ -79,8 +77,7 @@ func NewServer(
|
||||
userRepository: dependencies.Users, chatRepository: dependencies.Chats,
|
||||
messageRepository: dependencies.Messages,
|
||||
attachments: dependencies.Attachments, sessions: dependencies.Sessions,
|
||||
passwords: dependencies.Passwords, loginLimiter: dependencies.LoginLimiter,
|
||||
database: dependencies.Database, objects: dependencies.Objects,
|
||||
passwords: dependencies.Passwords, database: dependencies.Database, objects: dependencies.Objects,
|
||||
sessionTTL: config.SessionTTL, idempotencyTTL: config.IdempotencyTTL, requestTTL: config.RequestTTL,
|
||||
instanceID: config.InstanceID, logger: logger, swaggerPort: config.SwaggerPort,
|
||||
metrics: newMetrics(dependencies.Meter, dependencies.Metrics),
|
||||
@@ -115,7 +112,6 @@ func (s *Server) MetricsHandler() http.Handler {
|
||||
}
|
||||
|
||||
func (s *Server) serveHealth(w http.ResponseWriter, r *http.Request, handler requestHandler) {
|
||||
w.Header().Set("X-Instance-Id", s.instanceID)
|
||||
if err := handler(w, r); err != nil {
|
||||
writeError(w, "", err)
|
||||
}
|
||||
@@ -169,9 +165,6 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request) {
|
||||
if apiErr.status == http.StatusUnauthorized {
|
||||
wrapped.Header().Set("WWW-Authenticate", authenticationChallenge(r))
|
||||
}
|
||||
if apiErr.status == http.StatusTooManyRequests && wrapped.Header().Get("Retry-After") == "" {
|
||||
wrapped.Header().Set("Retry-After", "1")
|
||||
}
|
||||
writeError(wrapped, requestID, apiErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/password"
|
||||
)
|
||||
|
||||
var errDependency = errors.New("dependency unavailable")
|
||||
@@ -35,15 +34,14 @@ func (s *MessengerSuite) SetupTest() {
|
||||
}
|
||||
|
||||
type messengerStoreStub struct {
|
||||
pingErr error
|
||||
userByID model.User
|
||||
userByIDErr error
|
||||
credentials model.UserCredentials
|
||||
credentialsErr error
|
||||
message model.Message
|
||||
messageReplay bool
|
||||
messageErr error
|
||||
updatePasswordHash func(context.Context, string, string, string) (bool, error)
|
||||
pingErr error
|
||||
userByID model.User
|
||||
userByIDErr error
|
||||
credentials model.UserCredentials
|
||||
credentialsErr error
|
||||
message model.Message
|
||||
messageReplay bool
|
||||
messageErr error
|
||||
}
|
||||
|
||||
func (s messengerStoreStub) Ping(context.Context) error { return s.pingErr }
|
||||
@@ -56,12 +54,6 @@ func (s messengerStoreStub) UserByID(context.Context, string) (model.User, error
|
||||
func (s messengerStoreStub) UserByUsername(context.Context, string) (model.UserCredentials, error) {
|
||||
return s.credentials, s.credentialsErr
|
||||
}
|
||||
func (s messengerStoreStub) UpdatePasswordHash(ctx context.Context, userID, previousHash, passwordHash string) (bool, error) {
|
||||
if s.updatePasswordHash == nil {
|
||||
return false, nil
|
||||
}
|
||||
return s.updatePasswordHash(ctx, userID, previousHash, passwordHash)
|
||||
}
|
||||
func (messengerStoreStub) CreateChat(context.Context, string, []string, string) (model.Chat, error) {
|
||||
return model.Chat{}, nil
|
||||
}
|
||||
@@ -117,37 +109,15 @@ func (s sessionStub) UserID(context.Context, string) (string, error) { return s.
|
||||
func (sessionStub) Delete(context.Context, string) error { return nil }
|
||||
|
||||
type passwordsStub struct {
|
||||
verified bool
|
||||
err error
|
||||
hash string
|
||||
hashErr error
|
||||
needsRehash bool
|
||||
needsRehashErr error
|
||||
verified bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (s passwordsStub) Hash(string) (string, error) {
|
||||
if s.hash == "" {
|
||||
return "hash", s.hashErr
|
||||
}
|
||||
return s.hash, s.hashErr
|
||||
}
|
||||
func (passwordsStub) DummyHash() string { return "hash" }
|
||||
func (passwordsStub) Hash(string) (string, error) { return "hash", nil }
|
||||
func (passwordsStub) DummyHash() string { return "hash" }
|
||||
func (s passwordsStub) Verify(string, string) (bool, error) {
|
||||
return s.verified, s.err
|
||||
}
|
||||
func (s passwordsStub) NeedsRehash(string) (bool, error) {
|
||||
return s.needsRehash, s.needsRehashErr
|
||||
}
|
||||
|
||||
type loginLimiterStub struct {
|
||||
allowed bool
|
||||
retryAfter time.Duration
|
||||
err error
|
||||
}
|
||||
|
||||
func (s loginLimiterStub) Allow(context.Context, string, string) (bool, time.Duration, error) {
|
||||
return s.allowed, s.retryAfter, s.err
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestReadinessReturnsUnavailableForDependencyFailure() {
|
||||
t := s.T()
|
||||
@@ -240,64 +210,6 @@ func (s *MessengerSuite) TestAuthenticationChallenges() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestSessionCreationReturnsRateLimitWithRetryAfter() {
|
||||
server := s.serverWithLoginLimiter(
|
||||
messengerStoreStub{}, sessionStub{}, passwordsStub{},
|
||||
loginLimiterStub{retryAfter: 1500 * time.Millisecond},
|
||||
)
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", nil)
|
||||
request.SetBasicAuth("student", "T3st-password-123")
|
||||
response := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(response, request)
|
||||
|
||||
s.Equal(http.StatusTooManyRequests, response.Code)
|
||||
s.Equal("2", response.Header().Get("Retry-After"))
|
||||
s.Contains(response.Body.String(), `"code":"rate_limited"`)
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestPasswordOperationLimitReturnsRateLimit() {
|
||||
registration := s.newTestServer(messengerStoreStub{}, sessionStub{}, passwordsStub{hashErr: password.ErrBusy})
|
||||
response := serveRequest(registration, http.MethodPost, "/api/v1/users", `{"username":"student","display_name":"Student","password":"T3st-password-123"}`)
|
||||
s.Equal(http.StatusTooManyRequests, response.Code)
|
||||
s.Equal("1", response.Header().Get("Retry-After"))
|
||||
|
||||
store := messengerStoreStub{credentials: model.UserCredentials{PasswordHash: "hash"}}
|
||||
login := s.newTestServer(store, sessionStub{}, passwordsStub{err: password.ErrBusy})
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", nil)
|
||||
request.SetBasicAuth("student", "T3st-password-123")
|
||||
response = httptest.NewRecorder()
|
||||
login.Handler().ServeHTTP(response, request)
|
||||
s.Equal(http.StatusTooManyRequests, response.Code)
|
||||
s.Equal("1", response.Header().Get("Retry-After"))
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestSessionCreationRehashesPasswordWithCompareAndSwap() {
|
||||
var updated []string
|
||||
store := messengerStoreStub{
|
||||
credentials: model.UserCredentials{User: model.User{ID: "user-id"}, PasswordHash: "old-hash"},
|
||||
updatePasswordHash: func(_ context.Context, userID, previousHash, passwordHash string) (bool, error) {
|
||||
updated = []string{userID, previousHash, passwordHash}
|
||||
return true, nil
|
||||
},
|
||||
}
|
||||
server := s.newTestServer(store, sessionStub{}, passwordsStub{
|
||||
verified: true, needsRehash: true, hash: "new-hash",
|
||||
})
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", nil)
|
||||
request.SetBasicAuth("student", "T3st-password-123")
|
||||
response := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(response, request)
|
||||
|
||||
s.Equal(http.StatusCreated, response.Code)
|
||||
s.Equal([]string{"user-id", "old-hash", "new-hash"}, updated)
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestLoginSourceUsesAddressAppendedByIngress() {
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", nil)
|
||||
request.Header.Set("X-Forwarded-For", "203.0.113.9, 198.51.100.7")
|
||||
s.Equal("198.51.100.7", loginSource(request))
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestAttachmentContentAuthenticatesBeforeVariantValidation() {
|
||||
server := s.newTestServer(messengerStoreStub{}, sessionStub{}, passwordsStub{})
|
||||
response := serveRequest(
|
||||
@@ -468,34 +380,10 @@ func (s *MessengerSuite) server(
|
||||
passwords PasswordService,
|
||||
objects objectStoreStub,
|
||||
attachments AttachmentService,
|
||||
) *Server {
|
||||
return s.serverWithDependencies(
|
||||
store, sessions, passwords, loginLimiterStub{allowed: true}, objects, attachments,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) serverWithLoginLimiter(
|
||||
store messengerStoreStub,
|
||||
sessions SessionStore,
|
||||
passwords PasswordService,
|
||||
limiter LoginLimiter,
|
||||
) *Server {
|
||||
return s.serverWithDependencies(
|
||||
store, sessions, passwords, limiter, objectStoreStub{}, attachmentServiceStub{},
|
||||
)
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) serverWithDependencies(
|
||||
store messengerStoreStub,
|
||||
sessions SessionStore,
|
||||
passwords PasswordService,
|
||||
limiter LoginLimiter,
|
||||
objects objectStoreStub,
|
||||
attachments AttachmentService,
|
||||
) *Server {
|
||||
return NewServer(s.logger, Dependencies{
|
||||
Users: store, Chats: store, Messages: store, Attachments: attachments,
|
||||
Sessions: sessions, Passwords: passwords, LoginLimiter: limiter, Database: store, Objects: objects,
|
||||
Sessions: sessions, Passwords: passwords, Database: store, Objects: objects,
|
||||
}, Config{
|
||||
SessionTTL: time.Hour, IdempotencyTTL: 24 * time.Hour, RequestTTL: time.Second,
|
||||
InstanceID: "test-instance", SwaggerPort: "8081",
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -21,7 +19,6 @@ import (
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
)
|
||||
|
||||
var ErrNotFound = errors.New("object not found")
|
||||
@@ -33,7 +30,6 @@ type Config struct {
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
UseTLS bool
|
||||
CAPath string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
@@ -51,27 +47,11 @@ func New(config Config) (*Store, error) {
|
||||
if strings.TrimSpace(config.Bucket) == "" || config.Timeout <= 0 {
|
||||
return nil, errors.New("invalid object store configuration")
|
||||
}
|
||||
options := &minio.Options{
|
||||
client, err := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.AccessKey, config.SecretKey, ""),
|
||||
Secure: config.UseTLS,
|
||||
Region: config.Region,
|
||||
}
|
||||
if config.UseTLS {
|
||||
host, _, err := net.SplitHostPort(endpoint)
|
||||
if err != nil {
|
||||
return nil, errors.New("S3 endpoint must include a port")
|
||||
}
|
||||
tlsConfiguration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: config.CAPath, ServerName: host,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load S3 TLS configuration: %w", err)
|
||||
}
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
transport.TLSClientConfig = tlsConfiguration
|
||||
options.Transport = transport
|
||||
}
|
||||
client, err := minio.New(endpoint, options)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create S3 client: %w", err)
|
||||
}
|
||||
@@ -99,8 +79,12 @@ func endpointHost(value string, useTLS bool) (string, error) {
|
||||
func (s *Store) Ping(ctx context.Context) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||
defer cancel()
|
||||
if _, err := s.client.GetBucketLocation(ctx, s.bucket); err != nil {
|
||||
return fmt.Errorf("check S3 bucket location: %w", err)
|
||||
exists, err := s.client.BucketExists(ctx, s.bucket)
|
||||
if err != nil {
|
||||
return fmt.Errorf("check S3 bucket: %w", err)
|
||||
}
|
||||
if !exists {
|
||||
return errors.New("S3 bucket does not exist")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
var (
|
||||
ErrInvalidConfig = errors.New("invalid password configuration")
|
||||
ErrInvalidHash = errors.New("invalid password hash")
|
||||
ErrBusy = errors.New("password operation limit reached")
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -27,24 +26,17 @@ type Config struct {
|
||||
}
|
||||
|
||||
type Hasher struct {
|
||||
config Config
|
||||
dummyHash string
|
||||
operations chan struct{}
|
||||
config Config
|
||||
dummyHash string
|
||||
}
|
||||
|
||||
func New(config Config, maxConcurrentOperations int) (*Hasher, error) {
|
||||
func New(config Config) (*Hasher, error) {
|
||||
if err := validateConfig(config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if maxConcurrentOperations < 1 || maxConcurrentOperations > 64 {
|
||||
return nil, ErrInvalidConfig
|
||||
}
|
||||
salt := make([]byte, config.SaltLength)
|
||||
digest := argon2.IDKey([]byte("invalid-user-password"), salt, config.Iterations, config.MemoryKiB, config.Parallelism, config.KeyLength)
|
||||
return &Hasher{
|
||||
config: config, dummyHash: encode(config, salt, digest),
|
||||
operations: make(chan struct{}, maxConcurrentOperations),
|
||||
}, nil
|
||||
return &Hasher{config: config, dummyHash: encode(config, salt, digest)}, nil
|
||||
}
|
||||
|
||||
func validateConfig(config Config) error {
|
||||
@@ -59,10 +51,6 @@ func validateConfig(config Config) error {
|
||||
}
|
||||
|
||||
func (h *Hasher) Hash(value string) (string, error) {
|
||||
if !h.acquire() {
|
||||
return "", ErrBusy
|
||||
}
|
||||
defer h.release()
|
||||
salt := make([]byte, h.config.SaltLength)
|
||||
if _, err := rand.Read(salt); err != nil {
|
||||
return "", fmt.Errorf("generate password salt: %w", err)
|
||||
@@ -72,10 +60,6 @@ func (h *Hasher) Hash(value string) (string, error) {
|
||||
}
|
||||
|
||||
func (h *Hasher) Verify(value, encodedHash string) (bool, error) {
|
||||
if !h.acquire() {
|
||||
return false, ErrBusy
|
||||
}
|
||||
defer h.release()
|
||||
config, salt, digest, err := decode(encodedHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -84,27 +68,6 @@ func (h *Hasher) Verify(value, encodedHash string) (bool, error) {
|
||||
return subtle.ConstantTimeCompare(actual, digest) == 1, nil
|
||||
}
|
||||
|
||||
func (h *Hasher) acquire() bool {
|
||||
select {
|
||||
case h.operations <- struct{}{}:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Hasher) release() {
|
||||
<-h.operations
|
||||
}
|
||||
|
||||
func (h *Hasher) NeedsRehash(encodedHash string) (bool, error) {
|
||||
config, _, _, err := decode(encodedHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return config != h.config, nil
|
||||
}
|
||||
|
||||
func (h *Hasher) DummyHash() string {
|
||||
return h.dummyHash
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestPasswordSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) SetupTest() {
|
||||
hasher, err := New(testConfig(), 2)
|
||||
hasher, err := New(testConfig())
|
||||
s.Require().NoError(err)
|
||||
s.hasher = hasher
|
||||
}
|
||||
@@ -39,83 +39,6 @@ func (s *PasswordSuite) TestVerifyRejectsMalformedHash() {
|
||||
s.Error(err)
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) TestNeedsRehashDetectsChangedParameters() {
|
||||
currentHash, err := s.hasher.Hash("T3st-password-123")
|
||||
s.Require().NoError(err)
|
||||
needsRehash, err := s.hasher.NeedsRehash(currentHash)
|
||||
s.Require().NoError(err)
|
||||
s.False(needsRehash)
|
||||
|
||||
legacyConfig := testConfig()
|
||||
legacyConfig.KeyLength = 16
|
||||
legacy, err := New(legacyConfig, 2)
|
||||
s.Require().NoError(err)
|
||||
legacyHash, err := legacy.Hash("T3st-password-123")
|
||||
s.Require().NoError(err)
|
||||
needsRehash, err = s.hasher.NeedsRehash(legacyHash)
|
||||
s.Require().NoError(err)
|
||||
s.True(needsRehash)
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) TestBusyOperationsRecoverAfterCapacityIsReleased() {
|
||||
s.hasher.operations <- struct{}{}
|
||||
s.hasher.operations <- struct{}{}
|
||||
defer func() { <-s.hasher.operations }()
|
||||
_, err := s.hasher.Hash("T3st-password-123")
|
||||
s.ErrorIs(err, ErrBusy)
|
||||
_, err = s.hasher.Verify("T3st-password-123", s.hasher.DummyHash())
|
||||
s.ErrorIs(err, ErrBusy)
|
||||
|
||||
<-s.hasher.operations
|
||||
hash, err := s.hasher.Hash("T3st-password-123")
|
||||
s.Require().NoError(err)
|
||||
verified, err := s.hasher.Verify("T3st-password-123", hash)
|
||||
s.Require().NoError(err)
|
||||
s.True(verified)
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) TestNewRejectsInvalidOperationLimit() {
|
||||
_, err := New(testConfig(), 0)
|
||||
s.ErrorIs(err, ErrInvalidConfig)
|
||||
}
|
||||
|
||||
func testConfig() Config {
|
||||
return Config{MemoryKiB: 8 * 1024, Iterations: 1, Parallelism: 1, SaltLength: 16, KeyLength: 32}
|
||||
}
|
||||
|
||||
func BenchmarkArgon2idHash(b *testing.B) {
|
||||
hasher, err := New(productionConfig(), 2)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
if _, err := hasher.Hash("T3st-password-123"); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkArgon2idVerify(b *testing.B) {
|
||||
hasher, err := New(productionConfig(), 2)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
hash, err := hasher.Hash("T3st-password-123")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
verified, err := hasher.Verify("T3st-password-123", hash)
|
||||
if err != nil || !verified {
|
||||
b.Fatalf("verify: result=%v error=%v", verified, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func productionConfig() Config {
|
||||
return Config{MemoryKiB: 64 * 1024, Iterations: 3, Parallelism: 2, SaltLength: 16, KeyLength: 32}
|
||||
}
|
||||
|
||||
@@ -263,6 +263,21 @@ func scanAttachmentWithReferenceAndObjectKey(
|
||||
return err
|
||||
}
|
||||
|
||||
func scanAttachmentWithReference(row rowScanner, attachment *model.Attachment) error {
|
||||
var stagingKey *string
|
||||
err := row.Scan(
|
||||
&attachment.ID, &attachment.ChatID, &attachment.OwnerID, &attachment.Filename,
|
||||
&attachment.ContentType, &attachment.SizeBytes, &attachment.SHA256, &attachment.ObjectKey,
|
||||
&attachment.Status, &attachment.CreatedAt, &attachment.UpdatedAt, &attachment.ReadyAt,
|
||||
&attachment.PipelineVersion, &attachment.ErrorCode, &stagingKey,
|
||||
&attachment.Referenced,
|
||||
)
|
||||
if stagingKey != nil {
|
||||
attachment.StagingKey = *stagingKey
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) AttachmentReferenced(ctx context.Context, attachmentID string) (bool, error) {
|
||||
const query = `SELECT EXISTS (SELECT 1 FROM message_attachments WHERE attachment_id = $1)`
|
||||
var referenced bool
|
||||
|
||||
@@ -100,19 +100,6 @@ func (s *Store) UserByUsername(ctx context.Context, username string) (model.User
|
||||
return credentials, nil
|
||||
}
|
||||
|
||||
func (s *Store) UpdatePasswordHash(ctx context.Context, userID, previousHash, passwordHash string) (bool, error) {
|
||||
const query = `
|
||||
UPDATE users
|
||||
SET password_hash = $1
|
||||
WHERE id = $2 AND password_hash = $3`
|
||||
|
||||
result, err := s.pool.Exec(ctx, query, passwordHash, userID, previousHash)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("update password hash: %w", err)
|
||||
}
|
||||
return result.RowsAffected() == 1, nil
|
||||
}
|
||||
|
||||
func (s *Store) CreateChat(
|
||||
ctx context.Context,
|
||||
title string,
|
||||
|
||||
@@ -77,27 +77,6 @@ func (s *PostgresSuite) TestConcurrentUsernameCreation() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PostgresSuite) TestPasswordHashUpdateUsesCompareAndSwap() {
|
||||
username := uniqueUsername()
|
||||
user, err := s.store.CreateUser(context.Background(), username, "Password user", "old-hash")
|
||||
s.Require().NoError(err)
|
||||
|
||||
updated, err := s.store.UpdatePasswordHash(context.Background(), user.ID, "other-hash", "new-hash")
|
||||
s.Require().NoError(err)
|
||||
s.False(updated)
|
||||
|
||||
updated, err = s.store.UpdatePasswordHash(context.Background(), user.ID, "old-hash", "new-hash")
|
||||
s.Require().NoError(err)
|
||||
s.True(updated)
|
||||
updated, err = s.store.UpdatePasswordHash(context.Background(), user.ID, "old-hash", "stale-hash")
|
||||
s.Require().NoError(err)
|
||||
s.False(updated)
|
||||
|
||||
credentials, err := s.store.UserByUsername(context.Background(), username)
|
||||
s.Require().NoError(err)
|
||||
s.Equal("new-hash", credentials.PasswordHash)
|
||||
}
|
||||
|
||||
func (s *PostgresSuite) TestCreateChatRollsBackForUnknownMember() {
|
||||
t := s.T()
|
||||
pool := s.pool
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package mtlsproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ListenAddress string
|
||||
TargetAddress string
|
||||
CAPath string
|
||||
CertificatePath string
|
||||
PrivateKeyPath string
|
||||
AllowedClientURI string
|
||||
ALPNProtocols []string
|
||||
DialTimeout time.Duration
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, config Config) error {
|
||||
if config.ListenAddress == "" || config.TargetAddress == "" || config.DialTimeout <= 0 {
|
||||
return errors.New("invalid mTLS proxy configuration")
|
||||
}
|
||||
tlsConfiguration, err := tlsconfig.LoadServer(tlsconfig.ServerConfig{
|
||||
CAPath: config.CAPath, CertificatePath: config.CertificatePath,
|
||||
PrivateKeyPath: config.PrivateKeyPath, AllowedClientURI: config.AllowedClientURI,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tlsConfiguration.NextProtos = config.ALPNProtocols
|
||||
listener, err := net.Listen("tcp", config.ListenAddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("listen: %w", err)
|
||||
}
|
||||
defer func() { _ = listener.Close() }()
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
_ = listener.Close()
|
||||
}()
|
||||
|
||||
var connections sync.WaitGroup
|
||||
defer connections.Wait()
|
||||
for {
|
||||
connection, err := listener.Accept()
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("accept: %w", err)
|
||||
}
|
||||
connections.Add(1)
|
||||
go func() {
|
||||
defer connections.Done()
|
||||
serve(ctx, connection, config, tlsConfiguration)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func serve(ctx context.Context, connection net.Conn, config Config, tlsConfiguration *tls.Config) {
|
||||
client := tls.Server(connection, tlsConfiguration)
|
||||
defer func() { _ = client.Close() }()
|
||||
handshakeCtx, cancel := context.WithTimeout(ctx, config.DialTimeout)
|
||||
defer cancel()
|
||||
if err := client.HandshakeContext(handshakeCtx); err != nil {
|
||||
return
|
||||
}
|
||||
target, err := (&net.Dialer{Timeout: config.DialTimeout}).DialContext(ctx, "tcp", config.TargetAddress)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() { _ = target.Close() }()
|
||||
|
||||
result := make(chan struct{}, 2)
|
||||
copyConnection := func(destination, source net.Conn) {
|
||||
_, _ = io.Copy(destination, source)
|
||||
if writer, ok := destination.(interface{ CloseWrite() error }); ok {
|
||||
_ = writer.CloseWrite()
|
||||
}
|
||||
result <- struct{}{}
|
||||
}
|
||||
go copyConnection(target, client)
|
||||
go copyConnection(client, target)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-result:
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package tlsconfig
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ClientConfig struct {
|
||||
CAPath string
|
||||
CertificatePath string
|
||||
PrivateKeyPath string
|
||||
ServerName string
|
||||
}
|
||||
|
||||
func LoadClient(config ClientConfig) (*tls.Config, error) {
|
||||
if strings.TrimSpace(config.ServerName) == "" {
|
||||
return nil, errors.New("TLS server name is required")
|
||||
}
|
||||
caPEM, err := os.ReadFile(config.CAPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read server CA: %w", err)
|
||||
}
|
||||
roots := x509.NewCertPool()
|
||||
if !roots.AppendCertsFromPEM(caPEM) {
|
||||
return nil, errors.New("server CA does not contain a certificate")
|
||||
}
|
||||
|
||||
var certificates []tls.Certificate
|
||||
if config.CertificatePath != "" || config.PrivateKeyPath != "" {
|
||||
if config.CertificatePath == "" || config.PrivateKeyPath == "" {
|
||||
return nil, errors.New("TLS client certificate and private key must be configured together")
|
||||
}
|
||||
certificate, err := tls.LoadX509KeyPair(config.CertificatePath, config.PrivateKeyPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load client certificate: %w", err)
|
||||
}
|
||||
certificates = []tls.Certificate{certificate}
|
||||
}
|
||||
|
||||
return &tls.Config{
|
||||
MinVersion: tls.VersionTLS13,
|
||||
RootCAs: roots,
|
||||
Certificates: certificates,
|
||||
ServerName: config.ServerName,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package tlsconfig
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLoadClientLoadsTrustAndIdentity(t *testing.T) {
|
||||
caPath, certificatePath, keyPath := writeClientCertificate(t)
|
||||
|
||||
configuration, err := LoadClient(ClientConfig{
|
||||
CAPath: caPath, CertificatePath: certificatePath, PrivateKeyPath: keyPath, ServerName: "collector",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint16(0x0304), configuration.MinVersion)
|
||||
require.Equal(t, "collector", configuration.ServerName)
|
||||
require.Len(t, configuration.Certificates, 1)
|
||||
require.NotNil(t, configuration.RootCAs)
|
||||
}
|
||||
|
||||
func TestLoadClientRejectsPartialIdentity(t *testing.T) {
|
||||
caPath, certificatePath, _ := writeClientCertificate(t)
|
||||
|
||||
_, err := LoadClient(ClientConfig{CAPath: caPath, CertificatePath: certificatePath, ServerName: "collector"})
|
||||
require.ErrorContains(t, err, "configured together")
|
||||
}
|
||||
|
||||
func writeClientCertificate(t *testing.T) (string, string, string) {
|
||||
t.Helper()
|
||||
directory := t.TempDir()
|
||||
key, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
require.NoError(t, err)
|
||||
template := &x509.Certificate{
|
||||
SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "test"},
|
||||
NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour),
|
||||
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
|
||||
BasicConstraintsValid: true, IsCA: true,
|
||||
}
|
||||
der, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
|
||||
require.NoError(t, err)
|
||||
certificate := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der})
|
||||
privateKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})
|
||||
caPath := filepath.Join(directory, "ca.crt")
|
||||
certificatePath := filepath.Join(directory, "tls.crt")
|
||||
keyPath := filepath.Join(directory, "tls.key")
|
||||
require.NoError(t, os.WriteFile(caPath, certificate, 0o600))
|
||||
require.NoError(t, os.WriteFile(certificatePath, certificate, 0o600))
|
||||
require.NoError(t, os.WriteFile(keyPath, privateKey, 0o600))
|
||||
return caPath, certificatePath, keyPath
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func handshake(serverConfig, clientConfig *tls.Config) (error, error) {
|
||||
if err != nil {
|
||||
return err, err
|
||||
}
|
||||
defer func() { _ = listener.Close() }()
|
||||
defer listener.Close()
|
||||
serverResult := make(chan error, 1)
|
||||
go func() {
|
||||
connection, acceptErr := listener.Accept()
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -41,15 +40,11 @@ type Store struct {
|
||||
client valkey.Client
|
||||
}
|
||||
|
||||
func New(rawURL string, tlsConfiguration ...*tls.Config) (*Store, error) {
|
||||
func New(rawURL string) (*Store, error) {
|
||||
option, err := valkey.ParseURL(rawURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: parse Valkey URL: %w", ErrStore, err)
|
||||
}
|
||||
if len(tlsConfiguration) > 0 && tlsConfiguration[0] != nil {
|
||||
option.TLSConfig = tlsConfiguration[0].Clone()
|
||||
}
|
||||
option.DisableCache = true
|
||||
|
||||
client, err := valkey.NewClient(option)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/session"
|
||||
)
|
||||
|
||||
@@ -35,14 +34,7 @@ func (s *SessionSuite) SetupSuite() {
|
||||
s.Require().NoError(err)
|
||||
rawURL = strings.TrimSpace(string(data))
|
||||
}
|
||||
tlsConfiguration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: os.Getenv("TEST_CACHE_TLS_CA_PATH"),
|
||||
CertificatePath: os.Getenv("TEST_CACHE_TLS_CERTIFICATE_PATH"),
|
||||
PrivateKeyPath: os.Getenv("TEST_CACHE_TLS_PRIVATE_KEY_PATH"),
|
||||
ServerName: os.Getenv("TEST_CACHE_TLS_SERVER_NAME"),
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
store, err := session.New(rawURL, tlsConfiguration)
|
||||
store, err := session.New(rawURL)
|
||||
s.Require().NoError(err)
|
||||
s.store = store
|
||||
}
|
||||
|
||||
@@ -26,9 +26,6 @@ import (
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.34.0"
|
||||
"google.golang.org/grpc/credentials"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -37,17 +34,13 @@ const (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServiceName string
|
||||
Version string
|
||||
InstanceID string
|
||||
Endpoint string
|
||||
Environment string
|
||||
Namespace string
|
||||
Insecure bool
|
||||
TLSCAPath string
|
||||
TLSCertificatePath string
|
||||
TLSPrivateKeyPath string
|
||||
TLSServerName string
|
||||
ServiceName string
|
||||
Version string
|
||||
InstanceID string
|
||||
Endpoint string
|
||||
Environment string
|
||||
Namespace string
|
||||
Insecure bool
|
||||
}
|
||||
|
||||
type Runtime struct {
|
||||
@@ -61,17 +54,13 @@ type Runtime struct {
|
||||
func ConfigFromEnvironment(serviceName, instanceID string) Config {
|
||||
resourceAttributes := parseResourceAttributes(os.Getenv("OTEL_RESOURCE_ATTRIBUTES"))
|
||||
return Config{
|
||||
ServiceName: serviceName,
|
||||
Version: firstValue(os.Getenv("SERVICE_VERSION"), resourceAttributes["service.version"], "dev"),
|
||||
InstanceID: instanceID,
|
||||
Endpoint: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")),
|
||||
Environment: firstValue(os.Getenv("DEPLOYMENT_ENVIRONMENT"), resourceAttributes["deployment.environment.name"], defaultEnvironment),
|
||||
Namespace: firstValue(os.Getenv("SERVICE_NAMESPACE"), resourceAttributes["service.namespace"], defaultNamespace),
|
||||
Insecure: strings.EqualFold(strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_INSECURE")), "true"),
|
||||
TLSCAPath: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_CERTIFICATE")),
|
||||
TLSCertificatePath: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE")),
|
||||
TLSPrivateKeyPath: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_CLIENT_KEY")),
|
||||
TLSServerName: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_SERVER_NAME")),
|
||||
ServiceName: serviceName,
|
||||
Version: firstValue(os.Getenv("SERVICE_VERSION"), resourceAttributes["service.version"], "dev"),
|
||||
InstanceID: instanceID,
|
||||
Endpoint: strings.TrimSpace(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")),
|
||||
Environment: firstValue(os.Getenv("DEPLOYMENT_ENVIRONMENT"), resourceAttributes["deployment.environment.name"], defaultEnvironment),
|
||||
Namespace: firstValue(os.Getenv("SERVICE_NAMESPACE"), resourceAttributes["service.namespace"], defaultNamespace),
|
||||
Insecure: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,12 +187,6 @@ func newTraceExporter(ctx context.Context, config Config) (trace.SpanExporter, e
|
||||
}
|
||||
if config.Insecure {
|
||||
options = append(options, otlptracegrpc.WithInsecure())
|
||||
} else {
|
||||
transportCredentials, err := telemetryCredentials(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options = append(options, otlptracegrpc.WithTLSCredentials(transportCredentials))
|
||||
}
|
||||
exporter, err := otlptracegrpc.New(ctx, options...)
|
||||
if err != nil {
|
||||
@@ -221,12 +204,6 @@ func newMetricExporter(ctx context.Context, config Config) (*otlpmetricgrpc.Expo
|
||||
}
|
||||
if config.Insecure {
|
||||
options = append(options, otlpmetricgrpc.WithInsecure())
|
||||
} else {
|
||||
transportCredentials, err := telemetryCredentials(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options = append(options, otlpmetricgrpc.WithTLSCredentials(transportCredentials))
|
||||
}
|
||||
exporter, err := otlpmetricgrpc.New(ctx, options...)
|
||||
if err != nil {
|
||||
@@ -244,12 +221,6 @@ func newLogExporter(ctx context.Context, config Config) (*otlploggrpc.Exporter,
|
||||
}
|
||||
if config.Insecure {
|
||||
options = append(options, otlploggrpc.WithInsecure())
|
||||
} else {
|
||||
transportCredentials, err := telemetryCredentials(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options = append(options, otlploggrpc.WithTLSCredentials(transportCredentials))
|
||||
}
|
||||
exporter, err := otlploggrpc.New(ctx, options...)
|
||||
if err != nil {
|
||||
@@ -258,17 +229,6 @@ func newLogExporter(ctx context.Context, config Config) (*otlploggrpc.Exporter,
|
||||
return exporter, nil
|
||||
}
|
||||
|
||||
func telemetryCredentials(config Config) (credentials.TransportCredentials, error) {
|
||||
tlsConfiguration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
|
||||
CAPath: config.TLSCAPath, CertificatePath: config.TLSCertificatePath,
|
||||
PrivateKeyPath: config.TLSPrivateKeyPath, ServerName: config.TLSServerName,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load OTLP TLS configuration: %w", err)
|
||||
}
|
||||
return credentials.NewTLS(tlsConfiguration), nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Logger() *slog.Logger {
|
||||
return r.logger
|
||||
}
|
||||
|
||||
+8
-35
@@ -18,7 +18,7 @@ TEMPO_BIND_ADDRESS=127.0.0.1:3200
|
||||
# Ресурсные атрибуты и внутренний OTLP endpoint приложений.
|
||||
DEPLOYMENT_ENVIRONMENT=lab
|
||||
SERVICE_VERSION=lab7
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT=https://otel-gateway:4317
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
|
||||
|
||||
# Число API-реплик за Nginx.
|
||||
@@ -28,31 +28,15 @@ API_REPLICAS=2
|
||||
POSTGRES_USER=messenger
|
||||
POSTGRES_DB=messenger
|
||||
POSTGRES_PASSWORD=local-postgres-password
|
||||
POSTGRES_API_PASSWORD=local-postgres-api-password
|
||||
POSTGRES_DISPATCHER_PASSWORD=local-postgres-dispatcher-password
|
||||
POSTGRES_WORKER_PASSWORD=local-postgres-worker-password
|
||||
POSTGRES_RECONCILER_PASSWORD=local-postgres-reconciler-password
|
||||
POSTGRES_EXPORTER_PASSWORD=local-postgres-exporter-password
|
||||
POSTGRES_MIGRATE_PASSWORD=local-postgres-migrate-password
|
||||
DATABASE_URL=postgres://messenger_api:local-postgres-api-password@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATABASE_MIGRATE_URL=postgres://messenger_migrate:local-postgres-migrate-password@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATABASE_DISPATCHER_URL=postgres://messenger_dispatcher:local-postgres-dispatcher-password@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATABASE_WORKER_URL=postgres://messenger_worker:local-postgres-worker-password@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATABASE_RECONCILER_URL=postgres://messenger_reconciler:local-postgres-reconciler-password@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/security/internal-ca/ca.crt&sslcert=/run/security/client/tls.crt&sslkey=/run/security/client/tls.key
|
||||
DATABASE_URL=postgres://messenger:local-postgres-password@postgres:5432/messenger?sslmode=disable
|
||||
|
||||
# Пароль локального Valkey и строка подключения API.
|
||||
VALKEY_API_PASSWORD=local-valkey-api-password
|
||||
VALKEY_EXPORTER_PASSWORD=local-valkey-exporter-password
|
||||
VALKEY_HEALTH_PASSWORD=local-valkey-health-password
|
||||
CACHE_URL=rediss://messenger_api:local-valkey-api-password@redis-gateway:16379/0
|
||||
VALKEY_PASSWORD=local-valkey-password
|
||||
CACHE_URL=redis://default:local-valkey-password@valkey:6379/0
|
||||
|
||||
# Redis Streams используется только как устойчивый брокер заданий.
|
||||
REDIS_DISPATCHER_PASSWORD=local-redis-dispatcher-password
|
||||
REDIS_WORKER_PASSWORD=local-redis-worker-password
|
||||
REDIS_EXPORTER_PASSWORD=local-redis-exporter-password
|
||||
REDIS_HEALTH_PASSWORD=local-redis-health-password
|
||||
BROKER_DISPATCHER_URL=rediss://messenger_dispatcher:local-redis-dispatcher-password@redis-gateway:26379/0
|
||||
BROKER_WORKER_URL=rediss://messenger_worker:local-redis-worker-password@redis-gateway:36379/0
|
||||
REDIS_BROKER_PASSWORD=local-redis-broker-password
|
||||
BROKER_URL=redis://default:local-redis-broker-password@redis-broker:6379/0
|
||||
|
||||
# Административные данные MinIO используются только при bootstrap.
|
||||
MINIO_ROOT_USER=local-minio-admin
|
||||
@@ -62,12 +46,8 @@ MINIO_ROOT_PASSWORD=local-minio-admin-password
|
||||
S3_ENDPOINT=s3:9000
|
||||
S3_REGION=us-east-1
|
||||
S3_BUCKET=messenger-attachments
|
||||
S3_API_ACCESS_KEY=messenger-api
|
||||
S3_API_SECRET_KEY=local-messenger-api-s3-password
|
||||
S3_WORKER_ACCESS_KEY=messenger-worker
|
||||
S3_WORKER_SECRET_KEY=local-messenger-worker-s3-password
|
||||
S3_RECONCILER_ACCESS_KEY=messenger-reconciler
|
||||
S3_RECONCILER_SECRET_KEY=local-messenger-reconciler-s3-password
|
||||
S3_ACCESS_KEY=messenger-app
|
||||
S3_SECRET_KEY=local-messenger-s3-password
|
||||
|
||||
# Порт Swagger внутри конфигурации CORS API.
|
||||
SWAGGER_PORT=8081
|
||||
@@ -91,13 +71,6 @@ GRAFANA_CPUS=1
|
||||
GRAFANA_MEMORY=512m
|
||||
OTEL_COLLECTOR_CPUS=0.5
|
||||
OTEL_COLLECTOR_MEMORY=256m
|
||||
OTEL_GATEWAY_CPUS=0.25
|
||||
OTEL_GATEWAY_MEMORY=128m
|
||||
REDIS_GATEWAY_CPUS=0.25
|
||||
REDIS_GATEWAY_MEMORY=128m
|
||||
OPENBAO_CPUS=0.5
|
||||
OPENBAO_MEMORY=256m
|
||||
OPENBAO_BIND_ADDRESS=127.0.0.1:8200
|
||||
LOKI_CPUS=1
|
||||
LOKI_MEMORY=512m
|
||||
TEMPO_CPUS=1
|
||||
|
||||
+2
-2
@@ -1471,8 +1471,8 @@
|
||||
"to": "now"
|
||||
},
|
||||
"timezone": "browser",
|
||||
"title": "Messenger lab7 security and observability",
|
||||
"uid": "messenger-lab7",
|
||||
"title": "Messenger lab6 observability",
|
||||
"uid": "messenger-lab6",
|
||||
"version": 1,
|
||||
"links": [
|
||||
{
|
||||
@@ -13,49 +13,38 @@ datasources:
|
||||
type: prometheus
|
||||
uid: prometheus
|
||||
access: proxy
|
||||
url: https://prometheus-grafana-gateway:8443
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
jsonData:
|
||||
httpMethod: POST
|
||||
tlsAuthWithCACert: true
|
||||
serverName: telemetry-gateway
|
||||
exemplarTraceIdDestinations:
|
||||
- name: trace_id
|
||||
datasourceUid: tempo
|
||||
secureJsonData: &mtls
|
||||
tlsCACert: $__file{/run/security/internal-ca/ca.crt}
|
||||
tlsClientCert: $__file{/run/security/client/tls.crt}
|
||||
tlsClientKey: $__file{/run/security/client/tls.key}
|
||||
|
||||
- name: Loki
|
||||
type: loki
|
||||
uid: loki
|
||||
access: proxy
|
||||
url: https://loki-grafana-gateway:8443
|
||||
url: http://loki:3100
|
||||
editable: false
|
||||
jsonData:
|
||||
maxLines: 1000
|
||||
tlsAuthWithCACert: true
|
||||
serverName: telemetry-gateway
|
||||
derivedFields:
|
||||
- name: TraceID
|
||||
matcherRegex: 'trace_id[=:" ]+([0-9a-f]{32})'
|
||||
datasourceUid: tempo
|
||||
url: '$${__value.raw}'
|
||||
secureJsonData: *mtls
|
||||
|
||||
- name: Tempo
|
||||
type: tempo
|
||||
uid: tempo
|
||||
access: proxy
|
||||
url: https://tempo-grafana-gateway:8443
|
||||
url: http://tempo:3200
|
||||
editable: false
|
||||
jsonData:
|
||||
nodeGraph:
|
||||
enabled: true
|
||||
tlsAuthWithCACert: true
|
||||
serverName: telemetry-gateway
|
||||
search:
|
||||
hide: false
|
||||
serviceMap:
|
||||
@@ -83,4 +72,3 @@ datasources:
|
||||
query: 'sum(rate(traces_spanmetrics_calls_total{$$__tags}[5m]))'
|
||||
- name: Error rate
|
||||
query: 'sum(rate(traces_spanmetrics_calls_total{$$__tags,span_status="STATUS_CODE_ERROR"}[5m]))'
|
||||
secureJsonData: *mtls
|
||||
|
||||
@@ -51,13 +51,6 @@ scrape_configs:
|
||||
type: A
|
||||
port: 9091
|
||||
refresh_interval: 2s
|
||||
scheme: https
|
||||
tls_config: &pipeline_tls
|
||||
ca_file: /run/security/internal-ca/ca.crt
|
||||
cert_file: /run/security/prometheus/tls.crt
|
||||
key_file: /run/security/prometheus/tls.key
|
||||
server_name: pipeline-metrics
|
||||
min_version: TLS13
|
||||
relabel_configs:
|
||||
- target_label: service_name
|
||||
replacement: messenger-worker
|
||||
@@ -69,8 +62,6 @@ scrape_configs:
|
||||
- job_name: outbox-dispatcher
|
||||
static_configs:
|
||||
- targets: ["dispatcher:9091"]
|
||||
scheme: https
|
||||
tls_config: *pipeline_tls
|
||||
relabel_configs:
|
||||
- target_label: service_name
|
||||
replacement: messenger-dispatcher
|
||||
@@ -81,11 +72,6 @@ scrape_configs:
|
||||
|
||||
- job_name: minio
|
||||
metrics_path: /minio/v2/metrics/cluster
|
||||
scheme: https
|
||||
tls_config:
|
||||
ca_file: /run/security/internal-ca/ca.crt
|
||||
server_name: s3
|
||||
min_version: TLS13
|
||||
static_configs:
|
||||
- targets: ["s3:9000"]
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user