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

feat: Verification for when sha1 is specified in BYOB TRW #641

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ec2e5f
Update buildTypes
ianlewis Jun 16, 2023
af33306
Update git ref checking
ianlewis Jun 16, 2023
77a0165
fix comment lint error
ianlewis Jun 18, 2023
1448434
Add tests to git utils
ianlewis Jun 18, 2023
dc1e6e3
add dot
ianlewis Jun 19, 2023
21ef45c
Get branch/tag from source URI
ianlewis Jun 19, 2023
a5ba959
Add byob provenance tests
ianlewis Jun 19, 2023
3c148a5
Add GetTag tests
ianlewis Jun 19, 2023
4759070
Update
ianlewis Jun 19, 2023
e3acd8f
Dedup code
ianlewis Jun 19, 2023
415db95
remove newline
ianlewis Jun 19, 2023
6ae0e82
Merge branch 'main' into 600-featurebyob-verification-for-sha1-provid…
ianlewis Jun 26, 2023
df1cf8c
Add test for New
ianlewis Jun 26, 2023
5512f19
Add test for resolvedDependency with no ref
ianlewis Jun 26, 2023
49086b4
Fix comment
ianlewis Jun 26, 2023
d6c9936
Remove old vars
ianlewis Jun 26, 2023
adb3f5b
Remove old vars
ianlewis Jun 26, 2023
2d53393
Verify buildType along with builder ID
ianlewis Jun 27, 2023
95f1328
Fix errors
ianlewis Jun 27, 2023
5041f82
fix builder ID
ianlewis Jun 27, 2023
f9ef890
Fix builderID
ianlewis Jun 27, 2023
61955a3
Merge branch 'main' into 600-featurebyob-verification-for-sha1-provid…
laurentsimon Jul 25, 2023
43fc1f9
Update provenance.go
laurentsimon Jul 25, 2023
c301c5e
Update provenance.go
laurentsimon Jul 25, 2023
6b6dbc2
Merge branch 'main' into 600-featurebyob-verification-for-sha1-provid…
laurentsimon Jul 25, 2023
59bf5c5
Don't fall back to previous source URI
ianlewis Jul 25, 2023
0c0ec92
Update tests
ianlewis Jul 25, 2023
59c7e97
Fix format
ianlewis Jul 25, 2023
c243903
Add tests
ianlewis Jul 25, 2023
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
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
ErrorMismatchPackageName = errors.New("package name does not match provenance")
ErrorMismatchBuilderID = errors.New("builderID does not match provenance")
ErrorInvalidBuilderID = errors.New("builderID is invalid")
ErrorInvalidBuildType = errors.New("buildType is invalid")
ErrorMismatchSource = errors.New("source used to generate the binary does not match provenance")
ErrorMismatchWorkflowInputs = errors.New("workflow input does not match")
ErrorMalformedURI = errors.New("URI is malformed")
Expand Down
14 changes: 8 additions & 6 deletions verifiers/internal/gha/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"strings"

fulcio "github.com/sigstore/fulcio/pkg/certificate"

serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
"github.com/slsa-framework/slsa-verifier/v2/options"
ghacommon "github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance/common"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils"
)

Expand All @@ -24,23 +26,23 @@
)

var defaultArtifactTrustedReusableWorkflows = map[string]bool{
trustedBuilderRepository + "/.github/workflows/generator_generic_slsa3.yml": true,
trustedBuilderRepository + "/.github/workflows/builder_go_slsa3.yml": true,
trustedBuilderRepository + "/.github/workflows/builder_container-based_slsa3.yml": true,
ghacommon.GenericGeneratorBuilderID: true,
ghacommon.GoBuilderID: true,
ghacommon.ContainerBasedBuilderID: true,
}

var defaultContainerTrustedReusableWorkflows = map[string]bool{
trustedBuilderRepository + "/.github/workflows/generator_container_slsa3.yml": true,
ghacommon.ContainerGeneratorBuilderID: true,
}

var (
delegatorGenericReusableWorkflow = trustedBuilderRepository + "/.github/workflows/delegator_generic_slsa3.yml"

Check failure on line 39 in verifiers/internal/gha/builder.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var `delegatorGenericReusableWorkflow` is unused (unused)
delegatorLowPermsGenericReusableWorkflow = trustedBuilderRepository + "/.github/workflows/delegator_lowperms-generic_slsa3.yml"
)

var defaultBYOBReusableWorkflows = map[string]bool{
delegatorGenericReusableWorkflow: true,
delegatorLowPermsGenericReusableWorkflow: true,
ghacommon.GenericDelegatorBuilderID: true,
ghacommon.GenericLowPermsDelegatorBuilderID: true,
}

// VerifyCertficateSourceRepository verifies the source repository.
Expand Down
53 changes: 35 additions & 18 deletions verifiers/internal/gha/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
intoto "github.com/in-toto/in-toto-golang/in_toto"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
serrors "github.com/slsa-framework/slsa-verifier/v2/errors"
"github.com/slsa-framework/slsa-verifier/v2/options"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/internal/gha/slsaprovenance/common"
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils"
Expand All @@ -25,13 +26,8 @@ type hosted string
const (
hostedSelf hosted = "self-hosted"
hostedGitHub hosted = "github-hosted"
)

const (
publishAttestationV01 = "https://github.com/npm/attestation/tree/main/specs/publish/"
builderLegacyGitHubRunnerID = "https://github.com/actions/runner"
builderGitHubHostedRunnerID = builderLegacyGitHubRunnerID + "/" + string(hostedGitHub)
builderSelfHostedRunnerID = builderLegacyGitHubRunnerID + "/" + string(hostedSelf)
publishAttestationV01 = "https://github.com/npm/attestation/tree/main/specs/publish/"
)

var errrorInvalidAttestations = errors.New("invalid npm attestations")
Expand Down Expand Up @@ -73,6 +69,7 @@ func (b *BundleBytes) UnmarshalJSON(data []byte) error {
type Npm struct {
ctx context.Context
root *TrustedRoot
verifiedBuilderID *utils.TrustedBuilderID
verifiedProvenanceAtt *SignedAttestation
verifiedPublishAtt *SignedAttestation
provenanceAttestation *attestation
Expand All @@ -98,8 +95,9 @@ func NpmNew(ctx context.Context, root *TrustedRoot, attestationBytes []byte) (*N
return nil, err
}
return &Npm{
ctx: ctx,
root: root,
ctx: ctx,
root: root,

provenanceAttestation: prov,
publishAttestation: pub,
}, nil
Expand Down Expand Up @@ -256,7 +254,7 @@ func (n *Npm) verifyPackageName(name *string) error {
}

// Verify subject name in provenance.
if err := verifyProvenanceSubjectName(n.verifiedProvenanceAtt, *name); err != nil {
if err := verifyProvenanceSubjectName(n.verifiedBuilderID, n.verifiedProvenanceAtt, *name); err != nil {
return err
}

Expand All @@ -279,7 +277,7 @@ func (n *Npm) verifyPackageVersion(version *string) error {
}

// Verify subject version in provenance.
if err := verifyProvenanceSubjectVersion(n.verifiedProvenanceAtt, *version); err != nil {
if err := verifyProvenanceSubjectVersion(n.verifiedBuilderID, n.verifiedProvenanceAtt, *version); err != nil {
return err
}

Expand All @@ -296,6 +294,25 @@ func (n *Npm) verifyPackageVersion(version *string) error {
return nil
}

func (n *Npm) verifyBuilderID(
provenanceOpts *options.ProvenanceOpts,
builderOpts *options.BuilderOpts,
defaultBuilders map[string]bool,
) (*utils.TrustedBuilderID, error) {
// Verify certificate information.
builder, err := verifyNpmEnvAndCert(
n.ProvenanceEnvelope(),
n.ProvenanceLeafCertificate(),
provenanceOpts, builderOpts,
defaultBuilders,
)
if err != nil {
return nil, err
}
n.verifiedBuilderID = builder
return builder, err
}

func verifyPublishPredicateVersion(att *SignedAttestation, expectedVersion string) error {
_, version, err := getPublishPredicateData(att)
if err != nil {
Expand Down Expand Up @@ -341,8 +358,8 @@ func getPublishPredicateData(att *SignedAttestation) (string, string, error) {
return statement.Predicate.Name, statement.Predicate.Version, nil
}

func verifyProvenanceSubjectVersion(att *SignedAttestation, expectedVersion string) error {
subject, err := getSubject(att)
func verifyProvenanceSubjectVersion(b *utils.TrustedBuilderID, att *SignedAttestation, expectedVersion string) error {
subject, err := getSubject(b, att)
if err != nil {
return err
}
Expand Down Expand Up @@ -383,15 +400,15 @@ func verifyPublishSubjectName(att *SignedAttestation, expectedName string) error
return verifyName(name, expectedName)
}

func verifyProvenanceSubjectName(att *SignedAttestation, expectedName string) error {
prov, err := slsaprovenance.ProvenanceFromEnvelope(att.Envelope)
func verifyProvenanceSubjectName(b *utils.TrustedBuilderID, att *SignedAttestation, expectedName string) error {
prov, err := slsaprovenance.ProvenanceFromEnvelope(b.Name(), att.Envelope)
if err != nil {
return nil
return fmt.Errorf("reading provenance: %w", err)
}

subjects, err := prov.Subjects()
if err != nil {
return fmt.Errorf("%w", serrors.ErrorInvalidDssePayload)
return fmt.Errorf("%w: %w", serrors.ErrorInvalidDssePayload, err)
}
if len(subjects) != 1 {
return fmt.Errorf("%w: expected 1 subject, got %v", serrors.ErrorInvalidDssePayload, len(subjects))
Expand Down Expand Up @@ -448,8 +465,8 @@ func getPackageNameAndVersion(name string) (string, string, error) {
return pkgname, pkgtag, nil
}

func getSubject(att *SignedAttestation) (string, error) {
prov, err := slsaprovenance.ProvenanceFromEnvelope(att.Envelope)
func getSubject(b *utils.TrustedBuilderID, att *SignedAttestation) (string, error) {
prov, err := slsaprovenance.ProvenanceFromEnvelope(b.Name(), att.Envelope)