Phase 10: central realm Registry, Host publishing lifecycle, deployment

crates/coa-registry-proto (protocol 1: types, limits, signed-request canonicalisation, test vectors),
services/coa-registry (axum + PostgreSQL, migrations, rate limits, Dockerfile, deploy files),
services/coa-registry-e2e (Host lifecycle against the real service, live VPS gate),
coa-core realm_registry (identity keys, client, publishing loop on its own thread),
Settings -> Public listing card, docs REGISTRY_PROTOCOL.md and REGISTRY_DEPLOYMENT.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-10-07 20:23:13 +05:00
1 parent ec40f146aa
commit 1267bcc41e
56 files changed
+10198 -13

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
{
# No domain yet: plain HTTP on :80 only, no ACME, no admin API. HTTPS is required before the public phases.
auto_https off
admin off
}
:80 {
respond /healthz "ok" 200
handle /registry/* {
request_body {
max_size 70KB
}
reverse_proxy coa-registry:8080 {
# the Registry rate-limits by the address Caddy saw, taken from the last entry of this header
header_up X-Forwarded-For {remote_host}
transport http {
dial_timeout 3s
response_header_timeout 15s
}
}
}
respond "not found" 404
}
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
# Run on the node as root: sudo sh audit-db.sh (the password is read inside the container from its own secret)
set -eu
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec psql -U coa -d coa_registry -X -q' < "$(dirname "$0")/audit-db.sql"
+14
View File
@@ -0,0 +1,14 @@
-- Phase-10 gate item 17: what the database holds. Run: sudo sh audit-db.sh
\echo == tables
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY 1;
\echo == columns of realms
SELECT column_name || ' ' || data_type FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'realms' ORDER BY ordinal_position;
\echo == any table or column that looks like players, characters, accounts, credentials, snapshots (must be empty)
SELECT table_name || '.' || column_name FROM information_schema.columns
WHERE table_schema = 'public' AND (column_name ~* '(password|passwd|secret|token|credential|account|character|snapshot|inventory|payload|session|canonical|guid|ra_user|mysql)' OR table_name ~* '(player|character|account|session|snapshot|credential)');
\echo == rows containing forbidden words anywhere in their text form (must be 0)
SELECT count(*) FROM realms r WHERE row_to_json(r)::text ~* '(password|credential|secret|snapshot|inventory|canonical|character_id|ra_password|mysql|private)';
\echo == the keys stored are public keys of 32 bytes (private keys are 32 bytes too: they are never sent, there is no field for them)
SELECT count(*) AS realms, count(*) FILTER (WHERE octet_length(public_key) = 32) AS keys32 FROM realms;
\echo == largest stored capabilities (bytes)
SELECT max(octet_length(capabilities::text)) FROM realms;
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
# Build the Registry image on the node from the working tree and (re)start the stack. Usage (from the repository root):
# VPS=ubuntu@<VPS_IP> TAG=p10c sh services/coa-registry/deploy/deploy.sh
# Secrets are never touched here: /opt/coa/secrets/{postgres_password,registry_db_password} must already exist (see docs/REGISTRY_DEPLOYMENT.md).
set -eu
: "${VPS:?set VPS=user@host}" "${TAG:?set TAG=<image tag>}"
tar --exclude=target -czf /tmp/registry-src.tgz crates/coa-registry-proto services/coa-registry .dockerignore
scp -q /tmp/registry-src.tgz "$VPS:/tmp/registry-src.tgz"
ssh "$VPS" "set -e
sudo rm -rf /opt/coa/registry/src && mkdir -p /opt/coa/registry/src && tar -xzf /tmp/registry-src.tgz -C /opt/coa/registry/src
cd /opt/coa/registry/src && sudo docker build -q -f services/coa-registry/Dockerfile -t coa-registry:$TAG . >/dev/null
cd /opt/coa/registry && sudo sed -i 's/^REGISTRY_TAG=.*/REGISTRY_TAG=$TAG/' .env && sudo docker compose up -d
sleep 8 && sudo docker ps --format '{{.Names}} {{.Status}}'"
@@ -0,0 +1,39 @@
#!/bin/sh
# Phase-10 gate items 2 and 14, driven from a workstation: VPS=ubuntu@<VPS_IP> REGISTRY_URL=http://<VPS_IP> sh gate-restarts.sh
# A realm is registered once (random key); after every restart below it must still be there and must still be able to heartbeat with its own key.
set -u
: "${VPS:?}" "${REGISTRY_URL:?}"
E2E="$(cd "$(dirname "$0")/../../coa-registry-e2e" && pwd)"
run() { (cd "$E2E" && REGISTRY_URL="$REGISTRY_URL" "$@" 2>&1); }
remote() { ssh "$VPS" "$1"; }
wait_healthy() { # $1 container, $2 seconds
i=0; while [ $i -lt "$2" ]; do
s=$(remote "sudo docker inspect -f '{{.State.Health.Status}}' $1 2>/dev/null"); [ "$s" = healthy ] && return 0; i=$((i+2)); sleep 2; done; return 1; }
wait_api() { i=0; while [ $i -lt 90 ]; do code=$(curl -s -o /dev/null -m 5 -w '%{http_code}' "$REGISTRY_URL/registry/v1/healthz"); [ "$code" = 200 ] && return 0; i=$((i+2)); sleep 2; done; return 1; }
out=$(run cargo test --test live_vps gate_persist_probe_write -- --ignored --nocapture | grep PERSIST_REALM)
set -- $out; REALM=$2; SEED=$3
[ -n "$REALM" ] || { echo "GATE FAIL: probe write"; exit 1; }
echo "probe realm $REALM written"
check() { # $1 label
r=$(PERSIST_REALM=$REALM PERSIST_SEED=$SEED run cargo test --test live_vps gate_persist_probe_read -- --ignored --nocapture | grep -E "PERSIST_OK|panicked")
case "$r" in *PERSIST_OK*) echo "GATE PASS $1: realm still registered, own key still accepted";; *) echo "GATE FAIL $1: $r"; return 1;; esac; }
echo "--- 2. Registry container restart"
remote "sudo docker restart coa-registry-registry-1 >/dev/null"; wait_healthy coa-registry-registry-1 90 && wait_api && check "2: after restarting the Registry container"
echo "--- 14a. PostgreSQL container restart (health is degraded meanwhile, then recovers by itself)"
remote "sudo docker restart coa-postgres-postgres-1 >/dev/null"
sleep 1; echo "health during the restart: $(curl -s -m 5 -o /dev/null -w '%{http_code}' "$REGISTRY_URL/registry/v1/healthz")"
wait_healthy coa-postgres-postgres-1 90 && wait_api && check "14a: after restarting PostgreSQL (the Registry container was not restarted)"
echo "--- 14b. both stopped, PostgreSQL started later than the Registry (the Registry waits for it)"
remote "sudo docker stop coa-registry-registry-1 coa-postgres-postgres-1 >/dev/null; sudo docker start coa-registry-registry-1 >/dev/null"
sleep 6; echo "Registry up without a database: health $(curl -s -m 5 -o /dev/null -w '%{http_code}' "$REGISTRY_URL/registry/v1/healthz")"
remote "sudo docker start coa-postgres-postgres-1 >/dev/null"
wait_healthy coa-postgres-postgres-1 90 && wait_healthy coa-registry-registry-1 120 && wait_api && check "14b: after a cold start in the wrong order"
echo "--- 14c. the stack taken down and brought up again (the data lives in the volume)"
remote "cd /opt/coa/registry && sudo docker compose down >/dev/null 2>&1; cd /opt/coa/postgres && sudo docker compose down >/dev/null 2>&1; cd /opt/coa/postgres && sudo docker compose up -d >/dev/null 2>&1; cd /opt/coa/registry && sudo docker compose up -d >/dev/null 2>&1"
wait_healthy coa-postgres-postgres-1 90 && wait_healthy coa-registry-registry-1 120 && wait_api && check "14c: after compose down/up of both stacks"
remote "sudo docker ps --format '{{.Names}} {{.Status}}'"
@@ -0,0 +1,37 @@
# /opt/coa/postgres/compose.yaml (Phase 10). No `ports:`: PostgreSQL is reachable only on the internal coa-db network.
# The superuser password is read from /opt/coa/secrets (never in git); the Registry has its own least-privilege role and database.
name: coa-postgres
services:
postgres:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_USER: coa
POSTGRES_DB: coa
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256 --auth-local=scram-sha-256"
command: ["postgres", "-c", "max_connections=40", "-c", "shared_buffers=128MB", "-c", "password_encryption=scram-sha-256", "-c", "log_min_duration_statement=1000"]
secrets:
- postgres_password
volumes:
- pgdata:/var/lib/postgresql/data
networks:
coa-db:
aliases:
- coa-postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U coa -d coa"]
interval: 15s
timeout: 5s
retries: 5
mem_limit: 768m
security_opt:
- no-new-privileges:true
secrets:
postgres_password:
file: /opt/coa/secrets/postgres_password
volumes:
pgdata:
networks:
coa-db:
external: true
@@ -0,0 +1,18 @@
#!/bin/sh
# Create the Registry's database role and database (idempotent). Run on the node as root: sudo sh provision-db.sh
# The password is read from /opt/coa/secrets/registry_db_password and goes to psql on stdin, never on a command line.
set -eu
PW=$(cat /opt/coa/secrets/registry_db_password)
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec psql -U coa -d coa -v ON_ERROR_STOP=1 -q' <<SQL
DO \$\$ BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'coa_registry') THEN
CREATE ROLE coa_registry LOGIN PASSWORD '$PW' NOSUPERUSER NOCREATEDB NOCREATEROLE CONNECTION LIMIT 20;
ELSE
ALTER ROLE coa_registry PASSWORD '$PW';
END IF;
END \$\$;
SELECT 'CREATE DATABASE coa_registry OWNER coa_registry' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'coa_registry')\gexec
REVOKE ALL ON DATABASE coa_registry FROM PUBLIC;
GRANT CONNECT ON DATABASE coa_registry TO coa_registry;
SQL
echo "registry role and database are in place"
@@ -0,0 +1,45 @@
# /opt/coa/registry/compose.yaml (Phase 10). The Registry publishes no host port: Caddy reaches it as coa-registry:8080 on coa-ingress,
# and it reaches PostgreSQL as coa-postgres on coa-db. The image is built on the node from the repository (see docs/REGISTRY_DEPLOYMENT.md).
name: coa-registry
services:
registry:
image: coa-registry:${REGISTRY_TAG:-latest}
restart: unless-stopped
environment:
REGISTRY_LISTEN: "0.0.0.0:8080"
REGISTRY_TRUST_PROXY: "1"
REGISTRY_DB_HOST: coa-postgres
REGISTRY_DB_NAME: coa_registry
REGISTRY_DB_USER: coa_registry
REGISTRY_DB_PASSWORD_FILE: /run/secrets/registry_db_password
REGISTRY_DB_POOL: "8"
REGISTRY_DB_STATEMENT_TIMEOUT_MS: "5000"
REGISTRY_MAX_CONNECTIONS: "256"
REGISTRY_MAX_IN_FLIGHT: "64"
REGISTRY_REQUEST_TIMEOUT_SECS: "10"
# staging: enough registrations from one address for the Phase-10 gate; the built-in default is 10 per hour
REGISTRY_REGISTER_BURST: "${REGISTRY_REGISTER_BURST:-10}"
REGISTRY_REGISTER_PER_HOUR: "${REGISTRY_REGISTER_PER_HOUR:-10}"
RUST_LOG: "info"
secrets:
- registry_db_password
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
mem_limit: 256m
pids_limit: 128
networks:
coa-ingress:
aliases:
- coa-registry
coa-db: {}
secrets:
registry_db_password:
file: /opt/coa/secrets/registry_db_password
networks:
coa-ingress:
external: true
coa-db:
external: true