secrets: preflight allowlist guard for .sandcastle/.env (part 1 of #592, protected-path) #593

Closed
opened 2026-08-19 17:24:37 +00:00 by ben · 1 comment
Owner

Machinery change — preflight allowlist guard for .sandcastle/.env (part 1 of #592)

Split out of #592: that ticket's part 2 (lab-dns secrets-file fallback) shipped
as a swarm slice, but part 1 is a protected .sandcastle/ change (rule 9 / #445)
— a swarm worker cannot touch the machinery that judges its own run, so it needs an
interactive session's standing.

What's needed

A preflight allowlist guard: refuse a host-mode run whose .sandcastle/.env
carries any key beyond the allowlist (CLAUDE_CODE_OAUTH_TOKEN / ANTHROPIC_API_KEY

  • the non-secret config already in .env.example: FORGEJO_API, MATTERMOST_URL,
    MATTERMOST_CHANNEL_ID, BASH_*_TIMEOUT_MS, REHEARSAL_*, SWARM_HOST,
    SWARM_RUN_ID). Any *TOKEN|SECRET|KEY|PASS-shaped stray → fail closed, same
    pattern as preflight-swarm.sh's empty-secret / content-not-existence check
    (guard_secrets_content). This stops the docker-inspect leak class (#578) from
    recurring silently: sandcastle forwards every .env key as docker run -e, landing
    it in docker inspect .Config.Env.
  • Host-mode only. CI is already safe — run-swarm.sh overwrites .env from
    .env.example under GITHUB_ACTIONS (#578), so the guard must not fire (or must
    no-op) on the CI path.
  • Natural homes: run-swarm.sh (host-mode entry) with a guard mirrored/tested in
    preflight-swarm.sh (guard_secrets_content sits right there).
  • Test-first: feed the guard an .env with a stray FOO_TOKEN=... (must refuse) and
    a clean allowlist-only .env (must pass) — the guard_healer_rails throwaway-fixture
    pattern already used in preflight-swarm.sh.

Secondary (same area, also protected)

.sandcastle/secrets/README.md's consumer table omits ourcloud_lab_dns_token
entirely. Add a row (ourcloud_lab_dns_token → .claude/skills/lab-dns/lab-dns)
now that part 2 wired the file fallback.

Found while closing #592 (part 2). Two-way door; ready-for-session per ADR 0174 +
#445 (protected-path machinery change).

## Machinery change — preflight allowlist guard for `.sandcastle/.env` (part 1 of #592) Split out of #592: that ticket's **part 2** (lab-dns secrets-file fallback) shipped as a swarm slice, but **part 1 is a protected `.sandcastle/` change** (rule 9 / #445) — a swarm worker cannot touch the machinery that judges its own run, so it needs an interactive session's standing. ### What's needed A **preflight allowlist guard**: refuse a **host-mode** run whose `.sandcastle/.env` carries any key beyond the allowlist (`CLAUDE_CODE_OAUTH_TOKEN` / `ANTHROPIC_API_KEY` + the non-secret config already in `.env.example`: `FORGEJO_API`, `MATTERMOST_URL`, `MATTERMOST_CHANNEL_ID`, `BASH_*_TIMEOUT_MS`, `REHEARSAL_*`, `SWARM_HOST`, `SWARM_RUN_ID`). Any `*TOKEN|SECRET|KEY|PASS`-shaped stray → **fail closed**, same pattern as `preflight-swarm.sh`'s empty-secret / content-not-existence check (`guard_secrets_content`). This stops the docker-inspect leak class (#578) from recurring silently: sandcastle forwards every `.env` key as `docker run -e`, landing it in `docker inspect .Config.Env`. - **Host-mode only.** CI is already safe — `run-swarm.sh` overwrites `.env` from `.env.example` under `GITHUB_ACTIONS` (#578), so the guard must not fire (or must no-op) on the CI path. - Natural homes: `run-swarm.sh` (host-mode entry) with a guard mirrored/tested in `preflight-swarm.sh` (`guard_secrets_content` sits right there). - Test-first: feed the guard an `.env` with a stray `FOO_TOKEN=...` (must refuse) and a clean allowlist-only `.env` (must pass) — the `guard_healer_rails` throwaway-fixture pattern already used in `preflight-swarm.sh`. ### Secondary (same area, also protected) `.sandcastle/secrets/README.md`'s consumer table omits `ourcloud_lab_dns_token` entirely. Add a row (`ourcloud_lab_dns_token` → `.claude/skills/lab-dns/lab-dns`) now that part 2 wired the file fallback. Found while closing #592 (part 2). Two-way door; `ready-for-session` per ADR 0174 + #445 (protected-path machinery change).
Author
Owner

Ruled by agent under ADR 0174 — veto anytime.

Two-way door: a commit/config change, provable by new offline test suites — landed.

Landed on main at 4d80a57:

  • New .sandcastle/env-allowlist-lib.sh (env_allowlist_violations): flags any *TOKEN|SECRET|KEY|PASS-shaped key in a .env file that isn't on the allowlist (mirrors .env.example: CLAUDE_CODE_OAUTH_TOKEN/ANTHROPIC_API_KEY + the documented non-secret config; REHEARSAL_* trusted as an open-ended prefix).
  • run-swarm.sh's .env materialize step now calls the guard in the host-mode branch only (.env pre-exists and GITHUB_ACTIONS unset) — the CI branch always overwrites .env from .env.example first, so the guard structurally never fires there, per the ticket's requirement. A violation fails the run loud (SWARM_EXIT_REASON=env-allowlist-violation) and leaves the offending .env untouched so the operator can fix it.
  • preflight-swarm.sh gained a 7th zero-token self-test guard, guard_secrets_allowlist, mirroring guard_secrets_content's content-not-existence pattern — a stray FOO_TOKEN throwaway fixture must trip it, a clean allowlist-only fixture must pass it.
  • Secondary ask: .sandcastle/secrets/README.md's consumer table now lists ourcloud_lab_dns_token → .claude/skills/lab-dns/lab-dns (#592 part 2 wired the file fallback but left the table stale).

Proof:

  • New tests/env-allowlist-lib-test.sh (8 cases: clean allowlist passes, ANTHROPIC_API_KEY allowed, stray FOO_TOKEN refused, all TOKEN|SECRET|KEY|PASS shapes caught, a benign non-secret-shaped stray is correctly out of scope, comment/blank/export parsing, missing file is not a violation, REHEARSAL_* prefix trusted) — green.
  • New tests/run-swarm-env-guard-test.sh (4 cases, the debounce-test.sh isolated-block pattern: CI mode always overwrites even over a bad .env; host-mode first run materializes; host-mode clean .env passes untouched; host-mode bad .env refused and left untouched) — green.
  • tests/preflight-swarm-test.sh updated for the guard count (6→7) and passing.
  • Full .sandcastle/tests/*.sh sweep (36 files) green after the change.

git pull --rebase clean, pushed straight to main (no swarm/session collision).

advances #593, advances #592

Ruled by agent under ADR 0174 — veto anytime. **Two-way door: a commit/config change, provable by new offline test suites — landed.** Landed on `main` at `4d80a57`: - New `.sandcastle/env-allowlist-lib.sh` (`env_allowlist_violations`): flags any `*TOKEN|SECRET|KEY|PASS`-shaped key in a `.env` file that isn't on the allowlist (mirrors `.env.example`: `CLAUDE_CODE_OAUTH_TOKEN`/`ANTHROPIC_API_KEY` + the documented non-secret config; `REHEARSAL_*` trusted as an open-ended prefix). - `run-swarm.sh`'s `.env` materialize step now calls the guard in the **host-mode** branch only (`.env` pre-exists and `GITHUB_ACTIONS` unset) — the CI branch always overwrites `.env` from `.env.example` first, so the guard structurally never fires there, per the ticket's requirement. A violation fails the run loud (`SWARM_EXIT_REASON=env-allowlist-violation`) and leaves the offending `.env` untouched so the operator can fix it. - `preflight-swarm.sh` gained a 7th zero-token self-test guard, `guard_secrets_allowlist`, mirroring `guard_secrets_content`'s content-not-existence pattern — a stray `FOO_TOKEN` throwaway fixture must trip it, a clean allowlist-only fixture must pass it. - Secondary ask: `.sandcastle/secrets/README.md`'s consumer table now lists `ourcloud_lab_dns_token` → `.claude/skills/lab-dns/lab-dns` (#592 part 2 wired the file fallback but left the table stale). **Proof:** - New `tests/env-allowlist-lib-test.sh` (8 cases: clean allowlist passes, `ANTHROPIC_API_KEY` allowed, stray `FOO_TOKEN` refused, all `TOKEN|SECRET|KEY|PASS` shapes caught, a benign non-secret-shaped stray is correctly out of scope, comment/blank/`export` parsing, missing file is not a violation, `REHEARSAL_*` prefix trusted) — green. - New `tests/run-swarm-env-guard-test.sh` (4 cases, the `debounce-test.sh` isolated-block pattern: CI mode always overwrites even over a bad `.env`; host-mode first run materializes; host-mode clean `.env` passes untouched; host-mode bad `.env` refused and left untouched) — green. - `tests/preflight-swarm-test.sh` updated for the guard count (6→7) and passing. - Full `.sandcastle/tests/*.sh` sweep (36 files) green after the change. `git pull --rebase` clean, pushed straight to `main` (no swarm/session collision). advances #593, advances #592
ben closed this issue 2026-08-19 17:36:16 +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.

Dependencies

No dependencies set.

Reference
Matou/idss#593
No description provided.