Add shared cluster credentials and readiness CI
ObjectStore CI / build (push) Successful in 10m22s

This commit is contained in:
admin committed 2026-11-16 03:41:32 +01:00
1 parent b724a21a0d
commit d73fa2c435
45 files changed
+2733 -226

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
FROM postgres:17-alpine
RUN apk add --no-cache python3 py3-pip py3-psycopg2 && \
python3 -m venv --system-site-packages /opt/patroni && \
/opt/patroni/bin/pip install --no-cache-dir 'patroni[etcd3]==4.1.5'
COPY patroni.yaml /etc/patroni.yaml
COPY bootstrap.sh /usr/local/bin/bootstrap-objectstore
RUN chmod 755 /usr/local/bin/bootstrap-objectstore
USER postgres
ENTRYPOINT ["/opt/patroni/bin/patroni", "/etc/patroni.yaml"]
+74
View File
@@ -0,0 +1,74 @@
# Metadata failover drill
This isolated test runs three PostgreSQL members under Patroni, three etcd voters,
two storage nodes, and one ObjectStore gateway. It tests automatic metadata
promotion and gateway reconnection. All containers run on one machine, so it
does not establish physical fault isolation or production readiness.
Requires Docker Compose, Python 3, and about 2 GiB of available Docker memory.
PostgreSQL and etcd use disposable volumes that survive container restarts. Only the gateway
has a published port, allocated on loopback. The script generates a unique
Compose project and removes its containers and volumes on exit. It never uses
the repository's `.env` or an existing deployment.
```sh
python3 scripts/test-ha.py --output out/ha-report.json
```
To reuse an image built from this checkout, add `--image IMAGE`. The report path
must not already exist. Keep reports outside Git if they contain local details.
The test:
1. Waits for a primary and synchronous standby, then writes small signed objects.
2. Kills the primary container without stopping the gateway.
3. Waits for Patroni promotion, reads every acknowledged object, and writes more.
4. Restarts the old primary and checks that it rejoins the cluster.
5. Kills both standbys and checks that strict replication stops acknowledging writes.
6. Restores them, then stops two etcd voters and checks that readiness and writes fail.
7. Restores quorum and verifies acknowledged objects again.
The database uses synchronous replication with `synchronous_mode_strict: true`.
Losing the eligible synchronous replicas can stop writes; availability must not
silently take priority over the configured durability policy. Requests interrupted
by a failure have uncertain outcomes and are not counted as acknowledged.
See [Patroni replication modes](https://patroni.readthedocs.io/en/latest/replication_modes.html).
## Operating metadata HA on separate machines
Use the tested configuration as a behavior reference, not deployment credentials.
The fixture has public test passwords, private-network plaintext traffic, and no
hardware watchdog. Never expose its database, etcd, or Patroni APIs.
For a separately operated HA deployment:
1. Place the three PostgreSQL members and etcd majority across independent machines.
Give each member durable storage and unique credentials. Keep ObjectStore's
database role separate from PostgreSQL superuser and replication roles.
2. Configure TLS and authentication for etcd peer/client traffic and Patroni's
management API. Enable PostgreSQL TLS with hostname verification on every client.
3. Enable Patroni synchronous mode, strict mode, and at least one synchronous
standby. Keep PostgreSQL `synchronous_commit=on`; do not override it in the
ObjectStore database or role settings.
4. Configure and test host fencing. Patroni's required watchdog mode refuses
promotion if its watchdog is unavailable. A stalled controller must not leave
an old primary accepting writes after its lease expires. The local fixture
intentionally cannot reboot the machine. See
[Patroni watchdog requirements](https://patroni.readthedocs.io/en/latest/watchdog.html).
5. Give each gateway and maintenance process a primary-only JDBC URL:
```text
jdbc:postgresql://db-a:5432,db-b:5432,db-c:5432/objectstore?targetServerType=primary&connectTimeout=3&socketTimeout=10&hostRecheckSeconds=1&sslmode=verify-full&sslrootcert=/certs/metadata-ca.pem
```
6. Back up PostgreSQL and storage independently of this cluster. Rehearse restore
into fresh infrastructure; replication does not protect against deletion or
an administrative mistake. Recover the managed-credential encryption key with
the metadata backup when managed credentials are enabled.
7. Repeat the drill on those machines, including network partitions and fencing,
before directing important data to them. Monitor replication lag, quorum,
disk space, backup age, and restore results.
ObjectStore reconnects to the elected primary; Patroni controls promotion and
demotion. Do not promote a database by hand while its former primary can still
accept traffic. Do not force promotion of a stale replica to make a test pass.
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu
psql "$1" -v ON_ERROR_STOP=1 -c \
"CREATE ROLE objectstore LOGIN PASSWORD 'ha-test-database-password'"
psql "$1" -v ON_ERROR_STOP=1 -c \
'CREATE DATABASE objectstore OWNER objectstore'
+128
View File
@@ -0,0 +1,128 @@
x-etcd: &etcd
image: quay.io/coreos/etcd:v3.6.5
entrypoint: /usr/local/bin/etcd
mem_limit: 128m
volumes:
- /etcd-data
security_opt:
- no-new-privileges:true
x-etcd-env: &etcd-env
ETCD_DATA_DIR: /etcd-data
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
ETCD_INITIAL_CLUSTER: etcd-a=http://etcd-a:2380,etcd-b=http://etcd-b:2380,etcd-c=http://etcd-c:2380
ETCD_INITIAL_CLUSTER_TOKEN: objectstore-disposable-ha-test
ETCD_INITIAL_CLUSTER_STATE: new
ETCD_QUOTA_BACKEND_BYTES: "33554432"
ETCD_MAX_WALS: "2"
ETCD_MAX_SNAPSHOTS: "2"
ETCD_LOG_LEVEL: warn
x-postgres: &postgres
image: objectstore-ha-postgres:local
build: .
mem_limit: 256m
volumes:
- /var/lib/postgresql/data
security_opt:
- no-new-privileges:true
depends_on:
- etcd-a
- etcd-b
- etcd-c
x-node: &node
image: ${OBJECTSTORE_HA_IMAGE:-objectstore-ha-test:local}
entrypoint: [java, -Xmx96m, --add-modules, "jdk.httpserver,java.net.http", -cp, /app:/app/postgresql.jar:/app/hash4j.jar, cloud.lunarsky.store.ClusterNode]
mem_limit: 160m
environment:
CLUSTER_TOKEN: ha-test-cluster-token-012345678901234567
CLUSTER_REPAIR_TOKEN: ha-test-repair-token-012345678901234567
CLUSTER_HOST_ID: 82ae31fb-522e-40c6-ac78-aa1c003f9a18
DATA_DIR: /data
NODE_BIND: 0.0.0.0
volumes:
- /data
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:9100/health"]
interval: 2s
timeout: 2s
retries: 30
services:
etcd-a:
<<: *etcd
environment:
<<: *etcd-env
ETCD_NAME: etcd-a
ETCD_ADVERTISE_CLIENT_URLS: http://etcd-a:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd-a:2380
etcd-b:
<<: *etcd
environment:
<<: *etcd-env
ETCD_NAME: etcd-b
ETCD_ADVERTISE_CLIENT_URLS: http://etcd-b:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd-b:2380
etcd-c:
<<: *etcd
environment:
<<: *etcd-env
ETCD_NAME: etcd-c
ETCD_ADVERTISE_CLIENT_URLS: http://etcd-c:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd-c:2380
db-a:
<<: *postgres
environment:
PATRONI_NAME: db-a
PATRONI_POSTGRESQL_CONNECT_ADDRESS: db-a:5432
PATRONI_RESTAPI_CONNECT_ADDRESS: db-a:8008
db-b:
<<: *postgres
environment:
PATRONI_NAME: db-b
PATRONI_POSTGRESQL_CONNECT_ADDRESS: db-b:5432
PATRONI_RESTAPI_CONNECT_ADDRESS: db-b:8008
db-c:
<<: *postgres
environment:
PATRONI_NAME: db-c
PATRONI_POSTGRESQL_CONNECT_ADDRESS: db-c:5432
PATRONI_RESTAPI_CONNECT_ADDRESS: db-c:8008
node-a:
<<: *node
node-b:
<<: *node
gateway:
image: ${OBJECTSTORE_HA_IMAGE:-objectstore-ha-test:local}
mem_limit: 256m
environment:
STORE_MODE: cluster
CLUSTER_LOCAL_DEV: "true"
CLUSTER_TEST_NODE_DOMAINS: "true"
CLUSTER_NODES: http://node-a:9100,http://node-b:9100
CLUSTER_TOKEN: ha-test-cluster-token-012345678901234567
POSTGRES_JDBC_URL: jdbc:postgresql://db-a:5432,db-b:5432,db-c:5432/objectstore?targetServerType=primary&connectTimeout=1&socketTimeout=5&hostRecheckSeconds=0
POSTGRES_USER: objectstore
POSTGRES_PASSWORD: ha-test-database-password
S3_ACCESS_KEY: HaTestAccessKey0001
S3_SECRET_KEY: ha-test-s3-secret-01234567890123456789
S3_BUCKET: ha-test
MAX_OBJECT_BYTES: "1048576"
MAX_TOTAL_BYTES: "16777216"
BIND_ADDRESS: 0.0.0.0
ports:
- "127.0.0.1::9000"
networks:
- default
- client
depends_on:
node-a:
condition: service_healthy
node-b:
condition: service_healthy
networks:
default:
internal: true
client: {}
+54
View File
@@ -0,0 +1,54 @@
scope: objectstore-ha-test
namespace: /objectstore-test/
restapi:
listen: 0.0.0.0:8008
authentication:
username: operator
password: ha-test-rest-password
etcd3:
hosts: etcd-a:2379,etcd-b:2379,etcd-c:2379
bootstrap:
dcs:
ttl: 20
loop_wait: 2
retry_timeout: 3
primary_start_timeout: 0
primary_stop_timeout: 5
synchronous_mode: true
synchronous_mode_strict: true
synchronous_node_count: 1
failsafe_mode: false
postgresql:
use_pg_rewind: true
parameters:
synchronous_commit: "on"
password_encryption: scram-sha-256
shared_buffers: 32MB
max_connections: 64
max_wal_size: 128MB
min_wal_size: 32MB
wal_keep_size: 64MB
max_slot_wal_keep_size: 128MB
initdb:
- encoding: UTF8
- data-checksums
post_bootstrap: /usr/local/bin/bootstrap-objectstore
postgresql:
listen: 0.0.0.0:5432
data_dir: /var/lib/postgresql/data/pgdata
pgpass: /tmp/pgpass
basebackup:
checkpoint: fast
authentication:
superuser:
username: postgres
password: ha-test-superuser-password
replication:
username: replicator
password: ha-test-replication-password
pg_hba:
- local all all trust
- host replication replicator all scram-sha-256
- host all all all scram-sha-256
watchdog:
mode: "off"
+2 -1
View File
@@ -17,9 +17,10 @@ services:
check:
build:
context: ../..
image: lunarsky-objectstore:metadata-test
image: ${OBJECTSTORE_TEST_IMAGE:-lunarsky-objectstore:metadata-test}
entrypoint: ["java", "--add-modules", "jdk.httpserver,java.net.http", "-cp", "/app:/app/postgresql.jar:/app/hash4j.jar", "cloud.lunarsky.store.ClusterMetadataTest"]
environment:
JAVA_TOOL_OPTIONS: -Xmx192m -XX:ActiveProcessorCount=2
POSTGRES_JDBC_URL: jdbc:postgresql://127.0.0.2:5432,metadata:5432/objectstore_test?connectTimeout=1&socketTimeout=10&targetServerType=primary&hostRecheckSeconds=0
POSTGRES_ADMIN_JDBC_URL: jdbc:postgresql://metadata:5432/postgres?connectTimeout=3&socketTimeout=10
POSTGRES_USER: objectstore_test
+1 -1
View File
@@ -47,4 +47,4 @@ Stop the node container on machine A and repeat the rejection and read checks us
For a manual metadata recovery drill, take a custom-format `pg_dump` after the last acknowledged write and verify it with `pg_restore --list`. Copy the dump to machine B and restore it into a fresh PostgreSQL volume there. Stop the original gateway and metadata container on machine A. Start a separate gateway against the restored database, then verify the journal. Finally stop the storage node on machine A and verify again: this forces reads to use both the restored metadata and the replica on machine B. Keep the backup and its credentials private.
Passing this drill does not prove every crash point, disk-controller write behavior, long-term bit-rot resistance, automatic metadata failover, or production readiness. The cluster still requires a manual metadata restore.
Passing this drill does not prove every crash point, disk-controller write behavior, long-term bit-rot resistance, automatic metadata failover, or production readiness. This drill uses manual metadata restore. The separate [local HA drill](../ha/README.md) tests automatic promotion with Patroni; it does not replace validation across physical machines.