Skip to content

Commit 76e3111

Browse files
authored
Collaborator trust model should trust collaborators (#18539)
* Collaborator trust model should trust collaborators There was an unintended regression in #17917 which leads to only repository admin commits being trusted. This PR restores the old logic. Fix #18501 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 92e81e9 commit 76e3111

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

models/asymkey/gpg_key_commit_verification.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const (
7171
)
7272

7373
// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
74-
func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isCodeReader func(*user_model.User) (bool, error)) []*SignCommit {
74+
func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error)) []*SignCommit {
7575
newCommits := make([]*SignCommit, 0, len(oldCommits))
7676
keyMap := map[string]bool{}
7777

@@ -81,7 +81,7 @@ func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustMod
8181
Verification: ParseCommitWithSignature(c.Commit),
8282
}
8383

84-
_ = CalculateTrustStatus(signCommit.Verification, repoTrustModel, isCodeReader, &keyMap)
84+
_ = CalculateTrustStatus(signCommit.Verification, repoTrustModel, isOwnerMemberCollaborator, &keyMap)
8585

8686
newCommits = append(newCommits, signCommit)
8787
}
@@ -455,7 +455,7 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *use
455455

456456
// CalculateTrustStatus will calculate the TrustStatus for a commit verification within a repository
457457
// There are several trust models in Gitea
458-
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isCodeReader func(*user_model.User) (bool, error), keyMap *map[string]bool) (err error) {
458+
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error), keyMap *map[string]bool) (err error) {
459459
if !verification.Verified {
460460
return
461461
}
@@ -500,11 +500,11 @@ func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_
500500
var has bool
501501
isMember, has = (*keyMap)[verification.SigningKey.KeyID]
502502
if !has {
503-
isMember, err = isCodeReader(verification.SigningUser)
503+
isMember, err = isOwnerMemberCollaborator(verification.SigningUser)
504504
(*keyMap)[verification.SigningKey.KeyID] = isMember
505505
}
506506
} else {
507-
isMember, err = isCodeReader(verification.SigningUser)
507+
isMember, err = isOwnerMemberCollaborator(verification.SigningUser)
508508
}
509509

510510
if !isMember {

models/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func ConvertFromGitCommit(commits []*git.Commit, repo *repo_model.Repository) []
1818
user_model.ValidateCommitsWithEmails(commits),
1919
repo.GetTrustModel(),
2020
func(user *user_model.User) (bool, error) {
21-
return IsUserRepoAdmin(repo, user)
21+
return IsOwnerMemberCollaborator(repo, user.ID)
2222
},
2323
),
2424
repo,

modules/gitgraph/graph_models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *repo_model.Repository, git
117117
c.Verification = asymkey_model.ParseCommitWithSignature(c.Commit)
118118

119119
_ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
120-
return models.IsUserRepoAdmin(repository, user)
120+
return models.IsOwnerMemberCollaborator(repository, user.ID)
121121
}, &keyMap)
122122

123123
statuses, _, err := models.GetLatestCommitStatus(repository.ID, c.Commit.ID.String(), db.ListOptions{})

routers/web/repo/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func Diff(ctx *context.Context) {
351351
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
352352

353353
if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
354-
return models.IsUserRepoAdmin(ctx.Repo.Repository, user)
354+
return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
355355
}, nil); err != nil {
356356
ctx.ServerError("CalculateTrustStatus", err)
357357
return

routers/web/repo/view.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
799799
verification := asymkey_model.ParseCommitWithSignature(latestCommit)
800800

801801
if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
802-
return models.IsUserRepoAdmin(ctx.Repo.Repository, user)
802+
return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
803803
}, nil); err != nil {
804804
ctx.ServerError("CalculateTrustStatus", err)
805805
return nil

0 commit comments

Comments
 (0)