8000 Fix ephemeral runner deletion by ChristopherHX · Pull Request #34447 · go-gitea/gitea · GitHub
[go: up one dir, main page]

Skip to content

Fix ephemeral runner deletion #34447

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ChristopherHX
Copy link
Contributor
@ChristopherHX ChristopherHX commented May 13, 2025
  • repository deletion, deletes active tasks as well skips regular cleanup
  • user deletion, implicitly deletes active tasks as well skips regular cleanup
  • delete ephemeral runners once status changes to done
  • You no longer see used ephemeral runners after the task is done, if you see one the cron job takes care of it

* repository deletion, deletes active tasks as well
* user deletion, implicitly deletes active tasks as well
* delete ephemeral runners once status changes to done
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 13, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 13, 2025
@ChristopherHX ChristopherHX added the backport/v1.24 This PR should be backported to Gitea 1.24 label May 13, 2025
@ChristopherHX
Copy link
Contributor Author
ChristopherHX commented May 13, 2025

@NorthRealm Thank you for you workflow run deletion PR, without yours I might have not noticed these defects in my ephemeral runner implementation.

I also noticed you can delete running workflows / tasks by deleting a User / Repository. If the ephemeral runner is shared to this repository this leaks....

Since the database is frozen for 1.24, I think this is the best that could be backported to 1.24.

Comment on lines -44 to -45
assert.Len(t, runnerList.Entries, 4)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad idea from myself for adding more test data, better just assert existence of a specific id. If we actually want to test paging via fixtures this problem reappears here.

@@ -160,16 +158,20 @@ func testActionsRunnerOwner(t *testing.T) {
runnerList := api.ActionRunnersResponse{}
DecodeJSON(t, runnerListResp, &runnerList)

assert.Len(t, runnerList.Entries, 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad idea from myself for adding more test data, better just assert existence of a specific id

@ChristopherHX ChristopherHX marked this pull request as ready for review May 13, 2025 19:12
// I would make ephemeral runners fully delete directly before formally finishing the task
//
// See also: https://github.com/go-gitea/gitea/pull/34337#issuecomment-2862222788
if err := actions_service.CleanupEphemeralRunnersByRepoID(ctx, repoID); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 178, &actions_model.ActionRunner{RepoID: repoID}, all runners will be deleted

Copy link
Contributor Author
@ChristopherHX ChristopherHX May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes all repository runners are going to be deleted by Line 178.
I also didn't notice this problem in my initial ephemeral runner Pull Request.

If I create an ephemeral runner on global/user/org level this scenario is possible

  • global ephemeral runner 1 picks task 1 from repo_id 5 (not deleted by line Line 178)
  • task 1 from repo_id 5 keeps running
  • you trigger repository deletion of repo_id 5 (anybody who can create an account can do)
  • task 1 is now deleted
    • global ephemeral runner 1 is not deleted
    • the ephemeral runner protection to prevent to pick a second task is now broken
    • allows picking a second task until it is deleted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean this addition lines looks duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not, this code deletes "global/user/org ephemeral runner 1" that is not part of the repository. I will update the comment.

The added repository deletion test must fail if this is removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed method and added correct comment

	// CleanupEphemeralRunnersByPickedTaskOfRepo deletes ephemeral global/org/user that have started any task of this repo
	// The cannot pick a second task hardening for ephemeral runners expect that task objects remain available until runner deletion
	// This method will delete affected ephemeral global/org/user runners
	// &actions_model.ActionRunner{RepoID: repoID} does only handle ephemeral repository runners

Any ephemeral runner that has picked any job of the to be deleted repository must be deleted.

Not relevant for normal runners, since they are allowed to pick another job from another repository.

See test testEphemeralActionsRunnerDeletionByRepository, that verifies the runner that previously wasn't deleted is deleted for a running task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v1.24 This PR should be backported to Gitea 1.24 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0