Skip to content

Commit 8b6d4dd

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 8b6d4dd

File tree

4 files changed

+52
-0
lines changed

4 files changed

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

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)