Skip to content

security: harden PyPI publishing against branch workflow dispatch #46

Closed

Description

@JuroOravec

Summary

High-priority supply-chain hardening is needed for the GitHub Actions to PyPI trust boundary.

A legitimate one-time citry-core==1.4.0 repair demonstrated that a maintainer with repository write access can:

  1. push a branch containing a modified revision of an already registered publishing workflow;
  2. manually dispatch that workflow revision because workflow_dispatch exists on the default branch;
  3. enter the shared pypi environment from the branch; and
  4. obtain an ephemeral OIDC credential accepted by PyPI Trusted Publishing.

This did not require a change to main, a new release tag, a stored PyPI token, an environment approval, or a matching deployment-branch rule. A compromised maintainer credential with write/workflow access could use the same trust path, while a maintainer watching mainly main and pull requests might miss the branch and deployment activity.

This is a hardening finding, not evidence that an unauthorized publish or credential compromise occurred.

Evidence captured on 2026-07-28

  • The pypi GitHub environment reports no protection rules and no deployment branch policy:

    {
      "protection_rules": [],
      "deployment_branch_policy": null
    }
  • These trusted-publishing workflows all currently combine workflow_dispatch, environment: pypi, and id-token: write:

    • .github/workflows/py--citry--publish.yml
    • .github/workflows/py--citry-core--publish.yml
    • .github/workflows/py--pygments-citry--publish.yml
  • Each checked-in publish step currently has a tag condition. That condition is useful for normal runs but is not an independent security boundary because a branch revision of the same trusted workflow file can alter it.

  • No repository rulesets currently protect the release-tag namespaces.

  • Authorized proof: branch release/citry-core-1.4.0-pyemscripten, commit 924b993fb6c622cf275237da9a11ff38c31eaf51, workflow run 30396856106. The branch-only job entered pypi and published successfully without approval.

The prerequisite is meaningful: this is not available to an unauthenticated visitor or an ordinary fork pull request. The threat is takeover or misuse of a credential/account that can push a repository branch and dispatch Actions workflows. The concern is that this access can be escalated into package publication without a reviewed default-branch change or release-tag workflow.

Why the current layers are insufficient

PyPI Trusted Publishing authorizes a GitHub repository, workflow filename, and optional environment. It does not inherently require the workflow to come from main or from a release tag. GitHub allows a manually dispatched workflow to select another branch with --ref when the workflow is dispatchable on the default branch.

Repository-local if: expressions cannot defend against a malicious rewrite of the same workflow on another repository branch. The strongest control needs to live outside the branch-controlled YAML, primarily in GitHub environment deployment policies and protected tag rules.

References:

Immediate containment

  • Restrict the pypi environment to selected tag patterns only, covering the intended package namespaces:
    • citry-core@*
    • citry@*
    • pygments-citry@*
  • Do not allow ordinary branches or pull-request refs to deploy to pypi.
  • Add at least one required reviewer to pypi.
  • Enable Prevent self-review.
  • Disable administrator bypass for the environment if the repository's operating model permits it.
  • Verify that each PyPI project's Trusted Publisher configuration requires the exact workflow filename and the pypi environment.
  • Review recent Actions deployments, package upload histories, branches, tags, collaborators, deploy keys, GitHub Apps, and active PAT/session access for unexpected activity. Record the audit result here. No current evidence requires package deletion or token rotation solely because of this finding.

Workflow and repository hardening

  • Remove workflow_dispatch from workflows that can publish, or split manual build/test workflows from tag-only publish workflows.
  • Ensure manual verification workflows have no pypi environment, no id-token: write, and no release-level contents: write.
  • Keep the actual publisher minimal and tag-only. Build/test jobs should pass an exact artifact inventory to one narrowly permissioned publishing job.
  • Add tag rulesets for the three package tag namespaces. Restrict tag creation, update, and deletion to the intended release role/process.
  • Consider required approval for every PyPI deployment even when triggered by a protected tag. A compromised release-capable account should not be sufficient by itself.
  • Add a repository check that flags future combinations of workflow_dispatch, environment: pypi, and publishing permissions/actions. This is defense in depth for reviewed changes, not a substitute for environment policy.
  • Document the security boundary, manual-repair procedure, approval path, and audit steps in docs/codebase.md.
  • Replace or retire the one-off repair branch after it is no longer needed for audit, according to the agreed retention policy.

Acceptance criteria

  • A workflow dispatched from an ordinary repository branch cannot enter pypi or obtain an OIDC token for that environment, even if the branch modifies a registered publishing workflow file.
  • Normal protected release tags can publish citry-core, citry, and pygments-citry after the configured approval.
  • Manual build/test workflows continue to work without publishing permissions.
  • PyPI publisher identities, GitHub environment configuration, tag rulesets, and required reviewers are independently verified and recorded.
  • The release documentation and automated workflow-policy checks cover this regression.

Activity

  1. added
    bug
    github_actions
    on Jul 28, 2026
  2. JuroOravec commented on Jul 28, 2026

    @JuroOravec
    MemberAuthor

    Applied the immediately actionable GitHub-side controls on 2026-07-28:

    • pypi now uses selected deployment refs with tag-only policies for citry-core@*, citry@*, and pygments-citry@*; it has no allowed branch or pull-request patterns.
    • Added active tag ruleset Protect package release tags.
    • The ruleset restricts creation, update, and deletion of all three release-tag namespaces.
    • The bypass list contains only the current release account, JuroOravec, rather than the general write/admin roles.

    This preserves the existing manual tag release flow and blocks other current or future collaborators from creating, moving, or deleting release tags. It does not defend against compromise of the sole bypass account itself; a separate release identity or second-person approval is still required for that threat.

  3. JuroOravec commented on Sep 10, 2026

    @JuroOravec
    MemberAuthor

    The technical remediation is complete. The release process uses qualified artifacts published from main, with separate controls for publishing credentials, tag creation and generated-site updates. The remaining item before closing this issue is the owner's private-account audit confirmation.

    • All three privileged environments (pypi, vscode-marketplaces, and release-maintenance) allow only the exact main branch. Legacy tag allowances have been removed.
    • A harmless modified publishing workflow on a temporary branch was rejected by all three environments before any job step ran: run 34462975239. This directly tests the branch-dispatch route described in this issue. The probe branch was deleted after retaining its commit and rejection evidence.
    • main has separate rulesets for PRs and required checks. JuroOravec has a PR-only bypass of the checks ruleset, allowing selected PRs to merge without waiting for checks. That exception does not bypass the PR requirement or resolved review conversations, and does not permit direct pushes. The dedicated release App is the only bypass actor for the PR ruleset. Its branch bypass is not path-scoped; the trusted workflow restricts generated-site writes to the documented paths. A separate rule prevents deletion and force pushes without bypass.
    • PR110 isolated generated-site updates in an App job. The release docs run used that App to commit the verified runtime and snapshot, and the docs deployment succeeded. The later replay started another docs update, which is still running at this audit checkpoint.
    • Merged PR114 separates publication, protected tag creation and GitHub Release creation. The first replay stopped because the reusable tag workflow received an empty App secret. Merged PR120 puts the isolated tag job directly in each of the six package publishers, retaining the shared Python helper. The App key is confined to tag creation and generated-site updates. Transfers and existing Releases are verified against the qualified bytes; mismatches stop recovery.
    • Active tag-creation ruleset 22759193 covers all six package tag namespaces and grants creation only to release App 4895716. Separate ruleset 22759196 blocks tag updates and deletion with no bypass actors.
    • Candidate replay 34469114248 completed successfully across all five selected package workers. It verified existing public files and recovered through matching existing tags and Releases. This exercised recovery and App-secret access, not live creation of a new protected tag.
    • The repository policy validator checks publishing environments, job dependencies, helper checkout refs and App-key placement. docs/codebase.md documents the boundary and recovery procedure.

    The accessible audit found only the expected maintainer collaborator, no deploy keys, and the expected installed Apps. Public PyPI provenance for 44 files across all five Python projects identifies the intended repository, package workflow and pypi environment. This checks the identities used for those publications; it does not enumerate private PyPI publisher settings or unused upload tokens, nor inspect private maintainer sessions/PATs. No unexpected activity was identified in the inspected records.

    Independent PR/deployment approval is deferred to #112, at the maintainer's request, until a second trusted maintainer is available. Administrator control over repository settings remains a stated trust boundary. The original repair branch is retained as audit evidence.

    Keep this issue open pending the owner's confirmation of the private PyPI publisher, upload-token and maintainer session/PAT audit. The public provenance checks above do not substitute for that confirmation. Independent approvals remain outside this issue's closure criteria and are tracked in #112.

  4. JuroOravec commented on Sep 10, 2026

    @JuroOravec
    MemberAuthor

    The maintainer has now confirmed the remaining private-account audit: all five PyPI Trusted Publisher configurations are correct, unnecessary PyPI API tokens were removed and none remain, and GitHub personal access was reviewed and cleaned up with all retained access recognized.

    Together with the recorded environment rejection test, protected main/tag rules, successful release recovery and documentation, this completes the current-process remediation and audit. Closing this issue. Independent approval requirements when the team grows remain tracked separately in #112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggithub_actions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions