Skip to content

ci: Publish to PyPI without a stored API token - #370

Open
emyller wants to merge 1 commit into
mainfrom
ci/pypi-trusted-publishing
Open

emyller wants to merge 1 commit into
mainfrom
ci/pypi-trusted-publishing

Conversation

@emyller

@emyller emyller commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Releases reach PyPI using a long-lived API token stored as a repository secret: whoever obtains it can publish flagsmith-flag-engine at will until someone revokes it by hand. PyPI now trusts this repository's publish workflow directly, so each release authenticates with a short-lived credential issued for that run, and no secret is stored.

Changes

  • Releases authenticate to PyPI as a trusted publisher instead of with a stored API token.
  • The package is built separately from the step that is allowed to publish, as in flagsmith-python-client.
  • The publish workflow's GitHub token is limited to reading the repository.
  • After the first release published this way, revoke the PyPI API token and delete the PYPI_API_TOKEN secret.

The workflow file is renamed to publish.yml because that is the filename PyPI's trusted publisher is bound to. It only runs on a release tag, so it stays unexercised until the next release.

Review effort: 2/5

🤖 Generated with Claude Code

Authenticate releases as a PyPI trusted publisher (OIDC) instead of the long-lived PYPI_API_TOKEN secret. The workflow is renamed to publish.yml, the filename PyPI trusts, and the build runs in a job that holds no publishing rights.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@emyller
emyller requested a review from a team as a code owner November 30, 2026 22:26
@emyller
emyller requested review from khvn26 and removed request for a team November 30, 2026 22:26
@github-actions

Copy link
Copy Markdown

File Coverage Missing
All files 100% ✅

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against 3624186

@codspeed

codspeed Bot commented Nov 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 1 untouched benchmark


Comparing ci/pypi-trusted-publishing (3624186) with main (3e7084c)

Open in CodSpeed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 2/5

  • In .github/workflows/publish.yml, scratch tags can trigger the OIDC-enabled publisher and attempt to publish the current package. Restrict the trigger to the release tag convention, such as v*.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".github/workflows/publish.yml">

<violation number="1" location=".github/workflows/publish.yml:6">
P1: This pattern matches scratch tags as well as releases, so any tag can invoke the OIDC-enabled publisher and attempt to publish the current package. Restrict it to the release tag convention, such as `v*`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

on:
push:
tags:
- '*'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: This pattern matches scratch tags as well as releases, so any tag can invoke the OIDC-enabled publisher and attempt to publish the current package. Restrict it to the release tag convention, such as v*.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/publish.yml, line 6:

<comment>This pattern matches scratch tags as well as releases, so any tag can invoke the OIDC-enabled publisher and attempt to publish the current package. Restrict it to the release tag convention, such as `v*`.</comment>

<file context>
@@ -0,0 +1,50 @@
+on:
+  push:
+    tags:
+      - '*'
+
+permissions:
</file context>
Suggested change
- '*'
- 'v*'

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.

1 participant