rehearsal-3: get.idss.nz bootstrap service — install script + pinned agent, the gateway /get contract mirrored #515

Closed
opened 2026-08-14 06:20:29 +00:00 by ben · 2 comments
Owner

Part of rehearsal phase 3 — gateway from home (spec docs/superpowers/specs/2026-08-14-183-phase-3-home-gateway-rehearsal-design.md, plan docs/superpowers/plans/2026-08-14-183-phase-3-home-gateway-rehearsal.md).
The plan section below is the work, verbatim; its Interfaces block names what neighbouring tasks consume — keep those names exact.

Global constraints (apply to every step)

  • Use the domain glossary's vocabulary (CONTEXT.md) in ALL copy, comments,
    commit messages: founding, gateway, agent, install command,
    enrollment code — never installer/daemon/token/join-key.
  • Fail loud, never fabricate (ADR 0100): a missing artifact/secret/seam is an
    error with the real reason, never a silent skip or a made-up value.
  • x86_64 only at v1; full install is the consented mode (ADR 0024); the
    install command is a doorway, not a kept tool (ADR 0028).
  • Never write closes #NNN (or any close keyword) in commits or issue bodies
    for the standing drive issue family — say "advances #NNN". Even DESCRIBING a
    close can auto-close (2026-08-10 lesson, twice).
  • Commits that change project state update STATUS.md in the same commit
    (CLAUDE.md rule); the drive-issue minting commit (Task 9) carries the
    STATUS + runbook update for the whole arc.
  • TDD: each step's test is written and seen red before its implementation.
  • Secrets never enter .sandcastle/.env (it forwards into worker containers);
    host-only secrets live in the executor's rehearsal-env.sh (2026-07-11
    lesson).

Task 1: The get.idss.nz bootstrap service (serving half)

Files:

  • Create: bootstrap/cmd/bootstrap/main.go
  • Create: bootstrap/cmd/bootstrap/main_test.go
  • Create: bootstrap/cmd/bootstrap/installscript.go (the served sh script as
    a Go string + its template test)
  • Modify: internal/controlapi/install_doorway.go — no behavior change; only
    if the handler needs exporting for reuse (see below), keep the gateway
    doorway's semantics byte-identical.

Interfaces:

  • Consumes: internal/controlapi.WithInstallDoorway(src AgentSource) and
    AgentSource (Agent(ctx, arch) (release string, binary []byte, err error))
    — the EXISTING gateway /get contract this service mirrors
    (internal/controlapi/install_doorway.go).

  • Consumes: internal/join device-end expectations — the install script must
    leave exactly what internal/install's Service adapter leaves (binary laid
    down, persistent systemd service started now AND at boot) and then run the
    agent's terminal join with the code (agent/cmd/agent subcommands; read
    internal/join/cli.go's package comment for the P2 doorway contract before
    writing the script).

  • Produces: an HTTP service, bootstrap serve --dir <artifacts> --addr :8091:

    • GET / → text/x-shellscript, the install script.
    • GET /get?arch=x86_64 → the agent binary from <artifacts>/agent-x86_64
      with X-OurCloud-Release from <artifacts>/RELEASE — 400 on missing
      arch param, 503 when nothing honest is seeded (ADR 0100), matching the
      gateway doorway's behavior.
    • The install script's contract (Task 6's driver and the real operator both
      depend on it): POSIX sh; takes the enrollment code as $1; refuses
      (exit non-zero, plain message) when uname -m ≠ x86_64 or $1 is
      empty; fetches https://get.idss.nz/get?arch=x86_64 to
      /usr/local/bin/ourcloud-agent; writes + enables + starts the
      ourcloud-agent.service systemd unit; then execs the agent's terminal
      join with the code in the foreground
      so consent (S8) happens in the
      operator's terminal (ADR 0024).
  • Step 1: Write the failing contract tests — main_test.go over
    httptest against the composed mux:

func TestServeRoot_ReturnsInstallScriptWithCodePassthrough(t *testing.T) {
    h := newHandler(t.TempDir()) // no artifacts: / still serves the script
    rec := httptest.NewRecorder()
    h.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil))
    if rec.Code != 200 { t.Fatalf("root: %d", rec.Code) }
    body := rec.Body.String()
    for _, must := range []string{`#!/bin/sh`, `uname -m`, `x86_64`,
        `/get?arch=`, `ourcloud-agent.service`, `"$1"`} {
        if !strings.Contains(body, must) { t.Fatalf("script lacks %q", must) }
    }
}

func TestServeGet_MirrorsGatewayDoorway(t *testing.T) {
    dir := t.TempDir()
    os.WriteFile(filepath.Join(dir, "agent-x86_64"), []byte("ELF..."), 0o755)
    os.WriteFile(filepath.Join(dir, "RELEASE"), []byte("r1\n"), 0o644)
    h := newHandler(dir)
    rec := httptest.NewRecorder()
    h.ServeHTTP(rec, httptest.NewRequest("GET", "/get?arch=x86_64", nil))
    if rec.Code != 200 || rec.Header().Get("X-OurCloud-Release") != "r1" {
        t.Fatalf("get: %d %q", rec.Code, rec.Header().Get("X-OurCloud-Release"))
    }
}

func TestServeGet_FailsLoud(t *testing.T) {
    h := newHandler(t.TempDir())
    for path, want := range map[string]int{"/get": 400, "/get?arch=x86_64": 503} {
        rec := httptest.NewRecorder()
        h.ServeHTTP(rec, httptest.NewRequest("GET", path, nil))
        if rec.Code != want { t.Fatalf("%s: got %d want %d", path, rec.Code, want) }
    }
}
  • Step 2: Run them — go test ./bootstrap/... — expect FAIL
    (newHandler undefined).
  • Step 3: Implement — newHandler(dir string) http.Handler: a
    dir-backed AgentSource (Agent reads agent-<arch> + RELEASE, error
    when either is missing) composed with
    controlapi's doorway registration for /get (reuse
    WithInstallDoorway/registerInstallDoorway; export the minimal hook if
    needed — the gateway's own behavior must not change), plus the / script
    handler from installscript.go. main = flag parsing + http.ListenAndServe
    (follow broker/cmd/broker/main.go's shape for logging/flags).
  • Step 4: Green — go test ./bootstrap/... ./internal/controlapi/....
  • Step 5: Shellcheck the script — add a test that writes the script to
    a temp file and runs sh -n on it (syntax gate; skip with the real reason
    if sh is absent in the sandbox).
  • Step 6: Commit — bootstrap: get.idss.nz serves the install script and the pinned agent (spec 2026-08-14, mirrors the gateway /get doorway).
Part of rehearsal **phase 3 — gateway from home** (spec `docs/superpowers/specs/2026-08-14-183-phase-3-home-gateway-rehearsal-design.md`, plan `docs/superpowers/plans/2026-08-14-183-phase-3-home-gateway-rehearsal.md`). The plan section below is the work, verbatim; its **Interfaces** block names what neighbouring tasks consume — keep those names exact. ## Global constraints (apply to every step) - Use the domain glossary's vocabulary (`CONTEXT.md`) in ALL copy, comments, commit messages: *founding*, *gateway*, *agent*, *install command*, *enrollment code* — never installer/daemon/token/join-key. - Fail loud, never fabricate (ADR 0100): a missing artifact/secret/seam is an error with the real reason, never a silent skip or a made-up value. - x86_64 only at v1; full install is the consented mode (ADR 0024); the install command is a doorway, not a kept tool (ADR 0028). - Never write `closes #NNN` (or any close keyword) in commits or issue bodies for the standing drive issue family — say "advances #NNN". Even DESCRIBING a close can auto-close (2026-08-10 lesson, twice). - Commits that change project state update `STATUS.md` in the same commit (CLAUDE.md rule); the drive-issue minting commit (Task 9) carries the STATUS + runbook update for the whole arc. - TDD: each step's test is written and seen red before its implementation. - Secrets never enter `.sandcastle/.env` (it forwards into worker containers); host-only secrets live in the executor's `rehearsal-env.sh` (2026-07-11 lesson). --- ### Task 1: The `get.idss.nz` bootstrap service (serving half) **Files:** - Create: `bootstrap/cmd/bootstrap/main.go` - Create: `bootstrap/cmd/bootstrap/main_test.go` - Create: `bootstrap/cmd/bootstrap/installscript.go` (the served `sh` script as a Go string + its template test) - Modify: `internal/controlapi/install_doorway.go` — no behavior change; only if the handler needs exporting for reuse (see below), keep the gateway doorway's semantics byte-identical. **Interfaces:** - Consumes: `internal/controlapi.WithInstallDoorway(src AgentSource)` and `AgentSource` (`Agent(ctx, arch) (release string, binary []byte, err error)`) — the EXISTING gateway `/get` contract this service mirrors (`internal/controlapi/install_doorway.go`). - Consumes: `internal/join` device-end expectations — the install script must leave exactly what `internal/install`'s `Service` adapter leaves (binary laid down, persistent systemd service started now AND at boot) and then run the agent's terminal join with the code (`agent/cmd/agent` subcommands; read `internal/join/cli.go`'s package comment for the P2 doorway contract before writing the script). - Produces: an HTTP service, `bootstrap serve --dir <artifacts> --addr :8091`: - `GET /` → `text/x-shellscript`, the install script. - `GET /get?arch=x86_64` → the agent binary from `<artifacts>/agent-x86_64` with `X-OurCloud-Release` from `<artifacts>/RELEASE` — 400 on missing arch param, 503 when nothing honest is seeded (ADR 0100), matching the gateway doorway's behavior. - The install script's contract (Task 6's driver and the real operator both depend on it): POSIX sh; takes the enrollment code as `$1`; refuses (exit non-zero, plain message) when `uname -m` ≠ `x86_64` or `$1` is empty; fetches `https://get.idss.nz/get?arch=x86_64` to `/usr/local/bin/ourcloud-agent`; writes + enables + starts the `ourcloud-agent.service` systemd unit; then **execs the agent's terminal join with the code in the foreground** so consent (S8) happens in the operator's terminal (ADR 0024). - [ ] **Step 1: Write the failing contract tests** — `main_test.go` over `httptest` against the composed mux: ```go func TestServeRoot_ReturnsInstallScriptWithCodePassthrough(t *testing.T) { h := newHandler(t.TempDir()) // no artifacts: / still serves the script rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) if rec.Code != 200 { t.Fatalf("root: %d", rec.Code) } body := rec.Body.String() for _, must := range []string{`#!/bin/sh`, `uname -m`, `x86_64`, `/get?arch=`, `ourcloud-agent.service`, `"$1"`} { if !strings.Contains(body, must) { t.Fatalf("script lacks %q", must) } } } func TestServeGet_MirrorsGatewayDoorway(t *testing.T) { dir := t.TempDir() os.WriteFile(filepath.Join(dir, "agent-x86_64"), []byte("ELF..."), 0o755) os.WriteFile(filepath.Join(dir, "RELEASE"), []byte("r1\n"), 0o644) h := newHandler(dir) rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest("GET", "/get?arch=x86_64", nil)) if rec.Code != 200 || rec.Header().Get("X-OurCloud-Release") != "r1" { t.Fatalf("get: %d %q", rec.Code, rec.Header().Get("X-OurCloud-Release")) } } func TestServeGet_FailsLoud(t *testing.T) { h := newHandler(t.TempDir()) for path, want := range map[string]int{"/get": 400, "/get?arch=x86_64": 503} { rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest("GET", path, nil)) if rec.Code != want { t.Fatalf("%s: got %d want %d", path, rec.Code, want) } } } ``` - [ ] **Step 2: Run them** — `go test ./bootstrap/...` — expect FAIL (`newHandler` undefined). - [ ] **Step 3: Implement** — `newHandler(dir string) http.Handler`: a dir-backed `AgentSource` (`Agent` reads `agent-<arch>` + `RELEASE`, error when either is missing) composed with `controlapi`'s doorway registration for `/get` (reuse `WithInstallDoorway`/`registerInstallDoorway`; export the minimal hook if needed — the gateway's own behavior must not change), plus the `/` script handler from `installscript.go`. `main` = flag parsing + `http.ListenAndServe` (follow `broker/cmd/broker/main.go`'s shape for logging/flags). - [ ] **Step 4: Green** — `go test ./bootstrap/... ./internal/controlapi/...`. - [ ] **Step 5: Shellcheck the script** — add a test that writes the script to a temp file and runs `sh -n` on it (syntax gate; skip with the real reason if `sh` is absent in the sandbox). - [ ] **Step 6: Commit** — `bootstrap: get.idss.nz serves the install script and the pinned agent (spec 2026-08-14, mirrors the gateway /get doorway)`.
Author
Owner

swarm-claim host=matou-dev-server-01 run=5898
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=5898 (automated multi-host claim — lowest live claim id works this ticket)
Author
Owner

close-report for #515 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 515,
  "status": "success",
  "commits": [
    "5e63d52"
  ],
  "changed_files": [
    "bootstrap/cmd/bootstrap/installscript.go",
    "bootstrap/cmd/bootstrap/main.go",
    "bootstrap/cmd/bootstrap/main_test.go"
  ],
  "tests": [
    {
      "command": "go test ./bootstrap/... ./internal/controlapi/...",
      "exit_code": 0
    }
  ],
  "criteria": {
    "GET / serves the install script as text/x-shellscript (no artifacts needed)": "bootstrap/cmd/bootstrap/main.go newHandlerWithLog GET / handler + installscript.go; TestServeRoot_ReturnsInstallScriptWithCodePassthrough asserts 200, content-type, and the #!/bin/sh, uname -m, x86_64, /get?arch=, ourcloud-agent.service, \"$1\" markers",
    "GET /get?arch=x86_64 mirrors the gateway doorway: agent binary + X-OurCloud-Release": "newHandler reuses controlapi.WithInstallDoorway over dirSource (<dir>/agent-<arch> + <dir>/RELEASE); TestServeGet_MirrorsGatewayDoorway asserts 200, release header r1, body",
    "Fail loud: 400 on missing arch, 503 when nothing seeded (ADR 0100)": "dirSource.Agent errors on missing RELEASE/binary -> doorway 503; missing arch -> doorway 400; TestServeGet_FailsLoud asserts /get=400 /get?arch=x86_64=503",
    "The install script's contract: POSIX sh, code as $1, refuses non-x86_64 and empty code, fetches /get?arch=x86_64, writes+enables+starts ourcloud-agent.service, execs the agent's terminal join in the foreground": "installscript.go: set -e, code=\"$1\" empty-check exit 2, uname -m != x86_64 exit 3, curl https://get.idss.nz/get?arch=x86_64 -o /usr/local/bin/ourcloud-agent, ourcloud-agent.service unit (byte-identical to internal/install Service unit) via systemctl enable --now, exec ourcloud-agent enroll \"$code\"; TestInstallScript_ShSyntax gates POSIX validity with sh -n",
    "bootstrap serve --dir <artifacts> --addr :8091 (broker main shape)": "bootstrap/cmd/bootstrap/main.go: serve subcommand, --dir required (fail loud ADR 0100), --addr default :8091, http.ListenAndServe over newHandlerWithLog",
    "gateway doorway behaviour unchanged": "internal/controlapi/install_doorway.go untouched (WithInstallDoorway already the exported hook, reused not modified); go test ./internal/controlapi/... exit 0"
  },
  "summary": "get.idss.nz bootstrap service serves the install script at / and the pinned agent at /get by reusing the gateway's own install doorway, with a POSIX sh install command that fetches the agent, lays down the persistent ourcloud-agent.service, and execs the agent's terminal enroll for in-terminal consent.",
  "reason": "",
  "blockers": []
}
**close-report** for #515 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 515, "status": "success", "commits": [ "5e63d52" ], "changed_files": [ "bootstrap/cmd/bootstrap/installscript.go", "bootstrap/cmd/bootstrap/main.go", "bootstrap/cmd/bootstrap/main_test.go" ], "tests": [ { "command": "go test ./bootstrap/... ./internal/controlapi/...", "exit_code": 0 } ], "criteria": { "GET / serves the install script as text/x-shellscript (no artifacts needed)": "bootstrap/cmd/bootstrap/main.go newHandlerWithLog GET / handler + installscript.go; TestServeRoot_ReturnsInstallScriptWithCodePassthrough asserts 200, content-type, and the #!/bin/sh, uname -m, x86_64, /get?arch=, ourcloud-agent.service, \"$1\" markers", "GET /get?arch=x86_64 mirrors the gateway doorway: agent binary + X-OurCloud-Release": "newHandler reuses controlapi.WithInstallDoorway over dirSource (<dir>/agent-<arch> + <dir>/RELEASE); TestServeGet_MirrorsGatewayDoorway asserts 200, release header r1, body", "Fail loud: 400 on missing arch, 503 when nothing seeded (ADR 0100)": "dirSource.Agent errors on missing RELEASE/binary -> doorway 503; missing arch -> doorway 400; TestServeGet_FailsLoud asserts /get=400 /get?arch=x86_64=503", "The install script's contract: POSIX sh, code as $1, refuses non-x86_64 and empty code, fetches /get?arch=x86_64, writes+enables+starts ourcloud-agent.service, execs the agent's terminal join in the foreground": "installscript.go: set -e, code=\"$1\" empty-check exit 2, uname -m != x86_64 exit 3, curl https://get.idss.nz/get?arch=x86_64 -o /usr/local/bin/ourcloud-agent, ourcloud-agent.service unit (byte-identical to internal/install Service unit) via systemctl enable --now, exec ourcloud-agent enroll \"$code\"; TestInstallScript_ShSyntax gates POSIX validity with sh -n", "bootstrap serve --dir <artifacts> --addr :8091 (broker main shape)": "bootstrap/cmd/bootstrap/main.go: serve subcommand, --dir required (fail loud ADR 0100), --addr default :8091, http.ListenAndServe over newHandlerWithLog", "gateway doorway behaviour unchanged": "internal/controlapi/install_doorway.go untouched (WithInstallDoorway already the exported hook, reused not modified); go test ./internal/controlapi/... exit 0" }, "summary": "get.idss.nz bootstrap service serves the install script at / and the pinned agent at /get by reusing the gateway's own install doorway, with a POSIX sh install command that fetches the agent, lays down the persistent ourcloud-agent.service, and execs the agent's terminal enroll for in-terminal consent.", "reason": "", "blockers": [] } ``` </details>
ben closed this issue 2026-08-14 06:39:54 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/idss#515
No description provided.