-
Notifications
You must be signed in to change notification settings - Fork 968
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
In Using a Publisher docs, call out that GitHub Actions permissions also need contents: read
to checkout private repositories
#17148
Comments
Thanks for filing an issue.
I don't think this is exactly true. For example, here's a workflow for At https://docs.pypi.org/trusted-publishers/using-a-publisher/ , we recommend adding a job-level permission, not a workflow-level permission: jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: pypi
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
# retrieve your distributions here
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1 The docs at https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token says:
My read of this is that job-level permissions are additive to default or specified workflow permissions, which seems to be the case based on that example. Here's another example that explicitly sets If you have an example workflow & run that is failing when only setting (PS, note that you have a typo, it's |
Thanks for the quick response! You're right about the typo, that was a mistake in the issue but not my code. Sorry about that. I've made edits to avoid confusion. I have been using a job-level permission. I think the issue could be that I'm attempting to checkout a private repository, whereas the examples you've seen are public. Here's the job contents if it helps. There's a custom action as the second step, but I saw failures in the first.
I can confirm that after I added the If this is only an issue for private repositories, I understand if that's less prevalent and doesn't meet the bar for a documentation update. |
content: read
to checkout repositoriescontent: read
to checkout private repositories
content: read
to checkout private repositoriescontents: read
to checkout private repositories
Indeed, seems like this is an undocumented behavior of private repositories: actions/checkout#445 (comment) And it's been identified here: pypa/gh-action-pypi-publish#237 Based on that, my understanding is that you would need to specify |
Oh, good find! If I'd seen that pypa/gh-action-pypi-publish#237 I wouldn't have opened this issue 😅 I didn't need the
So I think those are the defaults. Once I set the
I was surprised to see the Metadata permission is still present. I'll keep investigating on my end. It's clear I jumped to conclusions before opening this issue. Thank you for your patience and help refining the problem. |
I'm also happy to close this and follow pypa/gh-action-pypi-publish#237 if they're better owners. |
Huh, quite odd behavior. I think whatever the outcome in pypa/gh-action-pypi-publish#237 we'll want to do something similar in our docs, so OK to leave this open in addition. |
This docs page matches what I've been seeing: https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token Notably, the default "restricted" permissions set give read access to contents, metadata and packages like I saw without any Then we modified permissions, which is explained in https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token (emphasis mine)
So while I was surprised that read permission for metadata was still present, it seems to be a documented special case. No other permissions are available though unless they're explicitly set, which explains why I needed to add |
What's the problem this feature will solve?
https://docs.pypi.org/trusted-publishers/using-a-publisher/ gives examples of how to change a GitHub Actions workflow to use Trusted Publishing. There's an
IMPORTANT
comment that we add permissions to the job for writing OIDC tokens. I thought these permissions were merged with the default permissions. That's not true though, the permissions must be complete because they will override any defaults.Users who publish source distributions from a checkout of the GitHub repository, will also need the
contents: read
permission. Without it, the checkout fails withremote: Repository not found
. For more complete error output, see the bottom code block of https://github.com/orgs/community/discussions/57621 .Describe the solution you'd like
I'd like to see the documentation call out that
contents: read
is also required in the permissions to useactions/checkout
. I think the practice is common enough that it's worth clarifying. I expect most packages would publish using either a source distribution fromactions/checkout
, or wheels that are either built in the same job fromactions/checkout
or downloaded from a previous job withactions/download-artifact
. Downloading artifacts doesn't need any extra permissions, but the other two use cases will.The text was updated successfully, but these errors were encountered: