Skip to content

Support the "Trusted Publishing" flow directly in twine #999

Closed
@di

Description

@di

Last month PyPI added support for "Trusted Publishing": https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/. This uses an credential exchange flow to swap OIDC credentials with a short-lived PyPI API token, removing the need to maintain long-lived credentials/secrets. (More technical details on the exchange are here: https://docs.pypi.org/trusted-publishers/internals/)

We were able to do launch this without modifying twine directly because we instead updated https://github.com/pypa/gh-action-pypi-publish to do the token exchange prior to invoking twine upload.

That said, we're actively working on expanding support to other providers for which we don't have "canonical" workflows (such as pypi/warehouse#13551, pypi/warehouse#13575, and pypi/warehouse#13888).

For these providers (as well as for GitHub users who prefer not to use the pypi-publish GitHub action for whatever reason) it would be preferable to have twine be able to support the OIDC/API token exchange directly.

This would ideally include:

  1. detecting whether an "ambient" OIDC token is available at the time twine upload is run (this can be handled by https://pypi.org/p/id, so twine doesn't need to understand how to do this for N different providers)
  2. verifying that the OIDC token is acceptable for use with PyPI (this just requires that the aud claim of the token is set to the audience of the index that twine is attempting to upload to)
  3. exchanging the OIDC token for a PyPI API token (this is essentially the same as what the pypi-publish workflow does here: https://github.com/pypa/gh-action-pypi-publish/blob/110f54a3871763056757c3e203635d4c5711439f/oidc-exchange.py)

The alternative to twine supporting this directly is that the end user has to perform a fairly manual token exchange themselves directly (https://docs.pypi.org/trusted-publishers/using-a-publisher/#the-manual-way) which would be pretty bad UX overall.

Opening this issue to make sure maintainers are on board with the general idea before any implementation is started, please let me know if you have any thoughts.

(cc @woodruffw)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestsecurityIssue that is related to security features of twine or PyPI

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions