Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support npm v2 format #704

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/repo@v1.2.3",
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/repo@v1.2.3",
provMaterialsURI: "git+https://github.com/some/repo@v1.2.4",
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