From 193a44b1f1dfe9caf5f88f2deeaae82e0f12171a Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 4 Dec 2026 15:14:02 -0600 Subject: [PATCH] Provision OpsProof test database --- apps/opsproof/README.md | 13 +-- docs/jeannie.1.md | 5 ++ docs/opsproof-architecture.md | 3 + lib/jeannie/pipeline.sh | 83 +++++++++++++++++-- .../jeannie/test_privacy_services_pipeline.py | 10 +++ 5 files changed, 104 insertions(+), 10 deletions(-) diff --git a/apps/opsproof/README.md b/apps/opsproof/README.md index e926312..b9565e6 100644 --- a/apps/opsproof/README.md +++ b/apps/opsproof/README.md @@ -34,11 +34,14 @@ The Debian installation is owned by the Jeannie pipeline: ./jeannie deploy-opsproof ``` -The command downloads a checksum-pinned Go 1.27 toolchain into the OpsProof -data directory, checks out an exact Laravel Go starter commit, normalizes the UI -overlay with that starter's pinned formatter, runs its frontend checks and -build, runs its Go tests, builds the binary, installs a hardened systemd unit, -and verifies `/up`. It does not replace Debian's system Go. +The command starts a dedicated, persistent PostgreSQL container, downloads a +checksum-pinned Go 1.27 toolchain into the OpsProof data directory, checks out +an exact Laravel Go starter commit, normalizes the UI overlay with that +starter's pinned formatter, runs its frontend checks and build, runs the Go +feature tests against PostgreSQL, builds the binary, applies database +migrations, installs a hardened systemd unit, and verifies `/up`. Database +credentials are generated once and retained in the private OpsProof data +directory. It does not replace Debian's system Go. ## Security boundary diff --git a/docs/jeannie.1.md b/docs/jeannie.1.md index 4595e32..63aed9d 100644 --- a/docs/jeannie.1.md +++ b/docs/jeannie.1.md @@ -651,6 +651,11 @@ checksum-verified and does not replace Debian's system Go. : Pin the Laravel Go starter source used for the OpsProof build. The commit must be a full Git SHA. +`LAB_OPSPROOF_POSTGRES_IMAGE`, `LAB_OPSPROOF_POSTGRES_PORT` +: Override the pinned OpsProof PostgreSQL image and its loopback-only host port. + Defaults are `docker.io/postgres:18-alpine` and `55439`. The deployment + preserves generated database credentials and data under the OpsProof root. + `LAB_RPI_INSTALL_DOCKER=true` : Allow `rpi-services` to install Docker through `get.docker.com` on the Raspberry Pi when Docker is missing. Default is to fail. diff --git a/docs/opsproof-architecture.md b/docs/opsproof-architecture.md index 4237ce7..25ab50e 100644 --- a/docs/opsproof-architecture.md +++ b/docs/opsproof-architecture.md @@ -31,6 +31,7 @@ OpsProof on Debian |-- session, Dex identity, authorization |-- incident/proposal/audit records |-- redaction and public-demo projection + |-- dedicated PostgreSQL database | | authenticated structured requests v @@ -51,6 +52,8 @@ confirmed by deterministic validation. ## Deployment constraints - Run on Debian so a Kubernetes outage does not remove the incident UI. +- Keep OpsProof records in its own persistent PostgreSQL service and use the + same database contract for feature tests, migrations, and runtime. - Build with a pinned Laravel Go dependency and Go 1.27 or newer. - Publish a health endpoint independently from Jeannie health. - Send Laravel Go's OpenTelemetry traces to the existing Debian monitoring diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 0de0359..0e16ded 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -5676,11 +5676,19 @@ deploy_opsproof() { local starter_repo="${LAB_OPSPROOF_STARTER_REPO:-https://github.com/laravel/go.git}" local overlay_dir="${REPO_ROOT}/apps/opsproof/overlay" local service_user="${LAB_OPSPROOF_SERVICE_USER:-$(id -un)}" + local postgres_image="${LAB_OPSPROOF_POSTGRES_IMAGE:-docker.io/postgres:18-alpine}" + local postgres_port="${LAB_OPSPROOF_POSTGRES_PORT:-55439}" + local postgres_container="${LAB_OPSPROOF_POSTGRES_CONTAINER:-opsproof-postgres}" + local postgres_db="${LAB_OPSPROOF_POSTGRES_DB:-opsproof}" + local postgres_user="${LAB_OPSPROOF_POSTGRES_USER:-opsproof}" local toolchain_dir="${install_dir}/toolchains/go${go_version}" local release_dir="${install_dir}/releases/${starter_commit}" + local database_env="${install_dir}/.database.env" local build_dir="" local archive="" local app_key="" + local postgres_password="" + local database_url="" local elapsed=0 local node_major="" local required @@ -5707,8 +5715,18 @@ deploy_opsproof() { echo "LAB_OPSPROOF_SERVICE_USER is invalid." >&2 return 1 fi + if ! [[ "${postgres_port}" =~ ^[0-9]+$ ]] || ((postgres_port < 1 || postgres_port > 65535)); then + echo "LAB_OPSPROOF_POSTGRES_PORT must be a valid TCP port." >&2 + return 1 + fi + if ! [[ "${postgres_container}" =~ ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$ ]] || + ! [[ "${postgres_db}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || + ! [[ "${postgres_user}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then + echo "OpsProof PostgreSQL container, database, or user name is invalid." >&2 + return 1 + fi - for required in curl git npm openssl sha256sum systemctl tar; do + for required in curl docker git npm openssl sha256sum systemctl tar; do if ! command -v "${required}" >/dev/null 2>&1; then echo "OpsProof deployment requires ${required} on Debian." >&2 return 1 @@ -5726,6 +5744,51 @@ deploy_opsproof() { sudo install -d -o "${service_user}" -g "${service_user}" -m 0750 \ "${install_dir}" "${install_dir}/releases" "${install_dir}/toolchains" + sudo install -d -m 0700 "${install_dir}/postgres" + + if [[ -s "${database_env}" ]]; then + postgres_password="$(sed -n 's/^POSTGRES_PASSWORD=//p' "${database_env}" | head -n 1)" + fi + if ! [[ "${postgres_password}" =~ ^[[:xdigit:]]{64}$ ]]; then + postgres_password="$(openssl rand -hex 32)" + fi + umask 077 + printf '%s\n' \ + "POSTGRES_DB=${postgres_db}" \ + "POSTGRES_USER=${postgres_user}" \ + "POSTGRES_PASSWORD=${postgres_password}" >"${database_env}" + chmod 0600 "${database_env}" + database_url="postgres://${postgres_user}:${postgres_password}@127.0.0.1:${postgres_port}/${postgres_db}?sslmode=disable" + + cat >"${install_dir}/compose.yaml" </dev/null)" == "healthy" ]]; do + if ((elapsed >= 120)); then + echo "Timed out waiting for the OpsProof PostgreSQL service." >&2 + (cd "${install_dir}" && sudo docker compose ps && sudo docker compose logs --tail=120 database) >&2 || true + return 1 + fi + sleep 3 + elapsed=$((elapsed + 3)) + done if [[ ! -x "${toolchain_dir}/bin/go" ]]; then archive="$(mktemp "${install_dir}/go${go_version}.XXXXXX.tar.gz")" @@ -5760,7 +5823,7 @@ deploy_opsproof() { npm run check:fix npm run check npm run build - PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go test ./... + DATABASE_URL="${database_url}" PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go test ./... PATH="${toolchain_dir}/bin:${PATH}" GOTOOLCHAIN=local go build -trimpath -o opsproof . ) @@ -5784,6 +5847,7 @@ deploy_opsproof() { "APP_URL=http://${bind_ip}:${http_port}" \ "SERVER_HOST=${bind_ip}" \ "SERVER_PORT=${http_port}" \ + "DATABASE_URL=${database_url}" \ "SESSION_DRIVER=file" \ "CACHE_STORE=file" \ "QUEUE_CONNECTION=sync" \ @@ -5791,11 +5855,20 @@ deploy_opsproof() { "LOG_LEVEL=info" >"${install_dir}/.env" chmod 0600 "${install_dir}/.env" + sudo -u "${service_user}" env \ + APP_ENV=production \ + APP_KEY="${app_key}" \ + DATABASE_URL="${database_url}" \ + CACHE_STORE=file \ + SESSION_DRIVER=file \ + QUEUE_CONNECTION=sync \ + "${release_dir}/opsproof" migrate --force + sudo tee /etc/systemd/system/opsproof.service >/dev/null <