-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Also consider actions user when evaluating push privileges on protected branch #35057
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
base: main
Are you sure you want to change the base?
Conversation
The question is: do we want to make the Actions user be able to "push" (even more: have "write" permission to the whole repo)? Another question is what's the GitHub's behavior? (I don't know details, so just ask questions) |
For me personally it's very much expected that if I explicitly allow pushing to a branch within its protection rules, that that permission carries over to Actions tokens. The fact that it currently carries over to deploy keys, but not Actions tokens is rather unintuitive imo. In GitHub, this is handled via the permissions section of the workflow config, which we do not support yet (relevant discussion: #24635). Edit:
Actions tokens do already have "write" permissions to the whole repo, save for protected branches (regardless of their push settings, which this PR aims to rectify). |
Then should we implement the permissions first? Or, could there be a security problem? for example: a contributor with read access proposed a PR, then the Actions run the PR, then the PR use the Actions token to write the repository (which it shouldn't because the contributor only has "read" access)? |
Hmm, if it is already so, then I don't have more questions. |
To clarify, Actions run from the main repo have write permissions, forked repos are treated differently. See the relevant section here: gitea/routers/private/hook_pre_receive.go Lines 493 to 504 in 6599efb
Later there is an assertion that will return if the user cannot write to the repo (i.e. if it's an Action run from another repo): gitea/routers/private/hook_pre_receive.go Lines 65 to 77 in 6599efb
(if my understanding is correct) |
But "agit" PR will run in the same base repo? |
It depends on whether the workflow runs on
Any other workflow trigger, like |
I'm not familiar with agit, but if PRs created using it are always in the base repo, then they will have access to that repo's secrets & variables, as well as read/write permission (the latter coming in this PR). |
I would suggest that we'd better to figure out the whole (and correct) design first and fully understand the problem before changing the behavior. |
Currently, when attempting to push to a protected branch from a Gitea Action using the provided token, the push will always fail, even if "enable push" is set in the branch protection rule.
Relevant log output:
This is because if a branch protection rule exists, only deploy keys are checked for push privileges, and it is not considered that the pusher may be an actions user.
See:
gitea/routers/private/hook_pre_receive.go
Lines 168 to 172 in 6599efb
gitea/routers/private/hook_pre_receive.go
Lines 254 to 277 in 6599efb
Also checking for the actions user ID solves this problem, and grants them the same permissions as deploy keys for the purposes of pushing / force-pushing, as imo would be expected behavior.