Skip to content

Commit 997955f

Browse files
committed
fix: honor custom signer identity in chain evaluation
1 parent 9fd4af9 commit 997955f

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

pkg/sourcetool/backends/vcs/github/github.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,28 @@ var InherentControls = slsa.ControlNameSet{
6666
// slsa.SLSA_SOURCE_SCS_TWO_PARTY_REVIEW,
6767
}
6868

69-
func New(options *models.BackendOptions) *Backend {
70-
return &Backend{
69+
// Option configures a GitHub backend.
70+
type Option func(*Backend)
71+
72+
// WithVerifier configures the verifier used when reading prior attestations.
73+
func WithVerifier(verifier attest.Verifier) Option {
74+
return func(backend *Backend) {
75+
if verifier != nil {
76+
backend.verifier = verifier
77+
}
78+
}
79+
}
80+
81+
func New(options *models.BackendOptions, opts ...Option) *Backend {
82+
backend := &Backend{
7183
authenticator: auth.New(),
7284
Options: options,
85+
verifier: attest.GetDefaultVerifier(),
86+
}
87+
for _, opt := range opts {
88+
opt(backend)
7389
}
90+
return backend
7491
}
7592

7693
type Options struct {
@@ -81,6 +98,7 @@ type Options struct {
8198
type Backend struct {
8299
authenticator *auth.Authenticator
83100
Options *models.BackendOptions
101+
verifier attest.Verifier
84102
}
85103

86104
// getGitHubConnection builds a github connector to a repository
@@ -152,7 +170,7 @@ func (b *Backend) GetBranchControlsAtCommit(ctx context.Context, branch *models.
152170
// We need to manually check for PROVENANCE_AVAILABLE which is not
153171
// handled by ghcontrol
154172
attester, err := attest.NewAttester(
155-
attest.WithBackend(b), attest.WithVerifier(attest.GetDefaultVerifier()),
173+
attest.WithBackend(b), attest.WithVerifier(b.verifier),
156174
attest.WithAuthenticator(b.authenticator),
157175
)
158176
if err != nil {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: Copyright 2026 The SLSA Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package github
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/slsa-framework/source-tool/pkg/attest"
12+
"github.com/slsa-framework/source-tool/pkg/sourcetool/models"
13+
)
14+
15+
func TestNewUsesDefaultVerifier(t *testing.T) {
16+
t.Parallel()
17+
18+
backend := New(&models.BackendOptions{})
19+
verifier, ok := backend.verifier.(*attest.BndVerifier)
20+
21+
require.True(t, ok)
22+
require.Equal(t, attest.DefaultVerifierOptions, verifier.Options)
23+
}
24+
25+
func TestNewUsesConfiguredVerifier(t *testing.T) {
26+
t.Parallel()
27+
28+
verifier := attest.NewBndVerifier(attest.VerificationOptions{
29+
ExpectedIssuer: "https://token.actions.githubusercontent.com",
30+
ExpectedSan: "https://github.com/acme/project/.github/workflows/provenance.yml@refs/heads/main",
31+
})
32+
33+
backend := New(&models.BackendOptions{}, WithVerifier(verifier))
34+
35+
require.Same(t, verifier, backend.verifier)
36+
}
37+
38+
func TestWithVerifierIgnoresNil(t *testing.T) {
39+
t.Parallel()
40+
41+
backend := New(&models.BackendOptions{}, WithVerifier(nil))
42+
43+
require.NotNil(t, backend.verifier)
44+
}

pkg/sourcetool/tool.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ func New(funcs ...ConfigFn) (*Tool, error) {
5252
}
5353
}
5454

55-
t.backend = github.New(&t.Options.BackendOptions)
56-
5755
// Build the attestation verifier, honoring any identity overrides
5856
verifierOptions := attest.DefaultVerifierOptions
5957
if t.Options.ExpectedIssuer != "" {
@@ -65,10 +63,16 @@ func New(funcs ...ConfigFn) (*Tool, error) {
6563
verifierOptions.ExpectedSan = t.Options.ExpectedSan
6664
verifierOptions.AlternateSans = nil
6765
}
66+
verifier := attest.NewBndVerifier(verifierOptions)
67+
68+
t.backend = github.New(
69+
&t.Options.BackendOptions,
70+
github.WithVerifier(verifier),
71+
)
6872

6973
// Create the tool's attester
7074
attester, err := attest.NewAttester(
71-
attest.WithVerifier(attest.NewBndVerifier(verifierOptions)),
75+
attest.WithVerifier(verifier),
7276
attest.WithBackend(t.backend),
7377
attest.WithGithubCollector(t.Options.InitGHCollector),
7478
attest.WithNotesCollector(t.Options.InitNotesCollector),

0 commit comments

Comments
 (0)