Skip to content

Commit

Permalink
Add verification key to repository verified status
Browse files Browse the repository at this point in the history
This adds the ID of the key that was successful to the verified status
for GitRepository resources.

Signed-off-by: Kevin McDermott <kevin@weave.works>
  • Loading branch information
bigkevmcd committed Jun 28, 2023
1 parent 01ced04 commit c159d26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
keyRings = append(keyRings, string(v))
}
// Verify commit with GPG data from secret
if _, err := commit.Verify(keyRings...); err != nil {
entity, err := commit.Verify(keyRings...)
if err != nil {
e := serror.NewGeneric(
fmt.Errorf("signature verification of commit '%s' failed: %w", commit.Hash.String(), err),
"InvalidCommitSignature",
Expand All @@ -914,9 +915,9 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
}

conditions.MarkTrue(obj, sourcev1.SourceVerifiedCondition, meta.SucceededReason,
"verified signature of commit '%s'", commit.Hash.String())
"verified signature of commit '%s' with key '%s'", commit.Hash.String(), entity)
r.eventLogf(ctx, obj, eventv1.EventTypeTrace, "VerifiedCommit",
"verified signature of commit '%s'", commit.Hash.String())
"verified signature of commit '%s' with key '%s'", commit.Hash.String(), entity)
return sreconcile.ResultSuccess, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ func TestGitRepositoryReconciler_verifyCommitSignature(t *testing.T) {
},
want: sreconcile.ResultSuccess,
assertConditions: []metav1.Condition{
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of commit 'shasum'"),
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, meta.SucceededReason, "verified signature of commit 'shasum' with key '3299AEB0E4085BAF'"),
},
},
{
Expand Down

0 comments on commit c159d26

Please # to comment.