From 90735500628cc0babd6be3f83ae02118fbb94c7e Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 11 Nov 2026 17:11:54 -0500 Subject: [PATCH 1/2] feat: release pipeline, install scripts and self-update - release.yml with release-please: merging the release PR tags a version, builds archives for macOS, Linux (static musl) and Windows with sha256 files, attests build provenance, uploads them, and runs both install scripts against the release. - install.sh and install.ps1, checking the sha256 and, when gh is available, the attestation. - firebird-cli update [--check] [--tag], which verifies the archive's build provenance against Sigstore, pinned to this repo's release workflow, and is never given the site key. - CI gains Windows, MSRV and static-musl jobs; quality.yml runs cargo deny and zizmor; pr.yml requires conventional PR titles. Co-Authored-By: Claude Fable 5.2 --- .editorconfig | 15 + .gitattributes | 4 + .github/dependabot.yml | 19 + .github/pull_request_template.md | 9 + .github/workflows/ci.yml | 40 +- .github/workflows/pr.yml | 18 + .github/workflows/quality.yml | 40 + .github/workflows/release.yml | 252 ++++ .release-please-manifest.json | 3 + AGENTS.md | 53 +- CHANGELOG.md | 1 + CONTRIBUTING.md | 68 + Cargo.lock | 1204 ++++++++++++++++- Cargo.toml | 12 +- README.md | 69 +- SECURITY.md | 59 + about.hbs | 33 + about.toml | 19 + deny.toml | 35 + docs/GUIDE.md | 54 +- install.ps1 | 132 ++ install.sh | 180 +++ release-please-config.json | 20 + src/cli.rs | 28 +- src/commands/guide.rs | 4 + src/commands/mod.rs | 2 + src/commands/provenance.rs | 415 ++++++ src/commands/update.rs | 505 +++++++ src/error.rs | 2 +- src/testdata/geekcli-attestation-v0.12.1.json | 74 + tests/update.rs | 471 +++++++ 31 files changed, 3780 insertions(+), 60 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/quality.yml create mode 100644 .github/workflows/release.yml create mode 100644 .release-please-manifest.json create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md create mode 100644 about.hbs create mode 100644 about.toml create mode 100644 deny.toml create mode 100644 install.ps1 create mode 100755 install.sh create mode 100644 release-please-config.json create mode 100644 src/commands/provenance.rs create mode 100644 src/commands/update.rs create mode 100644 src/testdata/geekcli-attestation-v0.12.1.json create mode 100644 tests/update.rs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5f5b2d4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.rs] +indent_style = space +indent_size = 4 + +[*.{md,toml,yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b669e54 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto eol=lf +*.ps1 text eol=crlf +*.png binary +Cargo.lock linguist-generated=true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6396164 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" + # Wait a week before proposing a new version, so a compromised release + # that gets yanked never reaches a PR. Security updates are not delayed. + cooldown: + default-days: 7 + groups: + cargo: + patterns: ["*"] + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + cooldown: + default-days: 7 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..de8ba7e --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,9 @@ + + +## What and why + +## Checklist + +- [ ] `cargo fmt`, `cargo clippy --all-targets -- -D warnings` and `cargo test` pass +- [ ] New commands or flags are covered by a test and documented in `docs/GUIDE.md` +- [ ] No API keys, customer data or private site content in code, tests or docs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23aab28..a53529e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -71,3 +71,41 @@ jobs: - name: Guide renders shell: bash run: cargo run --locked --quiet -- guide setup | head -5 + + static-linux: + # The release ships static musl binaries; build one on every PR and run + # it on an old glibc and on Alpine so a release never finds out first. + name: Static Linux build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: stable + targets: x86_64-unknown-linux-musl + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + - run: sudo apt-get update && sudo apt-get install -y musl-tools + - name: Build + env: + CC_x86_64_unknown_linux_musl: musl-gcc + run: cargo build --locked --target x86_64-unknown-linux-musl + - name: Runs on Debian 11 and Alpine + run: | + for image in debian:11 alpine:3; do + docker run --rm -v "$PWD/target/x86_64-unknown-linux-musl/debug:/b:ro" "$image" /b/firebird-cli --version + done + + msrv: + name: MSRV (1.88) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: "1.88" + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + - run: cargo check --locked --all-targets diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..577bdd1 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,18 @@ +name: PR + +on: + pull_request: + branches: [main] + types: [opened, edited, synchronize, reopened] + +permissions: + pull-requests: read + +jobs: + main: + name: Lint Title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 0000000..cf4289f --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,40 @@ +name: Quality + +on: + push: + branches: [main] + pull_request: + branches: [main] + # Rerun periodically to pick up new advisories + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +permissions: + contents: read + +jobs: + deny: + # Advisories (RustSec), licenses, banned crates and sources; see deny.toml + name: Security Audit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1 + with: + command: check advisories licenses bans sources + + workflows: + # Lint the GitHub Actions workflows themselves (injection, permissions, pins) + name: Workflow lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: zizmorcore/zizmor-action@cc914d7f3750a2d13d75c7f184a1060aa0e9d482 # v0.6.4 + with: + advanced-security: false # fail the job on findings instead of only uploading them + annotations: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d9b8369 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,252 @@ +name: Release + +# release-please keeps a release PR open on main from the conventional +# commits; merging it tags a version. The build matrix makes one archive per +# platform with a read-only token (it runs every dependency's build script); +# publish then attests their build provenance and attaches them to the +# release, and verify-install runs the install scripts against it on each OS. + +on: + push: + branches: [main] + workflow_dispatch: + inputs: + tag: + description: "Existing release tag to (re)build assets for, e.g. v0.1.0" + required: true + +permissions: {} + +env: + CARGO_TERM_COLOR: always + +jobs: + release-please: + name: Release Please + if: github.event_name == 'push' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + steps: + # Settings come from release-please-config.json (no release-type input, + # which would ignore that file): it also bumps the tagged install-script + # URLs in the docs (extra-files, x-release-please-version markers). + - name: Release Please + id: release + uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 + + build: + name: Build ${{ matrix.settings.target }} + needs: release-please + if: ${{ always() && (needs.release-please.outputs.release_created == 'true' || github.event_name == 'workflow_dispatch') }} + runs-on: ${{ matrix.settings.os }} + permissions: + contents: read + strategy: + fail-fast: false + matrix: + settings: + - target: aarch64-apple-darwin + os: macos-latest + - target: x86_64-apple-darwin + os: macos-latest + # Static musl builds run on any Linux, whatever its glibc + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + - target: aarch64-unknown-linux-musl + os: ubuntu-24.04-arm + - target: x86_64-pc-windows-msvc + os: windows-latest + exe: .exe + env: + TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }} + TARGET: ${{ matrix.settings.target }} + EXE: ${{ matrix.settings.exe }} + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.TAG }} + persist-credentials: false + + - name: Install Rust + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: stable + targets: ${{ matrix.settings.target }} + + - name: Install musl tools + if: contains(matrix.settings.target, 'musl') + run: sudo apt-get update && sudo apt-get install -y musl-tools + + - name: Install cargo-about + uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28 + with: + # pinned: it runs over every dependency to write the shipped license file + tool: cargo-about@0.9.2 + + - name: Build binary + shell: bash + run: | + if [[ "$TARGET" == *musl* ]]; then + # ring's C code compiles with musl-gcc on the native-arch runner + export "CC_${TARGET//-/_}=musl-gcc" + fi + cargo build --release --locked --target "$TARGET" + + - name: Smoke test + shell: bash + run: '"target/$TARGET/release/firebird-cli$EXE" --version' + + - name: Package + id: archive + shell: bash + run: | + NAME="firebird-cli-${TAG}-${TARGET}" + mkdir -p "dist/$NAME" + cp "target/$TARGET/release/firebird-cli$EXE" README.md LICENSE docs/GUIDE.md "dist/$NAME/" + cargo about generate --locked --fail about.hbs > "dist/$NAME/THIRD_PARTY_LICENSES.html" + if [ "$RUNNER_OS" = "Windows" ]; then + ARCHIVE="$NAME.zip" + (cd dist && 7z a -tzip "../$ARCHIVE" "$NAME" >/dev/null) + else + ARCHIVE="$NAME.tar.gz" + tar -czf "$ARCHIVE" -C dist "$NAME" + fi + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$ARCHIVE" > "$ARCHIVE.sha256" + else + shasum -a 256 "$ARCHIVE" > "$ARCHIVE.sha256" + fi + cat "$ARCHIVE.sha256" + echo "archive=$ARCHIVE" >> "$GITHUB_OUTPUT" + + - name: Keep the archive for publish + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: ${{ steps.archive.outputs.archive }} + path: | + ${{ steps.archive.outputs.archive }} + ${{ steps.archive.outputs.archive }}.sha256 + if-no-files-found: error + + publish: + name: Attest and publish + needs: [release-please, build] + if: ${{ always() && needs.build.result == 'success' }} + runs-on: ubuntu-latest + permissions: + contents: write # upload the archives to the release + id-token: write # sign the provenance attestation + attestations: write + env: + TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }} + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: dist + merge-multiple: true + + - name: Attest build provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-path: | + dist/*.tar.gz + dist/*.zip + + - name: Upload assets to release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload --clobber "$TAG" dist/* -R "$GITHUB_REPOSITORY" + + verify-install: + name: Install on ${{ matrix.os }} + needs: [release-please, publish] + if: ${{ always() && needs.publish.result == 'success' }} + runs-on: ${{ matrix.os }} + permissions: + contents: read + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + env: + TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.TAG }} + persist-credentials: false + + - name: install.sh + if: runner.os != 'Windows' + run: | + export FIREBIRD_CLI_INSTALL_DIR="$RUNNER_TEMP/bin" + # gh is installed and GH_TOKEN set here, so provenance must be checked + sh install.sh --version "$TAG" 2> "$RUNNER_TEMP/install.log" || { cat "$RUNNER_TEMP/install.log"; exit 1; } + cat "$RUNNER_TEMP/install.log" + grep -F "Build provenance verified" "$RUNNER_TEMP/install.log" + "$FIREBIRD_CLI_INSTALL_DIR/firebird-cli" --version | grep -F "${TAG#v}" + + - name: install.sh piped (the documented curl | sh path) + if: runner.os != 'Windows' + run: | + # The flag forms that survive a pipe, since `| sh --version X` would + # hand the flag to sh and install nothing. + export FIREBIRD_CLI_INSTALL_DIR="$RUNNER_TEMP/bin-piped" + cat install.sh | sh -s -- --version "$TAG" + "$FIREBIRD_CLI_INSTALL_DIR/firebird-cli" --version | grep -F "${TAG#v}" + + export FIREBIRD_CLI_INSTALL_DIR="$RUNNER_TEMP/bin-env" + cat install.sh | FIREBIRD_CLI_VERSION="$TAG" sh + "$FIREBIRD_CLI_INSTALL_DIR/firebird-cli" --version | grep -F "${TAG#v}" + + cat install.sh | sh -s -- --help | grep -F 'FIREBIRD_CLI_VERSION' + + - name: Linux binary runs on an older glibc and on Alpine + if: runner.os == 'Linux' + run: | + for image in debian:11 alpine:3; do + docker run --rm -v "$RUNNER_TEMP/bin:/b:ro" "$image" /b/firebird-cli --version + done + + - name: Provenance verifies + if: runner.os == 'Linux' + run: | + gh release download "$TAG" -R "$GITHUB_REPOSITORY" -p "firebird-cli-$TAG-x86_64-unknown-linux-musl.tar.gz" -D "$RUNNER_TEMP/dl" + gh attestation verify "$RUNNER_TEMP/dl/firebird-cli-$TAG-x86_64-unknown-linux-musl.tar.gz" -R "$GITHUB_REPOSITORY" + + - name: install.ps1 + if: runner.os == 'Windows' + shell: pwsh + run: | + $env:FIREBIRD_CLI_INSTALL_DIR = "$env:RUNNER_TEMP\bin" + # gh is installed and GH_TOKEN set here, so provenance must be checked + $log = ./install.ps1 -Version $env:TAG 6>&1 | Out-String + Write-Host $log + if ($log -notmatch 'Build provenance verified') { throw 'install.ps1 did not verify build provenance' } + $out = & "$env:FIREBIRD_CLI_INSTALL_DIR\firebird-cli.exe" --version + if ($out -notmatch [regex]::Escape($env:TAG.TrimStart('v'))) { throw "unexpected version: $out" } + + - name: install.ps1 through iex (the documented irm | iex path) + if: runner.os == 'Windows' + shell: pwsh + run: | + # iex passes no arguments, so the version has to arrive in the + # environment or through a scriptblock. + $env:FIREBIRD_CLI_INSTALL_DIR = "$env:RUNNER_TEMP\bin-iex" + $env:FIREBIRD_CLI_VERSION = $env:TAG + Get-Content -Raw ./install.ps1 | Invoke-Expression + $out = & "$env:FIREBIRD_CLI_INSTALL_DIR\firebird-cli.exe" --version + if ($out -notmatch [regex]::Escape($env:TAG.TrimStart('v'))) { throw "unexpected version: $out" } + + Remove-Item Env:FIREBIRD_CLI_VERSION + $env:FIREBIRD_CLI_INSTALL_DIR = "$env:RUNNER_TEMP\bin-block" + & ([scriptblock]::Create((Get-Content -Raw ./install.ps1))) -Version $env:TAG + $out = & "$env:FIREBIRD_CLI_INSTALL_DIR\firebird-cli.exe" --version + if ($out -notmatch [regex]::Escape($env:TAG.TrimStart('v'))) { throw "unexpected version: $out" } diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/AGENTS.md b/AGENTS.md index f4dfba3..2c98a7e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,11 +12,17 @@ draft: add, patch, move, duplicate, remove and reorder blocks, then validate, publish or discard. Changing live settings, restoring a revision and uploading media have no command yet; they go through `firebird-cli api`. -Build it from a checkout (there are no release binaries yet): +Install a release, or build it from a checkout when the +[Releases page](https://github.com/RealGeeks/firebird-cli/releases) has none +yet: + ```bash -cargo install --path . +curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.sh | sh +# Windows: irm https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.ps1 | iex +# no release yet, or from a checkout: cargo install --path . ``` + Sign in. A key is made by the site's owner on the site's Integrations page, so ask your human for one: @@ -98,6 +104,8 @@ src/ ├── media.rs # media list / get (read only) ├── revisions.rs # revisions list / get (read only) ├── guide.rs # `guide [topic]` over docs/GUIDE.md + ├── update.rs # self-update from the GitHub release archives (self_update crate, its own client) + ├── provenance.rs # update's Sigstore check of the archive's build-provenance attestation (ring backend) └── api.rs # raw METHOD PATH escape hatch tests/ # end-to-end tests: the binary against a mockito server docs/GUIDE.md # agent-facing guide, embedded via include_str!; `guide ` prints one `## N. Title` section @@ -168,6 +176,27 @@ docs/GUIDE.md # agent-facing guide, embedded via include_str!; `guide < - Exit codes are a contract shared with geekcli (`error::exit`); do not renumber them. +- `firebird-cli update` is the one request path that leaves the API: it + talks to GitHub through `self_update`'s own client and must never be handed + the site's key or token (`cli::dispatch` runs it before any config is + read). Before extracting, it verifies the archive's build-provenance + attestation against the embedded Sigstore root, pinned to + `release.yml@refs/heads/main` of RealGeeks/firebird-cli whatever + `FIREBIRD_CLI_REPO` says (`commands/provenance.rs`); keep the sigstore + crates current so the root does not go stale. Nothing updates in the + background; scripts and agents need the version to stay put between calls. + `update::notify` mentions a newer release once a day, on a terminal only. +- The installer and updater variables are `FIREBIRD_CLI_*` (`_VERSION`, + `_INSTALL_DIR`, `_REPO`, `_SKIP_PROVENANCE`, `_NO_UPDATE_CHECK`); the ones + about a site and its API are `FIREBIRD_*`. +- Archive and folder names (`firebird-cli--.tar.gz|.zip`, with + a `.sha256` beside each) come from `release.yml`. `install.sh`, + `install.ps1` and `commands/update.rs` must stay in step with it. +- The provenance tests use a real attestation of a geekcli release + (`src/testdata/`), because firebird-cli had no release when they were + written: it proves the verifier works and that another repository's build + is refused. Once a release exists, add one of its own as the positive case. + ### Build and test ```bash @@ -178,9 +207,23 @@ cargo fmt --check ``` All must pass clean before a commit. Do not silence lints with `#[allow]`, -in tests either; fix the code (tests return `Result` and use `?`). CI -(`.github/workflows/ci.yml`) runs the same on every push and PR. Actions are -pinned by commit SHA. +in tests either; fix the code (tests return `Result` and use `?`). + +CI runs them on every push and PR (`ci.yml`: fmt, clippy, tests on Linux, +macOS and Windows, a static musl build run on old distros, and a check on +the MSRV, `rust-version` in Cargo.toml), plus `quality.yml`: `cargo deny +check` (advisories, licenses, sources; see `deny.toml`) and zizmor over the +workflows. `pr.yml` requires a conventional-commit PR title. Actions are +pinned by commit SHA; Dependabot updates the pins and the crates. + +`release.yml` uses release-please: it keeps a release PR open on `main` from +the conventional commits, and merging that PR tags a version, builds the +macOS/Linux (static musl)/Windows archives with THIRD_PARTY_LICENSES.html +(cargo-about, `about.toml`), attests their build provenance, uploads them to +the GitHub release, then runs `install.sh` and `install.ps1` against it. +release-please also bumps the version in Cargo.toml and in the lines marked +`x-release-please-version` in README.md, AGENTS.md, docs/GUIDE.md and the +install scripts. Never tag or edit a version by hand. ### Commits diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7b9da5c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,68 @@ +# Contributing to firebird-cli + +Thanks for helping. Bug reports, fixes and new commands for Firebird API +routes are all welcome. + +- **Security problems** go through [private reporting](SECURITY.md), never a + public issue. + +## Development + +You need a Rust toolchain (1.88 or newer). + +```bash +cargo build +cargo test +cargo clippy --all-targets -- -D warnings # pedantic; unwrap/expect/panic are denied +cargo fmt +``` + +All four must pass before a pull request is merged; CI runs them on Linux, +macOS and Windows, along with `cargo deny` (advisories and licenses), an MSRV +check, a static Linux build and a lint of the GitHub Actions workflows. Tests +run against mock servers; nothing in the test suite talks to a real site or +to GitHub. Point the CLI at a local API with +`FIREBIRD_BASE_URL=http://localhost:9006`. + +[AGENTS.md](AGENTS.md) describes the layout and the conventions the code +follows, for people and coding agents alike. In short: + +- Field names and flags mirror the Firebird API's names exactly. +- stdout is the result document, the API's response unchanged; anything for + humans goes to stderr. +- Lints are never silenced with `#[allow]`, in tests either. +- A new command gets a section (or a line in one) in `docs/GUIDE.md` and an + integration test. + +## Pull requests + +- Use a [conventional commit](https://www.conventionalcommits.org/) title + (`feat: …`, `fix: …`, `docs: …`): pull requests are squash-merged under + their title, and release notes are generated from those commits. +- Keep API keys, customer data, private site content and internal hostnames + out of code, tests, fixtures and screenshots. +- By contributing you agree that your contribution is licensed under the + project's [MIT license](LICENSE). + +## Releases + +Releases are cut by [release-please](https://github.com/googleapis/release-please) +in `.github/workflows/release.yml`; nobody tags or edits a version by hand. + +1. Every push to `main` updates an open pull request titled + `chore(main): release X.Y.Z`. It bumps the version in `Cargo.toml`, + `Cargo.lock`, the install commands in the docs and the install scripts, + and writes `CHANGELOG.md` from the commits since the last release. + Before 1.0, a `feat:` or a breaking change bumps the minor version and a + `fix:` the patch version. +2. Merging that pull request creates the tag and the GitHub release. The + same workflow run then builds the archives for macOS, Linux and Windows, + attests their build provenance, uploads them with their `.sha256` files, + and runs `install.sh` and `install.ps1` against the new release. +3. If the build fails after the tag exists, fix `main` if needed and re-run + it for that tag from the Actions tab: **Release → Run workflow**, on + `main`, with the tag. It must be dispatched from `main`: the attestation + is only trusted when it names `release.yml@refs/heads/main`. + +To force a particular version, put `Release-As: X.Y.Z` in the body of a +commit on `main`. diff --git a/Cargo.lock b/Cargo.lock index 493f15c..5c81582 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "aho-corasick" version = "1.1.5" @@ -107,6 +113,29 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "aws-lc-rs" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "048006790404103c488e6c5616b3e7e702a71292aadda08e8f7698a9e0d2eb53" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bfbe32ac36b3c428696ce315464181bc4029d689fd58e3f2a4e58c252242f52" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + [[package]] name = "base64" version = "0.22.1" @@ -119,12 +148,27 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bitflags" version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.12.1" @@ -164,6 +208,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] @@ -186,7 +232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.3.1", "rand_core 0.10.1", ] @@ -251,6 +297,27 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "cms" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730" +dependencies = [ + "const-oid 0.9.6", + "der", + "spki", + "x509-cert", +] + [[package]] name = "colorchoice" version = "1.0.5" @@ -266,6 +333,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "combine" +version = "4.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "comfy-table" version = "8.0.1" @@ -277,12 +354,56 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-oid" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a" +[[package]] +name = "constant_time_eq" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9" +dependencies = [ + "rustversion", +] + +[[package]] +name = "cookie" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b2c103cf610ec6cae3da84a766285b42fd16aad564758459e6ecf128c75206" +dependencies = [ + "cookie", + "document-features", + "idna", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + [[package]] name = "core-foundation" version = "0.10.1" @@ -299,6 +420,21 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "cpufeatures" version = "0.3.1" @@ -308,6 +444,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossterm" version = "0.29.0" @@ -331,6 +476,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "crypto-common" version = "0.2.2" @@ -340,21 +495,88 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid 0.9.6", + "der_derive", + "flagset", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "der_derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "deranged" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" + [[package]] name = "difflib" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + [[package]] name = "digest" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", + "block-buffer 0.12.1", + "const-oid 0.10.3", + "crypto-common 0.2.2", ] [[package]] @@ -398,6 +620,51 @@ dependencies = [ "litrs", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2 0.10.9", + "signature", + "subtle", + "zeroize", +] + +[[package]] +name = "encoding_rs" +version = "0.8.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + [[package]] name = "equivalent" version = "1.0.3" @@ -420,6 +687,22 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + [[package]] name = "find-msvc-tools" version = "0.1.15" @@ -437,18 +720,43 @@ dependencies = [ "clap_complete", "comfy-table", "dirs", + "flate2", "mockito", "predicates", - "reqwest", + "reqwest 0.12.28", + "ring", + "self_update", "serde", "serde_json", - "sha2", + "sha2 0.11.1", + "sigstore-crypto", + "sigstore-trust-root", + "sigstore-types", + "sigstore-verify", + "tar", "tempfile", "thiserror", "toml", "url", ] +[[package]] +name = "flagset" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe" + +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + [[package]] name = "float-cmp" version = "0.10.0" @@ -473,6 +781,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.34" @@ -522,6 +836,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.17" @@ -592,6 +916,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "1.5.0" @@ -866,76 +1196,197 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] -name = "js-sys" -version = "0.3.107" +name = "jiff" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +checksum = "26699905cc795a23e3949585cc7ba3ee8ade090872a27e4316304a777297894a" dependencies = [ - "cfg-if", - "futures-util", - "wasm-bindgen", + "jiff-core", + "jiff-static", + "jiff-tzdb-platform", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-link", ] [[package]] -name = "libc" -version = "0.2.191" +name = "jiff-core" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +checksum = "ffe6854081f5ac0a3046a9b223729ccd7a20b1e0e8277e44dc0660eedf67dfe2" +dependencies = [ + "log", +] [[package]] -name = "libredox" -version = "0.1.25" +name = "jiff-static" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +checksum = "4b4ff49b2887190c760b86207b55cdcaabbdecaf7a0660d68aa2ed6f652abf0a" dependencies = [ - "libc", + "jiff-core", + "proc-macro2", + "quote", + "syn 2.0.119", ] [[package]] -name = "linux-raw-sys" -version = "0.12.1" +name = "jiff-tzdb" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" [[package]] -name = "litemap" -version = "0.8.3" +name = "jiff-tzdb-platform" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" +dependencies = [ + "jiff-tzdb", +] [[package]] -name = "litrs" -version = "1.0.1" +name = "jni" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4744e383959f0db86ede514b809b1c53251889093803c05267acc7d4e7030d70" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys", + "log", + "simd_cesu8", + "thiserror", + "walkdir", + "windows-link", +] [[package]] -name = "lock_api" -version = "0.4.14" +name = "jni-macros" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" dependencies = [ - "scopeguard", + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn 2.0.119", ] [[package]] -name = "log" -version = "0.4.35" +name = "jni-sys" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] [[package]] -name = "lru-slab" -version = "0.1.3" +name = "jni-sys-macros" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" - -[[package]] +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "litrs" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4744e383959f0db86ede514b809b1c53251889093803c05267acc7d4e7030d70" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + +[[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "mio" version = "1.2.4" @@ -972,12 +1423,36 @@ dependencies = [ "tokio", ] +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + [[package]] name = "num-traits" version = "0.2.19" @@ -1034,6 +1509,25 @@ dependencies = [ "windows-link", ] +[[package]] +name = "pem" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d354a98a3d1251555de99e8fdd8afda05573c31b82f59063a7b0a29b5527f120" +dependencies = [ + "base64 0.23.1", + "serde_core", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -1046,6 +1540,37 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + [[package]] name = "potential_utf" version = "0.1.6" @@ -1055,6 +1580,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -1129,6 +1660,7 @@ version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe" dependencies = [ + "aws-lc-rs", "bytes", "getrandom 0.4.3", "lru-slab", @@ -1211,6 +1743,15 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "rand_core" version = "0.9.5" @@ -1324,6 +1865,46 @@ dependencies = [ "webpki-roots", ] +[[package]] +name = "reqwest" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a1cfa75cc186dd73d5818e510e042e40927bccc9c236b061cea97e1eb08029" +dependencies = [ + "base64 0.23.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "ring" version = "0.17.14" @@ -1344,6 +1925,15 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "1.1.6" @@ -1363,6 +1953,8 @@ version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ + "aws-lc-rs", + "log", "once_cell", "ring", "rustls-pki-types", @@ -1393,12 +1985,40 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-platform-verifier" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f" + [[package]] name = "rustls-webpki" version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -1416,6 +2036,21 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" +[[package]] +name = "ryu-js" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04d056b875a9d2e6cb9a61d127afee9ac5999b9f87bcb32079d1318e505be714" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.30" @@ -1454,6 +2089,47 @@ dependencies = [ "libc", ] +[[package]] +name = "self-replace" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609c5606d9d357b26e4ee1a7a01beac396628d0fa01ebbade2a09cefb88e65af" +dependencies = [ + "fastrand", + "tempfile", + "windows-sys 0.61.2", +] + +[[package]] +name = "self_update" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db894dc81dc2d26b41c4966e3e67ab2e0c21289912edd262012a07da9e4e0201" +dependencies = [ + "flate2", + "http", + "log", + "regex", + "reqwest 0.13.5", + "self-replace", + "semver", + "serde", + "serde_json", + "sha2 0.11.1", + "tar", + "tempfile", + "ureq", + "urlencoding", + "zip", + "zipsign-api", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.229" @@ -1497,6 +2173,17 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_json_canonicalizer" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f7bb64f8c7e9f783fdfe883b5fe93a90bee1597c63705baa91842c5f698620" +dependencies = [ + "ryu-js", + "serde", + "serde_json", +] + [[package]] name = "serde_spanned" version = "1.1.3" @@ -1518,6 +2205,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.11.1" @@ -1525,8 +2223,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.3.1", + "digest 0.11.3", ] [[package]] @@ -1535,6 +2233,171 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "sigstore-bundle" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442bc4f672eef040397e65d4ae34ca1b1dc8140b1a35b1246e0b219ce5f4e571" +dependencies = [ + "jiff", + "sigstore-types", + "thiserror", +] + +[[package]] +name = "sigstore-crypto" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045039ae523e86a8b856470a6fc8e9a4567bb61e723ec08a4d23fa8ce40167e9" +dependencies = [ + "const-oid 0.9.6", + "der", + "futures-io", + "jiff", + "rustls-pki-types", + "sigstore-types", + "spki", + "thiserror", + "x509-cert", +] + +[[package]] +name = "sigstore-merkle" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22923d7f1a03e21a3313a4a2e6a6485959327a2a084df09b4fff45810e46f08a" +dependencies = [ + "sigstore-crypto", + "sigstore-types", + "thiserror", +] + +[[package]] +name = "sigstore-rekor" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a46ca1954e5e92b8a35eeefb745f55a1eff2d82c6b80f946e733671b33508540" +dependencies = [ + "base64 0.23.1", + "hex", + "jiff", + "serde", + "serde_json", + "sigstore-merkle", + "sigstore-types", + "thiserror", +] + +[[package]] +name = "sigstore-trust-root" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9a49e390a5f52e0b05f1a17820be5ac747a3890bb9f54156d8a1147508420a7" +dependencies = [ + "jiff", + "serde", + "serde_json", + "sigstore-crypto", + "sigstore-types", + "thiserror", +] + +[[package]] +name = "sigstore-tsa" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36aa9c47f3480420ccb90753c5f3aae07823c489ab20762f0c96070ba35cd5cb" +dependencies = [ + "cms", + "const-oid 0.9.6", + "der", + "hex", + "jiff", + "rustls-pki-types", + "rustls-webpki", + "sigstore-crypto", + "sigstore-types", + "thiserror", + "tracing", + "x509-cert", +] + +[[package]] +name = "sigstore-types" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eec330f1cdb4c7ec6628ef43165c42978480d4213af70567e67e2891ec9072d8" +dependencies = [ + "base64 0.23.1", + "hex", + "jiff", + "pem", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "sigstore-verify" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465f37d73c80fc6a2fa519d1337befab2026fce47f490181f72842aa56d401e1" +dependencies = [ + "base64 0.23.1", + "const-oid 0.9.6", + "futures-io", + "hex", + "jiff", + "rustls-pki-types", + "rustls-webpki", + "serde", + "serde_json", + "serde_json_canonicalizer", + "sigstore-bundle", + "sigstore-crypto", + "sigstore-merkle", + "sigstore-rekor", + "sigstore-trust-root", + "sigstore-tsa", + "sigstore-types", + "thiserror", + "tls_codec", + "tracing", + "x509-cert", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + [[package]] name = "similar" version = "2.7.0" @@ -1563,6 +2426,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -1623,6 +2496,17 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -1672,6 +2556,37 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "js-sys", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.8.5" @@ -1688,6 +2603,27 @@ version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" +[[package]] +name = "tls_codec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de2e01245e2bb89d6f05801c564fa27624dbd7b1846859876c7dad82e90bf6b" +dependencies = [ + "tls_codec_derive", + "zeroize", +] + +[[package]] +name = "tls_codec_derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tokio" version = "1.54.1" @@ -1818,9 +2754,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -1836,6 +2784,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + [[package]] name = "typenum" version = "1.20.1" @@ -1866,6 +2820,40 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7be76686bdf7198002062423ca0d8cf9b75a27c8e1de804513b97e97b555d9d" +dependencies = [ + "base64 0.23.1", + "cookie_store", + "encoding_rs", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "ureq-proto", + "utf8-zero", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622dce33c252115466d83f63e9744a18f12b4406aae51a01c15ad8fcf1185eb3" +dependencies = [ + "base64 0.23.1", + "http", + "httparse", + "log", +] + [[package]] name = "url" version = "2.5.8" @@ -1878,6 +2866,18 @@ dependencies = [ "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + [[package]] name = "utf8_iter" version = "1.1.0" @@ -1899,6 +2899,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "wait-timeout" version = "0.2.1" @@ -1908,6 +2914,16 @@ dependencies = [ "libc", ] +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.2" @@ -2007,6 +3023,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-root-certs" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "293198dcebfb821155b5092ab94b5a82ff180eddd7241df3bd6e66a4ffd1a585" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "webpki-roots" version = "1.0.12" @@ -2032,6 +3057,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2197,6 +3231,28 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" +[[package]] +name = "x509-cert" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" +dependencies = [ + "const-oid 0.9.6", + "der", + "spki", + "tls_codec", +] + +[[package]] +name = "xattr" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "963d6fab92d5504b971dc8bd90ca743c2575e590bc8071ea5bc571598667ae08" +dependencies = [ + "libc", + "rustix", +] + [[package]] name = "yoke" version = "0.8.4" @@ -2266,6 +3322,20 @@ name = "zeroize" version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] [[package]] name = "zerotrie" @@ -2300,8 +3370,58 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "zip" +version = "9.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3476fd497ac8af5b1ec7b51acab7bef380f7e8dd8e0487595bafd839417a302" +dependencies = [ + "constant_time_eq", + "crc32fast", + "flate2", + "getrandom 0.4.3", + "indexmap", + "libc", + "memchr", + "nix", + "time", + "typed-path", + "windows-sys 0.61.2", + "zeroize", + "zopfli", +] + +[[package]] +name = "zipsign-api" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d866e1d567fd67738668647c2e06587851e0e3583df84298cc363c14602316" +dependencies = [ + "base64 0.22.1", + "ed25519-dalek", + "thiserror", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + [[package]] name = "zmij" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zopfli" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/Cargo.toml b/Cargo.toml index 86f117b..f2dd5e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/RealGeeks/firebird-cli" readme = "README.md" keywords = ["real-estate", "cms", "cli", "ai-agents", "firebird"] categories = ["command-line-utilities"] -include = ["/src", "/docs/GUIDE.md", "/README.md", "/LICENSE"] +include = ["/src", "/docs/GUIDE.md", "/README.md", "/LICENSE", "/CHANGELOG.md"] [lib] name = "firebird_cli" @@ -33,12 +33,22 @@ comfy-table = "8" sha2 = "0.11" base64 = "0.23" chrono = { version = "0.4", default-features = false, features = ["clock"] } +self_update = { version = "1.3", default-features = false, features = ["ureq", "rustls", "native-certs", "github", "archive-tar", "compression-tar-gz", "archive-zip", "compression-zip-deflate", "checksums"] } +# Build-provenance check in `update`. Their default crypto backend is aws-lc; +# `commands::provenance` plugs in ring, which the TLS stack already links. +sigstore-verify = { version = "0.15", default-features = false } +sigstore-trust-root = { version = "0.15", default-features = false } +sigstore-types = "0.15" +sigstore-crypto = { version = "0.15", default-features = false } +ring = "0.17" [dev-dependencies] assert_cmd = "2.0" predicates = "3.1" mockito = "1.6" tempfile = "3" +tar = "0.4" +flate2 = "1" [lints.rust] unsafe_code = "forbid" diff --git a/README.md b/README.md index 93edd40..8056316 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,67 @@ firebird-cli draft validate about firebird-cli draft publish about --message "New headline" ``` -## Build from source +## Install -There are no release binaries yet. With a Rust toolchain (1.88 or newer): +macOS and Linux: + + +```bash +curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.sh | sh +``` + +Windows (PowerShell): + +```powershell +irm https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.ps1 | iex +``` + + +These install a release from the +[Releases page](https://github.com/RealGeeks/firebird-cli/releases). If that +page lists no release yet, the first one has not been cut and the commands +above have nothing to download: [build from source](#build-from-source) +until it has. + +The scripts download the archive for your platform (macOS on Apple silicon +and Intel, Linux x86_64 and arm64 as static binaries, Windows x86_64), check +it against the `.sha256` published beside it and, when the +[GitHub CLI](https://cli.github.com/) is installed and logged in, verify its +build-provenance attestation; without `gh` they print the command to check +it yourself. `install.sh` installs to `/usr/local/bin` if you can write +there, else `~/.local/bin`; `install.ps1` to +`%LOCALAPPDATA%\Programs\firebird-cli`, which it adds to your PATH. + +| Variable | Flag (`install.sh` / `install.ps1`) | Meaning | +| -------------------------------- | ----------------------------------- | ------------------------------------------ | +| `FIREBIRD_CLI_VERSION` | `--version` / `-Version` | Install this tag instead of the latest | +| `FIREBIRD_CLI_INSTALL_DIR` | `--dir` / `-InstallDir` | Where the binary goes | +| `FIREBIRD_CLI_SKIP_PROVENANCE=1` | | Skip the attestation check (sha256 only) | +| `GH_TOKEN` / `GITHUB_TOKEN` | | Avoids GitHub's anonymous API rate limit | + +Piped into `sh`, flags go after `-s --`: +`curl … | sh -s -- --version v0.1.0`. + +### Updating + +```bash +firebird-cli update # install the latest release over this binary +firebird-cli update --check # only report whether one is available +firebird-cli update --tag v0.1.0 # x-release-please-version +``` + +`update` downloads the same archives as the install scripts, checks the +sha256, and verifies the archive's build-provenance attestation itself (no +`gh` needed) before replacing the binary: it must have been built by this +repository's release workflow on `main`. Nothing updates on its own. On a +terminal, a command mentions a newer release at most once a day; +`FIREBIRD_CLI_NO_UPDATE_CHECK=1` turns that off, and piped output and CI +never get it. The updater talks only to GitHub and is never given your site's +API key or token. + +### Build from source + +With a Rust toolchain (1.88 or newer): ```bash git clone https://github.com/RealGeeks/firebird-cli @@ -118,6 +176,7 @@ firebird-cli revisions list --type [--key ] [--chang firebird-cli api METHOD PATH [-p k=v]... [-d JSON | -d @file | -d -] [--no-auth] firebird-cli guide [topic] [--list] +firebird-cli update [--check] [--tag vX.Y.Z] firebird-cli completions ``` @@ -186,7 +245,7 @@ version. | 6 | Conflict (409) | | 7 | Rate limited (429) after every retry | | 8 | Network: the API could not be reached, timed out, or TLS failed | -| 9 | The API requires a newer firebird-cli (426) | +| 9 | The API requires a newer firebird-cli (426): run `firebird-cli update` | ## Development @@ -199,7 +258,9 @@ cargo fmt --check All four must pass clean. The tests run the binary against a mock API, so they need no Firebird site or key. See [AGENTS.md](AGENTS.md) for the layout -and conventions. +and conventions, [CONTRIBUTING.md](CONTRIBUTING.md) for pull requests and how +releases are made, and [SECURITY.md](SECURITY.md) to report a vulnerability +or verify a download. ## License diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..81499fc --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,59 @@ +# Security policy + +## Reporting a vulnerability + +Please report vulnerabilities privately through GitHub: on this repository's +**Security** tab choose **Report a vulnerability**, or go straight to +. Do not +open a public issue, pull request or discussion for a security problem. + +Useful details: the firebird-cli version (`firebird-cli --version`), your +operating system, the command involved, and what an attacker could do. Never +include a real API key; revoke any key that may have been exposed on the +site's **Integrations** page. + +We will acknowledge the report, keep you updated while we work on a fix, and +credit you in the advisory if you would like. + +## Supported versions + +Security fixes go into the latest release. Update with `firebird-cli update`, +the install command in the [README](README.md#install), or by downloading +the newest [release](https://github.com/RealGeeks/firebird-cli/releases). + +## Scope + +This repository covers the `firebird-cli` client and its install scripts. +Problems with a Firebird website or the Firebird API itself can be reported +the same way and will be passed to the right team. + +## Verifying a download + +Every release archive has a `.sha256` checksum beside it and a signed +build-provenance attestation. `firebird-cli update` verifies the attestation +itself (Sigstore's trust root is built in) and refuses an archive that was +not built by this repository's release workflow on `main`; the install +scripts do the same through the GitHub CLI when it is installed and logged +in, and otherwise print the command. To check an archive by hand: + +```bash +gh attestation verify firebird-cli--.tar.gz --repo RealGeeks/firebird-cli \ + --cert-identity https://github.com/RealGeeks/firebird-cli/.github/workflows/release.yml@refs/heads/main +``` + +`FIREBIRD_CLI_SKIP_PROVENANCE=1` skips the attestation in both, for mirrors +that cannot reach GitHub; the sha256 is still checked. + +## Stored keys and tokens + +API keys are kept in `~/.config/firebird-cli/config.toml`, and the +short-lived tokens they are exchanged for in `tokens.json` beside it. Both +are readable only by you (mode 600 in a 700 directory, restored with a +warning if found looser). They are not in the operating system's keychain; +that is a possible future option. Anyone who can run code as your user can +read the files, so revoke a key on the site's **Integrations** page if the +machine may be compromised. + +The key and token are sent only to the configured Firebird API origin, over +https. `firebird-cli update` and the install scripts talk to GitHub and are +never given either. diff --git a/about.hbs b/about.hbs new file mode 100644 index 0000000..9afd668 --- /dev/null +++ b/about.hbs @@ -0,0 +1,33 @@ + + + + +firebird-cli third-party licenses + + + +

Third-party licenses

+

firebird-cli is MIT licensed. It includes the open-source crates below, under these licenses.

+

Overview

+
    +{{#each overview}} +
  • {{name}} ({{count}})
  • +{{/each}} +
+

Licenses

+{{#each licenses}} +

{{name}}

+

Used by:

+ +
{{text}}
+{{/each}} + + diff --git a/about.toml b/about.toml new file mode 100644 index 0000000..220ae83 --- /dev/null +++ b/about.toml @@ -0,0 +1,19 @@ +# cargo-about: builds THIRD_PARTY_LICENSES.html for the release archives. +accepted = [ + "MIT", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "BSD-2-Clause", + "BSD-3-Clause", + "ISC", + "Zlib", + "Unicode-3.0", + "MPL-2.0", + "CDLA-Permissive-2.0", + "BSL-1.0", + "0BSD", + "Unlicense", +] +# Only what is compiled into the binary; build tools are not distributed. +ignore-build-dependencies = true +ignore-dev-dependencies = true diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..afc3d6e --- /dev/null +++ b/deny.toml @@ -0,0 +1,35 @@ +# cargo-deny: run in CI by the Quality workflow (`cargo deny check`). + +[graph] +all-features = false + +[advisories] +# RustSec advisories fail the build; unmaintained crates are reported too. +yanked = "deny" + +[licenses] +# Permissive licenses compatible with distributing MIT-licensed binaries. +allow = [ + "MIT", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "BSD-2-Clause", + "BSD-3-Clause", + "ISC", + "Zlib", + "Unicode-3.0", + "MPL-2.0", + "CDLA-Permissive-2.0", + "BSL-1.0", + "0BSD", + "Unlicense", +] +confidence-threshold = 0.9 + +[bans] +multiple-versions = "warn" +wildcards = "deny" + +[sources] +unknown-registry = "deny" +unknown-git = "deny" diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 3211e17..9265df5 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -15,10 +15,22 @@ go through `firebird-cli api METHOD PATH` (§11). Where this guide shows the ## 1. Setup -Build from source (there are no release binaries yet): +Install a release: ```bash -cargo install --path . # from a checkout of the repository +curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.sh | sh # macOS, Linux x-release-please-version +irm https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.ps1 | iex # Windows PowerShell x-release-please-version +``` + +The scripts verify the release checksum and, with the GitHub CLI logged in, +its build-provenance attestation; `firebird-cli --version` confirms it. +`firebird-cli update` installs a newer release later (§13); nothing updates +on its own. Releases are listed at +. If none is listed yet, +or to run unreleased code, build from a checkout of the repository instead: + +```bash +cargo install --path . firebird-cli --version ``` @@ -452,8 +464,44 @@ firebird-cli api GET /healthz/ready --no-auth # {"raw": "OK"} | 6 | Conflict (409), for example someone else holds a page's edit lock | | 7 | Rate limited (429) after every retry | | 8 | Network: the API could not be reached, timed out, or TLS failed | -| 9 | The API requires a newer firebird-cli (426) | +| 9 | The API requires a newer firebird-cli (426): run `firebird-cli update`, then the command again (§13) | On exit 5 or 6, read `error.body` on stderr: it is the API's response and names what to fix. On exit 3 with `unauthorized`, the key is wrong or revoked: sign in again with a new one (§1). + +## 13. Updating firebird-cli + +```bash +firebird-cli update # install the latest release over this binary +firebird-cli update --check # report only: {current_version, release_version, update_available} +firebird-cli update --tag v0.1.0 # install that release; an older tag downgrades x-release-please-version +``` + +- Nothing updates on its own: a script keeps the version it was written + against until something runs `firebird-cli update`. +- `update --check` exits 0 whether or not a newer release exists; branch on + `update_available`. `update` prints the same document with `updated`. +- Before the binary is replaced, the archive must match the sha256 published + beside it, and its build-provenance attestation must show it was built by + RealGeeks/firebird-cli's release workflow on `main` (the check + `gh attestation verify` makes; no `gh` needed). If either fails, nothing + is changed (exit 1). +- The updater talks to GitHub with its own client. The site's API key and + token are never sent there. +- When the repository has no release (exit 4), or none for this platform + (exit 1), nothing is changed. +- A binary in a directory you cannot write (a root-owned `/usr/local/bin`) + fails before downloading; re-run with `sudo`, or reinstall elsewhere with + `FIREBIRD_CLI_INSTALL_DIR`. +- On a terminal, any command says at most once a day when a newer release + exists. Piped output and CI never get that notice or its lookup; + `FIREBIRD_CLI_NO_UPDATE_CHECK=1` turns it off everywhere. + +| Variable | Meaning | +| -------------------------------- | --------------------------------------------------------- | +| `FIREBIRD_CLI_NO_UPDATE_CHECK=1` | Never look for or mention a newer release | +| `FIREBIRD_CLI_SKIP_PROVENANCE=1` | Skip the attestation (a mirror without GitHub access); the sha256 is still checked, and a warning says so | +| `FIREBIRD_CLI_REPO` | Look for releases in a fork (`owner/name`), with a warning; its builds must still be attested by RealGeeks/firebird-cli | +| `GH_TOKEN` / `GITHUB_TOKEN` | Raises GitHub's limit on anonymous release lookups | +| `FIREBIRD_CLI_VERSION`, `FIREBIRD_CLI_INSTALL_DIR` | Read by the install scripts: the tag to install, and where | diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..12609a0 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,132 @@ +<# +.SYNOPSIS + Install the firebird-cli CLI on Windows from its GitHub release archives. + + irm https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.ps1 | iex # x-release-please-version + + `iex` runs the script with no arguments, so -Version and -InstallDir reach it + only from the environment, or by turning the download into a scriptblock + ($url being the address above): + + $env:FIREBIRD_CLI_VERSION = 'v0.3.0' + irm $url | iex + + & ([scriptblock]::Create((irm $url))) -Version v0.3.0 + + Environment / parameters: + -Version vX.Y.Z FIREBIRD_CLI_VERSION a tag; default: the latest release + -InstallDir DIR FIREBIRD_CLI_INSTALL_DIR default: %LOCALAPPDATA%\Programs\firebird-cli + FIREBIRD_CLI_REPO default: realgeeks/firebird-cli + GH_TOKEN / GITHUB_TOKEN optional; avoids GitHub's anonymous + API rate limit + FIREBIRD_CLI_SKIP_PROVENANCE=1 skip the attestation check + + Verifies the sha256 the Release workflow publishes beside each archive and, + when the GitHub CLI is installed and logged in, the archive's build-provenance + attestation (as a build of realgeeks/firebird-cli's release workflow, whatever + FIREBIRD_CLI_REPO says); then adds the install directory to the user PATH. +#> +[CmdletBinding()] +param( + [string]$Version = $env:FIREBIRD_CLI_VERSION, + [string]$InstallDir = $env:FIREBIRD_CLI_INSTALL_DIR +) +$ErrorActionPreference = 'Stop' + +$repo = if ($env:FIREBIRD_CLI_REPO) { $env:FIREBIRD_CLI_REPO } else { 'realgeeks/firebird-cli' } +$token = if ($env:GH_TOKEN) { $env:GH_TOKEN } elseif ($env:GITHUB_TOKEN) { $env:GITHUB_TOKEN } else { $null } +$headers = @{ 'Accept' = 'application/vnd.github+json'; 'User-Agent' = 'firebird-cli-install' } +if ($token) { $headers['Authorization'] = "Bearer $token" } + +$arch = if ([System.Environment]::Is64BitOperatingSystem) { 'x86_64' } else { throw 'firebird-cli needs 64-bit Windows' } +$target = "$arch-pc-windows-msvc" + +if ($Version) { + if (-not $Version.StartsWith('v')) { $Version = "v$Version" } + $releaseUrl = "https://api.github.com/repos/$repo/releases/tags/$Version" +} else { + $releaseUrl = "https://api.github.com/repos/$repo/releases/latest" +} +try { + $release = Invoke-RestMethod -Uri $releaseUrl -Headers $headers +} catch { + throw "cannot read the release ($releaseUrl). If GitHub is rate limiting you, set GH_TOKEN. $_" +} +$tag = $release.tag_name +$name = "firebird-cli-$tag-$target" +$archive = "$name.zip" + +function Get-Asset([string]$assetName, [string]$dest) { + if ($token) { + $asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1 + if (-not $asset) { throw "release $tag has no asset $assetName" } + $h = $headers.Clone(); $h['Accept'] = 'application/octet-stream' + Invoke-WebRequest -Uri $asset.url -Headers $h -OutFile $dest + } else { + Invoke-WebRequest -Uri "https://github.com/$repo/releases/download/$tag/$assetName" -Headers @{ 'User-Agent' = 'firebird-cli-install' } -OutFile $dest + } +} + +$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("firebird-cli-install-" + [System.Guid]::NewGuid().ToString('N')) +New-Item -ItemType Directory -Path $tmp | Out-Null +try { + Write-Host "Downloading firebird-cli $tag for $target..." + Get-Asset $archive (Join-Path $tmp $archive) + Get-Asset "$archive.sha256" (Join-Path $tmp "$archive.sha256") + + $expected = ((Get-Content (Join-Path $tmp "$archive.sha256") -Raw) -split '\s+')[0].ToLower() + $actual = (Get-FileHash (Join-Path $tmp $archive) -Algorithm SHA256).Hash.ToLower() + if ($expected -ne $actual) { throw "checksum mismatch for $archive (expected $expected, got $actual)" } + + # Build provenance: the sha256 comes from the same release as the archive, + # the attestation from Sigstore. Always against the official repository. + $official = 'RealGeeks/firebird-cli' + $signer = "https://github.com/$official/.github/workflows/release.yml@refs/heads/main" + $verifyCmd = "gh attestation verify $archive --repo $official --cert-identity $signer" + $gh = Get-Command gh -ErrorAction SilentlyContinue + $ghReady = $false + if ($gh -and -not $env:FIREBIRD_CLI_SKIP_PROVENANCE) { + # Windows PowerShell turns a native command's stderr into an error under 'Stop' + $ErrorActionPreference = 'Continue' + $ghReady = [bool]$token + if (-not $ghReady) { + & $gh.Source auth status *> $null + $ghReady = ($LASTEXITCODE -eq 0) + } + if ($ghReady) { + & $gh.Source attestation verify (Join-Path $tmp $archive) --repo $official --cert-identity $signer *> $null + $verified = ($LASTEXITCODE -eq 0) + } + $ErrorActionPreference = 'Stop' + } + if ($env:FIREBIRD_CLI_SKIP_PROVENANCE) { + Write-Warning 'FIREBIRD_CLI_SKIP_PROVENANCE is set; build provenance not checked' + } elseif ($ghReady) { + if (-not $verified) { throw "$archive failed its build-provenance check: it was not built by $official's release workflow, or gh could not reach GitHub. Nothing was installed. To see why: $verifyCmd (FIREBIRD_CLI_SKIP_PROVENANCE=1 skips the check)" } + Write-Host "Build provenance verified ($official release workflow)." + } else { + Write-Host 'Build provenance not verified (needs the GitHub CLI, logged in). To check it yourself:' + Write-Host " $verifyCmd" + } + + Expand-Archive -Path (Join-Path $tmp $archive) -DestinationPath $tmp -Force + $exe = Join-Path $tmp "$name\firebird-cli.exe" + if (-not (Test-Path $exe)) { throw "$archive did not contain $name\firebird-cli.exe" } + + if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA 'Programs\firebird-cli' } + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null + Copy-Item $exe (Join-Path $InstallDir 'firebird-cli.exe') -Force + + $installed = & (Join-Path $InstallDir 'firebird-cli.exe') --version + Write-Host "Installed $InstallDir\firebird-cli.exe ($installed)" + + $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') + if (($userPath -split ';') -notcontains $InstallDir) { + [Environment]::SetEnvironmentVariable('Path', "$InstallDir;$userPath", 'User') + $env:Path = "$InstallDir;$env:Path" + Write-Host "Added $InstallDir to your PATH (open a new terminal to pick it up)." + } + Write-Host 'Next: firebird-cli auth login --site www.yoursite.com --api-key-stdin (then: firebird-cli guide)' +} finally { + Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue +} diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..d8acf8c --- /dev/null +++ b/install.sh @@ -0,0 +1,180 @@ +#!/bin/sh +# Install the firebird-cli CLI from its GitHub release archives. +# +# Verifies the sha256 that the Release workflow publishes beside each archive +# and, when the GitHub CLI is installed and logged in, the archive's +# build-provenance attestation. +set -eu + +usage() { + cat <<'USAGE' +Install the firebird-cli CLI from its GitHub release archives. + + sh install.sh [--version vX.Y.Z] [--dir DIR] + +Piped from curl, the flags belong to sh, not to this script, so pass them +after `-s --` or use the environment variables: + + curl -fsSL $RAW/install.sh | sh + curl -fsSL $RAW/install.sh | sh -s -- --version v0.3.0 + curl -fsSL $RAW/install.sh | FIREBIRD_CLI_VERSION=v0.3.0 sh + +`curl ... | sh --version v0.3.0` does NOT work: sh takes the flag itself. + +Options (flag or environment): + --version vX.Y.Z FIREBIRD_CLI_VERSION a tag; default: the latest release + --dir DIR FIREBIRD_CLI_INSTALL_DIR default: /usr/local/bin if writable, + else ~/.local/bin + FIREBIRD_CLI_REPO default: realgeeks/firebird-cli + GH_TOKEN / GITHUB_TOKEN optional; avoids GitHub's + anonymous API rate limit + FIREBIRD_CLI_SKIP_PROVENANCE=1 skip the attestation check + +With `gh` installed and logged in (or GH_TOKEN set), the archive must pass +`gh attestation verify` as a build of realgeeks/firebird-cli's release +workflow, whatever FIREBIRD_CLI_REPO says; without `gh` the script says it +could not check. +USAGE +} + +# Everything runs from main, called on the last line, so a download cut off +# part-way through executes nothing. +main() { +REPO="${FIREBIRD_CLI_REPO:-realgeeks/firebird-cli}" +VERSION="${FIREBIRD_CLI_VERSION:-}" +INSTALL_DIR="${FIREBIRD_CLI_INSTALL_DIR:-}" +TOKEN="${GH_TOKEN:-${GITHUB_TOKEN:-}}" + +while [ $# -gt 0 ]; do + case "$1" in + --version) [ $# -ge 2 ] || { echo "install.sh: --version needs a tag" >&2; exit 2; } + VERSION="$2"; shift 2 ;; + --version=*) VERSION="${1#--version=}"; shift ;; + --dir) [ $# -ge 2 ] || { echo "install.sh: --dir needs a directory" >&2; exit 2; } + INSTALL_DIR="$2"; shift 2 ;; + --dir=*) INSTALL_DIR="${1#--dir=}"; shift ;; + -h|--help) usage; exit 0 ;; + *) echo "install.sh: unknown option $1" >&2; usage >&2; exit 2 ;; + esac +done + +say() { printf '%s\n' "$*" >&2; } +die() { say "install.sh: $*"; exit 1; } + +need() { command -v "$1" >/dev/null 2>&1 || die "$1 is required"; } +need curl +need tar + +os=$(uname -s) +arch=$(uname -m) +case "$os" in + Darwin) os_part="apple-darwin" ;; + Linux) os_part="unknown-linux-musl" ;; # static: runs whatever the glibc + MINGW*|MSYS*|CYGWIN*) die "on Windows run install.ps1 instead: irm https://raw.githubusercontent.com/realgeeks/firebird-cli/v0.1.0/install.ps1 | iex" ;; # x-release-please-version + *) die "unsupported OS: $os" ;; +esac +case "$arch" in + x86_64|amd64) arch_part="x86_64" ;; + arm64|aarch64) arch_part="aarch64" ;; + *) die "unsupported architecture: $arch" ;; +esac +target="$arch_part-$os_part" + +auth_header="" +if [ -n "$TOKEN" ]; then + auth_header="Authorization: Bearer $TOKEN" +fi + +api() { + # $1: API URL. Prints the body. + if [ -n "$auth_header" ]; then + curl --proto =https --tlsv1.2 -fsSL -H "$auth_header" -H "Accept: application/vnd.github+json" "$1" + else + curl --proto =https --tlsv1.2 -fsSL -H "Accept: application/vnd.github+json" "$1" + fi +} + +if [ -z "$VERSION" ]; then + release_url="https://api.github.com/repos/$REPO/releases/latest" +else + case "$VERSION" in v*) ;; *) VERSION="v$VERSION" ;; esac + release_url="https://api.github.com/repos/$REPO/releases/tags/$VERSION" +fi + +release_json=$(api "$release_url") || die "cannot read the release ($release_url). If GitHub is rate limiting you, set GH_TOKEN." +tag=$(printf '%s' "$release_json" | sed -n 's/^ *"tag_name": *"\([^"]*\)".*/\1/p' | head -1) +[ -n "$tag" ] || die "no tag_name in the release response" + +name="firebird-cli-$tag-$target" +archive="$name.tar.gz" + +# With a token, fetch through the API (which also works for a private fork); +# without one, the public download URL. +asset_api_url() { + # GitHub lists each asset as url, id, node_id, name on consecutive lines. + printf '%s\n' "$release_json" | grep -B 5 "\"name\": *\"$1\"" | sed -n 's/^ *"url": *"\(https:\/\/api\.github\.com\/repos\/[^"]*\/assets\/[0-9]*\)".*/\1/p' | tail -1 +} +fetch_asset() { + # $1: asset name, $2: destination + if [ -n "$auth_header" ]; then + url=$(asset_api_url "$1") + [ -n "$url" ] || die "release $tag has no asset $1" + curl --proto =https --tlsv1.2 -fsSL -H "$auth_header" -H "Accept: application/octet-stream" -o "$2" "$url" + else + curl --proto =https --tlsv1.2 -fsSL -o "$2" "https://github.com/$REPO/releases/download/$tag/$1" + fi +} + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +say "Downloading firebird-cli $tag for $target..." +fetch_asset "$archive" "$tmp/$archive" +fetch_asset "$archive.sha256" "$tmp/$archive.sha256" + +expected=$(cut -d' ' -f1 "$tmp/$archive.sha256") +if command -v sha256sum >/dev/null 2>&1; then + actual=$(sha256sum "$tmp/$archive" | cut -d' ' -f1) +else + actual=$(shasum -a 256 "$tmp/$archive" | cut -d' ' -f1) +fi +[ "$expected" = "$actual" ] || die "checksum mismatch for $archive (expected $expected, got $actual)" + +# Build provenance: the sha256 comes from the same release as the archive, +# the attestation from Sigstore. Always against the official repository. +official="RealGeeks/firebird-cli" +signer="https://github.com/$official/.github/workflows/release.yml@refs/heads/main" +verify_cmd="gh attestation verify $archive --repo $official --cert-identity $signer" +if [ -n "${FIREBIRD_CLI_SKIP_PROVENANCE:-}" ]; then + say "warning: FIREBIRD_CLI_SKIP_PROVENANCE is set; build provenance not checked" +elif command -v gh >/dev/null 2>&1 && { [ -n "$TOKEN" ] || gh auth status >/dev/null 2>&1; }; then + gh attestation verify "$tmp/$archive" --repo "$official" --cert-identity "$signer" >/dev/null || + die "$archive failed its build-provenance check: it was not built by $official's release workflow, or gh could not reach GitHub. Nothing was installed. To see why: $verify_cmd (FIREBIRD_CLI_SKIP_PROVENANCE=1 skips the check)" + say "Build provenance verified ($official release workflow)." +else + say "Build provenance not verified (needs the GitHub CLI, logged in). To check it yourself:" + say " $verify_cmd" +fi + +tar -xzf "$tmp/$archive" -C "$tmp" +[ -f "$tmp/$name/firebird-cli" ] || die "$archive did not contain $name/firebird-cli" + +if [ -z "$INSTALL_DIR" ]; then + if [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then + INSTALL_DIR=/usr/local/bin + else + INSTALL_DIR="$HOME/.local/bin" + fi +fi +mkdir -p "$INSTALL_DIR" +install -m 755 "$tmp/$name/firebird-cli" "$INSTALL_DIR/firebird-cli" + +say "Installed $INSTALL_DIR/firebird-cli ($("$INSTALL_DIR/firebird-cli" --version))" +case ":$PATH:" in + *":$INSTALL_DIR:"*) ;; + *) say "Add it to your PATH: export PATH=\"$INSTALL_DIR:\$PATH\"" ;; +esac +say "Next: firebird-cli auth login --site www.yoursite.com --api-key-stdin (then: firebird-cli guide)" +} + +main "$@" diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..e791366 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "include-component-in-tag": false, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "packages": { + ".": { + "release-type": "rust", + "package-name": "firebird-cli", + "extra-files": [ + "README.md", + "AGENTS.md", + "docs/GUIDE.md", + "install.sh", + "install.ps1" + ], + "initial-version": "0.1.0" + } + } +} diff --git a/src/cli.rs b/src/cli.rs index 7bae34f..dea8d32 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,7 +6,8 @@ use clap_complete::Shell; use crate::client::Client; use crate::commands::{ - api, auth, blocks, draft, guide, media, nav, pages, revisions, settings, versions, Context, + api, auth, blocks, draft, guide, media, nav, pages, revisions, settings, update, versions, + Context, }; use crate::config::{self, Config, Overrides}; use crate::error::Result; @@ -24,7 +25,7 @@ then `draft validate about` and `draft publish about`. Nothing is live before th `firebird-cli guide` is the walkthrough for scripts and AI agents; `guide --list` shows its topics and `guide ` prints one, e.g. `guide drafts` (what is live and what waits in a draft), `guide blocks` (how block data is written), -`guide undo`, `guide exit`."; +`guide undo`, `guide exit`. `firebird-cli update` installs the latest release."; #[derive(Debug, Parser)] #[command(name = "firebird-cli", version, about = ABOUT, after_help = AFTER_HELP, propagate_version = true)] @@ -139,6 +140,9 @@ pub enum Command { Api(api::ApiArgs), /// The usage guide for scripts and AI agents, whole or one topic (`guide drafts`) Guide(guide::GuideArgs), + /// Replace this binary with the latest release + #[command(visible_alias = "upgrade")] + Update(update::UpdateArgs), /// Generate shell completions Completions { #[arg(value_enum)] @@ -172,10 +176,25 @@ fn on_command_line(matches: &ArgMatches, id: &str) -> bool { pub fn run(cli: Cli) -> Result<()> { let printer = Printer::new(cli.global.format(), cli.global.quiet); crate::sources::set_allow_any(cli.global.allow_any_source); + let notify = !matches!( + cli.command, + Command::Update(_) | Command::Guide(_) | Command::Completions { .. } + ); + let result = dispatch(cli, printer); + if notify { + update::notify(printer); + } + result +} + +fn dispatch(cli: Cli, printer: Printer) -> Result<()> { let overrides = cli.global.overrides(); match cli.command { Command::Guide(args) => guide::run(&args), + // Before any config is read: the updater talks to GitHub with its own + // clients and is never given the site's key or token. + Command::Update(args) => update::run(printer, &args), Command::Completions { shell } => { let mut cmd = Cli::command(); clap_complete::generate(shell, &mut cmd, "firebird-cli", &mut std::io::stdout()); @@ -218,7 +237,10 @@ pub fn run(cli: Cli) -> Result<()> { Command::Media(cmd) => media::run(&ctx, &cmd), Command::Revisions(cmd) => revisions::run(&ctx, &cmd), Command::Api(args) => api::run(&ctx, &args), - Command::Guide(_) | Command::Completions { .. } | Command::Auth(_) => Ok(()), + Command::Guide(_) + | Command::Update(_) + | Command::Completions { .. } + | Command::Auth(_) => Ok(()), } } } diff --git a/src/commands/guide.rs b/src/commands/guide.rs index 2983ae5..54db087 100644 --- a/src/commands/guide.rs +++ b/src/commands/guide.rs @@ -27,6 +27,10 @@ const ALIASES: &[(&str, &str)] = &[ ("login", "setup"), ("key", "setup"), ("install", "setup"), + ("update", "updating"), + ("upgrade", "updating"), + ("version", "updating"), + ("release", "updating"), ("json", "output"), ("errors", "exit codes"), ("exit", "exit codes"), diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d5392f8..f5c6995 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,8 +9,10 @@ pub mod guide; pub mod media; pub mod nav; pub mod pages; +pub mod provenance; pub mod revisions; pub mod settings; +pub mod update; pub mod versions; use std::io::{self, IsTerminal, Write}; diff --git a/src/commands/provenance.rs b/src/commands/provenance.rs new file mode 100644 index 0000000..b703a70 --- /dev/null +++ b/src/commands/provenance.rs @@ -0,0 +1,415 @@ +//! Build-provenance check for `firebird-cli update`: the archive about to be +//! installed must carry a GitHub artifact attestation, signed through the +//! public Sigstore instance by this repository's release workflow on `main`. +//! +//! The `.sha256` beside an archive and GitHub's per-asset digest both come +//! from the same release, so whoever can change the release can change them +//! too. The attestation cannot be forged that way: its certificate is issued +//! by Sigstore's Fulcio to the workflow run's OIDC identity and the signature +//! is logged in Rekor, and both are checked against Sigstore's trust root +//! compiled into this binary. Checking it is what `gh attestation verify +//! --repo RealGeeks/firebird-cli` does, without needing `gh`. +//! +//! The expected signer is fixed here, not taken from `FIREBIRD_CLI_REPO`, so +//! pointing the updater somewhere else cannot also change who it trusts. +//! +//! The trust root is the one `sigstore-trust-root` embeds; it is not +//! refreshed over TUF (that would pull in a second HTTP stack). When Sigstore +//! adds a log or CA that a future release is signed through, older binaries +//! will refuse that release until updated another way (the install script, +//! or `FIREBIRD_CLI_SKIP_PROVENANCE=1` once): a failure to the safe side. Keep +//! the sigstore crates current so each release carries a fresh root. +//! +//! The sigstore crates' default crypto backend is aws-lc, which would add +//! about 3 MB and a second C build; [`ring_backend`] supplies the few +//! verification primitives they need from ring, already linked for TLS. + +use std::fmt::Write as _; +use std::time::Duration; + +use base64::Engine as _; +use serde_json::Value; +use sha2::{Digest, Sha256}; +use sigstore_trust_root::{SigstoreInstance, TrustedRoot}; +use sigstore_types::{Bundle, Sha256Hash}; +use sigstore_verify::{IdentityMatcher, VerificationPolicy, Verifier}; + +/// The repository whose attestations are looked up and trusted. +pub const REPO: &str = "RealGeeks/firebird-cli"; +/// The certificate identity of a release build: `release.yml` run from `main` +/// (release-please's push, or a manual rebuild dispatched from `main`). +pub const SIGNER: &str = + "https://github.com/RealGeeks/firebird-cli/.github/workflows/release.yml@refs/heads/main"; +/// GitHub Actions' OIDC issuer. +pub const ISSUER: &str = "https://token.actions.githubusercontent.com"; +/// What `actions/attest-build-provenance` attests. +pub const PREDICATE: &str = "https://slsa.dev/provenance/v1"; +/// Set to skip the check (air-gapped mirrors); only the sha256 is checked then. +pub const SKIP_ENV: &str = "FIREBIRD_CLI_SKIP_PROVENANCE"; + +/// Hex SHA-256 of a file, streamed. +pub fn sha256_file(path: &std::path::Path) -> std::io::Result { + let mut file = std::fs::File::open(path)?; + let mut hasher = Sha256::new(); + let mut buf = vec![0; 64 * 1024]; + loop { + let n = std::io::Read::read(&mut file, &mut buf)?; + if n == 0 { + break; + } + hasher.update(&buf[..n]); + } + Ok(hasher + .finalize() + .iter() + .fold(String::with_capacity(64), |mut hex, b| { + let _ = write!(hex, "{b:02x}"); + hex + })) +} + +/// Fetch the attestations GitHub holds for `digest` (hex SHA-256) and check +/// that one of them is a valid provenance attestation from [`SIGNER`]. +/// `api_base` is `https://api.github.com` unless tests point it elsewhere. +pub fn check(api_base: &str, token: Option<&str>, digest: &str) -> Result<(), String> { + let attestations = fetch(api_base, token, digest)?; + verify(&attestations, digest) +} + +fn fetch(api_base: &str, token: Option<&str>, digest: &str) -> Result { + use self_update::errors::Error as HttpError; + use self_update::http_client::{header, HeaderMap, HttpClient, UreqClient}; + + let url = format!( + "{}/repos/{REPO}/attestations/sha256:{digest}", + api_base.trim_end_matches('/') + ); + // The client the download itself used (platform trust store, proxy from + // the environment), so a lookup works wherever the download did. Only + // these headers are sent: the site's API key never goes near GitHub. + let mut headers = HeaderMap::new(); + let mut add = |name: header::HeaderName, value: &str| { + if let Ok(value) = header::HeaderValue::from_str(value) { + headers.insert(name, value); + } + }; + add(header::ACCEPT, "application/vnd.github+json"); + add( + header::USER_AGENT, + concat!("firebird-cli/", env!("CARGO_PKG_VERSION")), + ); + if let Some(token) = token { + add(header::AUTHORIZATION, &format!("Bearer {token}")); + } + let response = UreqClient::default() + .get(&url, &headers, Some(Duration::from_secs(30))) + .map_err(|e| match e { + HttpError::NotFound { .. } => format!( + "GitHub has no build-provenance attestation for an archive with sha256 {digest}" + ), + HttpError::RateLimited { .. } => { + "GitHub is rate limiting attestation lookups from this address; set GH_TOKEN or retry later".into() + } + other => format!("cannot look up its attestation at {url}: {}", chain(&other)), + })?; + serde_json::from_reader(response.body()) + .map_err(|e| format!("unreadable attestation response from {url}: {e}")) +} + +/// An error and its causes, `a: b: c`; reqwest's own message alone is only +/// "error sending request". +fn chain(err: &dyn std::error::Error) -> String { + let mut text = err.to_string(); + let mut source = err.source(); + while let Some(cause) = source { + text.push_str(": "); + text.push_str(&cause.to_string()); + source = cause.source(); + } + text +} + +/// Check a `GET /repos/{repo}/attestations/sha256:{digest}` response: some +/// bundle in it must be an SLSA provenance statement naming this digest, +/// signed by [`SIGNER`], with a certificate chain and transparency-log entry +/// that verify against the embedded Sigstore trust root. +pub fn verify(attestations: &Value, digest: &str) -> Result<(), String> { + verify_signed_by(attestations, digest, SIGNER) +} + +fn verify_signed_by(attestations: &Value, digest: &str, signer: &str) -> Result<(), String> { + ring_backend::install(); + let digest_hash = + Sha256Hash::from_hex(digest).map_err(|e| format!("bad sha256 {digest}: {e}"))?; + let root = TrustedRoot::from_embedded(SigstoreInstance::PublicGood) + .map_err(|e| format!("cannot load Sigstore's trust root: {e}"))?; + let verifier = + Verifier::new(&root).map_err(|e| format!("cannot load Sigstore's trust root: {e}"))?; + let policy = VerificationPolicy::new(IdentityMatcher::Uri(signer.into()), ISSUER); + + let bundles: Vec<&Value> = attestations + .get("attestations") + .and_then(Value::as_array) + .map(|list| list.iter().filter_map(|a| a.get("bundle")).collect()) + .unwrap_or_default(); + let mut last = "the response held no attestation bundles".to_string(); + for bundle in bundles { + if predicate_type(bundle).as_deref() != Some(PREDICATE) { + last = "the attestation is not build provenance".into(); + continue; + } + let parsed = match Bundle::from_json(&bundle.to_string()) { + Ok(parsed) => parsed, + Err(e) => { + last = format!("unreadable attestation bundle: {e}"); + continue; + } + }; + match verifier.verify(digest_hash, &parsed, &policy) { + Ok(_) => return Ok(()), + Err(e) => last = format!("the attestation did not verify: {e}"), + } + } + Err(last) +} + +/// The in-toto statement's `predicateType`, read from the DSSE payload. +/// (The signature over the payload is what `verify` checks.) +fn predicate_type(bundle: &Value) -> Option { + let payload = bundle.pointer("/dsseEnvelope/payload")?.as_str()?; + let bytes = base64::engine::general_purpose::STANDARD + .decode(payload) + .ok()?; + let statement: Value = serde_json::from_slice(&bytes).ok()?; + statement.get("predicateType")?.as_str().map(str::to_string) +} + +/// A verification-only `sigstore_crypto::CryptoProvider` over ring: SHA-2 +/// digests and signature checks over whole messages, which is everything a +/// DSSE attestation needs (certificate chain, SCT, Rekor entry, envelope). +/// Checking a signature over a bare digest (`hashedrekord` bundles) is not +/// something ring offers, so it fails closed, as do ML-DSA keys. +mod ring_backend { + use ring::digest::{self, Context, SHA256, SHA384, SHA512}; + use ring::signature::{self, UnparsedPublicKey, VerificationAlgorithm}; + use sigstore_crypto::provider::{CryptoProvider, HashContext}; + use sigstore_crypto::{Error, Result, SigningScheme}; + use sigstore_types::HashAlgorithm; + + #[derive(Debug)] + struct Ring; + + static RING: Ring = Ring; + + /// Make ring the process's sigstore backend. Idempotent. + pub fn install() { + // Err only means a backend is already installed: this one, earlier. + let _ = sigstore_crypto::provider::install_default_provider(&RING); + } + + struct Hasher(Context); + + impl HashContext for Hasher { + fn update(&mut self, data: &[u8]) { + self.0.update(data); + } + + fn finalize(self: Box) -> Vec { + self.0.finish().as_ref().to_vec() + } + } + + fn algorithm(scheme: SigningScheme) -> Option<&'static dyn VerificationAlgorithm> { + Some(match scheme { + SigningScheme::EcdsaP256Sha256 => &signature::ECDSA_P256_SHA256_ASN1, + SigningScheme::EcdsaP256Sha384 => &signature::ECDSA_P256_SHA384_ASN1, + SigningScheme::EcdsaP384Sha256 => &signature::ECDSA_P384_SHA256_ASN1, + SigningScheme::EcdsaP384Sha384 => &signature::ECDSA_P384_SHA384_ASN1, + SigningScheme::Ed25519 => &signature::ED25519, + SigningScheme::RsaPssSha256 => &signature::RSA_PSS_2048_8192_SHA256, + SigningScheme::RsaPssSha384 => &signature::RSA_PSS_2048_8192_SHA384, + SigningScheme::RsaPssSha512 => &signature::RSA_PSS_2048_8192_SHA512, + SigningScheme::RsaPkcs1Sha256 => &signature::RSA_PKCS1_2048_8192_SHA256, + SigningScheme::RsaPkcs1Sha384 => &signature::RSA_PKCS1_2048_8192_SHA384, + SigningScheme::RsaPkcs1Sha512 => &signature::RSA_PKCS1_2048_8192_SHA512, + _ => return None, + }) + } + + impl CryptoProvider for Ring { + fn hash(&self, algorithm: HashAlgorithm) -> Result> { + let backend = match algorithm { + HashAlgorithm::Sha2256 => &SHA256, + HashAlgorithm::Sha2384 => &SHA384, + HashAlgorithm::Sha2512 => &SHA512, + other => { + return Err(Error::UnsupportedAlgorithm(format!( + "cannot compute {other} digests" + ))) + } + }; + Ok(Box::new(Hasher(Context::new(backend)))) + } + + fn sha256(&self, data: &[u8]) -> [u8; 32] { + let mut out = [0; 32]; + out.copy_from_slice(digest::digest(&SHA256, data).as_ref()); + out + } + + fn sha384(&self, data: &[u8]) -> [u8; 48] { + let mut out = [0; 48]; + out.copy_from_slice(digest::digest(&SHA384, data).as_ref()); + out + } + + fn sha512(&self, data: &[u8]) -> [u8; 64] { + let mut out = [0; 64]; + out.copy_from_slice(digest::digest(&SHA512, data).as_ref()); + out + } + + fn verify_raw( + &self, + scheme: SigningScheme, + spki_pubkey_bytes: &[u8], + data: &[u8], + signature: &[u8], + ) -> Result<()> { + let algorithm = algorithm(scheme).ok_or_else(|| { + Error::UnsupportedAlgorithm(format!("{} is not supported", scheme.name())) + })?; + UnparsedPublicKey::new(algorithm, spki_pubkey_bytes) + .verify(data, signature) + .map_err(|_| Error::Verification(format!("{} signature invalid", scheme.name()))) + } + + fn verify_prehashed( + &self, + scheme: SigningScheme, + _spki_pubkey_bytes: &[u8], + _digest: &[u8], + _signature: &[u8], + ) -> Result<()> { + Err(Error::UnsupportedAlgorithm(format!( + "{} over a precomputed digest is not supported", + scheme.name() + ))) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A real attestation, as GitHub serves it (minus its short-lived + /// `bundle_url`): the one for the v0.12.1 archives of geekcli, the + /// sibling CLI whose release pipeline this one copies. firebird-cli has + /// no release of its own to take one from yet. It exercises the whole + /// verifier, and shows that another repository's build is refused. + /// Verification uses the log's integrated time, so it does not expire. + const GEEKCLI: &str = include_str!("../testdata/geekcli-attestation-v0.12.1.json"); + const GEEKCLI_SIGNER: &str = + "https://github.com/RealGeeks/geekcli/.github/workflows/release.yml@refs/heads/main"; + const MACOS_ARM: &str = "abc70083b503abd91b54b213ae3f1040027d4071ba39b146dcf04c9f1100c879"; + const LINUX_X86: &str = "0784e85429a607f5fe0fda71e97ad21845811071b0d247de4cf416cb4456a504"; + + fn fixture() -> Value { + serde_json::from_str(GEEKCLI).unwrap_or_default() + } + + #[test] + fn the_trusted_signer_is_this_repositorys_release_workflow_on_main() { + assert_eq!( + SIGNER, + format!("https://github.com/{REPO}/.github/workflows/release.yml@refs/heads/main") + ); + assert_eq!(REPO, "RealGeeks/firebird-cli"); + } + + #[test] + fn a_release_archive_verifies_against_its_own_signer() { + assert_eq!( + verify_signed_by(&fixture(), MACOS_ARM, GEEKCLI_SIGNER), + Ok(()) + ); + // one attestation covers every archive of the release + assert_eq!( + verify_signed_by(&fixture(), LINUX_X86, GEEKCLI_SIGNER), + Ok(()) + ); + } + + #[test] + fn a_genuine_attestation_from_another_repository_is_refused() { + // what `update` runs: only firebird-cli's release workflow is trusted + let err = verify(&fixture(), MACOS_ARM).err().unwrap_or_default(); + assert!(err.contains("identity"), "{err}"); + } + + #[test] + fn only_the_release_workflow_on_main_is_trusted() { + for signer in [ + "https://github.com/RealGeeks/geekcli/.github/workflows/release.yml@refs/heads/other", + "https://github.com/RealGeeks/geekcli/.github/workflows/ci.yml@refs/heads/main", + "https://github.com/someone/geekcli/.github/workflows/release.yml@refs/heads/main", + ] { + let err = verify_signed_by(&fixture(), MACOS_ARM, signer) + .err() + .unwrap_or_default(); + assert!(err.contains("identity"), "{signer}: {err}"); + } + } + + #[test] + fn another_digest_does_not() { + let other = "1".repeat(64); + let err = verify_signed_by(&fixture(), &other, GEEKCLI_SIGNER) + .err() + .unwrap_or_default(); + assert!(err.contains("does not match"), "{err}"); + } + + #[test] + fn a_tampered_statement_does_not() { + let mut doc = fixture(); + let payload = doc + .pointer("/attestations/0/bundle/dsseEnvelope/payload") + .and_then(Value::as_str) + .map(str::to_string) + .unwrap_or_default(); + assert!(!payload.is_empty(), "fixture has no payload"); + let engine = base64::engine::general_purpose::STANDARD; + let text = + String::from_utf8(engine.decode(payload).unwrap_or_default()).unwrap_or_default(); + // claim a different archive digest in the signed statement + let forged = text.replace(MACOS_ARM, &"2".repeat(64)); + assert_ne!(forged, text); + if let Some(p) = doc.pointer_mut("/attestations/0/bundle/dsseEnvelope/payload") { + *p = Value::String(engine.encode(forged)); + } + let err = verify_signed_by(&doc, &"2".repeat(64), GEEKCLI_SIGNER) + .err() + .unwrap_or_default(); + assert!(err.contains("did not verify"), "{err}"); + } + + #[test] + fn nothing_to_verify_is_a_failure() { + assert!(verify(&serde_json::json!({"attestations": []}), MACOS_ARM).is_err()); + assert!(verify(&serde_json::json!({}), MACOS_ARM).is_err()); + } + + #[test] + fn hashes_a_file() -> std::io::Result<()> { + let dir = tempfile::tempdir()?; + let path = dir.path().join("a"); + std::fs::write(&path, b"hello")?; + assert_eq!( + sha256_file(&path)?, + "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" + ); + Ok(()) + } +} diff --git a/src/commands/update.rs b/src/commands/update.rs new file mode 100644 index 0000000..f5929aa --- /dev/null +++ b/src/commands/update.rs @@ -0,0 +1,505 @@ +//! `firebird-cli update` — replace this binary with a release from GitHub. +//! +//! It installs the same archives `install.sh` and `install.ps1` do, checked +//! against the same `.sha256` files and, before anything is extracted, +//! against the archive's build-provenance attestation (`provenance`). The +//! requests go to GitHub through their own clients, so the site's API key and +//! token are never part of them. + +use std::io::IsTerminal; +use std::path::Path; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use clap::Args; +use self_update::backends::github; +use self_update::errors::Error as UpdateError; +use self_update::Release; +use serde_json::json; + +use super::provenance; +use crate::config; +use crate::error::{Error, Result}; +use crate::output::{Format, Printer}; + +const REPO: &str = "RealGeeks/firebird-cli"; +const CURRENT: &str = env!("CARGO_PKG_VERSION"); +/// How often `notify` looks for a newer release, and the file in the config +/// directory that holds the time of the last look. +const CHECK_INTERVAL: u64 = 24 * 60 * 60; +const CHECK_FILE: &str = "update-check"; + +#[derive(Debug, Args)] +#[command(after_help = "Notes: + Nothing updates on its own: a script keeps the version it was written + against until something runs `firebird-cli update`. + On a terminal, any command says once a day when a newer release exists. + Piped output and CI never get that notice or its lookup; + FIREBIRD_CLI_NO_UPDATE_CHECK=1 turns it off everywhere. + `--check` prints {\"current_version\", \"release_version\", \"update_available\"} + and exits 0 either way; branch on `update_available`. + The archive is verified against the sha256 published beside it and its + build-provenance attestation must show it was built by RealGeeks/firebird-cli's + release workflow (the check `gh attestation verify` makes); the running + binary is only replaced after both pass. FIREBIRD_CLI_SKIP_PROVENANCE=1 + skips the attestation (for mirrors without GitHub access) and says so. + A binary in a directory you cannot write (a root-owned /usr/local/bin) + fails before downloading; re-run with sudo, or reinstall elsewhere with + FIREBIRD_CLI_INSTALL_DIR. + GitHub limits anonymous lookups per address; GH_TOKEN or GITHUB_TOKEN + raises the limit. FIREBIRD_CLI_REPO names a fork, as it does for install.sh, with + a warning; its builds still have to be attested by RealGeeks/firebird-cli.")] +pub struct UpdateArgs { + /// Report whether a newer release exists without installing it + #[arg(long)] + pub check: bool, + /// Install this release instead of the latest, e.g. v0.3.0; an older tag downgrades + #[arg(long, value_name = "TAG", conflicts_with = "check")] + pub tag: Option, +} + +/// Where releases come from: the repository, and the settings `install.sh` +/// reads from the same environment variables. +struct Source { + owner: String, + name: String, + api_url: Option, + token: Option, +} + +const GITHUB_API: &str = "https://api.github.com"; + +impl Source { + fn from_env() -> Result { + let repo = env("FIREBIRD_CLI_REPO").unwrap_or_else(|| REPO.to_string()); + let Some((owner, name)) = repo.split_once('/') else { + return Err(Error::Config(format!( + "FIREBIRD_CLI_REPO must be owner/name, got '{repo}'" + ))); + }; + // Tests point this at a mock server; the same https rule as the API applies. + let api_url = env("FIREBIRD_CLI_UPDATE_API_URL"); + if let Some(url) = &api_url { + config::check_transport(url).map_err(|_| { + Error::Config(format!( + "FIREBIRD_CLI_UPDATE_API_URL must be https (plain http only for local hosts), got {url}" + )) + })?; + } + Ok(Self { + owner: owner.to_string(), + name: name.to_string(), + api_url, + token: env("GH_TOKEN").or_else(|| env("GITHUB_TOKEN")), + }) + } + + /// Where releases come from when it is not the official repository on + /// github.com, for the warning `run` prints. + fn redirected(&self) -> Option { + let repo = format!("{}/{}", self.owner, self.name); + let other_repo = !repo.eq_ignore_ascii_case(REPO); + match (&self.api_url, other_repo) { + (None, false) => None, + (None, true) => Some(format!("FIREBIRD_CLI_REPO={repo}")), + (Some(url), false) => Some(format!("FIREBIRD_CLI_UPDATE_API_URL={url}")), + (Some(url), true) => Some(format!( + "FIREBIRD_CLI_REPO={repo} and FIREBIRD_CLI_UPDATE_API_URL={url}" + )), + } + } + + fn builder(&self, target: &str) -> github::UpdateBuilder { + let mut builder = github::Update::configure(); + builder + .repo_owner(&self.owner) + .repo_name(&self.name) + .bin_name("firebird-cli") + .current_version(CURRENT) + .target(target) + // no prompt, and nothing printed on stdout but the result document + .unattended(); + if let Some(url) = &self.api_url { + builder.api_base_url(url); + } + if let Some(token) = &self.token { + builder.auth_token(token); + } + builder + } +} + +fn env(name: &str) -> Option { + std::env::var(name).ok().filter(|v| !v.trim().is_empty()) +} + +/// The target triple of the release archive for this machine. Linux is +/// always the static musl build, whatever this binary was compiled against. +pub fn release_target() -> Result { + let arch = std::env::consts::ARCH; + let os = match std::env::consts::OS { + "macos" => "apple-darwin", + "linux" => "unknown-linux-musl", + "windows" => "pc-windows-msvc", + other => { + return Err(Error::Other(format!( + "firebird-cli publishes no release for {other}; build it from source" + ))) + } + }; + Ok(format!("{arch}-{os}")) +} + +/// The archive `release.yml` publishes for a tag and target. +pub fn archive_name(tag: &str, target: &str) -> String { + let ext = if target.contains("windows") { + "zip" + } else { + "tar.gz" + }; + format!("firebird-cli-{tag}-{target}.{ext}") +} + +pub fn run(printer: Printer, args: &UpdateArgs) -> Result<()> { + let target = release_target()?; + let source = Source::from_env()?; + // In every output mode, like API warnings: a redirected update source is + // worth knowing about even when an agent is the one reading. + if let Some(redirect) = source.redirected() { + eprintln!( + "warning: looking for releases somewhere other than {REPO} on github.com ({redirect}); only builds attested by {REPO}'s release workflow are installed" + ); + } + let updater = source.builder(&target).build().map_err(failure)?; + + let release = match &args.tag { + Some(tag) => { + let tag = normalize_tag(tag); + updater.get_release_version(&tag).map_err(|err| match err { + UpdateError::NotFound { .. } => not_found(format!("no release {tag}")), + other => failure(other), + })? + } + None => updater + .get_latest_release() + .map_err(|err| match err { + UpdateError::NotFound { .. } => not_found(format!( + "{}/{} has no published release yet; build from source until it does", + source.owner, source.name + )), + other => failure(other), + })? + .into_vec() + .into_iter() + .next() + .ok_or_else(|| { + not_found(format!("{}/{} has no releases", source.owner, source.name)) + })?, + }; + let version = release.version().to_string(); + let newer = self_update::version::bump_is_greater(CURRENT, &version).map_err(failure)?; + + let mut doc = json!({ + "current_version": CURRENT, + "release_version": version, + "update_available": newer, + "updated": false, + "target": target, + }); + // An explicit tag installs whatever it names; the latest only when it is newer. + let wanted = if args.tag.is_some() { + version != CURRENT + } else { + newer + }; + if args.check || !wanted { + if newer { + printer.note(&format!( + "firebird-cli {version} is available (this is {CURRENT}); run `firebird-cli update`" + )); + } else { + printer.note(&format!("firebird-cli {CURRENT} is up to date")); + } + return printer.raw(&doc); + } + + install(printer, &source, &release, &target)?; + doc["updated"] = json!(true); + if let Ok(path) = std::env::current_exe() { + doc["path"] = json!(path.display().to_string()); + } + printer.note(&format!("Updated firebird-cli {CURRENT} to {version}")); + printer.raw(&doc) +} + +/// After a command, at most once a day, tell a person at a terminal that a +/// newer release exists. Scripts, agents and CI get nothing: their stdout is +/// not a terminal. Failures are silent; this must never break a +/// command. +pub fn notify(printer: Printer) { + let wanted = printer.format == Format::Table + && std::io::stderr().is_terminal() + && env("CI").is_none() + && env("FIREBIRD_CLI_NO_UPDATE_CHECK").is_none(); + if !wanted { + return; + } + let Ok(dir) = config::config_dir() else { + return; + }; + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_or(0, |d| d.as_secs()); + if let Some(version) = newer_release(&dir.join(CHECK_FILE), now, latest_version) { + printer.note(&format!( + "firebird-cli {version} is available (this is {CURRENT}); run `firebird-cli update`" + )); + } +} + +/// The newer release to announce, if a look is due. The time is recorded +/// before looking, so a failed or slow lookup is not repeated by every +/// command; when it cannot be recorded (no config directory yet) nothing +/// is looked up at all. +fn newer_release( + stamp: &Path, + now: u64, + latest: impl FnOnce() -> Option, +) -> Option { + let last = std::fs::read_to_string(stamp) + .ok() + .and_then(|text| text.trim().parse::().ok()); + if last.is_some_and(|then| now.saturating_sub(then) < CHECK_INTERVAL) { + return None; + } + std::fs::write(stamp, now.to_string()).ok()?; + let version = latest()?; + self_update::version::bump_is_greater(CURRENT, &version) + .ok()? + .then_some(version) +} + +fn latest_version() -> Option { + let source = Source::from_env().ok()?; + let release = source + .builder(&release_target().ok()?) + .timeout(Duration::from_secs(3)) + .build() + .ok()? + .get_latest_release() + .ok()? + .into_vec() + .into_iter() + .next()?; + Some(release.version().to_string()) +} + +fn install(printer: Printer, source: &Source, release: &Release, target: &str) -> Result<()> { + let tag = format!("v{}", release.version()); + let archive = archive_name(&tag, target); + let folder = format!("firebird-cli-{tag}-{target}"); + if !release.assets().iter().any(|a| a.name() == archive) { + return Err(Error::Other(format!( + "release {tag} has no archive for {target} ({archive})" + ))); + } + + check_writable()?; + printer.note(&format!("Downloading firebird-cli {tag} for {target}...")); + let wanted = archive.clone(); + let mut builder = source.builder(target); + builder + .release_tag(&tag) + // by exact name: the `.sha256` beside each archive also contains the target + .asset_matcher(move |assets| assets.iter().find(|a| a.name() == wanted).cloned()) + .checksum_from_asset(format!("{archive}.sha256")) + .bin_path_in_archive(format!( + "{folder}/firebird-cli{}", + std::env::consts::EXE_SUFFIX + )); + if env(provenance::SKIP_ENV).is_some() { + eprintln!( + "warning: {} is set: not checking the archive's build provenance, only its sha256", + provenance::SKIP_ENV + ); + } else { + // After the sha256 and GitHub's digest pass, before anything is extracted. + let api = source + .api_url + .clone() + .unwrap_or_else(|| GITHUB_API.to_string()); + let token = source.token.clone(); + builder.verify_archive(move |path| { + let digest = provenance::sha256_file(path).map_err(UpdateError::from)?; + provenance::check(&api, token.as_deref(), &digest) + .map_err(UpdateError::archive_verification_rejected) + }); + } + builder + .build() + .map_err(failure)? + .update_extended() + .map_err(failure)?; + Ok(()) +} + +const NOT_WRITABLE: &str = + "re-run with sudo, or reinstall to a directory you own (FIREBIRD_CLI_INSTALL_DIR)"; + +/// Fail before downloading when the binary's directory cannot take the new +/// file. The probe creates a file beside the binary and never opens the +/// binary itself: on macOS, opening a signed executable for writing gets it +/// killed on its next run, so a refused update would break a working install. +fn check_writable() -> Result<()> { + let exe = std::env::current_exe()?; + let Some(dir) = exe.parent() else { + return Ok(()); + }; + let probe = dir.join(format!(".firebird-cli-update-{}", std::process::id())); + match std::fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(&probe) + { + Ok(_) => { + // best effort: a leftover empty file is harmless + let _ = std::fs::remove_file(&probe); + Ok(()) + } + Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => Err(Error::Io(format!( + "cannot write to {}; {NOT_WRITABLE}", + dir.display() + ))), + // anything else is inconclusive: let the install itself report it + Err(_) => Ok(()), + } +} + +fn normalize_tag(tag: &str) -> String { + let tag = tag.trim(); + if tag.starts_with('v') { + tag.to_string() + } else { + format!("v{tag}") + } +} + +fn not_found(message: String) -> Error { + Error::Api { + status: 404, + code: "not_found".into(), + message, + body: None, + retry_after: None, + } +} + +/// Map the updater's errors onto the CLI's exit codes. +fn failure(err: UpdateError) -> Error { + match err { + UpdateError::Transport(e) => Error::Network(e.to_string()), + UpdateError::RateLimited { retry_after, .. } => Error::Api { + status: 429, + code: "rate_limited".into(), + message: "GitHub is rate limiting release lookups from this address; set GH_TOKEN or retry later".into(), + body: None, + retry_after: retry_after.map(|d| d.as_secs()), + }, + UpdateError::NotFound { .. } => not_found("the release was not found on GitHub".into()), + UpdateError::ArchiveVerificationRejected { reason, .. } => Error::Other(format!( + "refusing to install: the archive's build provenance did not check out ({}). Nothing was changed. If you are installing from a mirror that cannot reach GitHub, set {}=1 to rely on the sha256 alone", + reason.unwrap_or_else(|| "no reason given".into()), + provenance::SKIP_ENV + )), + UpdateError::InstallPathNotWritable { path, .. } => Error::Io(format!( + "cannot write {}; {NOT_WRITABLE}", + path.display() + )), + other => Error::Other(format!("update failed: {other}")), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn archive_names_match_the_release_workflow() { + assert_eq!( + archive_name("v0.6.0", "aarch64-apple-darwin"), + "firebird-cli-v0.6.0-aarch64-apple-darwin.tar.gz" + ); + assert_eq!( + archive_name("v0.6.0", "x86_64-pc-windows-msvc"), + "firebird-cli-v0.6.0-x86_64-pc-windows-msvc.zip" + ); + } + + #[test] + fn linux_always_takes_the_static_build() -> Result<()> { + let target = release_target()?; + assert!(!target.contains("gnu"), "{target}"); + Ok(()) + } + + #[test] + fn a_newer_release_is_announced_once_a_day() -> std::io::Result<()> { + let dir = tempfile::tempdir()?; + let stamp = dir.path().join(CHECK_FILE); + let newer = || Some("999.0.0".to_string()); + + assert_eq!( + newer_release(&stamp, 1_000_000, newer).as_deref(), + Some("999.0.0") + ); + // within the day: no lookup at all + let looked = std::cell::Cell::new(false); + let spy = || { + looked.set(true); + Some("999.0.0".to_string()) + }; + assert_eq!( + newer_release(&stamp, 1_000_000 + CHECK_INTERVAL - 1, spy), + None + ); + assert!(!looked.get()); + // a day later it looks again + assert!(newer_release(&stamp, 1_000_000 + CHECK_INTERVAL, newer).is_some()); + Ok(()) + } + + #[test] + fn nothing_is_announced_when_current_or_offline() -> std::io::Result<()> { + let dir = tempfile::tempdir()?; + let stamp = dir.path().join(CHECK_FILE); + assert_eq!( + newer_release(&stamp, 1_000_000, || Some(CURRENT.to_string())), + None + ); + // a failed lookup still counts as today's + let offline = dir.path().join("offline"); + assert_eq!(newer_release(&offline, 1_000_000, || None), None); + assert_eq!( + newer_release(&offline, 1_000_001, || Some("999.0.0".into())), + None + ); + Ok(()) + } + + #[test] + fn without_a_config_directory_nothing_is_looked_up() { + let looked = std::cell::Cell::new(false); + let stamp = Path::new("/nonexistent-firebird-cli-dir/update-check"); + let spy = || { + looked.set(true); + Some("999.0.0".to_string()) + }; + assert_eq!(newer_release(stamp, 1_000_000, spy), None); + assert!(!looked.get()); + } + + #[test] + fn tags_gain_their_v() { + assert_eq!(normalize_tag("0.6.0"), "v0.6.0"); + assert_eq!(normalize_tag(" v0.6.0 "), "v0.6.0"); + } +} diff --git a/src/error.rs b/src/error.rs index 6bb124c..a9e2c1f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -82,7 +82,7 @@ impl Error { ), 413 => Some("the request body is too large; keep JSON bodies small"), 426 => Some( - "this firebird-cli is older than the API accepts; build a newer one, then run the command again", + "this firebird-cli is older than the API accepts; run `firebird-cli update`, then run the command again", ), _ => None, }, diff --git a/src/testdata/geekcli-attestation-v0.12.1.json b/src/testdata/geekcli-attestation-v0.12.1.json new file mode 100644 index 0000000..a8e4f74 --- /dev/null +++ b/src/testdata/geekcli-attestation-v0.12.1.json @@ -0,0 +1,74 @@ +{ + "attestations": [ + { + "bundle": { + "mediaType": "application/vnd.dev.sigstore.bundle.v0.3+json", + "verificationMaterial": { + "tlogEntries": [ + { + "logIndex": "3171132247", + "logId": { + "keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0=" + }, + "kindVersion": { + "kind": "dsse", + "version": "0.0.1" + }, + "integratedTime": "1791577256", + "inclusionPromise": { + "signedEntryTimestamp": "MEUCIAxM1K4ls369FiSh4Ms+T3McyS7jOUW3hGspzoTKsDNxAiEAmoEKmOHa+AgWD7XcrrMlP2ptmbKcdWUoWOxC77eWdMs=" + }, + "inclusionProof": { + "logIndex": "3049227985", + "rootHash": "Hl6cjU12fFQpcf8tKQNI2xEASBtE1BbgKgFra0sp7Pk=", + "treeSize": "3049228010", + "hashes": [ + "qjK0upfencqMZ0zeN+UeIAhllGV5XJtZORDjs2pr4CE=", + "JE09D6cU3fDRA6IwW+05W+bVwEdN2YTD8RgL2MXN7ts=", + "IVXLhVW4VULO/XMfpLjIVX8fkwyIbJjv6b2X8M55DXo=", + "0r29Ho9nBe226UihMBZsFOZEyTJC5CJieXFpRQH/jYc=", + "L3SwzrKL8F0OxVDy8f59XSoCqF9WRgRZKpaRvmB2RVc=", + "dFMceOo+5pnmfyIJmUA6Q9wo5wTWGA0w6mm/Xvl61mM=", + "TGCymIZTxs0OikfzMtKEdQPckXQ6QgCGPULJgN7913Y=", + "sLapSLZ7ICaoZKtGr0OhgwJPWsV6SQlUVLt9o8rU98A=", + "FwciFLddbKeNf9DdCxk+03UG4+UIEYlmRbd99r5TLDE=", + "rKcEI/sdw5gOosZ7iwFa5LydUE68LJb1QqMtjj85pMA=", + "Xf/UyHmrUnWnX/i55QRwBHCt1Aa0U4bbBauavshb4wY=", + "kBgEatPkeK7VVAn3veYBhEhOWEumRgrYF4U6gOMXjsM=", + "PcVOiXySfiSyMWqyXKVWYGMHvWyxRJVftoWg1LrD8TY=", + "2gHbxs6CHaFSBK0Ei2A9qogCvAsMIs3odoqggE3MXxQ=", + "Dm5sNgRpblK41Ps2SD2V0FLHpP70IIIRuFJYPgHDau8=", + "L5ugmREK1YnDZfcR0vZxB/PwZgyPBNxP6QgiVGGnKr4=", + "nFIZ2brO1ANHPk5prvv9TLEBDqqNgaYEBmsyP40B0O0=", + "4Qh+oTbYMNZG8o6b5TjkLowu8zTMD/YGtu9os93Mfiw=", + "wSaHrpTQFjMB4RSxQVUhglqJvAGe2z1ilppo9GSYLkY=", + "hafZfJdzUX/yyCr3Anv7Qq1DWVaWxotaclNRcl/O9SQ=", + "NlOclldmKPA1tMKIskqHAwuQDYHp31YwpK+OOMrMccc=", + "qxzHanAzz57SDdmJe0B7bJK72NTIBbwEMGBBKvDOROw=", + "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY=" + ], + "checkpoint": { + "envelope": "rekor.sigstore.dev - 1193050959916656506\n3049228010\nHl6cjU12fFQpcf8tKQNI2xEASBtE1BbgKgFra0sp7Pk=\n\n\u2014 rekor.sigstore.dev wNI9ajBEAiB8y/hhGKvl1qSrdixKvKoLUyWtNJ79Ha+MY3wj91qDQQIgD72kWSJkAUgW/86z1SIzb28E2Nw/UggziDGZPhz9ke8=\n" + } + }, + "canonicalizedBody": "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiZHNzZSIsInNwZWMiOnsiZW52ZWxvcGVIYXNoIjp7ImFsZ29yaXRobSI6InNoYTI1NiIsInZhbHVlIjoiNjQ1MWEwM2Q1YjVhNTkyNDQ2MzhhMDhkNzliMjQ0ZGZjZTg1NGJjMGMyNWNiYjE5ZTA3OGIyZGVkNjEzMTE0ZCJ9LCJwYXlsb2FkSGFzaCI6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ya2Zsb3dzL3JlbGVhc2UueW1sIn19LCJpbnRlcm5hbFBhcmFtZXRlcnMiOnsiZ2l0aHViIjp7ImV2ZW50X25hbWUiOiJwdXNoIiwicmVwb3NpdG9yeV9pZCI6IjE0MDIwNjAyODgiLCJyZXBvc2l0b3J5X293bmVyX2lkIjoiNjE3ODM4IiwicnVubmVyX2Vudmlyb25tZW50IjoiZ2l0aHViLWhvc3RlZCJ9fSwicmVzb2x2ZWREZXBlbmRlbmNpZXMiOlt7InVyaSI6ImdpdCtodHRwczovL2dpdGh1Yi5jb20vUmVhbEdlZWtzL2dlZWtjbGlAcmVmcy9oZWFkcy9tYWluIiwiZGlnZXN0Ijp7ImdpdENvbW1pdCI6IjgyMTk4NTFkNGEyYTQyYWRhYjNiMTgwNjJlNmI2NDM2MGIwM2I3MzUifX1dfSwicnVuRGV0YWlscyI6eyJidWlsZGVyIjp7ImlkIjoiaHR0cHM6Ly9naXRodWIuY29tL1JlYWxHZWVrcy9nZWVrY2xpLy5naXRodWIvd29ya2Zsb3dzL3JlbGVhc2UueW1sQHJlZnMvaGVhZHMvbWFpbiJ9LCJtZXRhZGF0YSI6eyJpbnZvY2F0aW9uSWQiOiJodHRwczovL2dpdGh1Yi5jb20vUmVhbEdlZWtzL2dlZWtjbGkvYWN0aW9ucy9ydW5zLzM3OTg1NjIyMzYwL2F0dGVtcHRzLzEifX19fQ==", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "sig": "MEUCIQD7gVvuaStF2QJfM4/gM7u9B7WlrGynLaomtGOeq/nOoQIgCX2u3HT6XEzuOHdeCLzldVr52UxKb4ks9hfE8e8896w=" + } + ] + } + } + } + ] +} \ No newline at end of file diff --git a/tests/update.rs b/tests/update.rs new file mode 100644 index 0000000..9aeccc2 --- /dev/null +++ b/tests/update.rs @@ -0,0 +1,471 @@ +//! `firebird-cli update` against a mock of GitHub's releases API. The +//! installing tests run a copy of the binary, since a successful update +//! replaces it. + +use std::error::Error; + +use assert_cmd::Command; +use mockito::{Matcher, Mock, Server, ServerGuard}; +use serde_json::{json, Value}; + +type TestResult = Result<(), Box>; + +const CURRENT: &str = env!("CARGO_PKG_VERSION"); +const RELEASES: &str = "/repos/RealGeeks/firebird-cli/releases"; +const KEY: &str = "fb_test_abcdEFGHijklMNOPqrstUVWXyz0123456789"; + +struct Env { + server: ServerGuard, + config_dir: tempfile::TempDir, +} + +impl Env { + fn new() -> Result> { + Ok(Self { + server: Server::new(), + config_dir: tempfile::tempdir()?, + }) + } + + fn cmd(&self) -> Result> { + Ok(self.configure(Command::cargo_bin("firebird-cli")?)) + } + + fn configure(&self, mut cmd: Command) -> Command { + cmd.env_clear() + .env( + "SYSTEMROOT", + std::env::var("SYSTEMROOT").unwrap_or_default(), + ) + .env("PATH", std::env::var("PATH").unwrap_or_default()) + // a site key in the environment must never reach the release host + .env("FIREBIRD_SITE", "www.test.local") + .env("FIREBIRD_API_KEY", KEY) + .env("FIREBIRD_BASE_URL", self.server.url()) + .env("FIREBIRD_CONFIG_DIR", self.config_dir.path()) + .env("FIREBIRD_CLI_UPDATE_API_URL", self.server.url()); + cmd + } + + fn release(&mut self, path: &str, tag: &str, assets: &Value) -> Mock { + self.server + .mock("GET", format!("{RELEASES}/{path}").as_str()) + .match_header("authorization", Matcher::Missing) + .match_header("x-api-key", Matcher::Missing) + .with_body( + json!({ + "tag_name": tag, + "name": tag, + "created_at": "2026-01-01T00:00:00Z", + "assets": assets, + }) + .to_string(), + ) + .create() + } + + /// Fails the test if the updater ever exchanges the site key or calls the API. + fn no_site_requests(&mut self) -> Mock { + self.server + .mock("POST", "/auth/client-integration") + .expect(0) + .create() + } +} + +fn parse(out: &[u8]) -> Result> { + Ok(serde_json::from_slice(out)?) +} + +/// The JSON error document: the last line of stderr, after any warnings +/// (every test here points FIREBIRD_CLI_UPDATE_API_URL at a mock, which warns). +fn parse_error(stderr: &[u8]) -> Result> { + let text = String::from_utf8_lossy(stderr); + let last = text.lines().rfind(|l| !l.trim().is_empty()).unwrap_or(""); + parse(last.as_bytes()) +} + +fn message(stderr: &[u8]) -> Result> { + Ok(parse_error(stderr)?["error"]["message"] + .as_str() + .unwrap_or_default() + .to_string()) +} + +#[test] +fn check_reports_a_newer_release_and_installs_nothing() -> TestResult { + let mut env = Env::new()?; + let latest = env.release("latest", "v99.0.0", &json!([])); + let site = env.no_site_requests(); + + let out = env.cmd()?.args(["update", "--check"]).output()?; + + assert!(out.status.success()); + latest.assert(); + site.assert(); + let doc = parse(&out.stdout)?; + assert_eq!(doc["current_version"], CURRENT); + assert_eq!(doc["release_version"], "99.0.0"); + assert_eq!(doc["update_available"], true); + assert_eq!(doc["updated"], false); + // neither the key nor a token file is part of an update + let printed = [out.stdout, out.stderr].concat(); + assert!(!String::from_utf8_lossy(&printed).contains(KEY)); + assert!(!env.config_dir.path().join("tokens.json").exists()); + Ok(()) +} + +#[test] +fn upgrade_is_an_alias() -> TestResult { + let mut env = Env::new()?; + env.release("latest", &format!("v{CURRENT}"), &json!([])); + let out = env.cmd()?.args(["upgrade", "--check"]).output()?; + assert!(out.status.success()); + assert_eq!(parse(&out.stdout)?["update_available"], false); + Ok(()) +} + +#[test] +fn the_current_release_is_up_to_date_without_downloading() -> TestResult { + let mut env = Env::new()?; + // no assets and no download mocks: anything fetched beyond this would fail + env.release("latest", &format!("v{CURRENT}"), &json!([])); + + let out = env.cmd()?.arg("update").output()?; + + assert!(out.status.success()); + let doc = parse(&out.stdout)?; + assert_eq!(doc["update_available"], false); + assert_eq!(doc["updated"], false); + Ok(()) +} + +#[test] +fn a_repository_with_no_release_yet_is_not_found() -> TestResult { + let mut env = Env::new()?; + // what GitHub answers for releases/latest before the first release + env.server + .mock("GET", format!("{RELEASES}/latest").as_str()) + .with_status(404) + .with_body(r#"{"message":"Not Found"}"#) + .create(); + + for args in [vec!["update"], vec!["update", "--check"]] { + let out = env.cmd()?.args(&args).output()?; + assert_eq!(out.status.code(), Some(4), "{args:?}"); + assert_eq!(parse_error(&out.stderr)?["error"]["code"], "not_found"); + assert!(out.stdout.is_empty()); + } + Ok(()) +} + +#[test] +fn an_unknown_tag_is_not_found() -> TestResult { + let mut env = Env::new()?; + env.server + .mock("GET", format!("{RELEASES}/tags/v0.0.1").as_str()) + .with_status(404) + .with_body(r#"{"message":"Not Found"}"#) + .create(); + + let out = env.cmd()?.args(["update", "--tag", "0.0.1"]).output()?; + + assert_eq!(out.status.code(), Some(4)); + let err = parse_error(&out.stderr)?; + assert_eq!(err["error"]["code"], "not_found"); + // a redirected release source is announced in every output mode + assert!(String::from_utf8_lossy(&out.stderr) + .starts_with("warning: looking for releases somewhere other than RealGeeks/firebird-cli")); + assert!(message(&out.stderr)?.contains("v0.0.1")); + Ok(()) +} + +#[test] +fn a_release_without_this_platform_fails_before_downloading() -> TestResult { + let mut env = Env::new()?; + env.release("latest", "v99.0.0", &json!([])); + + let out = env.cmd()?.arg("update").output()?; + + assert_eq!(out.status.code(), Some(1)); + assert!(message(&out.stderr)?.contains("has no archive for")); + Ok(()) +} + +#[test] +fn the_release_host_must_be_https() -> TestResult { + let out = Env::new()? + .cmd()? + .env("FIREBIRD_CLI_UPDATE_API_URL", "http://releases.example.com") + .args(["update", "--check"]) + .output()?; + + assert_eq!(out.status.code(), Some(3)); + Ok(()) +} + +#[test] +fn a_malformed_repo_override_is_a_config_error() -> TestResult { + let out = Env::new()? + .cmd()? + .env("FIREBIRD_CLI_REPO", "not-a-repo") + .args(["update", "--check"]) + .output()?; + + assert_eq!(out.status.code(), Some(3)); + assert!(message(&out.stderr)?.contains("owner/name")); + Ok(()) +} + +#[test] +fn piped_commands_never_look_for_a_newer_release() -> TestResult { + let mut env = Env::new()?; + let lookup = env + .server + .mock("GET", format!("{RELEASES}/latest").as_str()) + .expect(0) + .create(); + env.cmd()?.args(["auth", "sites"]).assert().success(); + env.cmd()?.args(["guide", "--list"]).assert().success(); + lookup.assert(); + assert!(!env.config_dir.path().join("update-check").exists()); + Ok(()) +} + +/// Replacing the binary: unix only, where a shell script can stand in for +/// the new release. +#[cfg(unix)] +mod install { + use std::fmt::Write; + use std::os::unix::fs::PermissionsExt; + use std::path::{Path, PathBuf}; + + use firebird_cli::commands::update::{archive_name, release_target}; + use flate2::{write::GzEncoder, Compression}; + use sha2::{Digest, Sha256}; + + use super::*; + + const TAG: &str = "v99.0.0"; + + /// A copy of the built binary that the test is free to replace. + fn copy_of_binary(dir: &Path) -> Result> { + let path = dir.join("firebird-cli"); + std::fs::copy(assert_cmd::cargo::cargo_bin("firebird-cli"), &path)?; + Ok(path) + } + + /// The archive `release.yml` would publish, holding a script that + /// answers `--version` as the new release. + fn archive(target: &str) -> Result, Box> { + let script = b"#!/bin/sh\necho 'firebird-cli 99.0.0'\n"; + let mut header = tar::Header::new_gnu(); + header.set_size(script.len() as u64); + header.set_mode(0o755); + let mut tar = tar::Builder::new(GzEncoder::new(Vec::new(), Compression::default())); + tar.append_data( + &mut header, + format!("firebird-cli-{TAG}-{target}/firebird-cli"), + &script[..], + )?; + Ok(tar.into_inner()?.finish()?) + } + + fn sha256(bytes: &[u8]) -> String { + Sha256::digest(bytes) + .iter() + .fold(String::new(), |mut hex, b| { + let _ = write!(hex, "{b:02x}"); + hex + }) + } + + /// Mock the release and its two assets; `sum` is what the `.sha256` says. + fn publish(env: &mut Env, bytes: &[u8], sum: &str) -> Result> { + let target = release_target()?; + let name = archive_name(TAG, &target); + let base = env.server.url(); + let assets = json!([ + // the checksum first, as GitHub may list it: selection is by name + {"name": format!("{name}.sha256"), "url": format!("{base}/assets/2")}, + {"name": name, "url": format!("{base}/assets/1")}, + ]); + env.release("latest", TAG, &assets); + env.release(&format!("tags/{TAG}"), TAG, &assets); + env.server + .mock("GET", "/assets/2") + .with_body(format!("{sum} {name}\n")) + .create(); + Ok(env + .server + .mock("GET", "/assets/1") + .match_header("authorization", Matcher::Missing) + .match_header("x-api-key", Matcher::Missing) + .with_body(bytes) + .create()) + } + + fn version_of(binary: &Path) -> Result> { + let out = std::process::Command::new(binary) + .arg("--version") + .output()?; + assert!( + out.status.success(), + "{} --version: {:?} {}", + binary.display(), + out.status, + String::from_utf8_lossy(&out.stderr) + ); + Ok(String::from_utf8_lossy(&out.stdout).trim().to_string()) + } + + /// Mock GitHub's attestation lookup for `digest`. + fn attestations(env: &mut Env, digest: &str) -> Mock { + env.server.mock( + "GET", + format!("/repos/RealGeeks/firebird-cli/attestations/sha256:{digest}").as_str(), + ) + } + + #[test] + fn update_replaces_the_binary_after_the_checksum_passes() -> TestResult { + let mut env = Env::new()?; + let dir = tempfile::tempdir()?; + let binary = copy_of_binary(dir.path())?; + let bytes = archive(&release_target()?)?; + let download = publish(&mut env, &bytes, &sha256(&bytes))?; + // a test archive has no real attestation: this is the documented way past it + let lookup = attestations(&mut env, &sha256(&bytes)).expect(0).create(); + let site = env.no_site_requests(); + + let out = env + .configure(Command::new(&binary)) + .env("FIREBIRD_CLI_SKIP_PROVENANCE", "1") + .arg("update") + .output()?; + lookup.assert(); + site.assert(); + assert!(String::from_utf8_lossy(&out.stderr) + .contains("not checking the archive's build provenance")); + + assert!( + out.status.success(), + "{}", + String::from_utf8_lossy(&out.stderr) + ); + download.assert(); + let doc = parse(&out.stdout)?; + assert_eq!(doc["release_version"], "99.0.0"); + assert_eq!(doc["updated"], true); + assert_eq!(version_of(&binary)?, "firebird-cli 99.0.0"); + let mode = std::fs::metadata(&binary)?.permissions().mode(); + assert_eq!(mode & 0o111, 0o111, "the new binary is executable"); + Ok(()) + } + + #[test] + fn an_archive_without_an_attestation_is_not_installed() -> TestResult { + let mut env = Env::new()?; + let dir = tempfile::tempdir()?; + let binary = copy_of_binary(dir.path())?; + let bytes = archive(&release_target()?)?; + let download = publish(&mut env, &bytes, &sha256(&bytes))?; + let lookup = attestations(&mut env, &sha256(&bytes)) + // the site key never goes to GitHub + .match_header("authorization", Matcher::Missing) + .match_header("x-api-key", Matcher::Missing) + .with_status(404) + .with_body(r#"{"message":"Not Found"}"#) + .create(); + + let out = env + .configure(Command::new(&binary)) + .arg("update") + .output()?; + + assert_eq!(out.status.code(), Some(1)); + download.assert(); + lookup.assert(); + assert!(out.stdout.is_empty(), "no result document on failure"); + let message = message(&out.stderr)?; + assert!( + message.contains("no build-provenance attestation"), + "{message}" + ); + assert!( + message.contains("FIREBIRD_CLI_SKIP_PROVENANCE"), + "{message}" + ); + assert_eq!(version_of(&binary)?, format!("firebird-cli {CURRENT}")); + Ok(()) + } + + #[test] + fn an_attestation_for_another_archive_is_not_accepted() -> TestResult { + let mut env = Env::new()?; + let dir = tempfile::tempdir()?; + let binary = copy_of_binary(dir.path())?; + let bytes = archive(&release_target()?)?; + publish(&mut env, &bytes, &sha256(&bytes))?; + // a genuine attestation (of geekcli v0.12.1), served for an archive it + // does not cover and signed by a workflow this CLI does not trust + let lookup = attestations(&mut env, &sha256(&bytes)) + .with_body(include_str!( + "../src/testdata/geekcli-attestation-v0.12.1.json" + )) + .create(); + + let out = env + .configure(Command::new(&binary)) + .arg("update") + .output()?; + + assert_eq!(out.status.code(), Some(1)); + lookup.assert(); + let message = message(&out.stderr)?; + assert!(message.contains("did not verify"), "{message}"); + assert_eq!(version_of(&binary)?, format!("firebird-cli {CURRENT}")); + Ok(()) + } + + #[test] + fn a_read_only_directory_fails_before_downloading() -> TestResult { + let mut env = Env::new()?; + let dir = tempfile::tempdir()?; + let binary = copy_of_binary(dir.path())?; + let bytes = archive(&release_target()?)?; + let download = publish(&mut env, &bytes, &sha256(&bytes))?.expect(0); + let read_only = std::fs::Permissions::from_mode(0o555); + std::fs::set_permissions(dir.path(), read_only)?; + + let out = env.configure(Command::new(&binary)).arg("update").output(); + std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o755))?; + let out = out?; + + assert_eq!(out.status.code(), Some(1)); + download.assert(); + assert!(message(&out.stderr)?.contains("cannot write to")); + assert_eq!(version_of(&binary)?, format!("firebird-cli {CURRENT}")); + Ok(()) + } + + #[test] + fn a_checksum_mismatch_leaves_the_binary_alone() -> TestResult { + let mut env = Env::new()?; + let dir = tempfile::tempdir()?; + let binary = copy_of_binary(dir.path())?; + let bytes = archive(&release_target()?)?; + publish(&mut env, &bytes, &"0".repeat(64))?; + + let out = env + .configure(Command::new(&binary)) + .arg("update") + .output()?; + + assert_eq!(out.status.code(), Some(1)); + assert!(out.stdout.is_empty(), "no result document on failure"); + assert!(message(&out.stderr)?.to_lowercase().contains("checksum")); + assert_eq!(version_of(&binary)?, format!("firebird-cli {CURRENT}")); + Ok(()) + } +} From 9e5cde683fbb9161eb0f3bffde3ac494a5564b82 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 11 Nov 2026 17:17:17 -0500 Subject: [PATCH 2/2] test: show stdout when the no-release check finds some Clippy 1.99 rejects assert!(x.is_empty()) because a failure hides the value. Co-Authored-By: Claude Fable 5.2 --- tests/update.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/update.rs b/tests/update.rs index 9aeccc2..f196ef0 100644 --- a/tests/update.rs +++ b/tests/update.rs @@ -154,7 +154,7 @@ fn a_repository_with_no_release_yet_is_not_found() -> TestResult { let out = env.cmd()?.args(&args).output()?; assert_eq!(out.status.code(), Some(4), "{args:?}"); assert_eq!(parse_error(&out.stderr)?["error"]["code"], "not_found"); - assert!(out.stdout.is_empty()); + assert_eq!(String::from_utf8_lossy(&out.stdout), "", "{args:?}"); } Ok(()) }