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

Clarify Actions resources ownership #31724

Merged
merged 9 commits into from
Aug 1, 2024

Conversation

wolfogre
Copy link
Member

@wolfogre wolfogre commented Jul 29, 2024

Fix #31707.

Also related to #31715.

Some Actions resources could has different types of ownership. It could be:

  • global: all repos and orgs/users can use it.
  • org/user level: only the org/user can use it.
  • repo level: only the repo can use it.

There are two ways to distinguish org/user level from repo level:

  1. {owner_id: 1, repo_id: 2} for repo level, and {owner_id: 1, repo_id: 0} for org level.
  2. {owner_id: 0, repo_id: 2} for repo level, and {owner_id: 1, repo_id: 0} for org level.

The first way seems more reasonable, but it may not be true. The point is that although a resource, like a runner, belongs to a repo (it can be used by the repo), the runner doesn't belong to the repo's org (other repos in the same org cannot use the runner). So, the second method makes more sense.

And the first way is not user-friendly to query, we must set the repo id to zero to avoid wrong results.

So, #31715 should be right. And the most simple way to fix #31707 is just:

-	shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID)
+	shared.GetRegistrationToken(ctx, 0, ctx.Repo.Repository.ID)

However, it is quite intuitive to set both owner id and repo id since the repo belongs to the owner. So I prefer to be compatible with it. If we get both owner id and repo id not zero when creating or finding, it's very clear that the caller want one with repo level, but set owner id accidentally. So it's OK to accept it but fix the owner id to zero.

@wolfogre wolfogre added type/enhancement An improvement of existing functionality topic/gitea-actions related to the actions of Gitea labels Jul 29, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 29, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 29, 2024
@wolfogre wolfogre added this to the 1.23.0 milestone Jul 29, 2024
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Jul 29, 2024
@github-actions github-actions bot removed the modifies/api This PR adds API routes or modifies them label Jul 29, 2024
lafriks pushed a commit that referenced this pull request Jul 29, 2024
Fix #31707.

It's split from #31724.

Although #31724 could also fix #31707, it has change a lot so it's not a
good idea to backport it.
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Jul 29, 2024
Fix go-gitea#31707.

It's split from go-gitea#31724.

Although go-gitea#31724 could also fix go-gitea#31707, it has change a lot so it's not a
good idea to backport it.
wolfogre added a commit that referenced this pull request Jul 30, 2024
)

Backport #31725 by @wolfogre

Fix #31707.

It's split from #31724.

Although #31724 could also fix #31707, it has change a lot so it's not a
good idea to backport it.

Co-authored-by: Jason Song <[email protected]>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 30, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 1, 2024
@wolfogre wolfogre added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 1, 2024
@wolfogre wolfogre enabled auto-merge (squash) August 1, 2024 08:34
@wolfogre wolfogre merged commit a33e74d into go-gitea:main Aug 1, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 1, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Aug 2, 2024
* giteaofficial/main:
  Clear up old Actions logs (go-gitea#31735)
  Fix createElementFromAttrs bug (go-gitea#31751)
  bump vue-bar-graph (go-gitea#31705)
  Use UTC as default timezone when schedule Actions cron tasks (go-gitea#31742)
  Add permission description for API to add repo collaborator (go-gitea#31744)
  Clarify Actions resources ownership (go-gitea#31724)
  Exclude protected branches from recently pushed (go-gitea#31748)
  [skip ci] Updated translations via Crowdin
  Distinguish LFS object errors to ignore missing objects during migration (go-gitea#31702)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. topic/gitea-actions related to the actions of Gitea type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runner registration token via API is broken for repo level runners
4 participants