Skip to content

Commit

Permalink
fix: Support npm v2 format (#704)
Browse files Browse the repository at this point in the history
closes #703

---------

Signed-off-by: laurentsimon <[email protected]>
  • Loading branch information
laurentsimon authored Sep 22, 2023
1 parent e2c7ca1 commit 54010d9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions verifiers/internal/gha/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ func Test_verifySourceURI(t *testing.T) {
expectedSourceURI: "https://github.com/some/repo",
err: serrors.ErrorInvalidDssePayload,
},
{
name: "match source no git no material ref (npm) v2 buildType",
provBuildType: common.NpmCLIBuildTypeV2,
provTriggerURI: "git+https://github.com/some/[email protected]",
provMaterialsURI: "git+https://github.com/some/repo",
expectedSourceURI: "https://github.com/some/repo",
// NOTE: Unlike for v1, we expect the URIs in material and trigger to match.
err: serrors.ErrorMalformedURI,
},
{
name: "mismatch source material ref (npm) v2 builtType",
provBuildType: common.NpmCLIBuildTypeV2,
provTriggerURI: "git+https://github.com/some/[email protected]",
provMaterialsURI: "git+https://github.com/some/[email protected]",
expectedSourceURI: "https://github.com/some/repo",
err: serrors.ErrorInvalidDssePayload,
},
{
name: "match source no git no material ref (byob)",
provBuildType: common.BYOBBuildTypeV0,
Expand Down
3 changes: 3 additions & 0 deletions verifiers/internal/gha/slsaprovenance/common/buildtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var (

// NpmCLIBuildTypeV1 is the buildType for provenance generated by the npm cli.
NpmCLIBuildTypeV1 = "https://github.com/npm/cli/gha@v1"

// NpmCLIBuildTypeV2 is the buildType for provenance generated by the npm cli.
NpmCLIBuildTypeV2 = "https://github.com/npm/cli/gha/v2"
)

// Legacy buildTypes.
Expand Down
11 changes: 9 additions & 2 deletions verifiers/internal/gha/slsaprovenance/v0.2/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ var buildTypeMap = map[string]map[string]provFunc{
common.GenericGeneratorBuilderID: {common.GenericGeneratorBuildTypeV1: newLegacyBuilderProvenance},
common.ContainerGeneratorBuilderID: {common.ContainerGeneratorBuildTypeV1: newLegacyBuilderProvenance},

common.NpmCLILegacyBuilderID: {common.NpmCLIBuildTypeV1: newLegacyBuilderProvenance},
common.NpmCLIHostedBuilderID: {common.NpmCLIBuildTypeV1: newLegacyBuilderProvenance},
common.NpmCLILegacyBuilderID: {
common.NpmCLIBuildTypeV1: newLegacyBuilderProvenance,
common.NpmCLIBuildTypeV2: newLegacyBuilderProvenance,
},

common.NpmCLIHostedBuilderID: {
common.NpmCLIBuildTypeV1: newLegacyBuilderProvenance,
common.NpmCLIBuildTypeV2: newLegacyBuilderProvenance,
},
// NOTE: we don't support Npm CLI on self-hosted.
}

Expand Down
2 changes: 0 additions & 2 deletions verifiers/internal/gha/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func verifyEnvAndCert(env *dsse.Envelope,
// There is a corner-case to handle: if the verified builder ID from the cert
// is a delegator builder, the user MUST provide an expected builder ID
// and we MUST match it against the content of the provenance.

if err := VerifyProvenance(env, provenanceOpts, verifiedBuilderID, byob, builderOpts.ExpectedID); err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -259,7 +258,6 @@ func (v *GHAVerifier) VerifyImage(ctx context.Context,
RekorPubKeys: trustedRoot.RekorPubKeys,
CTLogPubKeys: trustedRoot.CTPubKeys,
}

atts, _, err := container.RunCosignImageVerification(ctx,
artifactImage, opts)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion verifiers/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func VerifyImage(ctx context.Context, artifactImage string,
if err != nil {
return nil, nil, err
}

return verifier.VerifyImage(ctx, provenance, artifactImage, provenanceOpts, builderOpts)
}

Expand Down

0 comments on commit 54010d9

Please sign in to comment.