Skip to content

Commit 7bc2e49

Browse files
committed
POC adding bcr provenance gen to slsa-verifier
builder-is must be specified on the command line for the bazel builders release-workflow: https://github.com/bazel-contrib/.github/.github/workflows/release_ruleset.yaml publish-workflow: https://github.com/bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml Signed-off-by: Appu Goundan <[email protected]>
1 parent b53bd94 commit 7bc2e49

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

verifiers/internal/gha/slsaprovenance/common/builders.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ var (
2323
GenericDelegatorBuilderID = trustedBuilderRepository + "/.github/workflows/delegator_generic_slsa3.yml"
2424
// GenericLowPermsDelegatorBuilderID is the SLSA builder ID for the BYOB Generic Low-Permissions Delegated Builder.
2525
GenericLowPermsDelegatorBuilderID = trustedBuilderRepository + "/.github/workflows/delegator_lowperms-generic_slsa3.yml"
26+
27+
// BCRReleaseBuilderID is the bcr reusable workflow that generates provenance for a ruleset release.
28+
BCRReleaserBuilderID = "https://github.com/bazel-contrib/.github/.github/workflows/release_ruleset.yaml"
29+
// BCRPublisherBuilderID is the bcr reusable workflow that generates BCR repository metadata for a ruleset.
30+
BCRPublisherBuilderID = "https://github.com/bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml"
2631
)

verifiers/internal/gha/slsaprovenance/common/buildtypes.go

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var (
2424

2525
// NpmCLIGithubActionsBuildTypeV1 is the buildType for provenance by the npm cli from GitHub Actions.
2626
NpmCLIGithubActionsBuildTypeV1 = "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1"
27+
28+
GithubActionsBuildTypeV1 = "https://actions.github.io/buildtypes/workflow/v1"
2729
)
2830

2931
// Legacy buildTypes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package v1
2+
3+
import (
4+
"fmt"
5+
6+
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
7+
)
8+
9+
// GithubAttestBuildType is the build type for the github attest based builder
10+
var GithubAttestBuildType = "https://actions.github.io/buildtypes/workflow/v1"
11+
12+
// GithubAttestProvenance is provenance generated by an action using github's attest action
13+
type GithubAttestProvenance struct {
14+
*provenanceV1
15+
}
16+
17+
func (p *GithubAttestProvenance) TriggerURI() (string, error) {
18+
externalParams, err := p.getExternalParameters()
19+
if err != nil {
20+
return "", err
21+
}
22+
workflow, ok := externalParams["workflow"].(map[string]interface{})
23+
if !ok {
24+
return "", fmt.Errorf("%w: %s", serrors.ErrorInvalidFormat, "workflow parameters")
25+
}
26+
repository, ok := workflow["repository"].(string)
27+
if !ok {
28+
return "", fmt.Errorf("%w: %s", serrors.ErrorInvalidFormat, "workflow parameters: repository")
29+
}
30+
ref, ok := workflow["ref"].(string)
31+
if !ok {
32+
return "", fmt.Errorf("%w: %s", serrors.ErrorInvalidFormat, "workflow parameters: ref")
33+
}
34+
uri := fmt.Sprintf("git+%s@%s", repository, ref)
35+
return uri, nil
36+
}

verifiers/internal/gha/slsaprovenance/v1.0/provenance.go

+10
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,22 @@ func newNpmCLIGithubActions(a *Attestation) iface.Provenance {
5050
}
5151
}
5252

53+
func newGithubAttest(a *Attestation) iface.Provenance {
54+
return &GithubAttestProvenance{
55+
provenanceV1: &provenanceV1{
56+
prov: a,
57+
},
58+
}
59+
}
60+
5361
// buildTypeMap is a map of builder IDs to supported buildTypes.
5462
var buildTypeMap = map[string]map[string]provFunc{
5563
common.GenericDelegatorBuilderID: {common.BYOBBuildTypeV0: newBYOB},
5664
common.GenericLowPermsDelegatorBuilderID: {common.BYOBBuildTypeV0: newBYOB},
5765
common.ContainerBasedBuilderID: {common.ContainerBasedBuildTypeV01Draft: newContainerBased},
5866
common.NpmCLIHostedBuilderID: {common.NpmCLIGithubActionsBuildTypeV1: newNpmCLIGithubActions},
67+
common.BCRReleaserBuilderID: {common.GithubActionsBuildTypeV1: newGithubAttest},
68+
common.BCRPublisherBuilderID: {common.GithubActionsBuildTypeV1: newGithubAttest},
5969
}
6070

6171
// New returns a new Provenance object based on the payload.

0 commit comments

Comments
 (0)