Join our Newsletter — 33% off our NHI Course
Home› FAQ› Governance, Ownership & Risk› How do organisations implement PyPI Trusted Publishing?
Governance, Ownership & Risk

How do organisations implement PyPI Trusted Publishing?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 18, 2026 Domain: Governance, Ownership & Risk

Organisations implement PyPI Trusted Publishing by replacing long-lived upload secrets with short-lived, identity-bound publishing from an approved automation system. Configure the repository and PyPI trust relationship, restrict who can publish, and verify that release workflows only mint credentials for the intended package and branch or tag flow.

What Trusted Publishing changes operationally

trusted publishing changes PyPI release hygiene from secret possession to identity-based authorization. Instead of storing a long-lived upload token in a CI secret store, the publishing workflow requests a short-lived credential only when the approved release path runs. That reduces secret sprawl, narrows the usable window, and makes the release channel itself part of the control.

The practical shift is that the publishing job, the repository, and PyPI must agree on which workflow is allowed to mint a release credential. Teams should treat that trust relationship as production access, not just a convenience feature, because a mis-scoped workflow can publish a malicious or unintended package version as easily as a stolen token can.

How to configure the repository and PyPI trust relationship

Start by binding the package to the exact automation path that is allowed to publish it. That means choosing the repository, the branch or tag pattern, and the release workflow that PyPI should trust, then limiting that trust to the smallest viable scope. The direct answer’s emphasis on an approved automation system is important: the workflow identity is the control point, not the person who merges code.

Keep the release path narrow enough that it is easy to reason about. A release workflow should be separate from test jobs, should run only from protected refs, and should only mint a publishing credential for the intended project. The CI/CD Pipeline Identity Security Guide is useful here because the same design principle applies: keyless federation, pinned workflows, and restricted token permissions are safer than broad standing secrets.

Repository policy matters as much as PyPI-side trust. Restrict who can edit the release workflow, who can approve protected branches or tags, and who can change package metadata or release automation. If an attacker can alter the workflow definition, they can often redirect the trust relationship even when no upload secret exists.

Release workflow controls that prevent accidental or malicious publication

The release workflow should verify the package name, the repository, and the ref before publication. That check prevents a workflow from being reused across unrelated packages or from publishing on the wrong branch after a merge or tagging mistake. For organisations that publish multiple artifacts, this validation is especially important because one CI pipeline can otherwise become a shared publishing path.

Use the smallest possible publishing scope and keep the automation path auditable. A good release job should be predictable, deterministic, and easy to inspect after the fact. The Malicious Package and Dependency Confusion Guide is a relevant companion because it explains why package namespace mistakes, provenance gaps, and registry confusion can turn a normal release into a supply-chain event.

Trusted Publishing also works best when teams remove old upload secrets rather than leaving them in place as a fallback. If a legacy token remains available, the organisation has not fully moved to identity-bound publishing, and the weaker path becomes the one most likely to be abused during an incident. The safer operating model is to make the trusted path the only path, then monitor it closely.

Migration, exceptions, and verification after rollout

Migration should be treated as a control change, not a cosmetic update. Replace stored PyPI upload secrets, confirm that the release pipeline can still publish through the trusted path, and check that no other automation or maintainer process can bypass it. The point is to avoid a dual-path state where one flow uses Trusted Publishing and another still depends on long-lived credentials.

Where teams must support an exception, the exception should be explicit, time-bound, and reviewed. That usually means documenting why a package cannot yet use the trusted path, who approved the exception, and when it will be removed. If the release process also touches other sensitive build steps, such as signing or artifact promotion, make sure the publishing boundary remains separate from those downstream tasks.

Risk and Threat Considerations

Trusted Publishing reduces token theft risk, but it shifts attention to workflow integrity and trust configuration. If the release pipeline, repository permissions, or branch protections are weak, an attacker may not need to steal a secret at all, they can abuse the publishing automation itself. That makes release-path compromise, workflow tampering, and ref misbinding the main failure modes to watch.

Failure mechanism: A malicious or overbroad workflow can mint a valid short-lived publishing credential for the wrong package, wrong ref, or wrong release event, turning a legitimate trust relationship into an abuse path.

Impact: An attacker can publish a trojanised release, replace an expected package version, or bypass the protection that Trusted Publishing was meant to provide.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while CIS Controls v8 sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-01 — Improper OffboardingTrusted publishing reduces standing secret risk when release paths change.
NHI-02 — Secret LeakageThe topic replaces long-lived upload secrets with short-lived identity-bound credentials.
NHI-05 — Overprivileged NHIRelease workflows must be narrowly scoped to the intended package and ref.
Recommendation — Remove legacy PyPI upload secrets when moving packages to trusted publishing. Eliminate static publishing secrets and use short-lived release credentials. Restrict publishing workflows to the minimum package and branch or tag scope.
CIS Controls v8CIS-6 — Access Control ManagementThe question is about restricting who can publish and who can alter the release path.
CIS-16 — Application Software SecurityPackage publishing is a software release control that needs protected automation.
Recommendation — Limit who can approve, change, or execute the publishing workflow. Protect release automation and verify package publication paths before release.

Practitioner Guidance

What to verify: Confirm that only the intended repository, package, and protected ref can trigger publication, and that the workflow cannot be edited by broader contributor groups. Verify that the trusted path is the only publishing path left after migration.

Common mistake: Teams often secure the PyPI side but leave workflow permissions, branch protections, or release tagging rules too loose. That preserves a practical bypass even when the upload secret has been removed.

Practitioner takeaway: Trusted Publishing is only as strong as the release workflow that mints the credential, so the real control objective is to bound who can cause publication, not just to eliminate static secrets.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 18, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org