forked from mindersec/minder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle github repository transfer events. (mindersec#4130)
Github webhook events having type `repository` and action `transferred` are handled by producing an internal event that triggers an evaluation. Despite being safe, it cannot lead to any useful action since the github app installation lost permissions to operate on the repository. This change makes it so that `repository.transferred` events are handled as deletions. In order for such deletion to be successful, 403 Forbidden errors on webhook deletions must be handled gracefully, so that repository deletion can terminate without errors. This is safe since (b) there's nothing Minder can do about this, having lost the necessary permissions, and (b) repository registration removes stale webhooks. The latter point is relevant to fix repository transfers when auto registration is enabled: in these cases, repository ownership is migrated before the event is delivered to Minder, making it impossible to cleanup webhooks, which leads to an SQL deletion failure, which eventually makes it impossibile to re-register the repository under the destination project. Fixes mindersec#3274 Co-authored-by: Don Browne <[email protected]>
- Loading branch information
Showing
5 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,10 +343,6 @@ func (s *UnitTestSuite) TestHandleWebHookUnexistentRepoPackage() { | |
|
||
<-evt.Running() | ||
|
||
// mockStore.EXPECT(). | ||
// GetRepositoryByRepoID(gomock.Any(), gomock.Any()). | ||
// Return(db.Repository{}, sql.ErrNoRows) | ||
|
||
ts := httptest.NewServer(srv.HandleGitHubWebHook()) | ||
|
||
event := github.PackageEvent{ | ||
|
@@ -1759,7 +1755,7 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
}, | ||
), | ||
), | ||
topic: events.TopicQueueEntityEvaluate, | ||
topic: events.TopicQueueReconcileEntityDelete, | ||
statusCode: http.StatusOK, | ||
//nolint:thelper | ||
queued: func(t *testing.T, event string, ch <-chan *message.Message) { | ||
|
@@ -1851,7 +1847,7 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
event: "repository", | ||
// https://pkg.go.dev/github.com/google/go-github/[email protected]/github#RepositoryEvent | ||
payload: &github.RepositoryEvent{ | ||
Action: github.String("transferred"), | ||
Action: github.String("created"), | ||
Repo: &github.Repository{ | ||
ID: github.Int64(12345), | ||
Name: github.String("minder"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters