forked from mtusi2026/mtusi2026lab7
Lab 7: mTLS, OpenBao and least privilege #1
@@ -3,6 +3,7 @@
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.runtime
|
||||
secrets
|
||||
certs
|
||||
volumes
|
||||
|
||||
+64
-18
@@ -14,15 +14,19 @@ concurrency:
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab6-${{ github.run_id }}
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab7-${{ github.run_id }}
|
||||
API_BIND_ADDRESS: 127.0.0.1:0
|
||||
SWAGGER_BIND_ADDRESS: 127.0.0.1:0
|
||||
PROMETHEUS_BIND_ADDRESS: 127.0.0.1:0
|
||||
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,7 +37,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
go-version: "1.26.10"
|
||||
cache: false
|
||||
|
||||
- name: Check contract
|
||||
@@ -48,8 +52,8 @@ jobs:
|
||||
- name: Check formatting and shell scripts
|
||||
run: |
|
||||
test -z "$(gofmt -l cmd internal migrations)"
|
||||
sh -n infra/minio/bootstrap.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/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
|
||||
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
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
@@ -65,37 +69,79 @@ jobs:
|
||||
|
||||
- name: Prepare local stack
|
||||
run: |
|
||||
cp lab6.env.example .env
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 150
|
||||
./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 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: |
|
||||
set -a
|
||||
. ./.env
|
||||
set +a
|
||||
test "$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' "http://s3:9000/$S3_BUCKET")" = "403"
|
||||
make test BASE_URL=http://nginx:8080
|
||||
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"
|
||||
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
|
||||
docker compose --profile tests run --rm --build tests
|
||||
go run ./cmd/dependencycheck -base-url=http://nginx:8080
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://nginx:8080
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://nginx:8080
|
||||
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-lab5
|
||||
ENV_FILE=.env PROMETHEUS_URL=http://prometheus:9090 TEMPO_URL=http://tempo:3200 LOKI_URL=http://loki:3100 make test-lab6-smoke BASE_URL=http://nginx:8080
|
||||
make test-worker-compromise ENV_FILE=.env
|
||||
make scan-security
|
||||
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 .env ]; then docker compose logs --no-color --tail=200; fi
|
||||
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
|
||||
|
||||
- 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
|
||||
|
||||
+59
-28
@@ -12,7 +12,7 @@ jobs:
|
||||
name: Verify selected commit
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
timeout-minutes: 60
|
||||
outputs:
|
||||
api_image: ${{ steps.publish.outputs.api_image }}
|
||||
nginx_image: ${{ steps.publish.outputs.nginx_image }}
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
s3_image: ${{ steps.publish.outputs.s3_image }}
|
||||
s3_bootstrap_image: ${{ steps.publish.outputs.s3_bootstrap_image }}
|
||||
env:
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab6-deploy-${{ github.run_id }}
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab7-deploy-${{ github.run_id }}
|
||||
COMPOSE_FILE: compose.yaml:deploy/compose.images.yaml
|
||||
API_BIND_ADDRESS: 127.0.0.1:0
|
||||
SWAGGER_BIND_ADDRESS: 127.0.0.1:0
|
||||
@@ -30,13 +30,17 @@ 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
|
||||
API_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-api:${{ github.sha }}
|
||||
NGINX_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-nginx:${{ github.sha }}
|
||||
SWAGGER_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-swagger:${{ github.sha }}
|
||||
PROMETHEUS_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-prometheus:${{ github.sha }}
|
||||
GRAFANA_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-grafana:${{ github.sha }}
|
||||
S3_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-minio:${{ github.sha }}
|
||||
S3_BOOTSTRAP_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab6-minio-client:${{ github.sha }}
|
||||
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 }}
|
||||
PROMETHEUS_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-prometheus:${{ github.sha }}
|
||||
GRAFANA_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-grafana:${{ github.sha }}
|
||||
S3_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-minio:${{ github.sha }}
|
||||
S3_BOOTSTRAP_IMAGE: gitea.privcloud.tech/${{ github.repository_owner }}/mtusi2026lab7-minio-client:${{ github.sha }}
|
||||
steps:
|
||||
- name: Checkout exact commit
|
||||
run: |
|
||||
@@ -47,7 +51,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
go-version: "1.26.10"
|
||||
cache: false
|
||||
|
||||
- name: Check contract
|
||||
@@ -62,8 +66,8 @@ jobs:
|
||||
- name: Check formatting and shell scripts
|
||||
run: |
|
||||
test -z "$(gofmt -l cmd internal migrations)"
|
||||
sh -n infra/minio/bootstrap.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/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
|
||||
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
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v7
|
||||
@@ -79,27 +83,47 @@ jobs:
|
||||
|
||||
- name: Prepare local stack
|
||||
run: |
|
||||
cp lab6.env.example .env
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 150
|
||||
./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 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: |
|
||||
set -a
|
||||
. ./.env
|
||||
set +a
|
||||
test "$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' "http://s3:9000/$S3_BUCKET")" = "403"
|
||||
make test BASE_URL=http://nginx:8080
|
||||
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"
|
||||
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
|
||||
docker compose --profile tests run --rm --build tests
|
||||
go run ./cmd/dependencycheck -base-url=http://nginx:8080
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://nginx:8080
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://nginx:8080
|
||||
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-lab5
|
||||
ENV_FILE=.env PROMETHEUS_URL=http://prometheus:9090 TEMPO_URL=http://tempo:3200 LOKI_URL=http://loki:3100 make test-lab6-smoke BASE_URL=http://nginx:8080
|
||||
make test-worker-compromise ENV_FILE=.env
|
||||
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
|
||||
@@ -130,14 +154,21 @@ jobs:
|
||||
|
||||
- name: Container logs
|
||||
if: failure()
|
||||
run: if [ -f .env ]; then docker compose logs --no-color --tail=200; fi
|
||||
run: if [ -f "$CI_WORKSPACE/.env" ]; then cd "$CI_WORKSPACE"; 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:
|
||||
@@ -177,17 +208,17 @@ jobs:
|
||||
run: printf '%s' "$REGISTRY_PASSWORD" | ssh "$DEPLOY_USER@$DEPLOY_HOST" "docker login gitea.privcloud.tech --username '$REGISTRY_USERNAME' --password-stdin"
|
||||
|
||||
- name: Upload image manifest
|
||||
run: scp deploy-images.env "$DEPLOY_USER@$DEPLOY_HOST:/tmp/mtusi2026lab6-${{ github.run_id }}.env"
|
||||
run: scp deploy-images.env "$DEPLOY_USER@$DEPLOY_HOST:/tmp/mtusi2026lab7-${{ github.run_id }}.env"
|
||||
|
||||
- name: Deploy and verify
|
||||
run: |
|
||||
ssh "$DEPLOY_USER@$DEPLOY_HOST" "
|
||||
set -eu
|
||||
cd ~/mtusi2026lab6
|
||||
cd ~/mtusi2026lab7
|
||||
git fetch origin main
|
||||
git cat-file -e '$DEPLOY_SHA^{commit}'
|
||||
git reset --hard '$DEPLOY_SHA'
|
||||
manifest='/tmp/mtusi2026lab6-${{ github.run_id }}.env'
|
||||
manifest='/tmp/mtusi2026lab7-${{ github.run_id }}.env'
|
||||
if DEPLOY_GENERATION='${{ github.run_id }}' scripts/rolling-update.sh \"\$manifest\"; then
|
||||
rm -f \"\$manifest\"
|
||||
else
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
name: Lab 6 incidents
|
||||
name: Lab 7 inherited incidents
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: lab6-incidents-${{ github.repository }}-${{ github.ref }}
|
||||
group: lab7-incidents-${{ github.repository }}-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
@@ -12,13 +12,17 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 35
|
||||
env:
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab6-incidents-${{ github.run_id }}
|
||||
COMPOSE_PROJECT_NAME: mtusi2026lab7-incidents-${{ github.run_id }}
|
||||
API_BIND_ADDRESS: 127.0.0.1:0
|
||||
SWAGGER_BIND_ADDRESS: 127.0.0.1:0
|
||||
PROMETHEUS_BIND_ADDRESS: 127.0.0.1:0
|
||||
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: |
|
||||
@@ -29,22 +33,35 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
go-version: "1.26.10"
|
||||
cache: false
|
||||
|
||||
- name: Prepare stack
|
||||
run: |
|
||||
cp lab6.env.example .env
|
||||
mkdir -p "$CI_WORKSPACE"
|
||||
git archive HEAD | tar -x -C "$CI_WORKSPACE"
|
||||
cd "$CI_WORKSPACE"
|
||||
cp lab7.env.example .env
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --scale api=2 --wait --wait-timeout 180
|
||||
./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 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=http://nginx:8080 \
|
||||
BASE_URL=https://nginx:8443 \
|
||||
CA_FILE=.runtime/security/public-ca/ca.crt \
|
||||
PROMETHEUS_URL=http://prometheus:9090 \
|
||||
TEMPO_URL=http://tempo:3200 \
|
||||
LOKI_URL=http://loki:3100 \
|
||||
@@ -53,21 +70,30 @@ jobs:
|
||||
|
||||
- name: Upload sanitized evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
env:
|
||||
ACTIONS_RUNTIME_URL: https://gitea.privcloud.tech/api/actions_pipeline/
|
||||
with:
|
||||
name: lab6-incidents-${{ github.sha }}
|
||||
path: evidence/runtime/ci
|
||||
path: ${{ env.CI_WORKSPACE }}/evidence/runtime/ci
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
|
||||
- name: Container logs
|
||||
if: failure()
|
||||
run: docker compose logs --no-color --tail=200
|
||||
run: if [ -f "$CI_WORKSPACE/.env" ]; then cd "$CI_WORKSPACE"; 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
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.runtime/
|
||||
secrets/
|
||||
certs/private/
|
||||
*.key
|
||||
|
||||
+19
-5
@@ -1,12 +1,23 @@
|
||||
FROM golang:1.26.5-alpine3.24 AS build
|
||||
FROM alpine:3.24.2 AS security-test
|
||||
|
||||
RUN apk add --no-cache curl openssl
|
||||
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
|
||||
|
||||
ARG GOPROXY=https://proxy.golang.org
|
||||
|
||||
WORKDIR /src
|
||||
ENV GOMAXPROCS=2 GOMEMLIMIT=1GiB
|
||||
RUN apk add --no-cache git
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
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
|
||||
|
||||
@@ -27,19 +38,22 @@ 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.5-alpine AS loadbalancer
|
||||
FROM nginx:1.30.6-alpine AS loadbalancer
|
||||
|
||||
RUN apk upgrade --no-cache
|
||||
|
||||
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY nginx/upstream.conf /etc/nginx/conf.d/upstream.conf
|
||||
|
||||
FROM alpine:3.24.2
|
||||
|
||||
RUN addgroup -S app && adduser -S -G app -u 10001 app
|
||||
RUN apk upgrade --no-cache && 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
|
||||
HEALTHCHECK --interval=10s --timeout=2s --start-period=5s --retries=3 \
|
||||
CMD wget -q -O /dev/null "http://127.0.0.1:${APP_PORT}/health/ready" || exit 1
|
||||
CMD wget -q -O /dev/null "http://127.0.0.1:8082/health/ready" || exit 1
|
||||
CMD ["/app/messenger"]
|
||||
|
||||
@@ -2,9 +2,10 @@ PYTHON ?= python3
|
||||
BASE_URL ?= https://localhost:8443
|
||||
CA_FILE ?=
|
||||
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
|
||||
.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
|
||||
|
||||
help:
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||||
@@ -31,3 +32,37 @@ test-failover:
|
||||
|
||||
test-security:
|
||||
$(PYTHON) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
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
|
||||
|
||||
test-lab5-acceptance:
|
||||
./scripts/test-lab5-acceptance.sh
|
||||
|
||||
lab6-load:
|
||||
$(PYTHON) scripts/lab6-traffic.py --base-url "$(BASE_URL)" $(TLS_ARGS) --mode mixed --duration 60 --concurrency 4 --wait-ready
|
||||
|
||||
test-lab6-smoke:
|
||||
ENV_FILE="$(ENV_FILE)" BASE_URL="$(BASE_URL)" CA_FILE="$(CA_FILE)" ./scripts/test-lab6.sh smoke
|
||||
|
||||
test-lab6:
|
||||
ENV_FILE="$(ENV_FILE)" BASE_URL="$(BASE_URL)" CA_FILE="$(CA_FILE)" ./scripts/test-lab6.sh full
|
||||
|
||||
@@ -1,37 +1,186 @@
|
||||
# Отчёт — лабораторная 7
|
||||
# Отчёт — лабораторная работа № 7
|
||||
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
**Автор:** Пластинин Денис, БВТ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 дополнительно сопоставляется с разрешённой ролью.
|
||||
|
||||
## Запуск из чистого clone
|
||||
|
||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
||||
Требуются Docker с Compose v2, `make`, Python 3 и `curl`. Все используемые образы закреплены по версиям в `compose.yaml`. Локальные ключи и operator material создаются в игнорируемой директории `.runtime`.
|
||||
|
||||
## Архитектура и решения
|
||||
```sh
|
||||
cp lab7.env.example .env
|
||||
./scripts/bootstrap-local.sh .env
|
||||
```
|
||||
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab6, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
Скрипт создаёт локальную 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`.
|
||||
|
||||
## Доказательства критериев
|
||||
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| Критерий | Команда/сценарий | Наблюдаемый результат | Доказательство |
|
||||
| --- | --- | --- | --- |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
| Контракт и 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` |
|
||||
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
## Эксперимент: компрометация worker
|
||||
|
||||
## Эксперименты и отказы
|
||||
### Гипотеза
|
||||
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
Если worker credential будет скомпрометирован, злоумышленник получит только consumer operations своего stream, ограниченные таблицы PostgreSQL и два MinIO prefix. После смены broker password и worker secret старая identity перестанет работать, а уже поставленное задание сохранится и завершится после восстановления worker.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
### Методика
|
||||
|
||||
Стенд запускался в контейнерах с лимитом 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.
|
||||
|
||||
### Результат
|
||||
|
||||
| Воздействие | Ожидание | Наблюдение | Потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
| Старый 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 сохранён |
|
||||
|
||||
## Ограничения и следующие шаги
|
||||
Эксперимент доказывает ограничение blast radius и восстановление задания, но не моделирует кражу root-доступа к Docker host. Сценарий разрывает broker connections перезапуском gateway и завершает PostgreSQL sessions роли worker через `pg_terminate_backend`; затем проверяет новые подключения со старыми паролями и отказ старому S3 key. Для production потребуются внешний KMS/HSM для CA, response-wrapped SecretID, автоматизированный revoke и несколько независимых повторов с измерением времени восстановления.
|
||||
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
## 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-сценариями и воспроизводимыми отрицательными экспериментами.
|
||||
|
||||
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -17,10 +19,11 @@ import (
|
||||
)
|
||||
|
||||
type apiClient struct {
|
||||
baseURL string
|
||||
client *http.Client
|
||||
token string
|
||||
userID string
|
||||
baseURL string
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
token string
|
||||
userID string
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -32,9 +35,23 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
baseURL := flag.String("base-url", "http://localhost:8080", "API base URL")
|
||||
baseURL := flag.String("base-url", "https://localhost:8443", "API base URL")
|
||||
caFile := flag.String("ca-file", ".runtime/security/public-ca/ca.crt", "trusted CA certificate")
|
||||
flag.Parse()
|
||||
client := &apiClient{baseURL: *baseURL, client: &http.Client{Timeout: 10 * time.Second}}
|
||||
caPEM, err := os.ReadFile(*caFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read trusted CA: %w", err)
|
||||
}
|
||||
roots := x509.NewCertPool()
|
||||
if !roots.AppendCertsFromPEM(caPEM) {
|
||||
return fmt.Errorf("trusted CA does not contain a certificate")
|
||||
}
|
||||
transport := &http.Transport{TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12, RootCAs: roots}}
|
||||
defer transport.CloseIdleConnections()
|
||||
client := &apiClient{
|
||||
baseURL: *baseURL, client: &http.Client{Transport: transport, Timeout: 10 * time.Second},
|
||||
transport: transport,
|
||||
}
|
||||
if err := client.registerAndLogin(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -130,7 +147,9 @@ func (c *apiClient) verifyConcurrentIdempotency() error {
|
||||
instances = make(map[string]struct{})
|
||||
messageID string
|
||||
)
|
||||
transport := &http.Transport{DisableKeepAlives: true, MaxConnsPerHost: workers}
|
||||
transport := c.transport.Clone()
|
||||
transport.DisableKeepAlives = true
|
||||
transport.MaxConnsPerHost = workers
|
||||
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
|
||||
defer transport.CloseIdleConnections()
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -12,16 +14,18 @@ import (
|
||||
_ "image/jpeg"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
)
|
||||
|
||||
type apiState struct {
|
||||
BaseURL string `json:"base_url"`
|
||||
CAFile string `json:"ca_file"`
|
||||
Token string `json:"token"`
|
||||
AttachmentID string `json:"attachment_id"`
|
||||
}
|
||||
@@ -41,11 +45,15 @@ type apiChat struct {
|
||||
func runAPIProduce(arguments []string, output io.Writer) error {
|
||||
flags := flag.NewFlagSet("api-produce", flag.ContinueOnError)
|
||||
flags.SetOutput(io.Discard)
|
||||
baseURL := flags.String("base-url", "http://nginx:8080", "messenger base URL")
|
||||
baseURL := flags.String("base-url", "https://nginx:8443", "messenger base URL")
|
||||
caFile := flags.String("ca-file", "/run/security/public-ca/ca.crt", "trusted CA certificate")
|
||||
if err := flags.Parse(arguments); err != nil || flags.NArg() != 0 {
|
||||
return errors.New("usage: lab5experiment api-produce [-base-url URL]")
|
||||
return errors.New("usage: lab5experiment api-produce [-base-url URL] [-ca-file PATH]")
|
||||
}
|
||||
client, err := newAPIClient(*caFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
suffix := strings.ReplaceAll(uuid.NewString(), "-", "")[:12]
|
||||
password := "Lab5-" + uuid.NewString()
|
||||
owner, err := registerAPIUser(client, *baseURL, "qa_"+suffix, password)
|
||||
@@ -102,7 +110,9 @@ func runAPIProduce(arguments []string, output io.Writer) error {
|
||||
if response.StatusCode != http.StatusConflict {
|
||||
return fmt.Errorf("queued content returned %d, expected 409", response.StatusCode)
|
||||
}
|
||||
return json.NewEncoder(output).Encode(apiState{BaseURL: *baseURL, Token: token, AttachmentID: attachment.ID})
|
||||
return json.NewEncoder(output).Encode(apiState{
|
||||
BaseURL: *baseURL, CAFile: *caFile, Token: token, AttachmentID: attachment.ID,
|
||||
})
|
||||
}
|
||||
|
||||
func runAPIVerify(arguments []string, input io.Reader, output io.Writer) error {
|
||||
@@ -116,7 +126,10 @@ func runAPIVerify(arguments []string, input io.Reader, output io.Writer) error {
|
||||
if err := json.NewDecoder(input).Decode(&state); err != nil {
|
||||
return fmt.Errorf("decode API scenario state: %w", err)
|
||||
}
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
client, err := newAPIClient(state.CAFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *waitTimeout)
|
||||
defer cancel()
|
||||
var attachment model.Attachment
|
||||
@@ -176,6 +189,19 @@ func runAPIVerify(arguments []string, input io.Reader, output io.Writer) error {
|
||||
})
|
||||
}
|
||||
|
||||
func newAPIClient(caFile string) (*http.Client, error) {
|
||||
caPEM, err := os.ReadFile(caFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read trusted CA: %w", err)
|
||||
}
|
||||
roots := x509.NewCertPool()
|
||||
if !roots.AppendCertsFromPEM(caPEM) {
|
||||
return nil, errors.New("trusted CA does not contain a certificate")
|
||||
}
|
||||
transport := &http.Transport{TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12, RootCAs: roots}}
|
||||
return &http.Client{Transport: transport, Timeout: 10 * time.Second}, nil
|
||||
}
|
||||
|
||||
func registerAPIUser(client *http.Client, baseURL, username, password string) (apiUser, error) {
|
||||
body, err := json.Marshal(map[string]string{
|
||||
"username": username, "display_name": username, "password": password,
|
||||
|
||||
+20
-10
@@ -21,15 +21,16 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/worker"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/outbox"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/worker"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"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 (
|
||||
@@ -132,7 +133,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, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
@@ -143,6 +144,15 @@ 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()
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
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,33 +2,32 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/bootstrap"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/logger"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/bootstrap"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
appLogger := logger.New()
|
||||
if err := run(appLogger, os.Args[1:]); err != nil {
|
||||
if err := run(os.Args[1:]); err != nil {
|
||||
appLogger.Error("application stopped", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(logger *slog.Logger, arguments []string) error {
|
||||
func run(arguments []string) error {
|
||||
if len(arguments) == 0 {
|
||||
return bootstrap.RunServer(logger)
|
||||
return bootstrap.RunServer()
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "migrate" {
|
||||
return bootstrap.RunMigrations()
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "dispatch" {
|
||||
return bootstrap.RunDispatcher(logger)
|
||||
return bootstrap.RunDispatcher()
|
||||
}
|
||||
if len(arguments) == 1 && arguments[0] == "worker" {
|
||||
return bootstrap.RunWorker(logger)
|
||||
return bootstrap.RunWorker()
|
||||
}
|
||||
if arguments[0] == "reconcile-attachments" {
|
||||
return bootstrap.RunReconciliation(arguments[1:], os.Stdout)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
}
|
||||
+698
-106
File diff suppressed because it is too large
Load Diff
+33
-1
@@ -1,9 +1,21 @@
|
||||
version: 1
|
||||
|
||||
server:
|
||||
health_address: 127.0.0.1:8082
|
||||
metrics_address: 0.0.0.0:9091
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/api/tls.crt
|
||||
private_key_path: /run/security/api/tls.key
|
||||
allowed_client_uri: spiffe://mtusi/lab7/load-balancer
|
||||
allowed_metrics_client_uri: spiffe://mtusi/lab7/prometheus
|
||||
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
|
||||
@@ -17,6 +29,7 @@ server:
|
||||
parallelism: 2
|
||||
salt_length: 16
|
||||
key_length: 32
|
||||
max_concurrent_operations: 2
|
||||
|
||||
database:
|
||||
min_connections: 1
|
||||
@@ -26,11 +39,19 @@ 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: false
|
||||
use_tls: true
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
timeout: 5s
|
||||
|
||||
attachments:
|
||||
@@ -43,6 +64,11 @@ 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
|
||||
@@ -74,3 +100,9 @@ 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
|
||||
|
||||
+24
-34
@@ -1,37 +1,27 @@
|
||||
# Матрица доверия — заполнить в решении lab7
|
||||
# Матрица доверия
|
||||
|
||||
Это обязательная матрица покрытия. Для каждой строки укажите реальный порт, endpoint, CA, service identity, проверку SAN/ACL, срок жизни credentials и команду положительного/отрицательного теста. TLS шифрует и подтверждает сервер; mTLS также проверяет клиента. При доверенном CA всё равно нужно ограничивать разрешённую identity. Plaintext hop допустим только внутри закрытого локального transport/proxy boundary, без опубликованного обхода; границу и rationale нужно доказать.
|
||||
| Связь | Порт и протокол | 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 | Документированное ограничение стенда |
|
||||
|
||||
| Связь | Минимум на 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 |
|
||||
## Каналы bootstrap, health и scrape
|
||||
|
||||
Нет выбранного компонента — отметьте 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.
|
||||
- `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.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
module gitea.privcloud.tech/dizi/mtusi2026lab6
|
||||
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
|
||||
@@ -12,20 +14,21 @@ 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.13.0
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.20.0
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.60.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 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/exporters/prometheus v0.60.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
|
||||
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
|
||||
golang.org/x/crypto v0.57.0
|
||||
golang.org/x/sync v0.23.0
|
||||
google.golang.org/grpc v1.83.2
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -37,15 +40,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.3 // indirect
|
||||
github.com/go-logr/logr v1.4.4 // 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.27.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // 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.2 // indirect
|
||||
github.com/klauspost/compress v1.18.7 // 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
|
||||
@@ -66,18 +69,17 @@ 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.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.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.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||
golang.org/x/net v0.58.0 // indirect
|
||||
golang.org/x/net v0.60.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-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
|
||||
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
|
||||
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.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
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/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.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
|
||||
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/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.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
|
||||
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/klauspost/compress v1.18.7 h1:aUyZsS4kH3QTKurYhAOwAHxllVPnOthb3vPfnF1Ehjw=
|
||||
github.com/klauspost/compress v1.18.7/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
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.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
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/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,40 +116,42 @@ 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.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/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/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.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 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/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.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.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.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=
|
||||
@@ -158,24 +160,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.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
|
||||
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
|
||||
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
||||
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
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.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=
|
||||
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=
|
||||
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=
|
||||
|
||||
Regular → Executable
+101
-12
@@ -2,35 +2,124 @@
|
||||
|
||||
set -eu
|
||||
|
||||
alias_name=bootstrap
|
||||
policy_name=messenger-attachments
|
||||
policy_file=/tmp/messenger-attachments-policy.json
|
||||
: "${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}"
|
||||
|
||||
mc alias set "$alias_name" http://s3:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
|
||||
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"
|
||||
|
||||
mc alias set "$alias_name" https://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_file" <<EOF
|
||||
cat >"$policy_dir/messenger-api.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
|
||||
"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"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/attachments/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/*"]
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/staging/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
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-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 alias set application http://s3:9000 "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
|
||||
mc ls "application/$S3_BUCKET" >/dev/null
|
||||
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
|
||||
|
||||
@@ -10,7 +10,11 @@ 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"]
|
||||
|
||||
+42
-4
@@ -1,7 +1,45 @@
|
||||
# OpenBao — реализовать конфигурацию и политики
|
||||
# OpenBao
|
||||
|
||||
Добавьте non-dev конфигурацию listener/storage/TLS, API/worker policies, bootstrap и rotation scripts. Credentials и unseal material создаются локально; здесь нет готового root token или private key.
|
||||
OpenBao работает вне dev-mode с single-node integrated Raft. Данные сохраняются в `/openbao/data`, API принимает только TLS 1.3 на `8200`, cluster transport использует `8201`. Сертификат и ключ передаются в `/run/security/openbao`, а не входят в образ.
|
||||
|
||||
Решение должно показать реальную сервисную аутентификацию и получение нужного secret по ограниченной policy; просто работающий контейнер OpenBao не засчитывается. На 3 статический KV secret допустим. На 4 покажите expiry/renewal/rotation и allow/deny. Путь KV v2 data/metadata и ACL должен соответствовать фактическому mount; не копируйте широкое `path "*"` для приложения.
|
||||
## Идентичности
|
||||
|
||||
Документируйте шаги оператора init/unseal и восстановление после restart. Скрипт не должен печатать tokens/shares или хранить их в Git. См. contracts/trust-matrix.md и REPORT.md.
|
||||
`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 отзываются при завершении.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{{- with secret "secret/data/messenger/api" -}}
|
||||
{{ .Data.data | toJSON }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,43 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{{- with secret "secret/data/messenger/worker" -}}
|
||||
{{ .Data.data | toJSON }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,43 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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"
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/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"
|
||||
@@ -0,0 +1,31 @@
|
||||
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"]
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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:4317
|
||||
endpoint: 0.0.0.0:14317
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
endpoint: 0.0.0.0:14318
|
||||
|
||||
processors:
|
||||
memory_limiter:
|
||||
@@ -29,9 +29,12 @@ exporters:
|
||||
- service.version
|
||||
- deployment.environment.name
|
||||
otlp_grpc/tempo:
|
||||
endpoint: tempo:4317
|
||||
endpoint: tempo-collector-gateway:8443
|
||||
tls:
|
||||
insecure: true
|
||||
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
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
@@ -42,7 +45,12 @@ exporters:
|
||||
max_interval: 5s
|
||||
max_elapsed_time: 30s
|
||||
otlp_http/loki:
|
||||
endpoint: http://loki:3100/otlp
|
||||
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
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
@@ -58,6 +66,13 @@ service:
|
||||
telemetry:
|
||||
logs:
|
||||
level: info
|
||||
metrics:
|
||||
readers:
|
||||
- pull:
|
||||
exporter:
|
||||
prometheus:
|
||||
host: 0.0.0.0
|
||||
port: 8888
|
||||
pipelines:
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
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
|
||||
Executable
+158
@@ -0,0 +1,158 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
umask 077
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
repo_dir=$(CDPATH= cd -- "$script_dir/../.." && pwd)
|
||||
security_dir="$repo_dir/.runtime/security"
|
||||
staging_dir="$security_dir/.bootstrap.$$"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$staging_dir"
|
||||
}
|
||||
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
if [ "${1:-}" = "--force" ]; then
|
||||
force=1
|
||||
elif [ "$#" -eq 0 ]; then
|
||||
force=0
|
||||
else
|
||||
echo "usage: $0 [--force]" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -d "$security_dir/public-ca" ] || [ -d "$security_dir/internal-ca" ]; then
|
||||
if [ "$force" -ne 1 ]; then
|
||||
echo "security material already exists; use --force to replace it" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$security_dir" "$staging_dir"
|
||||
chmod 0700 "$security_dir" "$staging_dir"
|
||||
|
||||
create_ca() {
|
||||
name=$1
|
||||
common_name=$2
|
||||
directory="$staging_dir/$name"
|
||||
|
||||
mkdir -p "$directory"
|
||||
openssl genpkey -quiet -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "$directory/ca.key"
|
||||
openssl req -new -x509 -sha256 -days 3650 \
|
||||
-key "$directory/ca.key" \
|
||||
-out "$directory/ca.crt" \
|
||||
-subj "/CN=$common_name" \
|
||||
-config "$script_dir/templates/ca.cnf" \
|
||||
-extensions v3_ca
|
||||
}
|
||||
|
||||
create_leaf() {
|
||||
name=$1
|
||||
common_name=$2
|
||||
issuer=$3
|
||||
template=$4
|
||||
directory="$staging_dir/$name"
|
||||
issuer_directory="$staging_dir/$issuer"
|
||||
|
||||
mkdir -p "$directory"
|
||||
openssl genpkey -quiet -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "$directory/tls.key"
|
||||
openssl req -new -sha256 \
|
||||
-key "$directory/tls.key" \
|
||||
-out "$directory/tls.csr" \
|
||||
-subj "/CN=$common_name"
|
||||
openssl x509 -req -sha256 -days 30 \
|
||||
-in "$directory/tls.csr" \
|
||||
-CA "$issuer_directory/ca.crt" \
|
||||
-CAkey "$issuer_directory/ca.key" \
|
||||
-CAcreateserial \
|
||||
-out "$directory/tls.crt" \
|
||||
-extfile "$script_dir/templates/$template"
|
||||
rm "$directory/tls.csr"
|
||||
}
|
||||
|
||||
create_ca public-ca "MTUSI Lab 7 Public CA"
|
||||
create_ca internal-ca "MTUSI Lab 7 Internal CA"
|
||||
create_ca foreign-ca "MTUSI Lab 7 Foreign CA"
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
rm -rf "$security_dir/$directory"
|
||||
mv "$staging_dir/$directory" "$security_dir/$directory"
|
||||
done
|
||||
|
||||
echo "local PKI created in .runtime/security"
|
||||
@@ -0,0 +1,141 @@
|
||||
#!/bin/sh
|
||||
|
||||
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
|
||||
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 {} \;
|
||||
|
||||
rm -rf /target/nginx/ingress /target/nginx/public-ca /target/nginx/internal-ca /target/nginx/load-balancer
|
||||
mkdir -p /target/nginx/ingress /target/nginx/public-ca /target/nginx/internal-ca /target/nginx/load-balancer
|
||||
cp /source/ingress/tls.crt /target/nginx/ingress/tls.crt
|
||||
cp /source/ingress/tls.key /target/nginx/ingress/tls.key
|
||||
cp /source/public-ca/ca.crt /target/nginx/public-ca/ca.crt
|
||||
cp /source/internal-ca/ca.crt /target/nginx/internal-ca/ca.crt
|
||||
cp /source/load-balancer/tls.crt /target/nginx/load-balancer/tls.crt
|
||||
cp /source/load-balancer/tls.key /target/nginx/load-balancer/tls.key
|
||||
chown -R 0:0 /target/nginx
|
||||
find /target/nginx -type d -exec chmod 0700 {} \;
|
||||
find /target/nginx -type f -exec chmod 0600 {} \;
|
||||
|
||||
rm -rf /target/prometheus/internal-ca /target/prometheus/prometheus
|
||||
mkdir -p /target/prometheus/internal-ca /target/prometheus/prometheus
|
||||
cp /source/internal-ca/ca.crt /target/prometheus/internal-ca/ca.crt
|
||||
cp /source/prometheus/tls.crt /target/prometheus/prometheus/tls.crt
|
||||
cp /source/prometheus/tls.key /target/prometheus/prometheus/tls.key
|
||||
chown -R 65534:65534 /target/prometheus
|
||||
find /target/prometheus -type d -exec chmod 0700 {} \;
|
||||
find /target/prometheus -type f -exec chmod 0600 {} \;
|
||||
|
||||
rm -rf /target/client/public-ca
|
||||
mkdir -p /target/client/public-ca
|
||||
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 {} \;
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/api
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,10 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
DNS.1 = api
|
||||
URI.1 = spiffe://mtusi/lab7/api
|
||||
@@ -0,0 +1,12 @@
|
||||
[req]
|
||||
distinguished_name = distinguished_name
|
||||
prompt = no
|
||||
|
||||
[distinguished_name]
|
||||
CN = local-ca
|
||||
|
||||
[v3_ca]
|
||||
basicConstraints = critical,CA:TRUE,pathlen:0
|
||||
keyUsage = critical,keyCertSign,cRLSign
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/collector
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/dispatcher
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,9 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
URI.1 = spiffe://mtusi/lab7/worker
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/grafana
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,11 @@
|
||||
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
|
||||
@@ -0,0 +1,11 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
DNS.1 = localhost
|
||||
DNS.2 = nginx
|
||||
IP.1 = 127.0.0.1
|
||||
@@ -0,0 +1,9 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = @subject_alt_names
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[subject_alt_names]
|
||||
URI.1 = spiffe://mtusi/lab7/load-balancer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/migrate
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:s3
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,11 @@
|
||||
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
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:otel-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:pipeline-metrics
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/postgres-bootstrap
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/postgres-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:postgres
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,4 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/prometheus
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/reconciler
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:redis-broker
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/redis-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/redis-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:redis-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:telemetry-gateway
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/valkey-exporter
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = DNS:valkey
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
@@ -0,0 +1,6 @@
|
||||
basicConstraints = critical,CA:FALSE
|
||||
keyUsage = critical,digitalSignature
|
||||
extendedKeyUsage = clientAuth
|
||||
subjectAltName = URI:spiffe://mtusi/lab7/worker
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/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"
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
@@ -0,0 +1,15 @@
|
||||
# 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
|
||||
@@ -0,0 +1,11 @@
|
||||
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'
|
||||
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/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"
|
||||
@@ -0,0 +1,136 @@
|
||||
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}
|
||||
@@ -0,0 +1,17 @@
|
||||
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
|
||||
@@ -0,0 +1,16 @@
|
||||
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
|
||||
Executable
+199
@@ -0,0 +1,199 @@
|
||||
#!/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"
|
||||
@@ -3,8 +3,8 @@ package bootstrap
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
)
|
||||
|
||||
func RunMigrations() error {
|
||||
|
||||
@@ -2,6 +2,7 @@ package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
@@ -14,19 +15,20 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/pipeline"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/worker"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/outbox"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/pipeline"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/worker"
|
||||
"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(logger *slog.Logger) error {
|
||||
func RunDispatcher() error {
|
||||
settings, err := config.LoadDispatcher()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -48,7 +50,11 @@ func RunDispatcher(logger *slog.Logger) error {
|
||||
if err := telemetry.ObserveDatabasePool(observability.MeterProvider().Meter("messenger-dispatcher/database"), pool); err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL)
|
||||
brokerTLSConfiguration, err := loadClientTLS(settings.BrokerTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL, brokerTLSConfiguration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -61,9 +67,6 @@ func RunDispatcher(logger *slog.Logger) 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,
|
||||
@@ -74,11 +77,17 @@ func RunDispatcher(logger *slog.Logger) 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, metrics.Handler(), dispatcher.Run)
|
||||
return runPipelineProcess(
|
||||
logger, settings.MetricsAddress, settings.HealthAddress, metricsTLSConfiguration, metrics.Handler(), dispatcher.Run,
|
||||
)
|
||||
}
|
||||
|
||||
func RunWorker(logger *slog.Logger) error {
|
||||
func RunWorker() error {
|
||||
settings, err := config.LoadWorker()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -103,12 +112,16 @@ func RunWorker(logger *slog.Logger) 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, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL)
|
||||
brokerTLSConfiguration, err := loadClientTLS(settings.BrokerTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := newRedisClient(settings.BrokerURL, brokerTLSConfiguration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -144,15 +157,36 @@ func RunWorker(logger *slog.Logger) 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, metrics.Handler(), processorWorker.Run)
|
||||
return runPipelineProcess(
|
||||
logger, settings.MetricsAddress, settings.HealthAddress, metricsTLSConfiguration, metrics.Handler(), processorWorker.Run,
|
||||
)
|
||||
}
|
||||
|
||||
func newRedisClient(rawURL string) (*redis.Client, error) {
|
||||
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) {
|
||||
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()
|
||||
@@ -166,19 +200,32 @@ func newRedisClient(rawURL string) (*redis.Client, error) {
|
||||
func runPipelineProcess(
|
||||
logger *slog.Logger,
|
||||
metricsAddress string,
|
||||
healthAddress string,
|
||||
metricsTLSConfiguration *tls.Config,
|
||||
metricsHandler http.Handler,
|
||||
run func(context.Context) error,
|
||||
) error {
|
||||
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)
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
serveResult := make(chan error, 1)
|
||||
go func() { serveResult <- server.Serve(listener) }()
|
||||
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) }()
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
@@ -195,8 +242,10 @@ func runPipelineProcess(
|
||||
}
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(shutdownCtx); err != nil && result == nil {
|
||||
result = err
|
||||
for _, server := range []*http.Server{metricsServer, healthServer} {
|
||||
if err := server.Shutdown(shutdownCtx); err != nil && result == nil {
|
||||
result = err
|
||||
}
|
||||
}
|
||||
if errors.Is(result, http.ErrServerClosed) || errors.Is(result, context.Canceled) {
|
||||
return nil
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/reconcile"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/reconcile"
|
||||
)
|
||||
|
||||
type reconciliationOutput struct {
|
||||
@@ -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, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
)
|
||||
|
||||
func RunAttachmentReplay(arguments []string, output io.Writer) error {
|
||||
|
||||
+118
-32
@@ -2,33 +2,58 @@ package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/database"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/httpapi"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/password"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/session"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"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"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/password"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/postgres"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/session"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
func RunServer(logger *slog.Logger) error {
|
||||
type serverResult struct {
|
||||
name string
|
||||
err error
|
||||
}
|
||||
|
||||
func RunServer() error {
|
||||
settings, err := config.LoadServer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instanceID, err := os.Hostname()
|
||||
apiTLSConfiguration, err := tlsconfig.LoadServer(tlsconfig.ServerConfig{
|
||||
CAPath: settings.TLSCAPath, CertificatePath: settings.TLSCertificatePath,
|
||||
PrivateKeyPath: settings.TLSPrivateKeyPath, AllowedClientURI: settings.TLSAllowedClientURI,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metricsTLSConfiguration, err := tlsconfig.LoadServer(tlsconfig.ServerConfig{
|
||||
CAPath: settings.TLSCAPath, CertificatePath: settings.TLSCertificatePath,
|
||||
PrivateKeyPath: settings.TLSPrivateKeyPath, AllowedClientURI: settings.TLSAllowedMetricsClientURI,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instanceUUID, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instanceID := "api-" + instanceUUID.String()
|
||||
observability, logger, err := startTelemetry("messenger-api", instanceID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -42,16 +67,32 @@ func RunServer(logger *slog.Logger) error {
|
||||
if err := telemetry.ObserveDatabasePool(observability.MeterProvider().Meter("messenger-api/database"), pool); err != nil {
|
||||
return err
|
||||
}
|
||||
sessions, err := session.New(settings.CacheURL)
|
||||
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)
|
||||
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
|
||||
}
|
||||
@@ -70,40 +111,85 @@ func RunServer(logger *slog.Logger) error {
|
||||
}
|
||||
app := httpapi.NewServer(logger, httpapi.Dependencies{
|
||||
Users: repository, Chats: repository, Messages: repository, Attachments: attachments,
|
||||
Sessions: sessions, Passwords: passwords, Database: repository, Objects: objects,
|
||||
Sessions: sessions, Passwords: passwords, LoginLimiter: loginLimiter,
|
||||
Database: repository, Objects: objects,
|
||||
Meter: observability.MeterProvider().Meter("messenger-api"), Metrics: observability.MetricsHandler(),
|
||||
}, httpapi.Config{
|
||||
SessionTTL: settings.SessionTTL, IdempotencyTTL: settings.IdempotencyTTL,
|
||||
RequestTTL: settings.RequestTimeout, InstanceID: instanceID, SwaggerPort: settings.SwaggerPort,
|
||||
})
|
||||
server := &http.Server{
|
||||
apiServer := &http.Server{
|
||||
Addr: settings.Address, Handler: app.Handler(), ReadHeaderTimeout: settings.HTTPReadHeaderTimeout,
|
||||
ReadTimeout: settings.HTTPReadTimeout, WriteTimeout: settings.HTTPWriteTimeout,
|
||||
IdleTimeout: settings.HTTPIdleTimeout,
|
||||
IdleTimeout: settings.HTTPIdleTimeout, TLSConfig: apiTLSConfiguration,
|
||||
}
|
||||
listener, err := net.Listen("tcp", server.Addr)
|
||||
healthServer := &http.Server{
|
||||
Addr: settings.HealthAddress, Handler: app.HealthHandler(),
|
||||
ReadHeaderTimeout: settings.HTTPReadHeaderTimeout, ReadTimeout: settings.HTTPReadTimeout,
|
||||
WriteTimeout: settings.HTTPWriteTimeout, IdleTimeout: settings.HTTPIdleTimeout,
|
||||
}
|
||||
metricsServer := &http.Server{
|
||||
Addr: settings.MetricsAddress, Handler: app.MetricsHandler(),
|
||||
ReadHeaderTimeout: settings.HTTPReadHeaderTimeout, ReadTimeout: settings.HTTPReadTimeout,
|
||||
WriteTimeout: settings.HTTPWriteTimeout, IdleTimeout: settings.HTTPIdleTimeout,
|
||||
TLSConfig: metricsTLSConfiguration,
|
||||
}
|
||||
apiListener, err := net.Listen("tcp", apiServer.Addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
serveResult := make(chan error, 1)
|
||||
go func() { serveResult <- server.Serve(listener) }()
|
||||
logger.Info("server started", "address", server.Addr)
|
||||
healthListener, err := net.Listen("tcp", healthServer.Addr)
|
||||
if err != nil {
|
||||
_ = apiListener.Close()
|
||||
return err
|
||||
}
|
||||
metricsListener, err := net.Listen("tcp", metricsServer.Addr)
|
||||
if err != nil {
|
||||
_ = apiListener.Close()
|
||||
_ = healthListener.Close()
|
||||
return err
|
||||
}
|
||||
serveResults := make(chan serverResult, 3)
|
||||
go serveHTTP(serveResults, "api", apiServer, tls.NewListener(apiListener, apiTLSConfiguration))
|
||||
go serveHTTP(serveResults, "health", healthServer, healthListener)
|
||||
go serveHTTP(serveResults, "metrics", metricsServer, tls.NewListener(metricsListener, metricsTLSConfiguration))
|
||||
logger.Info("servers started", "api_address", apiServer.Addr, "health_address", healthServer.Addr, "metrics_address", metricsServer.Addr)
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
var serveErr error
|
||||
select {
|
||||
case err := <-serveResult:
|
||||
return err
|
||||
case result := <-serveResults:
|
||||
serveErr = fmt.Errorf("%s server stopped: %w", result.name, result.err)
|
||||
case <-ctx.Done():
|
||||
logger.Info("shutdown requested")
|
||||
app.SetReady(false)
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), settings.HTTPShutdownTimeout)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(shutdownCtx); err != nil {
|
||||
_ = server.Close()
|
||||
return err
|
||||
}
|
||||
}
|
||||
app.SetReady(false)
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), settings.HTTPShutdownTimeout)
|
||||
defer cancel()
|
||||
shutdownErr := shutdownServers(shutdownCtx, apiServer, healthServer, metricsServer)
|
||||
return errors.Join(serveErr, shutdownErr)
|
||||
}
|
||||
|
||||
func serveHTTP(results chan<- serverResult, name string, server *http.Server, listener net.Listener) {
|
||||
results <- serverResult{name: name, err: server.Serve(listener)}
|
||||
}
|
||||
|
||||
func shutdownServers(ctx context.Context, servers ...*http.Server) error {
|
||||
results := make(chan error, len(servers))
|
||||
for _, server := range servers {
|
||||
go func() { results <- server.Shutdown(ctx) }()
|
||||
}
|
||||
var shutdownErr error
|
||||
for range servers {
|
||||
shutdownErr = errors.Join(shutdownErr, <-results)
|
||||
}
|
||||
if shutdownErr == nil {
|
||||
return nil
|
||||
}
|
||||
for _, server := range servers {
|
||||
_ = server.Close()
|
||||
}
|
||||
return shutdownErr
|
||||
}
|
||||
|
||||
func databaseConfig(settings config.ServerConfig) database.Config {
|
||||
@@ -118,6 +204,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, Timeout: settings.S3Timeout,
|
||||
UseTLS: settings.S3UseTLS, CAPath: settings.S3CAPath, Timeout: settings.S3Timeout,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
func startTelemetry(serviceName, instanceID string) (*telemetry.Runtime, *slog.Logger, error) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/outbox"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/outbox"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
+186
-41
@@ -12,41 +12,54 @@ import (
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Address 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
|
||||
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
|
||||
}
|
||||
|
||||
type MigrationConfig struct {
|
||||
@@ -74,6 +87,7 @@ type ReconciliationConfig struct {
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3CAPath string
|
||||
S3Timeout time.Duration
|
||||
}
|
||||
|
||||
@@ -94,9 +108,24 @@ 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 {
|
||||
@@ -111,6 +140,34 @@ func LoadServer() (ServerConfig, error) {
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
healthAddress, err := loopbackAddress(values, "server.health_address")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
metricsAddress, err := nonLoopbackAddress(values, "server.metrics_address")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
tlsCAPath, err := requiredString(values, "server.tls.ca_path")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
tlsCertificatePath, err := requiredString(values, "server.tls.certificate_path")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
tlsPrivateKeyPath, err := requiredString(values, "server.tls.private_key_path")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
tlsAllowedClientURI, err := requiredString(values, "server.tls.allowed_client_uri")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
tlsAllowedMetricsClientURI, err := requiredString(values, "server.tls.allowed_metrics_client_uri")
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
}
|
||||
database, err := loadDatabaseConfig(values)
|
||||
if err != nil {
|
||||
return ServerConfig{}, err
|
||||
@@ -119,6 +176,10 @@ 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
|
||||
@@ -135,6 +196,18 @@ 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
|
||||
@@ -179,6 +252,10 @@ 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
|
||||
@@ -216,9 +293,16 @@ func LoadServer() (ServerConfig, error) {
|
||||
}
|
||||
|
||||
return ServerConfig{
|
||||
Address: net.JoinHostPort(host, port), DatabaseURL: database.url, CacheURL: cacheURL,
|
||||
Address: net.JoinHostPort(host, port), HealthAddress: healthAddress, MetricsAddress: metricsAddress,
|
||||
TLSCAPath: tlsCAPath, TLSCertificatePath: tlsCertificatePath,
|
||||
TLSPrivateKeyPath: tlsPrivateKeyPath, TLSAllowedClientURI: tlsAllowedClientURI,
|
||||
TLSAllowedMetricsClientURI: tlsAllowedMetricsClientURI,
|
||||
DatabaseURL: database.url, CacheURL: cacheURL, CacheTLS: cacheTLS,
|
||||
SessionTTL: sessionTTL, IdempotencyTTL: idempotencyTTL,
|
||||
DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
LoginRateLimitAccountAttempts: loginRateLimitAccountAttempts,
|
||||
LoginRateLimitSourceAttempts: loginRateLimitSourceAttempts,
|
||||
LoginRateLimitWindow: loginRateLimitWindow,
|
||||
DBMaxConns: int32(database.maxConns), DBMinConns: int32(database.minConns),
|
||||
DBMaxConnectionAge: database.maxConnectionAge, DBMaxConnectionIdle: database.maxConnectionIdle,
|
||||
DBHealthCheckPeriod: database.healthCheckPeriod, DependencyTimeout: database.dependencyTimeout,
|
||||
RequestTimeout: requestTimeout,
|
||||
@@ -227,9 +311,10 @@ func LoadServer() (ServerConfig, error) {
|
||||
HTTPShutdownTimeout: shutdownTimeout, PasswordMemoryKiB: uint32(passwordMemory),
|
||||
PasswordIterations: uint32(passwordIterations), PasswordParallelism: uint8(passwordParallelism),
|
||||
PasswordSaltLength: uint32(passwordSaltLength), PasswordKeyLength: uint32(passwordKeyLength),
|
||||
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
PasswordMaxConcurrentOperations: passwordMaxConcurrentOperations,
|
||||
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
|
||||
S3AccessKey: storage.accessKey, S3SecretKey: storage.secretKey,
|
||||
S3UseTLS: storage.useTLS, S3Timeout: storage.timeout,
|
||||
S3UseTLS: storage.useTLS, S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
AttachmentMaxBytes: int64(attachmentMaxBytes), AttachmentMaxPixels: int64(attachmentMaxPixels),
|
||||
AttachmentBodyMemory: int64(attachmentBodyMemory),
|
||||
AttachmentDecodeMemory: int64(attachmentDecodeMemory),
|
||||
@@ -277,7 +362,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, S3Timeout: storage.timeout,
|
||||
S3UseTLS: storage.useTLS, S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -306,13 +391,40 @@ 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, timeout: timeout,
|
||||
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,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -371,6 +483,39 @@ func requiredPort(values *viper.Viper, name string) (string, error) {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func loopbackAddress(values *viper.Viper, name string) (string, error) {
|
||||
value, err := requiredString(values, name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
host, port, err := net.SplitHostPort(value)
|
||||
if err != nil || host != "127.0.0.1" {
|
||||
return "", fmt.Errorf("%s: must use 127.0.0.1 with an explicit port", name)
|
||||
}
|
||||
if _, err := integerValue(port, 1, 65535); err != nil {
|
||||
return "", fmt.Errorf("%s: %w", name, err)
|
||||
}
|
||||
return net.JoinHostPort(host, port), nil
|
||||
}
|
||||
|
||||
func nonLoopbackAddress(values *viper.Viper, name string) (string, error) {
|
||||
value, err := requiredString(values, name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
host, port, err := net.SplitHostPort(value)
|
||||
if err != nil || host == "" || strings.EqualFold(host, "localhost") {
|
||||
return "", fmt.Errorf("%s: must use a non-loopback host with an explicit port", name)
|
||||
}
|
||||
if address := net.ParseIP(host); address != nil && address.IsLoopback() {
|
||||
return "", fmt.Errorf("%s: must use a non-loopback host with an explicit port", name)
|
||||
}
|
||||
if _, err := integerValue(port, 1, 65535); err != nil {
|
||||
return "", fmt.Errorf("%s: %w", name, err)
|
||||
}
|
||||
return net.JoinHostPort(host, port), nil
|
||||
}
|
||||
|
||||
func duration(values *viper.Viper, name string, minimum, maximum time.Duration) (time.Duration, error) {
|
||||
value, err := requiredString(values, name)
|
||||
if err != nil {
|
||||
|
||||
@@ -46,6 +46,67 @@ func TestLoadValuesRejectsUnknownVersion(t *testing.T) {
|
||||
require.ErrorContains(t, err, "version: must be 1")
|
||||
}
|
||||
|
||||
func TestLoadServerLoadsTLSAndHealthSettings(t *testing.T) {
|
||||
setConfigEnvironment(t, validTestConfig)
|
||||
|
||||
settings, err := LoadServer()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "127.0.0.1:8082", settings.HealthAddress)
|
||||
require.Equal(t, "0.0.0.0:9091", settings.MetricsAddress)
|
||||
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) {
|
||||
content := strings.Replace(validTestConfig, "health_address: 127.0.0.1:8082", "health_address: 0.0.0.0:8082", 1)
|
||||
setConfigEnvironment(t, content)
|
||||
|
||||
_, err := LoadServer()
|
||||
require.ErrorContains(t, err, "server.health_address: must use 127.0.0.1")
|
||||
}
|
||||
|
||||
func TestLoadServerRejectsLoopbackMetricsAddress(t *testing.T) {
|
||||
content := strings.Replace(validTestConfig, "metrics_address: 0.0.0.0:9091", "metrics_address: 127.0.0.1:9091", 1)
|
||||
setConfigEnvironment(t, content)
|
||||
|
||||
_, err := LoadServer()
|
||||
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")
|
||||
@@ -64,9 +125,21 @@ func setConfigEnvironment(t *testing.T, content string) {
|
||||
|
||||
const validTestConfig = `version: 1
|
||||
server:
|
||||
health_address: 127.0.0.1:8082
|
||||
metrics_address: 0.0.0.0:9091
|
||||
tls:
|
||||
ca_path: /run/security/internal-ca/ca.crt
|
||||
certificate_path: /run/security/api/tls.crt
|
||||
private_key_path: /run/security/api/tls.key
|
||||
allowed_client_uri: spiffe://mtusi/lab7/load-balancer
|
||||
allowed_metrics_client_uri: spiffe://mtusi/lab7/prometheus
|
||||
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
|
||||
@@ -80,6 +153,7 @@ server:
|
||||
parallelism: 2
|
||||
salt_length: 16
|
||||
key_length: 32
|
||||
max_concurrent_operations: 2
|
||||
database:
|
||||
min_connections: 0
|
||||
max_connections: 4
|
||||
@@ -87,10 +161,17 @@ 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
|
||||
@@ -100,6 +181,11 @@ 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
|
||||
@@ -128,4 +214,10 @@ 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
|
||||
`
|
||||
|
||||
+63
-11
@@ -1,8 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -12,17 +14,32 @@ import (
|
||||
const supportedConfigVersion = 1
|
||||
|
||||
var environmentKeys = map[string]string{
|
||||
"server.host": "APP_HOST",
|
||||
"server.port": "APP_PORT",
|
||||
"server.swagger_port": "SWAGGER_PORT",
|
||||
"database.url": "DATABASE_URL",
|
||||
"cache.url": "CACHE_URL",
|
||||
"object_storage.endpoint": "S3_ENDPOINT",
|
||||
"object_storage.region": "S3_REGION",
|
||||
"object_storage.bucket": "S3_BUCKET",
|
||||
"object_storage.access_key": "S3_ACCESS_KEY",
|
||||
"object_storage.secret_key": "S3_SECRET_KEY",
|
||||
"broker.url": "BROKER_URL",
|
||||
"server.host": "APP_HOST",
|
||||
"server.port": "APP_PORT",
|
||||
"server.health_address": "APP_HEALTH_ADDRESS",
|
||||
"server.metrics_address": "APP_METRICS_ADDRESS",
|
||||
"server.tls.ca_path": "APP_TLS_CA_PATH",
|
||||
"server.tls.certificate_path": "APP_TLS_CERTIFICATE_PATH",
|
||||
"server.tls.private_key_path": "APP_TLS_PRIVATE_KEY_PATH",
|
||||
"server.tls.allowed_client_uri": "APP_TLS_ALLOWED_CLIENT_URI",
|
||||
"server.tls.allowed_metrics_client_uri": "APP_TLS_ALLOWED_METRICS_CLIENT_URI",
|
||||
"server.swagger_port": "SWAGGER_PORT",
|
||||
"database.url": "DATABASE_URL",
|
||||
"cache.url": "CACHE_URL",
|
||||
"object_storage.endpoint": "S3_ENDPOINT",
|
||||
"object_storage.region": "S3_REGION",
|
||||
"object_storage.bucket": "S3_BUCKET",
|
||||
"object_storage.access_key": "S3_ACCESS_KEY",
|
||||
"object_storage.secret_key": "S3_SECRET_KEY",
|
||||
"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) {
|
||||
@@ -43,5 +60,40 @@ 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,6 +18,7 @@ type DispatcherConfig struct {
|
||||
DBHealthCheckPeriod time.Duration
|
||||
DependencyTimeout time.Duration
|
||||
BrokerURL string
|
||||
BrokerTLS ClientTLSConfig
|
||||
Stream string
|
||||
ConsumerGroup string
|
||||
FailedStream string
|
||||
@@ -31,6 +32,8 @@ type DispatcherConfig struct {
|
||||
CleanupInterval time.Duration
|
||||
CleanupBatchSize int
|
||||
MetricsAddress string
|
||||
HealthAddress string
|
||||
MetricsTLS ServerTLSConfig
|
||||
}
|
||||
|
||||
type WorkerConfig struct {
|
||||
@@ -47,8 +50,10 @@ type WorkerConfig struct {
|
||||
S3AccessKey string
|
||||
S3SecretKey string
|
||||
S3UseTLS bool
|
||||
S3CAPath string
|
||||
S3Timeout time.Duration
|
||||
BrokerURL string
|
||||
BrokerTLS ClientTLSConfig
|
||||
Stream string
|
||||
ConsumerGroup string
|
||||
FailedStream string
|
||||
@@ -67,6 +72,8 @@ type WorkerConfig struct {
|
||||
AttachmentMaxPixels int64
|
||||
MemoryBytes int64
|
||||
MetricsAddress string
|
||||
HealthAddress string
|
||||
MetricsTLS ServerTLSConfig
|
||||
}
|
||||
|
||||
type JobAdminConfig struct {
|
||||
@@ -116,6 +123,10 @@ 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
|
||||
@@ -152,16 +163,24 @@ 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, Stream: broker.stream, ConsumerGroup: broker.consumerGroup,
|
||||
BrokerURL: broker.url, BrokerTLS: brokerTLS, 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,
|
||||
MetricsAddress: metricsAddress, HealthAddress: healthAddress, MetricsTLS: metricsTLS,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -182,6 +201,10 @@ 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
|
||||
@@ -247,13 +270,22 @@ 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,
|
||||
S3Timeout: storage.timeout, BrokerURL: broker.url, Stream: broker.stream,
|
||||
S3CAPath: storage.caPath, S3Timeout: storage.timeout,
|
||||
BrokerURL: broker.url, BrokerTLS: brokerTLS, Stream: broker.stream,
|
||||
ConsumerGroup: broker.consumerGroup, FailedStream: broker.failedStream,
|
||||
FailedStreamMaxLength: int64(broker.failedStreamMaxLength),
|
||||
Concurrency: concurrency, Prefetch: prefetch, LeaseDuration: leaseDuration,
|
||||
@@ -261,6 +293,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -279,6 +312,29 @@ 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 {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/migrations"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/migrations"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
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}
|
||||
`
|
||||
@@ -0,0 +1,111 @@
|
||||
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))
|
||||
}
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
)
|
||||
|
||||
func TestUploadLifecycle(t *testing.T) {
|
||||
|
||||
@@ -23,11 +23,11 @@ import (
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/broker/redisstream"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/objectstore"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment/transform"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/objectstore"
|
||||
)
|
||||
|
||||
func TestConfigRequiresEnoughMemoryForMaximumImage(t *testing.T) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -16,9 +15,9 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/telemetry"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
|
||||
)
|
||||
|
||||
func (s *Server) uploadAttachment(w http.ResponseWriter, r *http.Request) *apiError {
|
||||
@@ -153,22 +152,6 @@ 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,12 +1,16 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
)
|
||||
|
||||
func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError {
|
||||
@@ -21,10 +25,19 @@ 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 internalError()
|
||||
return passwordOperationError(verifyErr)
|
||||
}
|
||||
return unauthorized()
|
||||
}
|
||||
@@ -33,11 +46,14 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
|
||||
}
|
||||
verified, err := s.passwords.Verify(passwordValue, credentials.PasswordHash)
|
||||
if err != nil {
|
||||
return internalError()
|
||||
return passwordOperationError(err)
|
||||
}
|
||||
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()
|
||||
@@ -51,6 +67,57 @@ 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,7 +2,10 @@ package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/password"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,6 +39,17 @@ 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"}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
)
|
||||
|
||||
var usernamePattern = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
|
||||
@@ -32,12 +32,15 @@ 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"})
|
||||
@@ -61,7 +64,7 @@ func (s *Server) users(w http.ResponseWriter, r *http.Request) *apiError {
|
||||
}
|
||||
passwordHash, err := s.passwords.Hash(input.Password)
|
||||
if err != nil {
|
||||
return internalError()
|
||||
return passwordOperationError(err)
|
||||
}
|
||||
user, err := s.userRepository.CreateUser(r.Context(), input.Username, input.DisplayName, passwordHash)
|
||||
if errors.Is(err, model.ErrConflict) {
|
||||
|
||||
@@ -4,14 +4,15 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
)
|
||||
|
||||
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 {
|
||||
@@ -45,5 +46,10 @@ 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)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user