fix(docker): create the first admin declaratively on compose deploys - #175
fix(docker): create the first admin declaratively on compose deploys#175shani-singh1 wants to merge 1 commit into
Conversation
A fresh `docker compose up` had no supported way to create the first administrator through the web flow: public sign-up is disabled, and the loopback bootstrap shortcut never fires because the request reaches the API from a Docker-bridge IP rather than 127.0.0.1 (issue oblien#138). Add an optional one-shot `init-admin` service that calls the existing internal-token-gated `POST /api/system/bootstrap-admin` endpoint — the same path the CLI wizard uses — with credentials the operator declares in `.env` (`OPENSHIP_ADMIN_NAME` / `_EMAIL` / `_PASSWORD`). - No-op unless the admin vars are set, so nothing changes for operators who create the admin another way. - Does not enable public sign-up; reuses the invite-only bootstrap path. - Idempotent: bootstrap-admin returns 409 once an admin exists, which the script treats as success, so re-running compose never mutates an admin. Closes oblien#138.
|
Rebasing this on the latest Two things I noticed:
Where I'd like your read: is there still a gap for raw If you'd like, I can either:
Happy to go whichever way you prefer — just don't want to push a duplicate of what the CLI now does. |
Problem
On a fresh Docker Compose deployment there's no supported way to create the first admin through the web flow. Public sign-up is disabled on self-hosted instances, and the loopback bootstrap shortcut in the sign-up guard never fires because the request reaches the API from a Docker-bridge IP (e.g.
172.18.x.x) rather than127.0.0.1, so it always returnsSIGNUP_DISABLED.openship up's interactive wizard has no Compose equivalent.Fixes #138.
Approach
This follows the direction discussed in #138 (declarative credentials at start, endorsed by @Hydralerne) and reuses the exact mechanism the CLI already relies on — the internal-token-gated, one-shot
POST /api/system/bootstrap-adminendpoint. Public sign-up is not touched.An optional one-shot
init-adminCompose service runs once the API is healthy and creates the first admin from credentials the operator declares in.env:Properties:
0, so nothing changes for operators who create the admin another way.depends_onis one-directional; no other service waits on it.INTERNAL_TOKEN. It does not enable public registration.bootstrap-adminreturns409once an admin exists, which the script treats as success, so re-runningdocker compose upnever mutates an existing admin.Changes
scripts/docker-init-admin.sh— the bootstrap script (POSIXsh; JSON body is escaped for embedded quotes/backslashes).docker-compose.yml— theinit-adminservice (pinnedcurlimages/curl, mounts the script read-only, waits forapihealth, then exits)..env.example— documents the optionalOPENSHIP_ADMIN_*vars.docs/installation.md— a "Create the first admin" note in the Docker section.Testing
docker compose configrenders cleanly;init-adminreceivesINTERNAL_TOKENandOPENSHIP_API_URL.sh -n/bash -nsyntax-check pass.bootstrap-admincontract covering every branch: vars-unset skip, successful create (incl. a password with embedded"and\to confirm JSON escaping), idempotent409re-run,401wrong-token, missing-INTERNAL_TOKENabort, and unreachable-API. Success/skip paths exit0; error paths exit non-zero without blocking the rest of the stack.Notes for reviewers
restart: "no", nothing depends on it), so an error state surfaces as anExited (1)container without affecting the API/dashboard.