Keep the update token on the release host across redirects #148

Merged
aluminum-ice merged 1 commit from update-token-redirects into main 2026-11-01 23:08:29 +00:00
Owner

What this PR does

Makes the in-place update engine's redirect handling explicit, so the update token stays on the configured release host.

  • update-apply.py: http_fetch now opens requests through _OPENER, built with a _Redirects handler that:
    • follows a redirect only to an https:// address, refusing anything else with a clear Refused message;
    • follows at most five (MAX_REDIRECTS);
    • removes the Authorization header once a redirect leaves the host and port the request was made to. A release file served from other storage still downloads, without the token.
  • kestrel.sh: when a token is set, the release clone also gets http.followRedirects=false, through the same GIT_CONFIG_* environment that carries the token header (GIT_CONFIG_COUNT=2). Releases are cloned from the host's own git endpoint, which doesn't redirect. The anonymous clone is unchanged.

Checklist

  • Lint passes — make lint (ansible --syntax-check, yamllint, shellcheck --severity=error, and the real-data check). The Lint workflow runs this on the PR.
  • Tests pass — make test (the kestrel_pi pytest suite and the real-data check's tests). The Test workflow runs this on the PR.
  • Nothing real: no secrets, no personal information, no real data. This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, .env files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you.
  • Consent gates intact. Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced.
  • Docs updated in the same PR, if this changes something an operator sees or configures: the README package table, the relevant page under docs/, and the on-device operator guide (GUIDE_MD in kestrel_pi/userguide.py) where it applies.
  • Commit messages are short and imperative.

Release impact

  • App-layer-safe — changes only files the in-place update engine carries: the kestrel_pi package, plugins/*.py, systemd units, the journald drop-in, a lib script already in the engine's LIB_SCRIPTS, or the CLI.
  • Reflash-class — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / config.txt / cmdline, kernel modules, the base image or partition size, builder/config.json, builder/config.yml, the Makefile, the Release workflow (.forgejo/workflows/main.yml), a shipped config default (config.toml / default.conf), or a brand-new lib script.

Notes for review

  • The updates plugin's own checks are unchanged: they use requests, which already drops Authorization on a change of host or a move from https to http.
  • When it takes effect: the clone runs from the installed CLI, so the git setting applies from the update after the one that installs it. The engine's fetch applies once it is installed.
  • Tests:
    • The handler: a same-host redirect keeps the header; another host, or the same host on another port, drops it (from both header maps); a plain-http target is refused; at most five redirects; http_fetch goes through the opener.
    • Real HTTPS: a test with two loopback HTTPS servers (the dashboard's self-signed certificate code) checks what each server actually received.
    • The clone setting: checked statically in kestrel.sh.
  • Docs: the update security notes in docs/developer/updates-setup.md.
  • Locally: the suite passes except the two tests that depend on this host (the daemon SIGHUP test and the GPS serial-device test); CI runs both.

🤖 Generated with Claude Code

## What this PR does Makes the in-place update engine's redirect handling explicit, so the update token stays on the configured release host. - **`update-apply.py`:** `http_fetch` now opens requests through `_OPENER`, built with a `_Redirects` handler that: - follows a redirect only to an `https://` address, refusing anything else with a clear `Refused` message; - follows at most five (`MAX_REDIRECTS`); - removes the `Authorization` header once a redirect leaves the host and port the request was made to. A release file served from other storage still downloads, without the token. - **`kestrel.sh`:** when a token is set, the release clone also gets `http.followRedirects=false`, through the same `GIT_CONFIG_*` environment that carries the token header (`GIT_CONFIG_COUNT=2`). Releases are cloned from the host's own git endpoint, which doesn't redirect. The anonymous clone is unchanged. ## Checklist - [x] **Lint passes** — `make lint` (ansible `--syntax-check`, `yamllint`, `shellcheck --severity=error`, and the real-data check). The **Lint** workflow runs this on the PR. - [x] **Tests pass** — `make test` (the `kestrel_pi` pytest suite and the real-data check's tests). The **Test** workflow runs this on the PR. - [x] **Nothing real: no secrets, no personal information, no real data.** This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, `.env` files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you. - [x] **Consent gates intact.** Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced. - [x] **Docs updated in the same PR**, if this changes something an operator sees or configures: the README package table, the relevant page under `docs/`, and the on-device operator guide (`GUIDE_MD` in `kestrel_pi/userguide.py`) where it applies. - [x] Commit messages are short and imperative. ## Release impact - [x] **App-layer-safe** — changes only files the in-place update engine carries: the `kestrel_pi` package, `plugins/*.py`, systemd units, the journald drop-in, a lib script already in the engine's `LIB_SCRIPTS`, or the CLI. - [ ] **Reflash-class** — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / `config.txt` / `cmdline`, kernel modules, the base image or partition size, `builder/config.json`, `builder/config.yml`, the `Makefile`, the Release workflow (`.forgejo/workflows/main.yml`), a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. ## Notes for review - **The `updates` plugin's own checks are unchanged:** they use `requests`, which already drops `Authorization` on a change of host or a move from https to http. - **When it takes effect:** the clone runs from the installed CLI, so the git setting applies from the update after the one that installs it. The engine's fetch applies once it is installed. - **Tests:** - **The handler:** a same-host redirect keeps the header; another host, or the same host on another port, drops it (from both header maps); a plain-http target is refused; at most five redirects; `http_fetch` goes through the opener. - **Real HTTPS:** a test with two loopback HTTPS servers (the dashboard's self-signed certificate code) checks what each server actually received. - **The clone setting:** checked statically in `kestrel.sh`. - **Docs:** the update security notes in `docs/developer/updates-setup.md`. - **Locally:** the suite passes except the two tests that depend on this host (the daemon SIGHUP test and the GPS serial-device test); CI runs both. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Keep the update token on the release host across redirects
All checks were successful
Test / test (push) Successful in 32s
Lint / lint (push) Successful in 33s
Test / test (pull_request) Successful in 32s
Lint / lint (pull_request) Successful in 33s
1554f3e210
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch update-token-redirects 2026-11-01 23:08:29 +00:00
Sign in to join this conversation.
No reviewers
No labels
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
aluminum-ice/kestrel!148
No description provided.