Skip to content
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

No permission to create comment #15

Open
sudo-bmitch opened this issue Mar 29, 2024 · 9 comments
Open

No permission to create comment #15

sudo-bmitch opened this issue Mar 29, 2024 · 9 comments

Comments

@sudo-bmitch
Copy link

While trying out this action, I'm encountering the error: "GraphQL: Resource not accessible by integration (addComment)".

I tried passing the GITHUB_TOKEN environment variable, setting the pull-requests: write permission on the workflow rather than only the job, and adding the issues: write permission, but so far no luck. My best guess is that the gh command is running in the context of your repository instead of my own.

Here's an example run: https://github.com/regclient/regclient/actions/runs/8484759635/job/23248287252?pr=706

(Note that I have continue-on-error: true defined on the job so that it always shows as successful.)

@captainbeardo
Copy link

This set of permissions I have set on my job that works are:

   permissions:
      contents: read
      pull-requests: write
      packages: read
      actions: read

That is only set on the job and I don't pass in GITHUB_TOKEN. I do have the coverage in an entirely separate job than the steps generating the coverage. I don't think that makes it work, but that is a difference.

@fgrosse
Copy link
Owner

fgrosse commented Apr 5, 2024

You can see at the top of your run when you expand the "Set up job" step and then click on GITHUB_TOKEN Permissions, that it actually has the wrong permissions (PullRequests: read) for some reason:

image

Just a hunch but can you check if you defined a variable or secret called GITHUB_TOKEN that is automatically passed into your jobs? You can check here: https://github.com/regclient/regclient/settings/secrets/actions

The reason why I am asking is because GITHUB_TOKEN is listed as environment variable in the log of your job (next to GH_TOKEN):
image

In my own working tests, the GITHUB_TOKEN is not defined as environment variable to the job step even though I copied your permissions settings.

@sudo-bmitch
Copy link
Author

There's no GITHUB_TOKEN secret explicitly defined, that's getting generated by GH for the individual workflow, and the quickly expires. Passing it through was an attempt to fix the issue since I've seen it used on actions like github.com/actions/stale and github.com/softprops/action-gh-release. Setting the top level permissions is flagged by the OpenSSF Scorecard, but they were opened up and retried with different variations without any luck.

@fgrosse
Copy link
Owner

fgrosse commented Apr 8, 2024

Not sure how to proceed here as the issue seems to be in your repository or workflow/job configuration.

I checked on a recent job run in your repo and verified the same issue I tried to explain in my last comment. The GITHUB_TOKEN Permissions are set to PullRequests: read but you need write access to comment on PRs.

image

Interestingly I also found another run in your repository which was triggered by merging into your main branch. In this case, the permissions are set to PullRequests: write.

@fgrosse
Copy link
Owner

fgrosse commented Apr 8, 2024

To debug this, you can try if there is any effect when you remove the top-level permissions field. Since you only have a single job in your Coverage Report workflow, it shouldn't actually change any semantics the way I understand it because job level permissions would overwrite default permissions if I understood the help page correctly.

Unfortunately the help doesn't state explicitly what happens if you set both the workflow and job permissions but it says you can either do one or the other but I suppose that's probably not meant in a strict way 🤷

You can use permissions either as a top-level key, to apply to all jobs in the workflow, or within specific jobs.

Good luck!

@sudo-bmitch
Copy link
Author

I checked on a recent job run in your repo and verified the same issue I tried to explain in my last comment. The GITHUB_TOKEN Permissions are set to PullRequests: read but you need write access to comment on PRs.

Looks like that is on the pull request open action, and the branch is my personal fork rather than the regclient project repo, so I'm guessing GitHub security is blocking the GitHub action from getting access to my personal fork, or maybe it's blocking the fork from getting access to the project.

To debug this, you can try if there is any effect when you remove the top-level permissions field.

Removing the top level permissions was one of the things I tested without luck, and adding the write permission there also didn't help.

I'll revisit this later when I have more time to see if I can sort out the difference in token permissions.

@sudo-bmitch
Copy link
Author

A quick check of the GITHUB_TOKEN permissions shows that GitHub removes all write access from the token on pull requests from a fork of a public repository. I'm going to need to do some more homework on if I want to change that setting since it's there for security reasons that I probably want.

https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

@fgrosse
Copy link
Owner

fgrosse commented Apr 12, 2024

Yeah that makes sense. I didn't really think about forks yet but I think this action wouldn't work well for them exactly because of these (sensible) security defaults 🤔

@sudo-bmitch
Copy link
Author

I believe the workaround would be to use pull_request_target, but that comes with a big security warning to not checkout code that was submitted by the user. The risk is probably fairly small for a job that can only update the pull request and that doesn't execute any of the code that is checked out. But given the added risk I'm going to put this on my backlog to revisit sometime when I have more availability.

Feel free to close this issue out if it's not a scenario you want to work on. Overall, I still think this is a neat idea that fills a need. So even if I'm not able to use it, thanks for creating it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants