-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for publishing to PyPI with a trusted publisher #7940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As I understand it, this needs no change at all in poetry itself: an API token derived from OIDC is a token like any other. It just happens to be short-lived. So I guess this feature request is asking for a github action? This repository does not currently publish any github actions. In my opinion that's fine, it's something that others can build on poetry if they want to. No need to for it to be another thing for maintainers here to worry about. Also for what it's worth: if there's already a satisfactory github action out there in the world that publishes using the authentication method that you like - I'd say just use that! |
I looked at pdm, fwiw that will do the pypi oidc exchange itself, if the github-specific environment variables are present (as set up by a workflow with In my opinion that is such a github-workflows-only piece of code that it belongs better in a github action than it does in poetry. (Or in pdm, for that matter!) But clearly the pdm project takes a different view, perhaps someone here will think that poetry should too. |
I see your point, @dimbleby, about this being very specific to GitHub workflows. In addition, PyPI's docs on security state:
This means, there should be 2 jobs:
And for job #2, there is indeed a perfectly fine and official solution from the PyPA. Perhaps it's a better separation of concerns and less code to maintain for the Poetry project to not duplicate the OIDC logic in Poetry. But then, I think it might be useful to provide a suggested workflow snippet in the Poetry docs. |
just ran into https://github.com/tschm/token-mint-action, which provides a github action for obtaining the necessary token - and reports that it did its testing with a poetry published project. so I double down on: there's no need for poetry to do anything here - and recommend closing this. |
If it's already supported, would it make sense to document this more fully to show how users can leverage this functionality to avoid future issues created for this? |
sure, go for it |
Poetry itself doesn't support trusted publishing, but the mentioned GitHub action can generate the token that poetry can use. I think it would still be best practice to have poetry support this feature natively since it concerns a security-sensitive matter. |
What "best practice"? You might just as well say that "it would be best practice to have something other than poetry handle this, since it concerns a security-sensitive matter" - both sentences are equally (un)convincing. If you are worried about security then in fact I expect you will have a better time auditing the tiny amount of code in |
Generally, it's not best practice to include more and more dependencies if it can be integrated with comparably little effort. Poetry is often appreciated for its user-friendly publishing process, this would furthermore add some degree of complexity. It makes the debugging and monitoring of a security-sensitive matter more complex. Is it somehow possible that the token from the GitHub action leaks, etc.?
There's one issue with your comparison. Poetry uses locked dependencies. This means that every dependency audit remains valid into the future, since the wheels are stored by a trusted party. GitHub actions can be modified when tags are used for reference. So you would have to pin the recommendation by commit hash, and audit every update as such. To be fair, it's possible that GitHub protection rules can guarantee a certain level of tag security, but I'm not sure how transparent this is. Pinning would remain the secure equivalent to poetry's locking. |
pretty much the exact opposite, actually
|
I just noticed that the project contains the lock file. What would be the reason for ignoring it? That all dependencies have their own trusted independent security supervision? Not that it affects the reasoning for my argument.
That's what I meant by pinning. Tagging a version, however, does not ensure that. |
the tool that understands you think that avoiding extra dependencies is valuable. I think that poetry already has more features than maintainers can cope with; and that this is a great example of something that is already solved by several other tools: poetry doesn't have to do everything. We can agree to disagree. Unless and until anyone submits a merge request, no-one has to make a decision either way. |
We have the poetry export for that, don't we?
I don't think that. And I mostly support the integration of smaller dependencies that don't have many maintainers, even if there is a greater risk that they have to be migrated to another dependency at some time in the future. This instance isn't a simple dependency though, it's more about complexity.
Of course, I only suggested leaving this issue open because it's not really "supported" by poetry. Unless there's an agreement that this falls out of scope. I'm not even a contributor, only a user who cares. Cheers! |
tschm here. I am one of the authors of https://github.com/tschm/token-mint-action. This action is using poetry as an example but it also has a place in a world without poetry. So, I don't think it should be integrated into poetry. I would like to point you to pypi/warehouse#13555... I think folks there are not happy with poetry publish in the first place. |
We now use PyPI trusted publishers. Using the mint token action until poetry supports trusted publishers natively. See: python-poetry/poetry#7940
We now use PyPI trusted publishers. Using the mint token action until poetry supports trusted publishers natively. See: python-poetry/poetry#7940
We now use PyPI trusted publishers. Using the mint token action until poetry supports trusted publishers natively. See: python-poetry/poetry#7940
fwiw it's no longer GitHub-specific since trusted publishers support other providers now https://blog.pypi.org/posts/2024-04-17-expanding-trusted-publisher-support/ |
that is true: but it does not mean that writing code in poetry to mint tokens in a github pipeline would help the other cases. Eg the exact means for getting a token from a gitlab pipeline is different than the mechanism for getting a token from a github pipeline, and so on. to my mind this speaks against doing anything in poetry: all the more reason to leave token-minting to CI pipeline actions written for the environment in which they run. |
Yeah, just wanted to comment on the update. For GitHub in particular I'd still recommend using hynek/build-and-inspect-python-package and pypa/gh-action-pypi-publish for publishing to PyPI. |
Until it's supported by Poetry. See python-poetry/poetry#7940
twine >= 6.1.0 supports publishing to PyPI using the "trusted publisher" openid-connect authentication mechanism, see the corresponding issue pypa/twine#999 and merge request pypa/twine#1194 |
Feature Request
pypi.org supports publishing packages via OIDC (with a "trusted publisher"). Since one of Poetry's benefits is building and publishing packages with a single CLI, I think it would be great to support this authentication scheme as well. Also
pdm
supports it already.Currently, the best approach seems to be using the GitHub Action
pypa/gh-action-pypi-publish
after building the distribution files using Poetry:The text was updated successfully, but these errors were encountered: