Skip to content

Migrate PyPI publishing to Trusted Publishing (OIDC) - #1699

Open
andife wants to merge 2 commits into
Python-Markdown:masterfrom
andife:pypi-trusted-publishing
Open

andife wants to merge 2 commits into
Python-Markdown:masterfrom
andife:pypi-trusted-publishing

Conversation

@andife

@andife andife commented Nov 8, 2026

Copy link
Copy Markdown

Description

Migrates PyPI publishing from a long-lived API token (secrets.PYPI_PASSWORD) to PyPI Trusted Publishing (OIDC):

  • The Publish to PyPI step no longer passes user/password; pypa/gh-action-pypi-publish authenticates with a short-lived OIDC token minted per workflow run.
  • The pypi job is granted id-token: write and bound to a pypi deployment environment (with the project URL), so environment protection rules (required reviewers, tag restrictions) can be applied.
  • As a side benefit, gh-action-pypi-publish automatically generates and uploads PEP 740 attestations when using Trusted Publishing.

This eliminates the risk of the long-lived PyPI token being exfiltrated from repository secrets.

⚠️ Required maintainer actions before the next release:

  1. On pypi.org → Markdown project → Publishing, add a GitHub trusted publisher: owner Python-Markdown, repository markdown, workflow deploy.yml, environment pypi.
  2. Create the pypi environment under repository Settings → Environments (optionally restrict it to tags / require reviewers).
  3. After the first successful OIDC-based release, delete the PYPI_PASSWORD secret and revoke the token on PyPI.

Note: this PR is stacked on top of the general supply-chain hardening PR (action SHA pinning + least-privilege permissions); its own change is the last commit only.

Validation: the workflow file was checked with a YAML parser (yaml.safe_load) — parses successfully. The publish path can only be fully exercised on the next tagged release after the PyPI trusted publisher is configured.

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.

  • AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.

    AI tools were use to assist with the following:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: GitHub Copilot CLI (workflow/CI configuration changes)

Checklist

  • This PR follows the contribution guidelines.
  • The code follows the Code Style Guide.
  • The commit message follows the Commit Message Style Guide.
  • I have added or updated relevant docs, including release notes if applicable which follow the Documentation Style Guide. (Not applicable: CI-configuration-only change; required maintainer steps are documented above.)
  • I have added or updated relevant tests. (Not applicable: no Python code changed; workflow validated via YAML parsing.)
  • I have not requested, and will not request, an automated AI review for this PR.

andife and others added 2 commits November 8, 2026 13:06
Pin all GitHub Actions to full commit SHAs with version comments to
protect against tag-rewrite attacks, add least-privilege permissions
blocks to all workflows, disable credential persistence on checkouts
that do not push, add a Dependabot config to keep Actions and Python
dependencies up to date, and add the OpenSSF Scorecard workflow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the long-lived PYPI_PASSWORD API token with short-lived OIDC
tokens via PyPI Trusted Publishing. Bind the publish job to a 'pypi'
environment and grant it the id-token write permission. This also
enables automatic PEP 740 attestations for published distributions.

Requires a trusted publisher to be configured for the Markdown project
on PyPI before the next release.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@waylan

waylan commented Nov 9, 2026

Copy link
Copy Markdown
Member

There is an open issue for this at #1560. I have not made this change because the existing implementation works (if it an't broke, don't fix it). Therefore, this will likely continue to sit here until such time as GitHub changes something which forces this change to be made.

@waylan waylan added the needs-review Needs to be reviewed and/or approved. label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Needs to be reviewed and/or approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants