Skip to content

Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.

Data signs data/index.json after merge to dev

tellyscope-agent50513ff96412
diff --git a/.github/workflows/data.yml b/.github/workflows/data.yml
index 6755191..5031185 100644
--- a/.github/workflows/data.yml
+++ b/.github/workflows/data.yml
@@ -1,8 +1,10 @@
name: Data
-# data/ is downloaded by every installed app straight from main, so it may only change with a valid signature.
+# data/ is downloaded by every installed app straight from dev (alpha) and main, so it may only reach them
+# signed. Pull requests into dev are signed after merge, by the sign job below: nobody signs locally.
on:
pull_request:
+ branches: [dev, main]
paths: ["data/**", "tools/data.py", "tools/test_data.py", "tools/data-keys/**", ".github/workflows/data.yml"]
push:
branches: [main, dev]
@@ -14,10 +16,71 @@ permissions:
jobs:
check:
name: data/ index and signature
+ if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
+ with:
+ persist-credentials: false
- name: Tests
run: python3 -m unittest discover -s tools -p 'test_data.py' -v
- - name: data/index.json is fresh and its signature verifies
- run: python3 tools/data.py check
+ - name: data/index.json is fresh, and signed unless this pull request goes into dev
+ env:
+ BASE: ${{ github.base_ref }}
+ run: |
+ if [ "$BASE" = dev ]; then python3 tools/data.py check --unsigned; else python3 tools/data.py check; fi
+
+ needs-sign:
+ name: data/index.json needs a signature
+ if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
+ runs-on: ubuntu-latest
+ outputs:
+ needed: ${{ steps.check.outputs.needed }}
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ - name: Tests
+ run: python3 -m unittest discover -s tools -p 'test_data.py' -v
+ - id: check
+ run: |
+ python3 tools/data.py index
+ if python3 tools/data.py check; then echo needed=false; else echo needed=true; fi >> "$GITHUB_OUTPUT"
+
+ # Waits for the data-signing environment's reviewer, so it runs only when the index really changed.
+ sign:
+ name: Sign data/index.json
+ needs: needs-sign
+ if: needs.needs-sign.outputs.needed == 'true'
+ runs-on: ubuntu-latest
+ environment: data-signing
+ permissions:
+ contents: write
+ concurrency:
+ group: data-signing
+ cancel-in-progress: false
+ steps:
+ # dev's tip, not the pushed commit: a run that waited signs whatever dev holds now.
+ - uses: actions/checkout@v7
+ with:
+ ref: dev
+ - name: Index and sign, unless dev is already signed
+ env:
+ KEY: ${{ secrets.DATA_SIGNING_KEY }}
+ run: |
+ python3 tools/data.py index
+ if ! python3 tools/data.py check 2>/dev/null; then
+ (umask 077 && printf '%s\n' "$KEY" > "$RUNNER_TEMP/data-signing.pem")
+ python3 tools/data.py sign --key "$RUNNER_TEMP/data-signing.pem"
+ fi
+ - name: Delete the key
+ if: always()
+ run: rm -f "$RUNNER_TEMP/data-signing.pem"
+ - name: Check, commit and push
+ run: |
+ python3 tools/data.py check
+ git diff --quiet -- data/index.json && exit 0
+ git config user.name 'github-actions[bot]'
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
+ git commit -q -m "data/index.json: sign version $(jq -r .version data/index.json)" -- data/index.json
+ git push origin HEAD:dev
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 58745b2..51095a6 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -57,30 +57,39 @@ line 2 cut out. Nothing parses and rewrites the JSON to check it, so a file refo
fails, and `index` puts it right. A checker skips tags it doesn't know and passes if any `p256` entry
verifies against any key, so a new key or algorithm can sign next to the old one. The public keys
are built into the app and kept in [`tools/data-keys/`](tools/data-keys/) for the `Data` check: a primary,
-used for every update, and a backup kept offline, so losing the primary doesn't lock apps out. The
-private keys stay on the maintainer's machine, never in this repo or in CI. Make each one once:
+used for every update, and a backup, so losing or leaking the primary doesn't lock apps out.
+
+**Nobody signs locally.** The `Data` workflow signs after merge, on every push to `dev` that changes the
+index:
+
+1. Contributors run `python3 tools/data.py index` and `python3 tools/data.py check --unsigned`, which is
+ also what `Data` checks on a pull request into `dev`.
+2. After the merge, `Data`'s `needs-sign` job runs `index` and `check` without secrets. When the index
+ needs a signature, the `sign` job waits for the maintainer's approval in the `data-signing`
+ environment, signs with its `DATA_SIGNING_KEY` secret, and commits the signed `data/index.json` to
+ `dev`. Alpha builds read that.
+3. The `dev` → `main` release carries the signed index; `Data` runs the full `check` on pull requests
+ into `main` and on `main` itself.
+
+Signing only after merge matters: once a signed `data/index.json` is on GitHub it stays fetchable by its
+commit forever, and anyone serving it gets it treated as signed.
+
+The keys are made once, by the maintainer:
```sh
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out tellyscope-data-primary.pem
openssl pkey -in tellyscope-data-primary.pem -pubout -outform DER | openssl base64 -A > tools/data-keys/primary.pub
-# the same with tellyscope-data-backup.pem > tools/data-keys/backup.pub, then store the backup offline
+# the same with tellyscope-data-backup.pem > tools/data-keys/backup.pub
```
-Changing a public key needs an app release. To rotate, sign with both private keys
-(`sign --key old.pem --key new.pem`) until no app that knows only the old key is in use.
-
-**Sign last, after review, and only a branch you'll merge.** Once a signed `data/index.json` is on
-GitHub it stays fetchable by its commit forever, and anyone serving it gets it treated as signed, even
-if the pull request was rejected.
+- The primary `.pem` goes, whole, into the secret `DATA_SIGNING_KEY` of the `data-signing` environment
+ (deployment branches `dev` and `main`, the maintainer as required reviewer), and no copy stays anywhere
+ else.
+- The backup `.pem` stays offline and is used only to rotate after the primary is lost or leaked.
+- Neither ever goes in this repository.
-Every change to `data/`:
-
-1. Contributors run `python3 tools/data.py index` and `python3 tools/data.py check --unsigned`. The
- `Data` check fails on the signature until the maintainer signs.
-2. After review, on the pull request's branch, the maintainer runs
- `python3 tools/data.py sign --key ~/path/to/tellyscope-data-primary.pem`. It refuses a key that
- `tools/data-keys/` doesn't verify.
-3. Commit `data/index.json`, let `Data` pass, merge.
+Changing a public key needs an app release. To rotate, the `sign` job signs with both keys
+(`sign --key old.pem --key new.pem`) until no app that knows only the old key is in use.
`index` leaves `data/index.json` alone, signature included, while nothing changes. Otherwise it raises
`version` (`YYYYMMDDNN`, UTC) and writes it unsigned; the app refuses an index older than the one it has.