Skip to content

Fix verifyMergeable functionality#1316

Open
IITI-tushar wants to merge 1 commit into
gittuf:mainfrom
IITI-tushar:fix-verifymergeable-issue-1315
Open

Fix verifyMergeable functionality#1316
IITI-tushar wants to merge 1 commit into
gittuf:mainfrom
IITI-tushar:fix-verifymergeable-issue-1315

Conversation

@IITI-tushar

Copy link
Copy Markdown
Contributor

Refers #1315

Description

This pull request makes a targeted update to the logic for verifying principals in the verifyGitObjectAndAttestationsUsingVerifiers function. The change ensures that only the principals actually counted toward the verification threshold are accepted, rather than all trusted principals.

  • Verification logic update:
    • In verifyGitObjectAndAttestationsUsingVerifiers (internal/policy/verify.go), changed assignment so that only the principals used to meet the threshold (trustedUsedPrincipalIDs) are accepted, instead of all trusted principals (trustedPrincipalIDs). This tightens the logic to accurately reflect which principals contributed to verification.

AI Usage

  • I did not use generative AI at all in making the content of this pull
    request.
  • I did use generative AI in some form in making the content of this
    pull request. I have described my use of AI below.

Contributor Checklist

  • I have manually reviewed all content submitted to gittuf in this pull
    request.
  • I fully understand the content I am submitting.
  • The changes introduced are documented and have tests included if
    applicable.
  • My changes do not infringe on copyright/trademarks/etc.
  • All commits in this pull request include a DCO
    Signoff
    .
  • By submitting this pull request, I agree to follow the gittuf Code of
    Conduct
    .

@patzielinski patzielinski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for sending this in, @IITI-tushar.

Can you also add tests for this to make sure this doesn't regress?

Signed-off-by: Tushar Saxena <019saxenatushar@gmail.com>
Copilot AI review requested due to automatic review settings May 1, 2026 19:45
@IITI-tushar IITI-tushar force-pushed the fix-verifymergeable-issue-1315 branch from 7447544 to af83670 Compare May 1, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens VerifyMergeable/VerifyMergeableForCommit verification by ensuring global threshold checks only count principals that actually contributed toward meeting the verification threshold, rather than counting all trusted principals.

Changes:

  • Fix verifyGitObjectAndAttestationsUsingVerifiers to set acceptedPrincipalIDs to trustedUsedPrincipalIDs in mergeable mode.
  • Add regression tests intended to cover the global-threshold bypass scenario in mergeable verification paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/policy/verify.go Corrects accepted-principal accounting in mergeable verification to prevent inflating principal counts for global threshold checks.
internal/policy/verify_test.go Adds new test cases meant to ensure mergeable verification fails when global thresholds aren’t satisfied.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1381 to +1399
repo, _ := createTestRepository(t, func(t *testing.T) *State {
state := createTestStateWithThresholdPolicyAndGitHubAppTrustForMixedAttestations(t)

rootMetadata, err := state.GetRootMetadata(false)
require.NoError(t, err)
require.NoError(t, rootMetadata.AddGlobalRule(
tufv01.NewGlobalRuleThreshold("global-threshold-3", []string{"git:refs/heads/main"}, 3),
))

signer := setupSSHKeysForSigning(t, rootKeyBytes, rootPubKeyBytes)
rootEnv, err := dsse.CreateEnvelope(rootMetadata)
require.NoError(t, err)
rootEnv, err = dsse.SignEnvelope(testCtx, rootEnv, signer)
require.NoError(t, err)

state.Metadata.RootEnvelope = rootEnv
require.NoError(t, state.preprocess())
return state
})

@IITI-tushar IITI-tushar May 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot give fix based on this feedback

Comment on lines +2082 to +2100
repo, _ := createTestRepository(t, func(t *testing.T) *State {
state := createTestStateWithThresholdPolicyAndGitHubAppTrustForMixedAttestations(t)

rootMetadata, err := state.GetRootMetadata(false)
require.NoError(t, err)
require.NoError(t, rootMetadata.AddGlobalRule(
tufv01.NewGlobalRuleThreshold("global-threshold-3", []string{"git:refs/heads/main"}, 3),
))

signer := setupSSHKeysForSigning(t, rootKeyBytes, rootPubKeyBytes)
rootEnv, err := dsse.CreateEnvelope(rootMetadata)
require.NoError(t, err)
rootEnv, err = dsse.SignEnvelope(testCtx, rootEnv, signer)
require.NoError(t, err)

state.Metadata.RootEnvelope = rootEnv
require.NoError(t, state.preprocess())
return state
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VerifyMergeable counts all trusted principals instead of actual signers, bypassing global threshold checks

3 participants