Skip to content

Sign the release APK in a job of its own - #313

Open
lazzurs wants to merge 2 commits into
parawanderer:mainfrom
lazzurs:fix/s02-split-release-signing
Open

lazzurs wants to merge 2 commits into
parawanderer:mainfrom
lazzurs:fix/s02-split-release-signing

Conversation

@lazzurs

@lazzurs lazzurs commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes audit finding S-02: the release keystore was written to disk at the start of the one release job, which then ran pip install, the bridge tests, Gradle and its plugins, and every action in the file, with the keystore passwords exported to three Gradle runs (one of them assembleDebug). Any of that code, compromised, could read the key. The app is sideloaded with no Play App Signing behind it, so a stolen key signs updates that install over every existing install.

What changes

build-release.yml is split into three jobs:

Job Environment permissions Gets
build Android Build Release contents: read MAPS_API_KEY only
sign Android Build Release {} SIGNING_KEY, KEY_STORE_PASSWORD, KEY_PASSWORD
publish none contents: write the run's own GITHUB_TOKEN
  • build runs the same checks as before (translation check, ./gradlew test, the bridge tests, build -x lint, assembleDebug) and then assembleRelease, which now produces app-release-unsigned.apk. It uploads that as an internal artifact (unsigned-release-apk, kept 1 day). It never references a signing secret.
  • sign checks nothing out and runs nothing from the repository or from a package registry. It downloads the unsigned APK, finds the newest build-tools on the runner image, checks the APK is zip-aligned (16 KB pages, zipalign -c -P 16 4), writes the keystore to $RUNNER_TEMP with umask 077 for one step and deletes it on exit, and signs with apksigner, with the passwords passed as env: references, never on the command line. Then it verifies: v2 signature present, exactly one signer, signer certificate SHA-256 equals e85e6f91…ecf92 (the certificate 1.2.0 and earlier were signed with), and alignment still intact. It writes the APK's SHA-256 to the job summary and uploads the signed APK under the same artifact name as before (<date> - OpenTagViewer - OpenTagViewer - APK(s) release generated).
  • publish checks out (no persisted credentials), downloads the signed APK, fetches and hash-checks Unicorn's source tarball exactly as before, and runs gh release upload --clobber and gh release edit --title "OpenTagViewer Android App <version>". Same two assets and the same title as before.

app/build.gradle.kts: the release build type uses the release signing config only when its keystore file exists, so assembleRelease with no keystore produces an unsigned APK instead of failing. A maintainer building locally with the keystore still gets a signed APK as before.

Signing settings are kept as AGP used them: v2 only (the published 1.2.0 APK verifies as v1 false, v2 true, v3 false), same alias (upload), same key. So an APK from this workflow installs over 1.2.0 the same way.

Also in this PR:

  • softprops/action-gh-release and the ANDROID_BUILD_RELEASE_GITHUB_TOKEN PAT are no longer used by this workflow (the audit's S-03 fix suggests this replacement). The exporter workflow still uses both; that is untouched here.
  • S-08 for the lines rewritten here: the keystore is no longer echoed through ${{ secrets.SIGNING_KEY }} interpolated into a script, and the new steps take the tag, version and passwords from env:. The other interpolations S-08 lists (--tag "${{ github.ref }}", the MAPS_API_KEY echo) are on lines this PR doesn't touch, so they are left for a separate change.
  • CONTRIBUTING.md: the CI table row and "Releasing the Android app" describe the split, the certificate check and the double approval.

What the maintainer needs to do

  • Nothing is required before the next release. No secret, environment or setting has to change. Secrets stay in Android Build Release under the same names.
  • A release now asks for approval twice, because build and sign both use Android Build Release, which has you as a required reviewer: once when the run starts (build), once ~20 minutes later (sign). If that's annoying, move MAPS_API_KEY to a new environment with no reviewers (or to Android Build, if that environment's MAPS_API_KEY is the same release key; I can't see secret values, so I couldn't check) and point build at it. Then only signing asks. That also stops relying on GitHub's behaviour of passing a job only the secrets that job references, which is what currently keeps the signing secrets off the build runner.
  • Optional: once a release has gone out through this workflow, ANDROID_BUILD_RELEASE_GITHUB_TOKEN can be deleted from the environment. Nothing references it any more.
  • If the release key is ever rotated, update EXPECTED_SIGNER_SHA256 in the workflow, or sign will refuse to publish.

Other workflows checked

macos-exporter-python.yml doesn't sign anything: no keystore or code-signing secret, only MACOS_EXPORTER_APP_GITHUB_TOKEN for the release upload. build-debug.yml uses DEBUG_KEYSTORE_BASE64, which is the deliberately public-grade debug key (see CONTRIBUTING), so it's out of scope. No other workflow touches signing secrets.

Verified

  • actionlint on the new workflow: no new findings (only the existing SC2086 notes on untouched lines, plus SC2012 info on the ls build-tools line).

  • A dry run on my fork, generated mechanically from this exact workflow with the release-only bits swapped out: push trigger instead of release, no environments, the fork's missing MAPS_API_KEY replaced by the debug default, a throwaway keystore generated with keytool, and the gh release calls replaced by a listing. Final run: https://github.com/lazzurs/OpenTagViewer/actions/runs/45187049391 (all three jobs green; re-run after rebasing onto Pin every action to a commit SHA, and let Dependabot move them #314, with the pinned SHAs). In that run:

    • build passed the full test suite and produced app-release-unsigned.apk
    • apksigner verify fails on the unsigned APK (so build signed nothing)
    • the unsigned APK passes the 16 KB alignment check
    • sign signed it with permissions: {}, and verification passed against the throwaway key's certificate
    • negative control: the same verification step, run with the real release certificate's digest, rejected the throwaway-key APK
    • the keystore file was gone from $RUNNER_TEMP afterwards
    • publish downloaded the signed APK and fetched and hash-checked the Unicorn tarball.
  • The dry run caught a bug in the first version of this PR. build-tools 35 and 36 print Signer #1 certificate SHA-256 digest:, but 37 (what ubuntu-latest has now) prints V2 Signer: certificate SHA-256 digest:, so the original check refused a correctly signed APK. It now collects every certificate digest the report names and requires exactly one, equal to the pin. That's the second commit.

  • Locally, the exact verify script extracted from the workflow, run against the published OpenTagViewer-1.2.0.apk with build-tools 35, 36 and 37: it passes with the real pin and fails with any other on all three. This also confirmed 1.2.0 is v2-only and is signed by e85e6f91…ecf92.

  • Because this touches app/build.gradle.kts, the PR's own checks ran on the rebased head: Instrumented tests (emulator), build, Static checks and check all pass. The earlier fork runs on the pre-rebase head are Generate APK (Debug) (884 instrumented tests, 0 failed) and Static checks. The first attempt there hit the 00:00–02:00 UTC flake in DebugModeReachesEveryScreenTest (AMapWithTagsOnIt seeds a report at "now − 2 h", which is yesterday at that hour); a rerun after 02:00 passed.

Not verified

  • The real path end to end: the real keystore, the real environment approvals, and gh release upload / gh release edit against a real release. I can't create releases. The first real release through this workflow is the test, so it's worth watching that run.
  • Whether contents: write on GITHUB_TOKEN is enough for gh release edit on this repository. It should be (the old comment in this file says the action falls back to that same grant), but it hasn't been exercised here.
  • Installing the CI-signed APK over a real 1.2.0 install. The signer check makes a mismatch fail the run rather than ship, but nobody has installed one yet.

Relationship to the other two PRs

This is one of three PRs from the same audit (S-02, S-03, S-04), tracked in #318. S-03 (#314) has since merged, and this branch is rebased onto it. Every uses: in build-release.yml follows #314's convention, using the same SHAs #314 pinned elsewhere: actions/checkout@3d3c42e… # v7.0.1, actions/setup-java@d1374f8… # v6.3.0, actions/setup-python@6d4fd22… # v7.1.0, actions/upload-artifact@cf430e0… # v7.0.2, and the newly used actions/download-artifact@9000827… # v8.0.2. The softprops/action-gh-release line #314 had pinned in this file is gone, because this PR replaces it with gh release.

🤖 Generated with Claude Code

@parawanderer

Copy link
Copy Markdown
Owner

#314 is merged, so rebase this onto it and pin the actions/upload-artifact / actions/download-artifact lines this adds.

In the same rebase, change build's environment: to Android Build. It has the same MAPS_API_KEY and no required reviewers, so a release asks for approval once, before sign, and the signing secrets are no longer in the build job's environment. Update the CONTRIBUTING paragraph that says a release asks twice.

Drafted by Claude Code, reviewed by @parawanderer

Rob Lazzurs and others added 2 commits November 23, 2026 13:44
The release keystore was written to disk at the start of the one release
job, which then ran pip installs, the bridge tests, Gradle and its
plugins and every action in the file, with the passwords exported to
three Gradle runs. Any of that code, compromised, could read the key.

build-release.yml now has three jobs. `build` runs the same checks and
builds the release APK unsigned; it never references the signing
secrets. `sign` checks nothing out: it downloads that APK, writes the
keystore to the runner's temp directory for one step, signs with the
runner image's apksigner (v2 only, as AGP did), and checks the
signature, the 16 KB alignment and that the signer is the certificate
1.2.0 was signed with. `publish` attaches the APK and Unicorn's source
with `gh` and the run's own token, so the release PAT and
softprops/action-gh-release are no longer used.

app/build.gradle.kts leaves a release unsigned when no keystore is
present, which is what lets `build` run assembleRelease without one.

Artifact names, the release title and the assets are unchanged. Since
`build` and `sign` both use the Android Build Release environment, a
release now asks for approval twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
build-tools 35 and 36 print "Signer #1 certificate SHA-256 digest:",
37 prints "V2 Signer: certificate SHA-256 digest:". The check matched
only the first, so on the runner's 37 it refused a correctly signed APK.
It now collects every certificate digest the report names and requires
exactly one, equal to the release certificate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
Android Build — d818ef96 Deployed Nov 23, 2026 by lazzurs via build #423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants