From e72e0aae2ffc82fa200a24f6724599c76b726b3c Mon Sep 17 00:00:00 2001 From: maksimtech <268127343+maksimtech@users.noreply.github.com> Date: Sun, 22 Nov 2026 14:20:32 +0100 Subject: [PATCH] ci(codecov): upload coverage with OIDC instead of a token Codecov files an upload under the project its token belongs to. This repository's CODECOV_TOKEN secret held exeradar's token, so every coverage report since at least 2026-10-17 went to exeradar's project, and codecov/patch on #111 waited for one that never came. The upload now uses OIDC (use_oidc: true; id-token: write on the test job, contents: read repeated since job permissions replace the workflow's): GitHub tells Codecov which repository the job runs in. test_the_upload_is_given_a_token becomes a test that requires OIDC and forbids the secret. Same as maksimtech/mailradar#135. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 11 ++++++++++- CHANGELOG.md | 9 +++++++++ tests/test_codecov_contract.py | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ac47fc..7016bbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,12 @@ jobs: test: runs-on: ubuntu-26.04 timeout-minutes: 10 + # id-token: write lets the coverage upload prove to Codecov, through GitHub's + # OIDC, which repository it comes from. Job permissions replace the workflow's, + # so contents: read is repeated here. + permissions: + contents: read + id-token: write strategy: fail-fast: false matrix: @@ -60,7 +66,10 @@ jobs: if: matrix.python-version == '3.12' uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 with: - token: ${{ secrets.CODECOV_TOKEN }} + # OIDC, not a CODECOV_TOKEN secret: Codecov files an upload under the + # project its token belongs to, and this repository's secret held + # exeradar's, so the reports went there (tests/test_codecov_contract.py). + use_oidc: true files: coverage.xml # A failed upload loses a metric; it does not invalidate the tests that # just passed. What it must not do is stay silent forever — ask Codecov diff --git a/CHANGELOG.md b/CHANGELOG.md index 4028cd2..c3e16fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,15 @@ what has already shipped, and for nothing else. See `RELEASING.md`. (`tests/test_scout_binary.py`). Sources: [docker/scout-action#116](https://github.com/docker/scout-action/issues/116). +- **Coverage reaches this repository's Codecov project again.** The upload authenticated with a + `CODECOV_TOKEN` secret, and Codecov files an upload under the project its token belongs to: the + secret here held exeradar's token, so every report since at least 2026-10-17 went to exeradar's + project, and `codecov/patch` waited on #111 for one that never came. The upload now uses OIDC + (`use_oidc: true`, `id-token: write` on the test job): GitHub tells Codecov which repository the job + runs in, and there is no secret left to mix up. The test that required the token now requires OIDC + and forbids the secret (`tests/test_codecov_contract.py`). Same as maksimtech/mailradar#135 and + maksimtech/cookieradar#104. + ### Security - **CVE-2026-121482 (OpenSSL, CRL distribution points) is accepted until Debian ships a fix.** Docker diff --git a/tests/test_codecov_contract.py b/tests/test_codecov_contract.py index 675a07a..b25d424 100644 --- a/tests/test_codecov_contract.py +++ b/tests/test_codecov_contract.py @@ -61,10 +61,31 @@ def test_the_upload_runs_once_on_a_version_the_matrix_has(workflow): ) -def test_the_upload_is_given_a_token(workflow): - """Codecov wants one even for a public repository; without it the upload is - rejected, and quietly.""" - assert "CODECOV_TOKEN" in workflow +def test_the_upload_proves_which_repository_it_comes_from(workflow): + """Codecov wants the upload authenticated even for a public repository; without + it the upload is rejected, and quietly. + + It was a `CODECOV_TOKEN` secret until 2026-11-22, and Codecov files an upload + under the project the token belongs to, not under the repository that sends it: + this repository's secret held exeradar's token, so every report since at least + 2026-10-17 went to exeradar's project, and `codecov/patch` here waited for one + that never came (#111). With OIDC, GitHub itself tells Codecov which repository + the job runs in, so the report cannot land anywhere else; there is no secret to + get wrong. The job needs `id-token: write` for that, and a token in the step + would only be ignored next to `use_oidc` and mislead whoever reads it.""" + import yaml + + jobs = yaml.safe_load(workflow)["jobs"] + uploads = [(name, job, step) for name, job in jobs.items() for step in job.get("steps", []) + if str(step.get("uses", "")).startswith("codecov/codecov-action@")] + assert uploads, "nothing uploads coverage" + for name, job, step in uploads: + options = step.get("with") or {} + assert options.get("use_oidc") is True, f"{name}: the upload does not use OIDC" + assert "token" not in options, f"{name}: a token next to use_oidc is ignored" + assert (job.get("permissions") or {}).get("id-token") == "write", ( + f"{name}: without id-token: write the job cannot ask GitHub for the OIDC token") + assert "secrets.CODECOV_TOKEN" not in workflow, "the secret is still read somewhere" def test_the_coverage_is_measured_on_this_package(workflow):