Skip to content

ci: check the WineHQ and apt.llvm.org signing keys' fingerprints - #4198

Open
Exopus-0x65f7ad0 wants to merge 1 commit into
ItsNotRexed:mainfrom
Exopus-0x65f7ad0:build/pin-apt-keys
Open

Exopus-0x65f7ad0 wants to merge 1 commit into
ItsNotRexed:mainfrom
Exopus-0x65f7ad0:build/pin-apt-keys

Conversation

@Exopus-0x65f7ad0

Copy link
Copy Markdown

Claim: #3918 (comment) (new BUILD item)

Problem

Two CI steps trust an apt signing key on first fetch:

  • .github/workflows/runtime.yml (wine job, winehq-stable): sudo wget -q -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
  • .github/workflows/ci.yml (translator-tests): curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-snapshot.gpg

apt then installs whatever those keys sign. Every other download in CI is pinned (actions by commit SHA, glslang by SHA-256, the Vulkan headers by commit), so these two keys were the one unpinned trust root: a key swapped on either server (or appended to the file) would be trusted without anyone noticing.

Change

  • New scripts/check_apt_key.py KEYFILE FINGERPRINT (standard library; reads the file with gpg --show-keys --with-colons, which lists without importing): the file must hold exactly one primary key with that fingerprint (subkeys allowed). Exit 0/1, 2 on a usage error.
  • Both steps download the key to a mktemp file, check it, and only then install it (gpg --dearmor / install -m 644). Pinned fingerprints, as each project publishes them and as the keys served today read:
    • WineHQ: D43F 6401 4536 9C51 D786 DDEA 76F1 A20F F987 672F
    • apt.llvm.org: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421
  • The .sources file WineHQ's step also downloads is unchanged: it only names the keyring; the packages' signatures are what the key protects.

Tests

  • python -I tests/test_check_apt_key.py (new, picked up by ci.yml's standard-library loop): 13 tests, OK. GnuPG is stood in for by a small Python program, so they need no gpg or real key: the pinned key (with a subkey) passes; another key, two primary keys, an empty file, an unreadable file and a missing gpg fail; usage errors exit 2. A workflow scan fails for any .key/.gpg/.asc download that is piped, written into apt's keyrings, or not checked by check_apt_key.py right after; on main's workflows it fails at ci.yml:125 and runtime.yml:217.
  • The real keys, fetched from the URLs above today, with gpg 2.4.9: WineHQ key + WineHQ fingerprint → exit 0; LLVM key + LLVM fingerprint → exit 0; LLVM key + WineHQ fingerprint → exit 1 ("is key 6084…, expected D43F…"); both keys concatenated → exit 1 ("holds 2 primary keys"); junk bytes → exit 1.
  • The new ci.yml lines run under bash -eo pipefail (with sudo echoed): the pinned fingerprint reaches the install line; a wrong one stops the step with exit 1 before it.
  • tests/test_ci_registration.py, test_docs_repo_paths.py, test_text_write_line_endings.py: OK; scripts/check_no_game_data.py: clean.

Limitations

  • Not run on GitHub's runners from here (a fork PR's CI waits for approval); the commands are standard on ubuntu-24.04 (python3, gpg 2.4, wget, curl, install).
  • When a project rotates its key, the step fails until the pin is updated, which is the point; the failure message names both fingerprints.

AI-assisted (Claude Code). Tested on Windows 11 (Git for Windows gpg 2.4.9); no GPU or game files involved.

The wine job wrote https://dl.winehq.org/wine-builds/winehq.key straight
into /etc/apt/keyrings and the translator-tests job piped
https://apt.llvm.org/llvm-snapshot.gpg.key into gpg --dearmor, so apt
trusted whatever key those URLs served that day. Every other download in
CI is pinned (actions by commit, glslang by SHA-256, the Vulkan headers
by commit).

scripts/check_apt_key.py (standard library, gpg --show-keys) requires
the downloaded file to hold exactly one primary key with the given
fingerprint; both steps now download to a temporary file, check it
against the fingerprint each project publishes (WineHQ D43F6401...672F,
apt.llvm.org 6084F3CF...7421) and only then install it.

tests/test_check_apt_key.py: the parser and the check with a stand-in
gpg (the key, another key, two primary keys, subkeys, an unreadable
file, no gpg), the command line, and a scan of .github/workflows that
fails for a key download not checked right after (both of today's
downloads fail it on the old workflows).

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

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at f03dcbde on Windows 11:

  • python -I tests/test_check_apt_key.py -> 13 tests, OK.
  • python -I tests/test_ci_registration.py -> 8 tests, OK.
  • Both modified workflow YAML files parse with PyYAML; git diff --check clean.

check_apt_key.py reads the downloaded key with gpg --show-keys --with-colons (no keyring import), requires exactly one primary key, normalizes spaces/case, and rejects a second primary key appended to the file; subkeys are allowed. Both steps now verify before gpg --dearmor/install, and the pinned fingerprints are the published LLVM and WineHQ ones.

This is a duplicate of #4188 (Flyander) but is the earlier claim: #3918's claim by @Exopus-0x65f7ad0 at 2026-11-22T23:14:47Z precedes #4188's claim at 23:41:32Z. Under the coordination rule, this PR should land and #4188 close; it also carries the tested helper that #4188 lacks. I'll note that on #4188.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f03dcbde on Linux (Python 3.12) against the live keys fetched just now:

  • scripts/check_apt_key.py on https://apt.llvm.org/llvm-snapshot.gpg.key with 6084F3CF814B57C1CF12EFD515CF4D18AF4F7421: exit 0
  • on https://dl.winehq.org/wine-builds/winehq.key with D43F640145369C51D786DDEA76F1A20FF987672F: exit 0
  • the WineHQ key with the LLVM fingerprint: exit 1, "expected 6084F3CF…"
  • gpg --show-keys reports the same two primary fingerprints, and python -I tests/test_check_apt_key.py passes.

One overlap: #4204 adds a second, unchecked apt.llvm.org key fetch to runtime.yml (linux-gpu-tools). With both branches merged locally, runtime.yml:285 still runs curl … llvm-snapshot.gpg.key | sudo gpg --dearmor without check_apt_key.py. Whichever lands second should route that fetch through the check too.

AI-assisted.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key pin is bypassable through the unvalidated WineHQ source configuration fetched by this job.

key=$(mktemp)
wget -q -O "$key" https://dl.winehq.org/wine-builds/winehq.key
python3 -I scripts/check_apt_key.py "$key" D43F640145369C51D786DDEA76F1A20FF987672F
sudo install -m 644 "$key" /etc/apt/keyrings/winehq-archive.key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Pin or construct the WineHQ source stanza too. This pins the key file, but the next command still installs a .sources document downloaded directly from WineHQ without checking its contents. A modified stanza can set Trusted: yes, which makes APT trust the source even when authentication checks fail and bypasses the key fingerprint pin. Generate the small stanza locally with the intended URI, suite and Signed-By path, or validate the downloaded document and reject trust-bypass options. Debian documents that Trusted: yes disables parts of apt-secure: https://manpages.debian.org/testing/apt/sources.list.5.en.html.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked just now: the live winehq-noble.sources (and winehq-jammy.sources) is these six lines, with no Trusted: option:

Types: deb
URIs: https://dl.winehq.org/wine-builds/ubuntu
Suites: noble
Components: main
Architectures: amd64 i386
Signed-By: /etc/apt/keyrings/winehq-archive.key

Writing it locally gives a byte-identical file (cmp exit 0 against the download), so the second wget can go:

codename=$(. /etc/os-release && echo "$VERSION_CODENAME")
printf 'Types: deb\nURIs: https://dl.winehq.org/wine-builds/ubuntu\nSuites: %s\nComponents: main\nArchitectures: amd64 i386\nSigned-By: /etc/apt/keyrings/winehq-archive.key\n' "$codename" \
  | sudo tee "/etc/apt/sources.list.d/winehq-$codename.sources" >/dev/null

AI-assisted.

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.

4 participants