Every service connected to PostgreSQL as the database owner, which is a superuser, so anything that compromised an app process owned the cluster, and every connection reached the server with an empty application_name, so pg_stat_activity could not say which service a session belonged to. Split the DB credential into two login roles and name every pool: - archie_migrator owns public and its objects and runs goose. Migrations run on a short-lived pool opened from the new migration_database_url, before the serving pool opens. It is not a superuser. - archie_runtime serves requests with SELECT, INSERT, UPDATE, DELETE, sequence USAGE/SELECT and function EXECUTE only. It has no CREATE privilege, so it cannot change the schema. - Every pool sets application_name: archie-state-store, archie-gateway, and a -migrate / -recovery / -schema / -provision suffix on the transient administrative connections. Existing one-URL installs keep working: an absent migration_database_url falls back to database_url and the migration runs on the serving pool exactly as before. Provisioning is a new idempotent `archie-state-store provision` subcommand: it needs an admin URL the services never hold (database owner or superuser), creates or reconciles both roles, hands every public-schema object to the migration role, revokes PUBLIC's CREATE on public, sets row-level grants, and sets the migration role's default privileges so tables future migrations create are usable without a hand-run grant. It stores SCRAM verifiers, refuses superuser roles, and verifies the boundary before committing. install.sh now provisions the bundled path and separates the credentials: the superuser password the Compose database is created with lives only in a compose-only postgres.env, while the env file the units load holds the non-superuser PGPASSWORD. A bundled install that predates the split is upgraded in place: the roles are created, the superuser password is rotated out of the env file, and config.toml is moved to the runtime and migration URLs. External databases keep their operator-managed credential; the deployments README documents the one-shot provision command. setup writes both bundled URLs, dev:postgres provisions the dev database, the e2e stack provisions its throwaway server, and the deployment templates point at the two roles.
125 lines
5.3 KiB
YAML
125 lines
5.3 KiB
YAML
# PostgreSQL for the State Store, optional external NATS, and the agent images
|
|
# the daemon spawns per task.
|
|
#
|
|
# archied itself runs on the host under systemd, not here -- its chat tools
|
|
# operate on host files, which a container cannot reach. See
|
|
# deployments/systemd-user-service.md.
|
|
#
|
|
# Embedded NATS is the normal deployment and needs no Compose service.
|
|
# State Store DB: docker compose up -d postgres
|
|
# External broker: docker compose up -d nats
|
|
# Build worker: task image:agent (stamps this checkout's version)
|
|
# Profile image: docker compose build agent-net
|
|
# Stop external: docker compose down
|
|
# Logs: journalctl --user -u archied -f (the daemon)
|
|
# docker compose logs -f nats (the bus)
|
|
|
|
services:
|
|
# ── PostgreSQL (State Store) ───────────────────────────────────
|
|
# The standalone archie-state-store process's database. PostgreSQL 18 is
|
|
# the required minimum and target; `postgres.Open` refuses anything older.
|
|
# `task dev` brings this up before the State Store via dev:postgres. The
|
|
# This superuser is the dev database's admin: `task dev` runs archie-state-store
|
|
# provision after first start to create the least-privilege roles the
|
|
# mirroring deployments/dev.toml URLs name -- change them together.
|
|
postgres:
|
|
image: postgres:18
|
|
environment:
|
|
POSTGRES_USER: archie
|
|
POSTGRES_PASSWORD: archie
|
|
POSTGRES_DB: archie
|
|
# postgres:18 moved its default PGDATA under a versioned path; pin the
|
|
# classic location so the named volume keeps working across image updates.
|
|
PGDATA: /var/lib/postgresql/data/pgdata
|
|
ports:
|
|
- "127.0.0.1:5432:5432"
|
|
volumes:
|
|
- pg_data:/var/lib/postgresql/data
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U archie -d archie"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# ── NATS JetStream ────────────────────────────────────────────────
|
|
nats:
|
|
image: nats:2.14-alpine3.22
|
|
# The client port is published on every interface (agent containers reach
|
|
# it over the bridge), so it refuses to start without a token. Set
|
|
# NATS_TOKEN here and name the same value in [nats] token_env.
|
|
entrypoint:
|
|
- sh
|
|
- -c
|
|
- '[ -n "$$NATS_TOKEN" ] || { echo "NATS_TOKEN is required" >&2; exit 1; }; exec nats-server -js -m 8222 --auth "$$NATS_TOKEN"'
|
|
environment:
|
|
NATS_TOKEN: ${NATS_TOKEN:-}
|
|
ports:
|
|
- "4222:4222" # client
|
|
- "127.0.0.1:8222:8222" # monitoring (http://localhost:8222)
|
|
volumes:
|
|
- nats_data:/data
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "-", "http://localhost:8222/healthz"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# ── agent image (built once, spawned per task by the daemon) ───────
|
|
# Not a long-running service: the daemon starts agent containers itself
|
|
# via the Docker socket. This stanza exists only so the image can be
|
|
# built locally.
|
|
#
|
|
# The build profile keeps `up -d` from starting it. Without it compose
|
|
# creates a container that exits 0 immediately and still reports
|
|
# "Started", which reads like a crash loop. Naming the service explicitly
|
|
# still works without activating the profile:
|
|
#
|
|
# docker compose build agent
|
|
# docker compose pull agent -- plain `pull` skips profiled services
|
|
#
|
|
# Routine freshness is handled by the daemon, which pulls this image per
|
|
# task: see containers.pull_policy in the config. Watchtower cannot do it
|
|
# -- it only restarts long-running containers, and this is not one.
|
|
agent:
|
|
profiles: ["build"]
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
# Stamped into the agent so the version it reports is the one the rest of
|
|
# the install reports. `task image:agent` passes this checkout's version;
|
|
# a bare `docker build` passes nothing and the agent answers dev.
|
|
args:
|
|
RUNTIME_VERSION: ${RUNTIME_VERSION:-dev}
|
|
# A tag, not the digest: Compose refuses to build an image it is told to
|
|
# name by digest. The digest a task container actually runs is pinned in
|
|
# the daemon's own [containers] image, so nothing here decides it. See
|
|
# deployments/systemd-user-service.md#6-pinning-the-archie-agent-image.
|
|
image: git.catlow.cloud/sam/archie-agent:latest
|
|
|
|
# ── example agent profile image ─────────────────────────────────────
|
|
# The agent image plus network lookup tools, for a workflow that names
|
|
# `profile: network-investigator` (archipelago: workflows/firewall).
|
|
# Build-only for the same reason as agent. It is local, so leave
|
|
# containers.pull_policy at "missing": "always" would try to pull it.
|
|
agent-net:
|
|
profiles: ["build"]
|
|
build:
|
|
context: examples/profiles
|
|
dockerfile: Dockerfile.agent-net
|
|
image: archie-agent-net:local
|
|
|
|
volumes:
|
|
nats_data:
|
|
pg_data:
|
|
|
|
# The subnet is pinned for the optional external-broker profile because its
|
|
# configured URL must be reachable from both the native daemon and workers.
|
|
# Embedded mode discovers its selected bridge gateway at startup instead.
|
|
networks:
|
|
default:
|
|
ipam:
|
|
config:
|
|
- subnet: 172.19.0.0/16
|