secrets: .sandcastle/.env carries four real tokens against its own invariant — docker-inspect leak on host-mode runs #578

Closed
opened 2026-08-15 06:01:37 +00:00 by ben · 1 comment
Owner

Security gap — .sandcastle/.env carries four real tokens against its own invariant

.env.example:1-11 states the invariant: only CLAUDE_CODE_OAUTH_TOKEN lives in .env (everything else = files under secrets/, because sandcastle forwards every .env key as docker run -e — the documented 2026-07-11 docker-inspect leak vector).

Reality on the dev host: .sandcastle/.env currently holds real FORGEJO_TOKEN, MATTERMOST_BOT_TOKEN, DIGITALOCEAN_ACCESS_TOKEN, and OURCLOUD_LAB_DNS_TOKEN. CI runs are safe (run-swarm.sh:225-227 overwrites .env from the example under GITHUB_ACTIONS) — but any host-mode run exposes all four to docker inspect.

Fix (hands-on — genuinely ready-for-human)

  • move the four tokens to secrets/ files on every host carrying them (dev laptop, workstation, elitebook); scripts already read the file paths as fallback (notify-mattermost.sh:11-18 etc.)
  • grep the fleet's .env files for any other strays
  • consider a preflight guard: refuse a host-mode run whose .env contains keys beyond the allowlist (the same fail-closed pattern as the empty-secret check)

Check each host's .env before deleting lines — the workstation's rehearsal-env.sh sources some of these for cron jobs; those consumers keep working off secrets/ paths but verify before cutting over.

## Security gap — `.sandcastle/.env` carries four real tokens against its own invariant `.env.example:1-11` states the invariant: only `CLAUDE_CODE_OAUTH_TOKEN` lives in `.env` (everything else = files under `secrets/`, because sandcastle forwards **every `.env` key as `docker run -e`** — the documented 2026-07-11 docker-inspect leak vector). Reality on the dev host: `.sandcastle/.env` currently holds real `FORGEJO_TOKEN`, `MATTERMOST_BOT_TOKEN`, `DIGITALOCEAN_ACCESS_TOKEN`, and `OURCLOUD_LAB_DNS_TOKEN`. CI runs are safe (`run-swarm.sh:225-227` overwrites `.env` from the example under `GITHUB_ACTIONS`) — but **any host-mode run exposes all four to `docker inspect`**. ## Fix (hands-on — genuinely ready-for-human) - move the four tokens to `secrets/` files on every host carrying them (dev laptop, workstation, elitebook); scripts already read the file paths as fallback (`notify-mattermost.sh:11-18` etc.) - grep the fleet's `.env` files for any other strays - consider a preflight guard: refuse a host-mode run whose `.env` contains keys beyond the allowlist (the same fail-closed pattern as the empty-secret check) Check each host's `.env` before deleting lines — the workstation's `rehearsal-env.sh` sources some of these for cron jobs; those consumers keep working off `secrets/` paths but verify before cutting over.
Author
Owner

Done 2026-08-19 (Ben's session). Fleet state found + fixed:

  • dev laptop — the only host still carrying tokens in .env. All four (FORGEJO_TOKEN, MATTERMOST_BOT_TOKEN, DIGITALOCEAN_ACCESS_TOKEN, OURCLOUD_LAB_DNS_TOKEN) moved to secrets/ files (0600); .env now carries only CLAUDE_CODE_OAUTH_TOKEN (the documented exception) + non-secret config (FORGEJO_API, MATTERMOST_URL, MATTERMOST_CHANNEL_ID).
  • workstation — already clean (rehearsal-env.sh exports from secrets/ files; .env = timeouts + drive knobs only). Session-runner clone's .env: clean.
  • elitebook — already clean (both ourcloud and matou-app checkouts: timeouts only, secrets files present).
  • stray sweep — all .sandcastle/.env files on all three hosts grepped for TOKEN|SECRET|KEY|PASS keys: nothing beyond the allowed exception remains.

Caveat: the lab-dns skill reads only env/.env (no file fallback), so on the laptop it now needs OURCLOUD_LAB_DNS_TOKEN=$(cat .sandcastle/secrets/ourcloud_lab_dns_token) at invocation — file-fallback + the preflight allowlist guard filed as a follow-up.

**Done 2026-08-19 (Ben's session).** Fleet state found + fixed: - **dev laptop** — the only host still carrying tokens in `.env`. All four (`FORGEJO_TOKEN`, `MATTERMOST_BOT_TOKEN`, `DIGITALOCEAN_ACCESS_TOKEN`, `OURCLOUD_LAB_DNS_TOKEN`) moved to `secrets/` files (0600); `.env` now carries only `CLAUDE_CODE_OAUTH_TOKEN` (the documented exception) + non-secret config (`FORGEJO_API`, `MATTERMOST_URL`, `MATTERMOST_CHANNEL_ID`). - **workstation** — already clean (rehearsal-env.sh exports from `secrets/` files; `.env` = timeouts + drive knobs only). Session-runner clone's `.env`: clean. - **elitebook** — already clean (both ourcloud and matou-app checkouts: timeouts only, secrets files present). - **stray sweep** — all `.sandcastle/.env` files on all three hosts grepped for `TOKEN|SECRET|KEY|PASS` keys: nothing beyond the allowed exception remains. Caveat: the `lab-dns` skill reads only env/`.env` (no file fallback), so on the laptop it now needs `OURCLOUD_LAB_DNS_TOKEN=$(cat .sandcastle/secrets/ourcloud_lab_dns_token)` at invocation — file-fallback + the preflight allowlist guard filed as a follow-up.
ben closed this issue 2026-08-19 17:15:23 +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#578
No description provided.