Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 72 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: release

# Run from the Actions tab. Unticked, it builds every asset and publishes
# nothing -- the point is finding out whether they build. Ticked, it tags the
# Run from the Actions tab. Unticked, it builds every asset, signs them and
# publishes nothing -- the point is finding out whether they build and whether
# the signing key is the one the app trusts. Ticked, it tags the
# commit as v<Cargo.toml version>, publishes the release once every asset
# exists, and repoints the Homebrew cask. A version with a hyphen
# (0.2.0-rc.1) is published as a pre-release, may come from any branch, and
Expand Down Expand Up @@ -151,8 +152,60 @@ jobs:
target/windows/dbdelve-*-setup.exe
if-no-files-found: error

# Its own job, and not gated on publishing, so an unticked run proves the
# secret signs what the app will accept before a release depends on it.
sign:
needs: [linux, macos, windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true

# Every asset gets a minisign signature beside it, `<asset>.minisig`,
# which is what the app checks an update against before installing it.
# All of them, not only the DMG, so the other platforms' updaters need
# nothing new here. UPDATE_SIGNING_KEY is an unencrypted minisign secret
# key; without it nothing is published, since a release without
# signatures is one no installed app will update to.
- run: sudo apt-get update && sudo apt-get install -y minisign
- run: |
if [[ -z "$UPDATE_SIGNING_KEY" ]]; then
echo "the UPDATE_SIGNING_KEY secret is not set -- releases must be signed" >&2
exit 1
fi
# The key the app is built with, so a secret that does not match it
# fails here instead of in every installed app.
PUBLIC_KEY="$(sed -n 's/^const RELEASE_PUBLIC_KEY: &str = "\(.*\)";$/\1/p' src/update/macos.rs)"
if ! grep -qxF "PUBLIC_KEY=\"$PUBLIC_KEY\"" install.sh; then
echo "install.sh does not check downloads against the app's release key" >&2
exit 1
fi
KEY="$RUNNER_TEMP/update.key"
trap 'rm -f "$KEY"' EXIT
printf '%s\n' "$UPDATE_SIGNING_KEY" > "$KEY"
for ASSET in dist/*; do
minisign -S -s "$KEY" -m "$ASSET" -x "$ASSET.minisig" < /dev/null
# The app verifies prehashed signatures only (algorithm "ED");
# a minisign old enough to make the legacy kind must fail here.
if [[ "$(sed -n 2p "$ASSET.minisig" | base64 -d | head -c 2)" != ED ]]; then
echo "$ASSET.minisig is not a prehashed signature" >&2
exit 1
fi
minisign -V -q -P "$PUBLIC_KEY" -m "$ASSET" -x "$ASSET.minisig"
done
env:
UPDATE_SIGNING_KEY: ${{ secrets.UPDATE_SIGNING_KEY }}
- uses: actions/upload-artifact@v7
with:
name: signatures
path: dist/*.minisig
if-no-files-found: error

release:
needs: [version, linux, macos, windows]
needs: [version, sign]
if: inputs.publish
runs-on: ubuntu-latest
steps:
Expand All @@ -171,11 +224,13 @@ jobs:
"dbdelve-$VERSION-linux-aarch64.tar.gz" "dbdelve-$VERSION-aarch64.AppImage" \
"dbdelve-$VERSION-windows-x86_64.zip" \
"dbdelve-$VERSION-windows-x86_64-setup.exe"; do
if [[ ! -f "dist/$ASSET" ]]; then
echo "no $ASSET among the built assets" >&2
ls dist >&2
exit 1
fi
for FILE in "$ASSET" "$ASSET.minisig"; do
if [[ ! -f "dist/$FILE" ]]; then
echo "no $FILE among the built assets" >&2
ls dist >&2
exit 1
fi
done
done
PRERELEASE_FLAG=()
[[ "$PRERELEASE" == true ]] && PRERELEASE_FLAG=(--prerelease)
Expand Down Expand Up @@ -226,11 +281,20 @@ jobs:
desc "Fast, native, multi-engine database client"
homepage "https://github.com/ShayanAbbas1/dbdelve"

# The app updates itself, so Homebrew leaves upgrading it to the app.
auto_updates true
depends_on arch: :arm64
depends_on macos: :monterey

app "DBDelve.app"

# Ad-hoc signed and not notarized, so Gatekeeper refuses the app
# until its quarantine flag is cleared. Done here so a Homebrew
# install opens without the xattr command a manual one needs.
postflight_steps do
run "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "{{appdir}}/DBDelve.app"]
end

# Lowercase: the app writes "dbdelve", and a zap spelled any other way
# silently removes nothing. Saved passwords live in the Keychain, which zap
# cannot reach at all.
Expand Down
67 changes: 67 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@ windows-sys = { version = "=0.61.2", features = [
[target.'cfg(unix)'.dependencies]
libc = "=0.2.189"

# Checking a downloaded update against the key releases are signed with. Zero
# dependencies. macOS alone for now, as the one platform that updates itself.
[target.'cfg(target_os = "macos")'.dependencies]
minisign-verify = "=0.3.0"

# Signing the updater's test files the way the release pipeline's minisign
# does, so no tool has to be installed to run them.
[target.'cfg(target_os = "macos")'.dev-dependencies]
minisign = "=0.10.0"

[features]
# Lets an end-to-end test point the updater at its own feed and key, and lets a
# DBDELVE_VARIANT build update itself. Never on in a shipped build, so no
# released app can be redirected to another feed or key.
update-test-hooks = []

# Explorer shows the icon compiled into the .exe. The resource compiler is
# the Windows SDK's; macOS and Linux never run this build script's embed.
[target.'cfg(target_os = "windows")'.build-dependencies]
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ I wanted something which is performant, modern and consumes little ram. The exis

```sh
brew install --cask ShayanAbbas1/dbdelve/dbdelve
xattr -dr com.apple.quarantine /Applications/DBDelve.app
```

Don't skip the second line: the app isn't notarized, so macOS won't open it
until the quarantine flag is cleared.
The app isn't notarized, so the cask clears the quarantine flag macOS would
otherwise refuse it over. Without Homebrew:

```sh
curl -fsSL https://raw.githubusercontent.com/ShayanAbbas1/dbdelve/main/install.sh | sh
```

**Linux** (x86_64 or aarch64): `yay -S dbdelve-bin` from the AUR, or the
tarball or AppImage from [the latest release][releases].
Expand Down
12 changes: 10 additions & 2 deletions dev/bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# neither replace the released app nor touch what it has saved.
# DBDELVE_CHANNEL=release builds the app the release workflow ships.
#
# DBDELVE_FEATURES passes cargo features to the app's build (update-test-hooks
# for an end-to-end test of the updater), and DBDELVE_NO_LAUNCH=1 builds the
# dev app without opening it.
#
# Usage: dev/bundle.sh
set -euo pipefail

Expand Down Expand Up @@ -45,7 +49,11 @@ else
fi
fi

cargo build --release
FEATURES=()
if [[ -n "${DBDELVE_FEATURES:-}" ]]; then
FEATURES=(--features "$DBDELVE_FEATURES")
fi
cargo build --release ${FEATURES[@]+"${FEATURES[@]}"}
# Builds the ODBC bridge, which links unixODBC statically on macOS, and stages
# it under target/release/plugins/odbc.
dev/plugins.sh --release
Expand Down Expand Up @@ -141,7 +149,7 @@ codesign --verify --deep --strict "$APP"
# Neither variant installs. The release reaches /Applications by the DMG's
# drag-to-install, and the dev app runs where it was built so it can never be
# mistaken for -- or dropped over -- the real one.
if [[ "$CHANNEL" == release ]]; then
if [[ "$CHANNEL" == release || "${DBDELVE_NO_LAUNCH:-}" == 1 ]]; then
echo "built $APP (v$VERSION)"
exit 0
fi
Expand Down
41 changes: 38 additions & 3 deletions docs/agents/shipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ Four things in the script are load-bearing:
- **The font licences ship inside the bundle**, because the fonts are compiled
into the binary and the OFL asks the licence to travel with them.

## Self-update (macOS)

`src/update.rs` checks GitHub's `releases/latest` at launch and every six
hours. On macOS (`src/update/macos.rs`) an install that can replace itself
gets **Update and restart**: it downloads `DBDelve-<version>.dmg`, verifies
`DBDelve-<version>.dmg.minisig` against `RELEASE_PUBLIC_KEY`, copies the app
out of the image to a hidden sibling, checks it (`codesign --verify --deep
--strict`, same `CFBundleIdentifier`, `CFBundleShortVersionString` equal to the
release and newer than both the running build and the installed bundle),
exchanges the two in one `renamex_np(RENAME_SWAP)` and relaunches through
`App::restart`, which quits the way Quit does. A volume without the atomic
exchange fails the update and keeps the release link: moving the app aside
first would leave nothing installed if the process died in between. A lock on
the bundle's folder keeps two processes from clearing each other's hidden
sibling, and an install clears the one an interrupted install left.

- **Only the release build in a writable place updates itself.** A dev or
other `DBDELVE_VARIANT` build, a binary outside a `.app`, a bundle on a
read-only volume (run from the DMG), App-Translocated, or in a folder the
user cannot write, keeps the link to the release page. So does a release
missing either asset, and a build whose key is still the placeholder.
- **The release workflow signs every asset** with the `UPDATE_SIGNING_KEY`
secret (an unencrypted minisign secret key) and checks each signature is
prehashed and verifies against the key in `src/update/macos.rs`; it refuses
to publish otherwise. Changing the key strands every installed app on the
old one, which then never verifies another release.
- **The cask says `auto_updates true`**, so `brew upgrade` does not fight the
app over which copy is current.
- **`update-test-hooks` is the only way to point an app elsewhere.** Off by
default; with it the app reads `DBDELVE_UPDATE_FEED` and
`DBDELVE_UPDATE_PUBLIC_KEY` and a variant build may update itself.
`DBDELVE_FEATURES=update-test-hooks DBDELVE_NO_LAUNCH=1 dev/bundle.sh`
builds such a dev bundle without opening it.

## The ODBC bridge in each artifact

Every artifact carries `plugins/odbc` (never echo, which is test code), laid
Expand Down Expand Up @@ -115,13 +149,14 @@ Only once every asset exists does it tag the commit `v$VERSION` and publish,
then it rewrites `Casks/dbdelve.rb` in the `ShayanAbbas1/homebrew-dbdelve` tap
through the `TAP_TOKEN` secret. A version with a hyphen (`0.2.0-rc.1`) is a
pre-release, may run from any branch and leaves the cask alone. Unticked, the
workflow builds everything and publishes nothing.
workflow builds everything, signs it and publishes nothing, which is how to
check `UPDATE_SIGNING_KEY` against the app's key without releasing.

**There is no notarization and no Developer ID.** A release signs ad-hoc rather
than with `dev/identity.sh`'s certificate: that certificate is trusted only on
the machine that created it, and to Gatekeeper an issuer nobody trusts reads
worse than no issuer at all. The trade is that the ad-hoc hash moves with every
release, so an update costs one fresh Keychain prompt. Installing still means
clearing quarantine by hand:
release, so an update costs one fresh Keychain prompt. The cask clears quarantine
itself in a `postflight_steps` block; a `.dmg` installed by hand still needs
`xattr -dr com.apple.quarantine /Applications/DBDelve.app`.

Loading
Loading