Skip to content

Commit e7fc7a4

Browse files
Ian Lewislaurentsimon
Ian Lewis
andauthored
feat: Verification for when sha1 is specified in BYOB TRW (#641)
Fixes #600 --------- Signed-off-by: Ian Lewis <[email protected]> Signed-off-by: laurentsimon <[email protected]> Co-authored-by: laurentsimon <[email protected]>
1 parent 66ae6bc commit e7fc7a4

21 files changed

+1559
-397
lines changed

errors/errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var (
99
ErrorMismatchPackageName = errors.New("package name does not match provenance")
1010
ErrorMismatchBuilderID = errors.New("builderID does not match provenance")
1111
ErrorInvalidBuilderID = errors.New("builderID is invalid")
12+
ErrorInvalidBuildType = errors.New("buildType is invalid")
1213
ErrorMismatchSource = errors.New("source used to generate the binary does not match provenance")
1314
ErrorMismatchWorkflowInputs = errors.New("workflow input does not match")
1415
ErrorMalformedURI = errors.New("URI is malformed")

verifiers/internal/gha/builder.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"strings"
99

1010
fulcio "github.com/sigstore/fulcio/pkg/certificate"
11+
1112
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
1213
"github.com/slsa-framework/slsa-verifier/v2/options"
13-
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance/common"
14+
ghacommon "github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance/common"
1415
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils"
1516
)
1617

@@ -27,18 +28,18 @@ var (
2728
)
2829

2930
var defaultArtifactTrustedReusableWorkflows = map[string]bool{
30-
common.GenericGeneratorBuilderID: true,
31-
common.GoBuilderID: true,
32-
common.ContainerBasedBuilderID: true,
31+
ghacommon.GenericGeneratorBuilderID: true,
32+
ghacommon.GoBuilderID: true,
33+
ghacommon.ContainerBasedBuilderID: true,
3334
}
3435

3536
var defaultContainerTrustedReusableWorkflows = map[string]bool{
36-
common.ContainerGeneratorBuilderID: true,
37+
ghacommon.ContainerGeneratorBuilderID: true,
3738
}
3839

3940
var defaultBYOBReusableWorkflows = map[string]bool{
40-
common.GenericDelegatorBuilderID: true,
41-
common.GenericLowPermsDelegatorBuilderID: true,
41+
ghacommon.GenericDelegatorBuilderID: true,
42+
ghacommon.GenericLowPermsDelegatorBuilderID: true,
4243
}
4344

4445
var JReleaserRepository = httpsGithubCom + jReleaserActionRepository

verifiers/internal/gha/npm.go

+34-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
intoto "github.com/in-toto/in-toto-golang/in_toto"
1616
"github.com/secure-systems-lab/go-securesystemslib/dsse"
1717
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
18+
"github.com/slsa-framework/slsa-verifier/v2/options"
1819
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance"
1920
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance/common"
2021
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils"
@@ -68,6 +69,7 @@ func (b *BundleBytes) UnmarshalJSON(data []byte) error {
6869
type Npm struct {
6970
ctx context.Context
7071
root *TrustedRoot
72+
verifiedBuilderID *utils.TrustedBuilderID
7173
verifiedProvenanceAtt *SignedAttestation
7274
verifiedPublishAtt *SignedAttestation
7375
provenanceAttestation *attestation
@@ -93,8 +95,9 @@ func NpmNew(ctx context.Context, root *TrustedRoot, attestationBytes []byte) (*N
9395
return nil, err
9496
}
9597
return &Npm{
96-
ctx: ctx,
97-
root: root,
98+
ctx: ctx,
99+
root: root,
100+
98101
provenanceAttestation: prov,
99102
publishAttestation: pub,
100103
}, nil
@@ -251,7 +254,7 @@ func (n *Npm) verifyPackageName(name *string) error {
251254
}
252255

253256
// Verify subject name in provenance.
254-
if err := verifyProvenanceSubjectName(n.verifiedProvenanceAtt, *name); err != nil {
257+
if err := verifyProvenanceSubjectName(n.verifiedBuilderID, n.verifiedProvenanceAtt, *name); err != nil {
255258
return err
256259
}
257260

@@ -274,7 +277,7 @@ func (n *Npm) verifyPackageVersion(version *string) error {
274277
}
275278

276279
// Verify subject version in provenance.
277-
if err := verifyProvenanceSubjectVersion(n.verifiedProvenanceAtt, *version); err != nil {
280+
if err := verifyProvenanceSubjectVersion(n.verifiedBuilderID, n.verifiedProvenanceAtt, *version); err != nil {
278281
return err
279282
}
280283

@@ -291,6 +294,25 @@ func (n *Npm) verifyPackageVersion(version *string) error {
291294
return nil
292295
}
293296

297+
func (n *Npm) verifyBuilderID(
298+
provenanceOpts *options.ProvenanceOpts,
299+
builderOpts *options.BuilderOpts,
300+
defaultBuilders map[string]bool,
301+
) (*utils.TrustedBuilderID, error) {
302+
// Verify certificate information.
303+
builder, err := verifyNpmEnvAndCert(
304+
n.ProvenanceEnvelope(),
305+
n.ProvenanceLeafCertificate(),
306+
provenanceOpts, builderOpts,
307+
defaultBuilders,
308+
)
309+
if err != nil {
310+
return nil, err
311+
}
312+
n.verifiedBuilderID = builder
313+
return builder, err
314+
}
315+
294316
func verifyPublishPredicateVersion(att *SignedAttestation, expectedVersion string) error {
295317
_, version, err := getPublishPredicateData(att)
296318
if err != nil {
@@ -336,8 +358,8 @@ func getPublishPredicateData(att *SignedAttestation) (string, string, error) {
336358
return statement.Predicate.Name, statement.Predicate.Version, nil
337359
}
338360

339-
func verifyProvenanceSubjectVersion(att *SignedAttestation, expectedVersion string) error {
340-
subject, err := getSubject(att)
361+
func verifyProvenanceSubjectVersion(b *utils.TrustedBuilderID, att *SignedAttestation, expectedVersion string) error {
362+
subject, err := getSubject(b, att)
341363
if err != nil {
342364
return err
343365
}
@@ -378,15 +400,15 @@ func verifyPublishSubjectName(att *SignedAttestation, expectedName string) error
378400
return verifyName(name, expectedName)
379401
}
380402

381-
func verifyProvenanceSubjectName(att *SignedAttestation, expectedName string) error {
382-
prov, err := slsaprovenance.ProvenanceFromEnvelope(att.Envelope)
403+
func verifyProvenanceSubjectName(b *utils.TrustedBuilderID, att *SignedAttestation, expectedName string) error {
404+
prov, err := slsaprovenance.ProvenanceFromEnvelope(b.Name(), att.Envelope)
383405
if err != nil {
384-
return nil
406+
return fmt.Errorf("reading provenance: %w", err)
385407
}
386408

387409
subjects, err := prov.Subjects()
388410
if err != nil {
389-
return fmt.Errorf("%w", serrors.ErrorInvalidDssePayload)
411+
return fmt.Errorf("%w: %w", serrors.ErrorInvalidDssePayload, err)
390412
}
391413
if len(subjects) != 1 {
392414
return fmt.Errorf("%w: expected 1 subject, got %v", serrors.ErrorInvalidDssePayload, len(subjects))
@@ -443,8 +465,8 @@ func getPackageNameAndVersion(name string) (string, string, error) {
443465
return pkgname, pkgtag, nil
444466
}
445467

446-
func getSubject(att *SignedAttestation) (string, error) {
447-
prov, err := slsaprovenance.ProvenanceFromEnvelope(att.Envelope)
468+
func getSubject(b *utils.TrustedBuilderID, att *SignedAttestation) (string, error) {
469+
prov, err := slsaprovenance.ProvenanceFromEnvelope(b.Name(), att.Envelope)
448470
if err != nil {
449471
return "", err
450472
}

0 commit comments

Comments
 (0)