ci: add isolated backend-only P05 runtime acceptance

This commit is contained in:
Vib Tools committed 2026-11-22 05:47:38 -08:00
1 parent 4857558005
commit 03fb58954d
22 files changed
+370 -27

No files matched your search

+3 -1
View File
@@ -8,4 +8,6 @@
| [oidc_discovery.py](oidc_discovery.py) | Disposable ZITADEL ready/discovery/JWKS plus malformed issuer/JWKS negative contracts | P05-CI-01/P05-CI-02 |
| [account_negative.py](account_negative.py) | CI-only Account Portal unauthenticated 401/protected redirect smoke | P05-CI-02 |
| [advisory_triage.py](advisory_triage.py) | Extract registry audit advisory IDs/package/range/fix from npm/pnpm JSON | P05-CI-02 |
| [compose.portless.override.yaml](compose.portless.override.yaml) | CI-only override to clear inherited P02 proxy host port publishing; pending CI acceptance | P05-CI-02 post-run correction |
| [compose.portless.override.yaml](compose.portless.override.yaml) | CI-only override to clear inherited P02 proxy host port publishing; pending CI acceptance | P05-CI-02/P05-CI-03 |
| [backend_acceptance.sh](backend_acceptance.sh) | Backend-only runner preflight, four-service health, Postgres restart marker and OIDC/JWKS CI checks | P05-CI-03 |
| [backend_cleanup.sh](backend_cleanup.sh) | Always-run cleanup of marked CI-owned Compose project/volumes, with leftover verification | P05-CI-03 |
+4
View File
@@ -10,4 +10,8 @@ This folder contains **CI-only** source/lockfile checks and OIDC discovery smoke
No real credentials or production domains are used. Never print bootstrap PATs, admin secrets, session cookies or `.env` contents. Cleanup of disposable volumes is mandatory; never apply `docker compose down -v` to a user's non-CI stack.
- `backend_acceptance.sh` (P05-CI-03) is the manual backend-only Gitea runner preflight, portless Compose gate, four-service readiness, disposable database restart persistence and OIDC/JWKS smoke. Refuses pre-existing fixed network/project/volumes.
- `backend_cleanup.sh` (P05-CI-03) is the workflow's `always()` cleanup script. It tears down only a marked run-owned Compose project and verifies that no project containers, volumes or fixed network remain. Unverified cleanup is an explicit failure.
- Run from `.gitea/workflows/p05-backend-acceptance.yml` **only in isolated Gitea CI**, not on a production Docker host or local developer PC.
Add new CI checks and update `MINIFEST.md`, `project/`, `docs/`, and `notes/` in the same approved phase.
+96
View File
@@ -0,0 +1,96 @@
#!/bin/sh
# P05-CI-03: disposable Gitea runner only. CI source, not a local developer command.
set -eu
: "${GITHUB_RUN_ID:?Gitea run ID is required for isolated project ownership}"
case "$GITHUB_RUN_ID" in
*[!0-9]*|'') echo 'Invalid numeric Gitea run ID' >&2; exit 1 ;;
esac
project="zitplane-p05-$GITHUB_RUN_ID"
network="zitplane-backend-dev-internal"
marker=".p05-ci-owned"
dc() {
docker compose --env-file .env -p "$project" \
-f deployment/docker/compose.backend.dev.yaml \
-f tests/ci/compose.portless.override.yaml "$@"
}
echo "ZITPLANE_BACKEND_PROJECT=$project"
docker --version
docker compose version
docker info --format 'Docker driver={{.Driver}}' >/dev/null
echo 'ZITPLANE_DOCKER_DAEMON_PREFLIGHT_PASS'
# Never take over an existing named network, project, or persistent volume.
if docker network inspect "$network" >/dev/null 2>&1; then
echo '::error::Fixed P02 network already exists; refusing to touch another stack'
exit 1
fi
if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ] ||
[ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then
echo '::error::CI project containers/volumes already exist; refusing takeover'
exit 1
fi
for volume in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do
if docker volume inspect "$volume" >/dev/null 2>&1; then
echo '::error::Existing CI-named volume; refusing takeover'
exit 1
fi
done
# On a clean checkout the generated env must not already exist.
if [ -e .env ] || [ -e "$marker" ]; then
echo '::error::CI credentials or project marker already exist; refusing overwrite'
exit 1
fi
python3 -m unittest discover -s tests -p test_backend_dev.py -v
echo 'ZITPLANE_P02_BACKEND_CONTRACTS_PASS'
python3 core/backend/zitadel/dev.py init
dc config --quiet
dc config --format json |
python3 -c 'import json,sys; d=json.load(sys.stdin); required={"postgres","zitadel-api","zitadel-login","proxy"}; assert required==set(d["services"]), "Unexpected disposable services"; assert not d["services"]["proxy"].get("ports"), "CI proxy unexpectedly publishes host ports"; print("ZITPLANE_CI_PORTLESS_CONFIG_PASS")'
# Created only after the absence and effective-portless-config checks passed.
# The always() cleanup step must NEVER touch an unowned network.
touch "$marker"
dc up -d --wait
for service in postgres zitadel-api zitadel-login proxy; do
cid="$(dc ps -q "$service")"
if [ -z "$cid" ] || [ "$(docker inspect -f '{{.State.Running}}' "$cid")" != true ]; then
echo "::error::CI service not running: $service"
exit 1
fi
if [ "$service" != proxy ] &&
[ "$(docker inspect -f '{{.State.Health.Status}}' "$cid")" != healthy ]; then
echo "::error::CI service unhealthy: $service"
exit 1
fi
echo "ZITPLANE_SERVICE_RUNNING_PASS=$service"
done
echo 'ZITPLANE_FOUR_SERVICES_READY_PASS'
# Isolated persistence marker: disposable default 'postgres' database only.
dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \
-c 'CREATE TABLE IF NOT EXISTS public.zitplane_ci_persist(marker text PRIMARY KEY)'
dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \
-c "INSERT INTO public.zitplane_ci_persist(marker) VALUES ('p05-$project') ON CONFLICT DO NOTHING"
dc restart postgres
dc up -d --wait
result="$(dc exec -T postgres psql -U zitadel -d postgres -tAc \
"SELECT marker FROM public.zitplane_ci_persist WHERE marker = 'p05-$project' LIMIT 1")"
if [ "$result" != "p05-$project" ]; then
echo '::error::Postgres marker not retained across database restart'
exit 1
fi
echo 'ZITPLANE_POSTGRES_RESTART_PERSISTENCE_PASS'
# Read-only smoke inside the owned network; never publish a host HTTP port.
docker run --rm --network "$network" -e ZITPLANE_CI_PROXY=http://proxy \
python:3.12-alpine python -c "$(cat tests/ci/oidc_discovery.py)"
echo 'ZITPLANE_BACKEND_OIDC_READY_DISCOVERY_JWKS_PASS'
echo '::warning::Real user login, OIDC callback, Admin Console and MFA E2E remain DEFERRED'
echo 'ZITPLANE_BACKEND_ACCEPTANCE_CHECKS_PASS'
+60
View File
@@ -0,0 +1,60 @@
#!/bin/sh
# P05-CI-03 always() step: touch ONLY the project this run marked as owned.
set -eu
marker=".p05-ci-owned"
if [ ! -f "$marker" ]; then
# No project was started by this checkout; do not inspect/delete shared state.
rm -f .env
echo 'ZITPLANE_BACKEND_CLEANUP_NOT_REQUIRED'
exit 0
fi
: "${GITHUB_RUN_ID:?Missing run ID; cannot prove Docker ownership}"
case "$GITHUB_RUN_ID" in
*[!0-9]*|'') echo 'Unsafe Gitea run ID; cleanup needs manual review' >&2; exit 1 ;;
esac
project="zitplane-p05-$GITHUB_RUN_ID"
network="zitplane-backend-dev-internal"
dc() {
docker compose --env-file .env -p "$project" \
-f deployment/docker/compose.backend.dev.yaml \
-f tests/ci/compose.portless.override.yaml "$@"
}
# Preserve cleanup failure even when marker/env removal succeeds.
rc=0
if [ ! -f .env ]; then
echo '::error::Owned CI marker present but credentials missing; cleanup cannot be verified'
rc=1
elif ! dc down -v --remove-orphans; then
echo '::error::CI Compose teardown failed'
rc=1
fi
if docker network inspect "$network" >/dev/null 2>&1; then
echo '::error::CI Docker network remains after teardown'
rc=1
fi
if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ]; then
echo '::error::CI project containers remain after teardown'
rc=1
fi
if [ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then
echo '::error::CI project volumes remain after teardown'
rc=1
fi
for volume in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do
if docker volume inspect "$volume" >/dev/null 2>&1; then
echo "::error::CI volume remains: $volume"
rc=1
fi
done
rm -f .env "$marker"
if [ "$rc" -ne 0 ]; then
echo '::error::Disposable state cleanup NOT VERIFIED; operator review required'
exit 1
fi
echo 'ZITPLANE_BACKEND_CLEANUP_VERIFIED_PASS'