Skip to content

cli: decdn self-update and an update check on run #2537

Closed

Description

@thiras

Problem

A decdn binary has no way to learn that it is stale, and no way to replace itself. Today the only update paths are:

  • cargo install --locked decdn-cli again,
  • docker pull,
  • re-running the sponsored one-liner (https://up.decdn.org/decdn.sh / decdn.ps1), which reinstalls into ~/.local/bin/decdn only when the onramp's pinned release (sponsord_onramp_decdn_release) moves and the marker in ~/.decdn/installer/decdn no longer matches.

Someone who ran the one-liner once and then types decdn get … directly keeps the old binary forever. That matters more here than for most CLIs: pre-mainnet, wire-breaking changes are allowed and the testnet is redeployed rather than migrated (CLAUDE.md § Pre-mainnet). After a fleet upgrade, a stale client fails with whatever the mismatch surfaces as (a refused StreamRequest, an ABI mis-decode, a NotFound), not with "your decdn is out of date". The next release is likely v0.2.0 with #2482 breaking the lane signer, so this will bite the current one-liner users (see decdn/sponsord#83 for the pin dance it forces on the onramp side).

Proposal

Add self-update to the decdn CLI, in two layers:

  1. decdn self-update (explicit). Resolve the latest stable GitHub release, download SHA256SUMS + SHA256SUMS.asc and the decdn-<version>-<target> archive for the running target, verify, and replace the running binary in place.
  2. Update check on run (automatic). At most once per day (stamp under ~/.decdn/), after the command's real work, check the latest release and print one line: decdn <new> is available; run \decdn self-update`(or apply it whenself_update.auto = true/DECDN_SELF_UPDATE=auto). Never block a geton the check, never check in--json/non-tty output unless asked, and self_update.check = falseturns it off entirely. Aget` that was started should finish on the binary it started with.

Verification is the hard part

The release pipeline signs only SHA256SUMS (GPG, key in KEYS; SECURITY.md § Verify a binary archive). Individual archives carry no signature. So the client must:

  • embed the maintainer signing key(s) at build time (from KEYS, or a fingerprint allowlist) and verify SHA256SUMS.asc before trusting any checksum; a release that does not verify is refused, not warned about;
  • verify the archive against the signed manifest, extract, and only then swap the binary;
  • refuse downgrades (new <= running) and pre-releases unless --pre-release is given, so a compromised or stale "latest" cannot roll users back;
  • treat GitHub as an untrusted mirror: nothing it serves is trusted until the signature checks out.

Open question: a full OpenPGP verifier (sequoia-openpgp, pgp) is a heavy dependency for the client crate graph that .github/scripts/check_crate_edges.py keeps lean. The alternative is to add a second, client-oriented signature to the release pipeline (minisign / raw Ed25519 over SHA256SUMS, produced by sign-release.sh from a dedicated key published in KEYS-adjacent form) and have the CLI embed that public key. That keeps GPG as the human-facing channel and gives the binary a ~0-dep verifier. Needs a decision before implementation; the second option also needs a RELEASING.md + SECURITY.md update and a key-rotation story (the embedded key must be able to vouch for its successor).

Ownership of the installed binary

Only replace a binary we own. Detect the install channel and act accordingly:

Installed via Behaviour
sponsored installer (~/.local/bin/decdn + marker in ~/.decdn/installer/) or a previous self-update replace in place, then rewrite the installer marker (<SHA256SUMS digest> <target>) so the next one-liner run does not reinstall over it (decdn/sponsord crates/sponsord-onramp/assets/decdn.sh fetch_bin)
cargo install (~/.cargo/bin) refuse, print cargo install --locked decdn-cli
container image refuse, print docker pull …
distro package / unknown path, or not writable refuse, name the path and the reason

Windows cannot replace a running .exe; use the rename-then-replace pattern (e.g. the self-replace crate) and make sure a crash mid-swap leaves a working binary (write to a sibling temp file, fsync, atomic rename).

Out of scope

  • decdn-node: operators deploy it through devops/ (Ansible / Helm / Compose) and must not have a daemon replacing itself under a supervisor.
  • A protocol-level "minimum client version" signal from nodes. Worth a separate ADR discussion if version skew keeps hurting after this lands; this issue only closes the gap between "a new release exists" and "the user knows".

Acceptance

  • decdn self-update on a one-liner install moves ~/.local/bin/decdn to the latest signed release and decdn --version reports it; the installer marker matches and re-running the one-liner says decdn <tag> is already installed.
  • A tampered SHA256SUMS, a bad .asc, or an archive that does not match the manifest leaves the running binary untouched and exits non-zero with the reason.
  • A cargo install binary refuses with the right command.
  • The daily check adds no latency to decdn get and is silent with self_update.check = false.
  • Config knobs follow the usual surfacing (config schema, decdn config show/validate summary, DEFAULT_CONFIG, env + CLI flag, CHANGELOG).
  • Unit tests in their own <name>.rs files (CONTRIBUTING.md § Unit test placement); signature-verification tests use a test key, never the maintainer keys.
  • README § Install, SECURITY.md, and RELEASING.md describe the new channel and, if chosen, the second signature.

Related: #2466, #2476, #2482, #2487, decdn/sponsord#83.

Metadata

Metadata

Assignees

Labels

area:clikind:feature

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions