kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Migrate Kolibri PyPI publishing to OIDC trusted publishing

Open rtibbles opened this issue 7 months ago • 6 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Migrate the existing Kolibri PyPI publishing pipeline (pypi_upload.yml and its callers in release_kolibri.yml) from API-token authentication to PyPI OIDC trusted publishing. Drop GPG signing of artifacts, which PyPI deprecated in May 2023 (the API accepts but ignores GPG signatures, and the website no longer displays them).

This brings Kolibri's main package publishing in line with our other Python package repos and is a prerequisite for the Python monorepo setup (#14663), which will introduce a separate OIDC-based workflow for member packages.

Complexity: Medium Target branch: develop

Context

.github/workflows/pypi_upload.yml is a reusable workflow (workflow_call) that uploads pre-built Kolibri wheel/tarball artifacts to PyPI or TestPyPI. It currently:

  • Authenticates to PyPI/TestPyPI using long-lived API tokens (PYPI_API_TOKEN, TESTPYPI_API_TOKEN) passed as secrets.
  • GPG-signs both the .whl and .tar.gz before upload using GPG_SIGNING_KEY and GPG_PASSPHRASE.
  • Uploads via twine.

It is called from .github/workflows/release_kolibri.yml twice:

  • For TestPyPI after the wheel is built.
  • For PyPI after a manual approval gate (block_release_step).

Both call sites pass the four secrets above.

OIDC trusted publishing requires:

  • The caller workflow to grant permissions: id-token: write at the appropriate level for the reusable workflow to inherit it.
  • A trusted publisher configuration registered in the PyPI and TestPyPI project settings, naming this repository, the workflow filename, and (optionally) an environment.

GitHub Actions reusable workflows in the same repository inherit OIDC tokens from the caller, but the permissions and environment scoping have some quirks worth verifying during implementation.

The Change

Reusable workflow (pypi_upload.yml):

  • Replace twine upload with pypa/gh-action-pypi-publish, configured for OIDC trusted publishing (no password input).
  • Remove the GPG signing steps and the GPG_SIGNING_KEY / GPG_PASSPHRASE secrets from the workflow signature.
  • Remove the PYPI_API_TOKEN / TESTPYPI_API_TOKEN secrets from the workflow signature.
  • Add permissions: id-token: write to the publish job so OIDC tokens can be requested.
  • Keep the test boolean input — TestPyPI continues to be supported via the publish action's repository-url parameter.

Caller (release_kolibri.yml):

  • Update both call sites (the TestPyPI upload after build, and the PyPI upload after the release approval gate) to drop the now-unused secrets.
  • Add permissions: id-token: write at the appropriate level so the reusable workflow inherits the OIDC token.

PyPI configuration (manual, out-of-band):

  • Register a trusted publisher in the kolibri project's PyPI settings naming this repository and the pypi_upload.yml workflow filename. No environment scoping.
  • Register the equivalent trusted publisher in TestPyPI.

Out of Scope

  • The new monorepo member-package PyPI publishing workflow — added by #14663.
  • Changes to the release_kolibri.yml release flow beyond removing the now-unused secrets and adding id-token: write permissions.
  • Re-signing or back-signing previously published Kolibri releases.
  • Migration of any other repository's PyPI publishing.

Follow-up

After the next release publishes successfully under OIDC, the now-unused repository secrets (PYPI_API_TOKEN, TESTPYPI_API_TOKEN, GPG_SIGNING_KEY, GPG_PASSPHRASE) should be deleted from the learningequality/kolibri GitHub settings. A repo-wide search should first confirm no other workflow references them.

Acceptance Criteria

Reusable workflow

  • [ ] pypi_upload.yml uses pypa/gh-action-pypi-publish instead of twine.
  • [ ] OIDC trusted publishing is used; no PyPI/TestPyPI API tokens are passed as secrets.
  • [ ] permissions: id-token: write is set on the publish job.
  • [ ] GPG signing steps are removed.
  • [ ] GPG_SIGNING_KEY, GPG_PASSPHRASE, PYPI_API_TOKEN, TESTPYPI_API_TOKEN no longer appear in the workflow's secrets: block.
  • [ ] The test boolean input still toggles between TestPyPI and PyPI (via repository-url).

Caller workflow

  • [ ] Both pypi_upload.yml call sites in release_kolibri.yml no longer pass the removed secrets.
  • [ ] The caller grants permissions: id-token: write at the level needed for the reusable workflow to inherit it.

PyPI / TestPyPI configuration

  • [ ] A trusted publisher is registered for the kolibri project on PyPI naming this repository and the pypi_upload.yml workflow filename.
  • [ ] A trusted publisher is registered for the kolibri project on TestPyPI naming this repository and the pypi_upload.yml workflow filename.

References

  • Current reusable workflow: .github/workflows/pypi_upload.yml
  • Caller workflow: .github/workflows/release_kolibri.yml (search for pypi_upload.yml)
  • PyPI publish action: https://github.com/pypa/gh-action-pypi-publish
  • PyPI OIDC trusted publishing documentation: https://docs.pypi.org/trusted-publishers/
  • PyPI GPG signature deprecation: https://blog.pypi.org/posts/2023-05-23-removing-pgp/
  • Precedents in our other Python packages:
    • https://github.com/learningequality/le-utils/blob/main/.github/workflows/pypi-publish.yml
    • https://github.com/learningequality/morango/blob/main/.github/workflows/python-publish.yml
    • https://github.com/learningequality/ricecooker/blob/main/.github/workflows/python-publish.yml

AI usage

Used Claude Code to draft this issue iteratively from a brief prompt. I drove scope and decisions throughout — confirming OIDC as the goal, dropping GPG signing, declining to scope the trusted publisher to a GitHub Actions environment (after Claude raised the option and the reusable-workflow quirk), and choosing to verify the migration on the next real release rather than via manual workflow_dispatch testing. Claude reviewed the existing workflow and its callers, surfaced the OIDC token inheritance behaviour for reusable workflows, and edited drafts before each was accepted.

rtibbles avatar Apr 30 '26 23:04 rtibbles

Plan: Replace API-token + GPG signing in pypi_upload.yml with OIDC trusted publishing via pypa/gh-action-pypi-publish, and update release_kolibri.yml to grant the necessary OIDC permissions.

  • [ ] Migrate pypi_upload.yml to OIDC
  • [ ] Update release_kolibri.yml caller
  • [ ] Register Trusted Publishers on PyPI and TestPyPI (manual, out-of-band)
  • [ ] Final Verification Against Acceptance Criteria
  • [ ] Post-Release Secret Cleanup (follow-up, after first successful OIDC release)

status


@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jun 11 '26 22:06 rtibblesbot

The code changes for this issue are complete and committed:

  • pypi_upload.yml has been rewritten to use pypa/gh-action-pypi-publish with OIDC trusted publishing — no API tokens, no GPG signing, id-token: write set on the deploy job.
  • release_kolibri.yml has been updated to add id-token: write at the top-level permissions and both pypi_upload.yml call sites no longer pass the removed secrets.

Manual action required — Task 3:

Before the next release, a human with owner/maintainer access to the kolibri project on PyPI and TestPyPI needs to register trusted publishers:

TestPyPI: https://test.pypi.org/manage/project/kolibri/settings/publishing/

  • Owner: learningequality
  • Repository: kolibri
  • Workflow: pypi_upload.yml
  • Environment: (leave blank)

PyPI: https://pypi.org/manage/project/kolibri/settings/publishing/

  • Owner: learningequality
  • Repository: kolibri
  • Workflow: pypi_upload.yml
  • Environment: (leave blank)

Once those are registered, the workflow changes are ready to use on the next release. The four legacy secrets (PYPI_API_TOKEN, TESTPYPI_API_TOKEN, GPG_SIGNING_KEY, GPG_PASSPHRASE) can be deleted from repository settings after the first successful OIDC-authenticated publish.

rtibblesbot avatar Jun 11 '26 22:06 rtibblesbot

Yes, we will do that - please open the pull request for this work now though!

rtibbles avatar Jun 11 '26 23:06 rtibbles

Are you waiting for something else here? Please open the pull request.

rtibbles avatar Jun 12 '26 00:06 rtibbles

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 12 '26 02:06 rtibblesbot

I've given you a response, you're just not doing anything about it!

rtibbles avatar Jun 12 '26 02:06 rtibbles